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

@ -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(
<StrictMode>
<App />
</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;
// 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 = <T> (obj: T, path: string|Array<any>, defValue?: string) => {
);
// If found value is undefined return default value; otherwise return the value
return result === undefined ? defValue : result;
};
};