fix(ui): #21479 filter announcment widget from customisation (#21497)

This commit is contained in:
Chirag Madlani 2025-05-31 13:03:18 +05:30 committed by GitHub
parent 17c4ab872d
commit b5f47e3309
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 4 deletions

View File

@ -15,6 +15,7 @@ import { act, render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event'; import userEvent from '@testing-library/user-event';
import React from 'react'; import React from 'react';
import { PAGE_SIZE_MEDIUM } from '../../../../constants/constants'; import { PAGE_SIZE_MEDIUM } from '../../../../constants/constants';
import { LandingPageWidgetKeys } from '../../../../enums/CustomizablePage.enum';
import { mockWidgetsData } from '../../../../mocks/AddWidgetModal.mock'; import { mockWidgetsData } from '../../../../mocks/AddWidgetModal.mock';
import { getAllKnowledgePanels } from '../../../../rest/DocStoreAPI'; import { getAllKnowledgePanels } from '../../../../rest/DocStoreAPI';
import AddWidgetModal from './AddWidgetModal'; import AddWidgetModal from './AddWidgetModal';
@ -172,9 +173,17 @@ describe('AddWidgetModal component', () => {
expect(screen.getByText('ErrorPlaceHolder')).toBeInTheDocument(); expect(screen.getByText('ErrorPlaceHolder')).toBeInTheDocument();
}); });
it('AddWidgetModal should', async () => { it('AddWidgetModal should not show announcement widget', async () => {
(getAllKnowledgePanels as jest.Mock).mockImplementation(() =>
Promise.resolve({
data: [{ fullyQualifiedName: LandingPageWidgetKeys.ANNOUNCEMENTS }],
})
);
await act(async () => { await act(async () => {
render(<AddWidgetModal {...mockProps} />); render(<AddWidgetModal {...mockProps} />);
}); });
expect(screen.queryByTestId('Announcements-widget-tab-label')).toBeNull();
}); });
}); });

View File

@ -22,7 +22,10 @@ import {
PAGE_SIZE_MEDIUM, PAGE_SIZE_MEDIUM,
} from '../../../../constants/constants'; } from '../../../../constants/constants';
import { ERROR_PLACEHOLDER_TYPE } from '../../../../enums/common.enum'; import { ERROR_PLACEHOLDER_TYPE } from '../../../../enums/common.enum';
import { WidgetWidths } from '../../../../enums/CustomizablePage.enum'; import {
LandingPageWidgetKeys,
WidgetWidths,
} from '../../../../enums/CustomizablePage.enum';
import { Document } from '../../../../generated/entity/docStore/document'; import { Document } from '../../../../generated/entity/docStore/document';
import { getAllKnowledgePanels } from '../../../../rest/DocStoreAPI'; import { getAllKnowledgePanels } from '../../../../rest/DocStoreAPI';
import { getWidgetWidthLabelFromKey } from '../../../../utils/CustomizableLandingPageUtils'; import { getWidgetWidthLabelFromKey } from '../../../../utils/CustomizableLandingPageUtils';
@ -51,12 +54,18 @@ function AddWidgetModal({
const fetchKnowledgePanels = useCallback(async () => { const fetchKnowledgePanels = useCallback(async () => {
try { try {
setLoading(true); setLoading(true);
const response = await getAllKnowledgePanels({ const { data } = await getAllKnowledgePanels({
fqnPrefix: 'KnowledgePanel', fqnPrefix: 'KnowledgePanel',
limit: PAGE_SIZE_MEDIUM, limit: PAGE_SIZE_MEDIUM,
}); });
setWidgetsList(response.data); // User can't add / update / delete Announcements widget
setWidgetsList(
data.filter(
(widget) =>
widget.fullyQualifiedName !== LandingPageWidgetKeys.ANNOUNCEMENTS
)
);
} catch (error) { } catch (error) {
showErrorToast(error as AxiosError); showErrorToast(error as AxiosError);
} finally { } finally {