Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
import { Page, Tab } from '../../../generated/system/ui/page';
import { PageType } from '../../../generated/system/ui/uiCustomization';
import { useGridLayoutDirection } from '../../../hooks/useGridLayoutDirection';
import {

Check warning on line 30 in openmetadata-ui/src/main/resources/ui/src/components/Customization/CustomizeTabWidget/CustomizeTabWidget.tsx

View workflow job for this annotation

GitHub Actions / checkstyle

Pages are route-level composition modules. Move the shared implementation/type to a lower layer instead of importing a page from here
WidgetCommonProps,
WidgetConfig,
} from '../../../pages/CustomizablePage/CustomizablePage.interface';
import { useCustomizeStore } from '../../../pages/CustomizablePage/CustomizeStore';

Check warning on line 34 in openmetadata-ui/src/main/resources/ui/src/components/Customization/CustomizeTabWidget/CustomizeTabWidget.tsx

View workflow job for this annotation

GitHub Actions / checkstyle

Pages are route-level composition modules. Move the shared implementation/type to a lower layer instead of importing a page from here
import {
getLayoutWithEmptyWidgetPlaceholder,
getUniqueFilteredLayout,
Expand All @@ -42,7 +42,10 @@
getDefaultWidgetForTab,
} from '../../../utils/CustomizePage/CustomizePageDispatchUtils';
import { getTabDisplayName } from '../../../utils/CustomizePage/CustomizePageEntityTabUtils';
import { getAddWidgetHandler } from '../../../utils/CustomizePage/CustomizePageWidgetUtils';
import {
getAddWidgetHandler,
mergeGridLayout,
} from '../../../utils/CustomizePage/CustomizePageWidgetUtils';
import { getEntityName } from '../../../utils/EntityNameUtils';
import withSuspenseFallback from '../../AppRouter/withSuspenseFallback';
import { TabItem } from '../../common/DraggableTabs/DraggableTabs';
Expand Down Expand Up @@ -124,7 +127,7 @@
return hasEmptyWidgetPlaceholder
? layout
: getLayoutWithEmptyWidgetPlaceholder(layout, 2, 3);
}, [items, activeKey]);

Check warning on line 130 in openmetadata-ui/src/main/resources/ui/src/components/Customization/CustomizeTabWidget/CustomizeTabWidget.tsx

View workflow job for this annotation

GitHub Actions / checkstyle

React Hook useMemo has a missing dependency: 'currentPageType'. Either include it or remove the dependency array

const [isWidgetModalOpen, setIsWidgetModalOpen] = useState<boolean>(false);
const [placeholderWidgetKey, setPlaceholderWidgetKey] = useState<string>('');
Expand Down Expand Up @@ -234,7 +237,10 @@
layout.i.startsWith(DetailPageWidgetKeys.LEFT_PANEL)
);
if (sidePanelLayout) {
sidePanelLayout.children = updatedLayout;
sidePanelLayout.children = mergeGridLayout(
updatedLayout,
sidePanelLayout.children
);
}

updateCurrentPage({
Expand All @@ -245,7 +251,7 @@
} as Page);
}
},
[tabLayouts]

Check warning on line 254 in openmetadata-ui/src/main/resources/ui/src/components/Customization/CustomizeTabWidget/CustomizeTabWidget.tsx

View workflow job for this annotation

GitHub Actions / checkstyle

React Hook useCallback has missing dependencies: 'activeKey', 'currentPage', 'items', and 'updateCurrentPage'. Either include them or remove the dependency array
);

