From d6a1fedf51674ce685185e648c16b4a444b6b054 Mon Sep 17 00:00:00 2001 From: "Jason M. Hasperhoven" Date: Wed, 27 Nov 2024 19:48:14 +0400 Subject: [PATCH 1/3] Truncate unexpected error messages --- packages/ui/src/Toast/open.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/ui/src/Toast/open.ts b/packages/ui/src/Toast/open.ts index 2de1cd6a2..cc97cb4d4 100644 --- a/packages/ui/src/Toast/open.ts +++ b/packages/ui/src/Toast/open.ts @@ -27,6 +27,10 @@ export interface Toast { dismiss: VoidFunction; } +function truncateString(str: string, maxLength: number): string { + return str.length > maxLength ? `${str.slice(0, maxLength)}...` : str; +} + /** * If `` exists in the document, opens a toast with provided type and options. * By default, the toast is dismissible and has a duration of 4000 milliseconds. It can @@ -69,10 +73,14 @@ export const openToast = (props: ToastProps): Toast => { const open = () => { const fn = toastFnMap[options.type]; + console.log('TCL: open -> options', options); id = fn(options.message, { id, - description: options.description, + description: + typeof options.description === 'string' + ? truncateString(options.description, 200) + : options.description, closeButton: options.dismissible ?? true, dismissible: options.dismissible ?? true, duration: options.persistent ? Infinity : 4000, From 2032fc99c7d7e069c0bb1a31cb4484d2b987f8a9 Mon Sep 17 00:00:00 2001 From: "Jason M. Hasperhoven" Date: Wed, 27 Nov 2024 19:48:42 +0400 Subject: [PATCH 2/3] Remove console --- packages/ui/src/Toast/open.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/ui/src/Toast/open.ts b/packages/ui/src/Toast/open.ts index cc97cb4d4..36c8e1cde 100644 --- a/packages/ui/src/Toast/open.ts +++ b/packages/ui/src/Toast/open.ts @@ -73,7 +73,6 @@ export const openToast = (props: ToastProps): Toast => { const open = () => { const fn = toastFnMap[options.type]; - console.log('TCL: open -> options', options); id = fn(options.message, { id, From 8d779c7761571472cd545ebf74a80440bbb1fe9c Mon Sep 17 00:00:00 2001 From: "Jason M. Hasperhoven" Date: Wed, 27 Nov 2024 19:50:02 +0400 Subject: [PATCH 3/3] Add changeset --- .changeset/gorgeous-emus-shave.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/gorgeous-emus-shave.md diff --git a/.changeset/gorgeous-emus-shave.md b/.changeset/gorgeous-emus-shave.md new file mode 100644 index 000000000..43ba28812 --- /dev/null +++ b/.changeset/gorgeous-emus-shave.md @@ -0,0 +1,5 @@ +--- +'@penumbra-zone/ui': patch +--- + +Truncate Toast description