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)
This commit is contained in:
stacksmash76 2023-09-09 23:02:54 +02:00 committed by GitHub
parent 087471a1f7
commit 64f81a4614
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 6 deletions

View file

@ -46,6 +46,7 @@
"@typescript-eslint/parser": "^6.5.0", "@typescript-eslint/parser": "^6.5.0",
"@vitejs/plugin-react-swc": "^3.3.2", "@vitejs/plugin-react-swc": "^3.3.2",
"autoprefixer": "^10.4.15", "autoprefixer": "^10.4.15",
"buffer": "^6.0.3",
"date-fns": "^2.30.0", "date-fns": "^2.30.0",
"eslint": "^8.48.0", "eslint": "^8.48.0",
"eslint-plugin-import": "^2.28.1", "eslint-plugin-import": "^2.28.1",

18
web/pnpm-lock.yaml generated
View file

@ -59,6 +59,9 @@ dependencies:
autoprefixer: autoprefixer:
specifier: ^10.4.15 specifier: ^10.4.15
version: 10.4.15(postcss@8.4.29) version: 10.4.15(postcss@8.4.29)
buffer:
specifier: ^6.0.3
version: 6.0.3
date-fns: date-fns:
specifier: ^2.30.0 specifier: ^2.30.0
version: 2.30.0 version: 2.30.0
@ -2766,6 +2769,10 @@ packages:
resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==} resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==}
dev: false dev: false
/base64-js@1.5.1:
resolution: {integrity: sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==}
dev: false
/binary-extensions@2.2.0: /binary-extensions@2.2.0:
resolution: {integrity: sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==} resolution: {integrity: sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==}
engines: {node: '>=8'} engines: {node: '>=8'}
@ -2806,6 +2813,13 @@ packages:
resolution: {integrity: sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==} resolution: {integrity: sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==}
dev: false 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: /builtin-modules@3.3.0:
resolution: {integrity: sha512-zhaCDicdLuWN5UbN5IMnFqNMhNfo919sH85y2/ea+5Yg9TsTkeZxpL+JLbp6cgYFS4sRLp3YV4S6yDuqVWHYOw==} resolution: {integrity: sha512-zhaCDicdLuWN5UbN5IMnFqNMhNfo919sH85y2/ea+5Yg9TsTkeZxpL+JLbp6cgYFS4sRLp3YV4S6yDuqVWHYOw==}
engines: {node: '>=6'} engines: {node: '>=6'}
@ -3839,6 +3853,10 @@ packages:
resolution: {integrity: sha512-gchesWBzyvGHRO9W8tzUWFDycow5gwjvFKfyV9FF32Y7F50yZMp7mP+T2mJIWFx49zicqyC4uefHM17o6xKIVQ==} resolution: {integrity: sha512-gchesWBzyvGHRO9W8tzUWFDycow5gwjvFKfyV9FF32Y7F50yZMp7mP+T2mJIWFx49zicqyC4uefHM17o6xKIVQ==}
dev: false dev: false
/ieee754@1.2.1:
resolution: {integrity: sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==}
dev: false
/ignore@5.2.4: /ignore@5.2.4:
resolution: {integrity: sha512-MAb38BcSbH0eHNBxn7ql2NH/kX33OkB3lZ1BNdh7ENeRChHTYsTvWrMubiIAMNS2llXEEgZ1MUOBtXChP3kaFQ==} resolution: {integrity: sha512-MAb38BcSbH0eHNBxn7ql2NH/kX33OkB3lZ1BNdh7ENeRChHTYsTvWrMubiIAMNS2llXEEgZ1MUOBtXChP3kaFQ==}
engines: {node: '>= 4'} engines: {node: '>= 4'}

View file

@ -5,6 +5,7 @@
import { StrictMode } from "react"; import { StrictMode } from "react";
import { createRoot } from "react-dom/client"; import { createRoot } from "react-dom/client";
import { Buffer } from "buffer";
import "@fontsource-variable/inter"; import "@fontsource-variable/inter";
import "./index.css"; import "./index.css";
@ -18,6 +19,9 @@ declare global {
} }
window.APP = window.APP || {}; 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 // Initializes auth and theme contexts
InitializeGlobalContext(); InitializeGlobalContext();
@ -28,4 +32,4 @@ root.render(
<StrictMode> <StrictMode>
<App /> <App />
</StrictMode> </StrictMode>
); );

View file

@ -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; export type COL_WIDTHS = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
// simplify date // simplify date
export function simplifyDate(date: string) { export function simplifyDate(date?: string) {
if (date !== "0001-01-01T00:00:00Z") { if (typeof(date) === "string" && date !== "0001-01-01T00:00:00Z") {
return formatISO9075(new Date(date)); return formatISO9075(new Date(date));
} }
return "n/a"; return "n/a";
} }
// if empty date show as n/a // if empty date show as n/a
export function IsEmptyDate(date: string) { export function IsEmptyDate(date?: string) {
if (date !== "0001-01-01T00:00:00Z") { if (typeof(date) === "string" && date !== "0001-01-01T00:00:00Z") {
return formatDistanceToNowStrict( return formatDistanceToNowStrict(
new Date(date), new Date(date),
{ addSuffix: true } { addSuffix: true }
@ -82,4 +82,4 @@ export const get = <T> (obj: T, path: string|Array<any>, defValue?: string) => {
); );
// If found value is undefined return default value; otherwise return the value // If found value is undefined return default value; otherwise return the value
return result === undefined ? defValue : result; return result === undefined ? defValue : result;
}; };