From 64f81a461400c3d48c890e587893d45a7f0eb9b0 Mon Sep 17 00:00:00 2001 From: stacksmash76 <98354295+stacksmash76@users.noreply.github.com> Date: Sat, 9 Sep 2023 23:02:54 +0200 Subject: [PATCH] enhancement(web): improve functionality of utility components (#1094) added missing Buffer definition for Stacktracey, made date functions more robust against undefined values enhancement: made simplifyDate and IsEmptyDate prone against undefined values fix: added a global Buffer definition (apparently required by Stacktracey) --- web/package.json | 1 + web/pnpm-lock.yaml | 18 ++++++++++++++++++ web/src/index.tsx | 6 +++++- web/src/utils/index.ts | 10 +++++----- 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/web/package.json b/web/package.json index c819895..32e54ec 100644 --- a/web/package.json +++ b/web/package.json @@ -46,6 +46,7 @@ "@typescript-eslint/parser": "^6.5.0", "@vitejs/plugin-react-swc": "^3.3.2", "autoprefixer": "^10.4.15", + "buffer": "^6.0.3", "date-fns": "^2.30.0", "eslint": "^8.48.0", "eslint-plugin-import": "^2.28.1", diff --git a/web/pnpm-lock.yaml b/web/pnpm-lock.yaml index 7af9160..cdf93c6 100644 --- a/web/pnpm-lock.yaml +++ b/web/pnpm-lock.yaml @@ -59,6 +59,9 @@ dependencies: autoprefixer: specifier: ^10.4.15 version: 10.4.15(postcss@8.4.29) + buffer: + specifier: ^6.0.3 + version: 6.0.3 date-fns: specifier: ^2.30.0 version: 2.30.0 @@ -2766,6 +2769,10 @@ packages: resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==} dev: false + /base64-js@1.5.1: + resolution: {integrity: sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==} + dev: false + /binary-extensions@2.2.0: resolution: {integrity: sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==} engines: {node: '>=8'} @@ -2806,6 +2813,13 @@ packages: resolution: {integrity: sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==} dev: false + /buffer@6.0.3: + resolution: {integrity: sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==} + dependencies: + base64-js: 1.5.1 + ieee754: 1.2.1 + dev: false + /builtin-modules@3.3.0: resolution: {integrity: sha512-zhaCDicdLuWN5UbN5IMnFqNMhNfo919sH85y2/ea+5Yg9TsTkeZxpL+JLbp6cgYFS4sRLp3YV4S6yDuqVWHYOw==} engines: {node: '>=6'} @@ -3839,6 +3853,10 @@ packages: resolution: {integrity: sha512-gchesWBzyvGHRO9W8tzUWFDycow5gwjvFKfyV9FF32Y7F50yZMp7mP+T2mJIWFx49zicqyC4uefHM17o6xKIVQ==} dev: false + /ieee754@1.2.1: + resolution: {integrity: sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==} + dev: false + /ignore@5.2.4: resolution: {integrity: sha512-MAb38BcSbH0eHNBxn7ql2NH/kX33OkB3lZ1BNdh7ENeRChHTYsTvWrMubiIAMNS2llXEEgZ1MUOBtXChP3kaFQ==} engines: {node: '>= 4'} diff --git a/web/src/index.tsx b/web/src/index.tsx index 84c6a11..ad12b61 100644 --- a/web/src/index.tsx +++ b/web/src/index.tsx @@ -5,6 +5,7 @@ import { StrictMode } from "react"; import { createRoot } from "react-dom/client"; +import { Buffer } from "buffer"; import "@fontsource-variable/inter"; import "./index.css"; @@ -18,6 +19,9 @@ declare global { } window.APP = window.APP || {}; +// Apparently Stacktracey requires this for some weird reason +// (at least in local dev env) +window.Buffer = Buffer; // Initializes auth and theme contexts InitializeGlobalContext(); @@ -28,4 +32,4 @@ root.render( -); \ No newline at end of file +); diff --git a/web/src/utils/index.ts b/web/src/utils/index.ts index b93f922..a9c1ddb 100644 --- a/web/src/utils/index.ts +++ b/web/src/utils/index.ts @@ -39,16 +39,16 @@ export function classNames(...classes: string[]) { export type COL_WIDTHS = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12; // simplify date -export function simplifyDate(date: string) { - if (date !== "0001-01-01T00:00:00Z") { +export function simplifyDate(date?: string) { + if (typeof(date) === "string" && date !== "0001-01-01T00:00:00Z") { return formatISO9075(new Date(date)); } return "n/a"; } // if empty date show as n/a -export function IsEmptyDate(date: string) { - if (date !== "0001-01-01T00:00:00Z") { +export function IsEmptyDate(date?: string) { + if (typeof(date) === "string" && date !== "0001-01-01T00:00:00Z") { return formatDistanceToNowStrict( new Date(date), { addSuffix: true } @@ -82,4 +82,4 @@ export const get = (obj: T, path: string|Array, defValue?: string) => { ); // If found value is undefined return default value; otherwise return the value return result === undefined ? defValue : result; -}; \ No newline at end of file +};