const leftPanelWidget = useMemo(() => {
Expand Down Expand Up @@ -310,7 +316,7 @@
const widgets = useMemo(
// Re-render upon leftPanelWidget change
() => getWidgetFromLayout(tabLayouts),
[tabLayouts, leftPanelWidget]

Check warning on line 319 in openmetadata-ui/src/main/resources/ui/src/components/Customization/CustomizeTabWidget/CustomizeTabWidget.tsx

View workflow job for this annotation

GitHub Actions / checkstyle

React Hook useMemo has a missing dependency: 'getWidgetFromLayout'. Either include it or remove the dependency array
);

/**
Expand All @@ -326,22 +332,17 @@
item.id === activeKey
? {
...item,
layout: getUniqueFilteredLayout(updatedLayout).map(
(widget) => ({
...widget,
...(widget.i === DetailPageWidgetKeys.LEFT_PANEL
? // left panel widget will be updated separately
{ children: leftPanelWidget?.children }
: {}),
})
layout: mergeGridLayout(
getUniqueFilteredLayout(updatedLayout),
tabLayouts
),
}
: item
),
} as Page);
}
},
[tabLayouts, leftPanelWidget]
[tabLayouts]

Check warning on line 345 in openmetadata-ui/src/main/resources/ui/src/components/Customization/CustomizeTabWidget/CustomizeTabWidget.tsx

View workflow job for this annotation

GitHub Actions / checkstyle

React Hook useCallback has missing dependencies: 'activeKey', 'currentPage', 'items', and 'updateCurrentPage'. Either include them or remove the dependency array
);

const handleMainPanelAddWidget = useCallback(
Expand All @@ -366,7 +367,7 @@

setIsWidgetModalOpen(false);
},
[tabLayouts]

Check warning on line 370 in openmetadata-ui/src/main/resources/ui/src/components/Customization/CustomizeTabWidget/CustomizeTabWidget.tsx

View workflow job for this annotation

GitHub Actions / checkstyle

React Hook useCallback has missing dependencies: 'activeKey', 'currentPage', 'currentPageType', 'items', and 'updateCurrentPage'. Either include them or remove the dependency array
);

// call the hook to set the direction of the grid layout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/

import { act, render, screen } from '@testing-library/react';
import { WidgetConfig } from '../../../pages/CustomizablePage/CustomizablePage.interface';

Check warning on line 15 in openmetadata-ui/src/main/resources/ui/src/components/Customization/GenericTab/DynamicHeightWidget.test.tsx

View workflow job for this annotation

GitHub Actions / checkstyle

Pages are route-level composition modules. Move the shared implementation/type to a lower layer instead of importing a page from here
import { DynamicHeightWidget } from './DynamicHeightWidget';

// Mock ResizeObserver
Expand Down Expand Up @@ -189,6 +189,22 @@
expect(mockOnHeightChange).toHaveBeenCalledWith('test-widget', 16 / 116);
});

it('does not report height when the widget is not rendered (0x0 rect)', () => {
render(
<DynamicHeightWidget
widget={mockWidget}
onHeightChange={mockOnHeightChange}>
<div>Test Content</div>
</DynamicHeightWidget>
);

const resizeCallback = (global.ResizeObserver as jest.Mock).mock
.calls[0][0];
resizeCallback([{ contentRect: { width: 0, height: 0 } }]);

expect(mockOnHeightChange).not.toHaveBeenCalled();
});

it('handles very large height values', () => {
render(
<DynamicHeightWidget
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
GRID_ROW_HEIGHT,
GRID_VERTICAL_MARGIN,
} from '../../../constants/CustomizeWidgets.constants';
import { WidgetConfig } from '../../../pages/CustomizablePage/CustomizablePage.interface';

Check warning on line 18 in openmetadata-ui/src/main/resources/ui/src/components/Customization/GenericTab/DynamicHeightWidget.tsx

View workflow job for this annotation

GitHub Actions / checkstyle

Pages are route-level composition modules. Move the shared implementation/type to a lower layer instead of importing a page from here
import './generic-tab.less';

interface DynamicHeightWidgetProps {
Expand All @@ -41,6 +41,13 @@
useEffect(() => {
const resizeObserver = new ResizeObserver((entries) => {
for (const entry of entries) {
// A 0x0 rect means the widget is not rendered (e.g. an inactive tab pane
// under display:none that still reads the shared layout). Its height is
// unknown, not zero — reporting it collapses the visible pane's widget
// and ping-pongs with the visible observer.
if (entry.contentRect.width === 0 && entry.contentRect.height === 0) {
continue;
}
const newHeight =
(entry.contentRect.height + GRID_VERTICAL_MARGIN) /
(GRID_ROW_HEIGHT + GRID_VERTICAL_MARGIN);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
/*
* Copyright 2025 Collate.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { act, render, renderHook, screen } from '@testing-library/react';
import { EntityType } from '../../../enums/entity.enum';
import {
LabelType,
State,
TagSource,
type TagLabel,
} from '../../../generated/type/tagLabel';
import { useGenericContext } from '../../Customization/GenericProvider/GenericContext';
import {
useTagsUpdateHandler,
useTierSplit,
useUpdatedEntityData,
} from './CommonWidgets.hooks';
import { GenericEntity } from './CommonWidgets.types';

jest.mock('../../Customization/GenericProvider/GenericContext');

jest.mock('../../../utils/EntityVersionUtilsPure', () => ({
getEntityVersionByField: jest.fn(
(_: unknown, field: string, value: string) => `diff:${field}:${value}`
),
getEntityVersionTags: jest.fn(() => [{ tagFQN: 'diff.tag' }]),
}));

jest.mock(
'../../Glossary/GlossaryUpdateConfirmationModal/GlossaryUpdateConfirmationModal',
() => ({
GlossaryUpdateConfirmationModal: ({
onCancel,
onValidationSuccess,
}: {
onCancel: () => void;
onValidationSuccess: () => void;
}) => (
<div data-testid="glossary-confirmation-modal">
<button onClick={onValidationSuccess}>confirm</button>
<button onClick={onCancel}>cancel</button>
</div>
),
})
);

const tier: TagLabel = {
tagFQN: 'Tier.Tier1',
source: TagSource.Classification,
labelType: LabelType.Manual,
state: State.Confirmed,
};
const pii: TagLabel = {
tagFQN: 'PII.Sensitive',
source: TagSource.Classification,
labelType: LabelType.Manual,
state: State.Suggested,
};

const entity = {
id: 'id-1',
name: 'orders',
displayName: 'Orders',
description: 'desc',
tags: [tier, pii],
changeDescription: {},
} as unknown as GenericEntity;

const mockOnUpdate = jest.fn();

const mockContext = (type: EntityType) =>
(useGenericContext as jest.Mock).mockReturnValue({
type,
onUpdate: mockOnUpdate,
});

const TagsHarness = () => {
const { onTagsChange, confirmationModal } = useTagsUpdateHandler(
entity,
tier,
entity
);

return (
<>
<button onClick={() => onTagsChange([pii])}>change tags</button>
{confirmationModal}
</>
);
};

describe('CommonWidgets hooks', () => {
beforeEach(() => {
jest.clearAllMocks();
});

describe('useUpdatedEntityData', () => {
it('returns the entity as-is outside version view', () => {
const { result } = renderHook(() => useUpdatedEntityData(entity, false));

expect(result.current).toBe(entity);
});

it('applies version diffs to description, name, display name and tags in version view', () => {
const { result } = renderHook(() => useUpdatedEntityData(entity, true));

expect(result.current).toEqual(
expect.objectContaining({
description: 'diff:description:desc',
name: 'diff:name:orders',
displayName: 'diff:displayName:Orders',
tags: [{ tagFQN: 'diff.tag' }],
})
);
});
});

describe('useTierSplit', () => {
it('separates the tier tag from the other tags', () => {
const { result } = renderHook(() => useTierSplit(entity));

expect(result.current).toEqual({ tier, tags: [pii] });
});

it('handles an entity without tags', () => {
const { result } = renderHook(() =>
useTierSplit({ ...entity, tags: undefined })
);

expect(result.current).toEqual({ tier: undefined, tags: [] });
});
});

describe('useTagsUpdateHandler', () => {
it('saves the selected tags immediately and keeps the tier for non-glossary entities', async () => {
mockContext(EntityType.TABLE);
render(<TagsHarness />);

await act(async () => {
screen.getByText('change tags').click();
});

expect(mockOnUpdate).toHaveBeenCalledWith({
...entity,
tags: [tier, { ...pii, state: State.Confirmed }],
});
expect(
screen.queryByTestId('glossary-confirmation-modal')
).not.toBeInTheDocument();
});

it('asks for confirmation before saving tags on a glossary term', async () => {
mockContext(EntityType.GLOSSARY_TERM);
render(<TagsHarness />);

await act(async () => {
screen.getByText('change tags').click();
});

expect(mockOnUpdate).not.toHaveBeenCalled();

await act(async () => {
(await screen.findByText('confirm')).click();
});

expect(mockOnUpdate).toHaveBeenCalledWith({
...entity,
tags: [tier, { ...pii, state: State.Confirmed }],
});
});

it('drops the pending glossary tags when the confirmation is cancelled', async () => {
mockContext(EntityType.GLOSSARY_TERM);
render(<TagsHarness />);

await act(async () => {
screen.getByText('change tags').click();
});

await act(async () => {
(await screen.findByText('cancel')).click();
});

expect(
screen.queryByTestId('glossary-confirmation-modal')
).not.toBeInTheDocument();
expect(mockOnUpdate).not.toHaveBeenCalled();
});
});
});
Loading
Loading