From 8ae4fc83a5fb053499a807263c62214ff0eafe19 Mon Sep 17 00:00:00 2001 From: Ashish Gupta Date: Wed, 24 Jul 2024 15:25:36 +0530 Subject: [PATCH] #17021: fix the widget placement when adding new (#17151) * fix the widget placement when adding new * change the placement logic and fix the added widget check in add model if removed * minor fix --- .../AddWidgetModal/AddWidgetModal.test.tsx | 18 ++++++ .../AddWidgetModal/AddWidgetModal.tsx | 6 +- .../ui/src/mocks/CustomizablePage.mock.ts | 57 +++++++++++++++++++ .../CustomizableLandingPageUtils.test.tsx | 31 ++++++++++ .../utils/CustomizableLandingPageUtils.tsx | 8 ++- 5 files changed, 116 insertions(+), 4 deletions(-) create mode 100644 openmetadata-ui/src/main/resources/ui/src/utils/CustomizableLandingPageUtils.test.tsx diff --git a/openmetadata-ui/src/main/resources/ui/src/components/MyData/CustomizableComponents/AddWidgetModal/AddWidgetModal.test.tsx b/openmetadata-ui/src/main/resources/ui/src/components/MyData/CustomizableComponents/AddWidgetModal/AddWidgetModal.test.tsx index 8b67fa28cb5..9e4b1d7955b 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/MyData/CustomizableComponents/AddWidgetModal/AddWidgetModal.test.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/MyData/CustomizableComponents/AddWidgetModal/AddWidgetModal.test.tsx @@ -113,6 +113,24 @@ describe('AddWidgetModal component', () => { expect(screen.queryByTestId('TotalAssets-check-icon')).toBeNull(); }); + it('AddWidgetModal should not display check icons in the tab labels only if widget includes EmptyWidgetPlaceholder with it', async () => { + await act(async () => { + render( + + ); + }); + + expect(screen.getByTestId('ActivityFeed-check-icon')).toBeInTheDocument(); + expect(screen.queryByTestId('Following-check-icon')).toBeNull(); + expect(screen.queryByTestId('KPI-check-icon')).toBeNull(); + }); + it('AddWidgetModal should call handleAddWidget when clicked on add widget button', async () => { await act(async () => { render(); diff --git a/openmetadata-ui/src/main/resources/ui/src/components/MyData/CustomizableComponents/AddWidgetModal/AddWidgetModal.tsx b/openmetadata-ui/src/main/resources/ui/src/components/MyData/CustomizableComponents/AddWidgetModal/AddWidgetModal.tsx index 0348b721be9..5ed1388822d 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/MyData/CustomizableComponents/AddWidgetModal/AddWidgetModal.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/MyData/CustomizableComponents/AddWidgetModal/AddWidgetModal.tsx @@ -83,8 +83,10 @@ function AddWidgetModal({ label: ( {widget.name} - {addedWidgetsList.some((w) => - w.startsWith(widget.fullyQualifiedName) + {addedWidgetsList.some( + (w) => + w.startsWith(widget.fullyQualifiedName) && + !w.includes('EmptyWidgetPlaceholder') ) && ( { + it('should add new widget at EmptyWidgetPlaceholder place to be in the bottom', () => { + const result = getAddWidgetHandler( + mockWidget, + 'ExtraWidget.EmptyWidgetPlaceholder', + 1, + 3 + )(mockCurrentAddWidget); + + expect(result).toEqual(mockAddWidgetReturnValues); + }); +}); diff --git a/openmetadata-ui/src/main/resources/ui/src/utils/CustomizableLandingPageUtils.tsx b/openmetadata-ui/src/main/resources/ui/src/utils/CustomizableLandingPageUtils.tsx index 2770e43ea00..28f0884e98a 100644 --- a/openmetadata-ui/src/main/resources/ui/src/utils/CustomizableLandingPageUtils.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/utils/CustomizableLandingPageUtils.tsx @@ -55,13 +55,17 @@ export const getAddWidgetHandler = if ( placeholderWidgetKey === LandingPageWidgetKeys.EMPTY_WIDGET_PLACEHOLDER ) { + const emptyWidgetPlaceholder = currentLayout.find( + (item) => item.i === LandingPageWidgetKeys.EMPTY_WIDGET_PLACEHOLDER + ) ?? { x: 0, y: 99 }; + return [ ...moveEmptyWidgetToTheEnd(currentLayout), { w: widgetWidth, h: widgetHeight, - x: 0, - y: 0, + x: emptyWidgetPlaceholder.x, + y: emptyWidgetPlaceholder.y, i: widgetFQN, static: false, },