From e6d6c60363b29ca3f5605cc3ee83135698fadea4 Mon Sep 17 00:00:00 2001 From: Jason Long Date: Mon, 16 Dec 2024 18:19:58 +0800 Subject: [PATCH] improve shouldShowPreview logic Change-Id: Iae1ab3f0888318d403821eeb15a4b48b2790fb54 GitOrigin-RevId: 591ce7e03ea4821635a8d15b9e67a0d3df0c73a2 --- .../components/insert-panel/InsertPanel.tsx | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/platform/wab/src/wab/client/components/insert-panel/InsertPanel.tsx b/platform/wab/src/wab/client/components/insert-panel/InsertPanel.tsx index bd9ba5d3ec5..45d417b1048 100644 --- a/platform/wab/src/wab/client/components/insert-panel/InsertPanel.tsx +++ b/platform/wab/src/wab/client/components/insert-panel/InsertPanel.tsx @@ -216,15 +216,29 @@ export const InsertPanel = observer(function InsertPanel_({ // export const InsertPanel = React.forwardRef(InsertPanel_); export default InsertPanel; +/** + * Returns true if the item should show a full height preview. + * Returns false if the item should show a short height row with an icon. + */ const shouldShowPreview = (group: AddItemGroup): boolean => { - // We should only show the preview image in AddDrawer under these conditions + if ( + group.sectionKey === "Code Libraries" || + group.familyKey === "imported-packages" + ) { + return false; + } + + // All items in the section are like this + if (group.items.every((i) => !!i.previewImageUrl || !!i.previewVideoUrl)) { + return true; + } + if (group.items.every((i) => !i.previewImageUrl && !i.previewVideoUrl)) { + return false; + } + return ( - group.sectionKey !== "Code Libraries" && - group.familyKey !== "imported-packages" && - (group.sectionKey === "insertable-templates" || - group.familyKey === "hostless-packages" || - // All items in the section are like this - group.items.every((i) => !!i.previewImageUrl || !!i.previewVideoUrl)) + group.sectionKey === "insertable-templates" || + group.familyKey === "hostless-packages" ); }; // Compact only works when we should preview