From 8bbad08076e411de66651e07f55fdf30db5e6a8e Mon Sep 17 00:00:00 2001 From: Harsh Vador Date: Mon, 29 Dec 2025 12:51:55 +0530 Subject: [PATCH] code refactor --- .../ui/playwright/e2e/Pages/Lineage.spec.ts | 48 +++++++------- .../DataAssetSummaryPanelV1.tsx | 4 +- .../EntityRightPanelVerticalNav.constants.ts | 66 ++++++++++++------- .../EntityRightPanelVerticalNav.tsx | 12 ++-- 4 files changed, 75 insertions(+), 55 deletions(-) diff --git a/openmetadata-ui/src/main/resources/ui/playwright/e2e/Pages/Lineage.spec.ts b/openmetadata-ui/src/main/resources/ui/playwright/e2e/Pages/Lineage.spec.ts index 28a26a0a8b6..d6a08a92049 100644 --- a/openmetadata-ui/src/main/resources/ui/playwright/e2e/Pages/Lineage.spec.ts +++ b/openmetadata-ui/src/main/resources/ui/playwright/e2e/Pages/Lineage.spec.ts @@ -1665,16 +1665,14 @@ test.describe.serial('Test pagination in column level lineage', () => { // Wait for the lineage entity panel (sidebar drawer) to open const lineagePanel = page.getByTestId('lineage-entity-panel'); - await expect(lineagePanel).toBeVisible({ timeout: 10000 }); + await expect(lineagePanel).toBeVisible(); // Wait for the panel content to load await waitForAllLoadersToDisappear(page); // Try to find custom properties tab in the lineage sidebar - use data-testid first (priority 1) let customPropertiesTab = lineagePanel.getByTestId('custom-properties-tab'); - const isTabVisible = await customPropertiesTab - .isVisible({ timeout: 2000 }) - .catch(() => false); + const isTabVisible = await customPropertiesTab.isVisible(); if (!isTabVisible) { // Fallback: use getByRole (priority 2) within the lineage panel @@ -1684,9 +1682,7 @@ test.describe.serial('Test pagination in column level lineage', () => { } // Verify the custom properties tab is visible in the lineage sidebar - await expect(customPropertiesTab).toBeVisible({ - timeout: 10000, - }); + await expect(customPropertiesTab).toBeVisible(); // Verify the tab is clickable await expect(customPropertiesTab).toBeEnabled(); @@ -1695,8 +1691,6 @@ test.describe.serial('Test pagination in column level lineage', () => { await customPropertiesTab.click(); await waitForAllLoadersToDisappear(page); }); - - } finally { await Promise.all([ currentTable.delete(apiContext), @@ -1825,13 +1819,15 @@ test.describe.serial('Test pagination in column level lineage', () => { await sidebarClick(page, SidebarItem.LINEAGE); - await page.waitForSelector('[data-testid="search-entity-select"]'); - await page.click('[data-testid="search-entity-select"]'); + const searchEntitySelect = page.getByTestId('search-entity-select'); + await expect(searchEntitySelect).toBeVisible(); + await searchEntitySelect.click(); - await page.fill( - '[data-testid="search-entity-select"] .ant-select-selection-search-input', - service.entity.name - ); + // Use getByTestId for the input field if available, otherwise fallback to locator + const searchInput = page + .getByTestId('search-entity-select') + .locator('.ant-select-selection-search-input'); + await searchInput.fill(service.entity.name); await page.waitForRequest( (req) => @@ -1839,19 +1835,25 @@ test.describe.serial('Test pagination in column level lineage', () => { req.url().includes('deleted=false') ); - await page.waitForSelector('.ant-select-dropdown'); + // Wait for dropdown to appear using data-testid if available, otherwise use visible state + const dropdown = page.locator('.ant-select-dropdown'); + await expect(dropdown).toBeVisible(); - await page.waitForSelector( - `[data-testid="node-suggestion-${serviceFqn}"]` + const nodeSuggestion = page.getByTestId( + `node-suggestion-${serviceFqn}` ); - await page - .locator(`[data-testid="node-suggestion-${serviceFqn}"]`) - .dispatchEvent('click'); + await expect(nodeSuggestion).toBeVisible(); + await nodeSuggestion.click(); - await page.waitForResponse('/api/v1/lineage/getLineage?*'); + // Wait for specific lineage API response + await page.waitForResponse( + (response) => + response.url().includes('/api/v1/lineage/getLineage') && + response.status() === 200 + ); await expect( - page.locator(`[data-testid="lineage-node-${serviceFqn}"]`) + page.getByTestId(`lineage-node-${serviceFqn}`) ).toBeVisible(); await clickLineageNode(page, serviceFqn); diff --git a/openmetadata-ui/src/main/resources/ui/src/components/DataAssetSummaryPanelV1/DataAssetSummaryPanelV1.tsx b/openmetadata-ui/src/main/resources/ui/src/components/DataAssetSummaryPanelV1/DataAssetSummaryPanelV1.tsx index 0603349b28a..d631d6e3642 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/DataAssetSummaryPanelV1/DataAssetSummaryPanelV1.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/DataAssetSummaryPanelV1/DataAssetSummaryPanelV1.tsx @@ -61,7 +61,7 @@ import { DataAssetSummaryPanelProps, TestCaseStatusCounts, } from '../DataAssetSummaryPanelV1/DataAssetSummaryPanelV1.interface'; -import { ENTITY_RIGHT_PANEL_LINEAGE_TABS } from '../Entity/EntityRightPanel/EntityRightPanelVerticalNav.constants'; +import { hasLineageTab } from '../Entity/EntityRightPanel/EntityRightPanelVerticalNav.constants'; export const DataAssetSummaryPanelV1 = ({ dataAsset, @@ -168,7 +168,7 @@ export const DataAssetSummaryPanelV1 = ({ }, [dataAsset, entityType, highlights, charts, chartsDetailsLoading]); const shouldShowLineageSection = useMemo( - () => ENTITY_RIGHT_PANEL_LINEAGE_TABS.includes(entityType), + () => hasLineageTab(entityType), [entityType] ); diff --git a/openmetadata-ui/src/main/resources/ui/src/components/Entity/EntityRightPanel/EntityRightPanelVerticalNav.constants.ts b/openmetadata-ui/src/main/resources/ui/src/components/Entity/EntityRightPanel/EntityRightPanelVerticalNav.constants.ts index 0a1744551c1..0f6a5b42653 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/Entity/EntityRightPanel/EntityRightPanelVerticalNav.constants.ts +++ b/openmetadata-ui/src/main/resources/ui/src/components/Entity/EntityRightPanel/EntityRightPanelVerticalNav.constants.ts @@ -12,35 +12,36 @@ */ import { EntityType } from '../../../enums/entity.enum'; -export const ENTITY_RIGHT_PANEL_SCHEMA_TABS = [ - EntityType.TABLE, - EntityType.TOPIC, - EntityType.DASHBOARD, - EntityType.DATABASE_SCHEMA, - EntityType.DATABASE, - EntityType.PIPELINE, +// Internal Sets for O(1) lookup performance +const SCHEMA_TABS_SET = new Set([ EntityType.API_COLLECTION, - EntityType.SEARCH_INDEX, - EntityType.DASHBOARD_DATA_MODEL, EntityType.API_ENDPOINT, EntityType.CONTAINER, -]; - -export const ENTITY_RIGHT_PANEL_LINEAGE_TABS = [ - EntityType.TABLE, - EntityType.TOPIC, - EntityType.CONTAINER, EntityType.DASHBOARD, - EntityType.CHART, - EntityType.PIPELINE, - EntityType.MLMODEL, - EntityType.SEARCH_INDEX, EntityType.DASHBOARD_DATA_MODEL, - EntityType.API_ENDPOINT, - EntityType.DIRECTORY, -]; + EntityType.DATABASE, + EntityType.DATABASE_SCHEMA, + EntityType.PIPELINE, + EntityType.SEARCH_INDEX, + EntityType.TABLE, + EntityType.TOPIC, +]); -export const ENTITY_RIGHT_PANEL_CUSTOM_PROPERTIES_TABS = [ +const LINEAGE_TABS_SET = new Set([ + EntityType.API_ENDPOINT, + EntityType.CHART, + EntityType.CONTAINER, + EntityType.DASHBOARD, + EntityType.DASHBOARD_DATA_MODEL, + EntityType.DIRECTORY, + EntityType.MLMODEL, + EntityType.PIPELINE, + EntityType.SEARCH_INDEX, + EntityType.TABLE, + EntityType.TOPIC, +]); + +const CUSTOM_PROPERTIES_TABS_SET = new Set([ EntityType.API_COLLECTION, EntityType.API_ENDPOINT, EntityType.CHART, @@ -63,4 +64,21 @@ export const ENTITY_RIGHT_PANEL_CUSTOM_PROPERTIES_TABS = [ EntityType.TABLE, EntityType.TOPIC, EntityType.WORKSHEET, -]; +]); + +// Exported arrays for backward compatibility +export const ENTITY_RIGHT_PANEL_SCHEMA_TABS = Array.from(SCHEMA_TABS_SET); +export const ENTITY_RIGHT_PANEL_LINEAGE_TABS = Array.from(LINEAGE_TABS_SET); +export const ENTITY_RIGHT_PANEL_CUSTOM_PROPERTIES_TABS = Array.from( + CUSTOM_PROPERTIES_TABS_SET +); + +// Helper functions for cleaner and more performant usage +export const hasSchemaTab = (entityType: EntityType): boolean => + SCHEMA_TABS_SET.has(entityType); + +export const hasLineageTab = (entityType: EntityType): boolean => + LINEAGE_TABS_SET.has(entityType); + +export const hasCustomPropertiesTab = (entityType: EntityType): boolean => + CUSTOM_PROPERTIES_TABS_SET.has(entityType); diff --git a/openmetadata-ui/src/main/resources/ui/src/components/Entity/EntityRightPanel/EntityRightPanelVerticalNav.tsx b/openmetadata-ui/src/main/resources/ui/src/components/Entity/EntityRightPanel/EntityRightPanelVerticalNav.tsx index 59e2f1eb8c3..a36b6951697 100644 --- a/openmetadata-ui/src/main/resources/ui/src/components/Entity/EntityRightPanel/EntityRightPanelVerticalNav.tsx +++ b/openmetadata-ui/src/main/resources/ui/src/components/Entity/EntityRightPanel/EntityRightPanelVerticalNav.tsx @@ -21,9 +21,9 @@ import { ReactComponent as SchemaIcon } from '../../../assets/svg/explore-vertic import { ReactComponent as DataQualityIcon } from '../../../assets/svg/ic-data-contract.svg'; import { EntityType } from '../../../enums/entity.enum'; import { - ENTITY_RIGHT_PANEL_CUSTOM_PROPERTIES_TABS, - ENTITY_RIGHT_PANEL_LINEAGE_TABS, - ENTITY_RIGHT_PANEL_SCHEMA_TABS, + hasCustomPropertiesTab, + hasLineageTab, + hasSchemaTab, } from './EntityRightPanelVerticalNav.constants'; import { EntityRightPanelTab, @@ -46,7 +46,7 @@ const EntityRightPanelVerticalNav: React.FC = ]; // Add schema tab for entities that have schema - if (ENTITY_RIGHT_PANEL_SCHEMA_TABS.includes(entityType)) { + if (hasSchemaTab(entityType)) { items.push({ key: EntityRightPanelTab.SCHEMA, icon: , @@ -55,7 +55,7 @@ const EntityRightPanelVerticalNav: React.FC = }); } // Add lineage tab for most entities - if (ENTITY_RIGHT_PANEL_LINEAGE_TABS.includes(entityType)) { + if (hasLineageTab(entityType)) { items.push({ key: EntityRightPanelTab.LINEAGE, icon: , @@ -75,7 +75,7 @@ const EntityRightPanelVerticalNav: React.FC = } // Add custom properties tab - if (ENTITY_RIGHT_PANEL_CUSTOM_PROPERTIES_TABS.includes(entityType)) { + if (hasCustomPropertiesTab(entityType)) { items.push({ key: EntityRightPanelTab.CUSTOM_PROPERTIES, icon: ,