Skip to content

Commit 08f02bc

Browse files
gh-bot-collate[bot]pcbeingused333sweta1308
authored
fix: Restore domain display and editing for classifications (#38641) (#38725)
* fix: restore domain display and editing for classifications * fix(ui): save classification domains through the page's update handler Route the Domains panel's save through handleUpdateClassification, as the Owners panel does, so TagsPage's classification state reflects the new domains. Add a browser test that renders the assigned domain and replaces it through the picker. * fix(ui): open a new classification on its empty state without a tags table flash After creating a classification, make it the current one with termCount 0 instead of leaving the previous classification on screen until the name fetch lands, and render the empty state directly for a classification known to have no tags rather than the loading tags table. * fix(ui): keep the saved classification domains when a domain save fails Drop the onUpdate route through handleUpdateClassification: that handler swallows errors, so DomainLabel showed the unsaved selection after a rejected PATCH. DomainLabel's own API save keeps its previous domains on failure. Add a browser test for the rejected save. * fix(ui): keep classification domains read-only in version view and in sync after a panel save - Gate the Domains panel editor on !isVersionView, as the Owners widget is, so the version history page cannot PATCH the live classification. - Merge the saved domains into TagsPage's current classification through afterDomainUpdateAction, so the Edit drawer pre-fills the saved domains. - Drive the domain picker in browser tests through openPicker/setSelected, and add tests for the version-view gate and the edit-form domains. * fix(ui): keep a late domain save from landing on another classification Key the Domains panel by classification id so a save that resolves after switching classifications cannot update the new panel, and merge saved domains into TagsPage state only when the patched id matches the current classification. Add a browser test that holds the PATCH across a switch. --------- (cherry picked from commit bacceff) Co-authored-by: Alex Castillo González <82875882+pcbeingused333@users.noreply.github.com> Co-authored-by: Sweta Agarwalla <swetaagarwalla13@gmail.com> Co-authored-by: Sweta Agarwalla <105535990+sweta1308@users.noreply.github.com>
1 parent a917cf9 commit 08f02bc

4 files changed

Lines changed: 101 additions & 23 deletions

File tree

‎openmetadata-ui/src/main/resources/ui/src/components/Classifications/ClassificationDetails/ClassificationDetails.interface.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import { OperationPermission } from '../../../context/PermissionProvider/PermissionProvider.interface';
1414
import { Classification } from '../../../generated/entity/classification/classification';
1515
import { Tag } from '../../../generated/entity/classification/tag';
16+
import { EntityReference } from '../../../generated/entity/type';
1617
import { DeleteTagsType } from '../../../pages/TagsPage/TagsPage.interface';
1718

1819
export interface ClassificationDetailsProps {
@@ -30,6 +31,10 @@ export interface ClassificationDetailsProps {
3031
handleUpdateClassification?: (
3132
updatedClassification: Classification
3233
) => Promise<void>;
34+
handleClassificationDomainsUpdate?: (
35+
id: string,
36+
domains?: EntityReference[]
37+
) => void;
3338
handleToggleDisable?: (tag: Tag) => void;
3439
handleEditClassificationClick?: () => void;
3540
}

‎openmetadata-ui/src/main/resources/ui/src/components/Classifications/ClassificationDetails/ClassificationDetails.test.tsx‎

Lines changed: 68 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ import { Classification } from '../../../generated/entity/classification/classif
1919
import { Tag } from '../../../generated/entity/classification/tag';
2020
import { ENTITY_PERMISSIONS } from '../../../mocks/Permissions.mock';
2121
import { postExactAggregateFieldOptions } from '../../../rest/miscAPI';
22-
import { getTags } from '../../../rest/tagAPI';
22+
import {
23+
getClassificationByName,
24+
getTags,
25+
patchClassification,
26+
} from '../../../rest/tagAPI';
2327
import { renderWithQueryClient as render } from '../../../test/unit/test-utils';
2428
import ClassificationDetails from './ClassificationDetails';
2529

@@ -165,6 +169,8 @@ jest.mock('../../../context/PermissionProvider/PermissionProvider', () => ({
165169
}));
166170

167171
jest.mock('../../../rest/tagAPI', () => ({
172+
getClassificationByName: jest.fn(),
173+
patchClassification: jest.fn(),
168174
getTags: jest.fn().mockResolvedValue({
169175
data: [],
170176
paging: { total: 0 },
@@ -244,22 +250,25 @@ jest.mock('../../Customization/GenericProvider/GenericProvider', () => ({
244250
}));
245251

246252
jest.mock('../../common/WidgetCard/WidgetCard', () =>
247-
jest
248-
.fn()
249-
.mockImplementation(
250-
({ children, title }: { children?: React.ReactNode; title?: string }) => (
251-
<div data-testid="widget-card">
252-
{title && <div>{title}</div>}
253-
{children}
254-
</div>
255-
)
256-
)
253+
jest.fn().mockImplementation(({ children, headerExtra, title }) => (
254+
<div data-testid="widget-card">
255+
{title && <div>{title}</div>}
256+
{headerExtra}
257+
{children}
258+
</div>
259+
))
257260
);
258261

259-
jest.mock('../../common/DomainLabel/DomainLabel.component', () => ({
260-
DomainLabel: jest
261-
.fn()
262-
.mockImplementation(() => <div data-testid="domain-label">Domain</div>),
262+
jest.mock('../../common/DomainSelect/DomainSelect', () =>
263+
jest.fn().mockImplementation(({ onUpdate }) => (
264+
<button type="button" onClick={() => onUpdate([])}>
265+
Apply
266+
</button>
267+
))
268+
);
269+
270+
jest.mock('../../../rest/domainAPI', () => ({
271+
getDomainStyles: jest.fn().mockResolvedValue({ data: [] }),
263272
}));
264273

265274
jest.mock('../../common/Badge/Badge.component', () =>
@@ -470,7 +479,7 @@ describe('ClassificationDetails', () => {
470479
'TestClassification'
471480
);
472481
expect(screen.getByTestId('tag-row-Tag2')).toBeInTheDocument();
473-
expect(screen.getByTestId('domain-label')).toBeInTheDocument();
482+
expect(screen.getByText('label.domain-plural')).toBeInTheDocument();
474483
expect(screen.getByTestId('owner-label')).toBeInTheDocument();
475484
});
476485

@@ -692,6 +701,10 @@ describe('ClassificationDetails', () => {
692701
);
693702

694703
expect(screen.queryByTestId('add-new-tag-button')).not.toBeInTheDocument();
704+
expect(screen.getByText('label.domain-plural')).toBeInTheDocument();
705+
expect(
706+
screen.queryByRole('button', { name: 'Apply' })
707+
).not.toBeInTheDocument();
695708

696709
unmount();
697710

@@ -793,7 +806,7 @@ describe('ClassificationDetails', () => {
793806
expect(screen.getByTestId('loader')).toBeInTheDocument();
794807
expect(screen.queryByTestId('header')).not.toBeInTheDocument();
795808
expect(screen.queryByTestId('tags-table')).not.toBeInTheDocument();
796-
expect(screen.queryByTestId('domain-label')).not.toBeInTheDocument();
809+
expect(screen.queryByText('label.domain-plural')).not.toBeInTheDocument();
797810
expect(screen.queryByTestId('owner-label')).not.toBeInTheDocument();
798811
});
799812

@@ -827,10 +840,47 @@ describe('ClassificationDetails', () => {
827840
expect(screen.queryByTestId('loader')).not.toBeInTheDocument();
828841
expect(screen.getByTestId('header')).toBeInTheDocument();
829842
expect(screen.getByTestId('tags-table')).toBeInTheDocument();
830-
expect(screen.getByTestId('domain-label')).toBeInTheDocument();
843+
expect(screen.getByText('label.domain-plural')).toBeInTheDocument();
831844
expect(screen.getByTestId('owner-label')).toBeInTheDocument();
832845
});
833846

847+
it('should show the assigned domain and apply domain changes to the classification', async () => {
848+
const classification = {
849+
...mockClassification,
850+
domains: [{ id: 'domain-id', type: 'domain', name: 'Finance' }],
851+
};
852+
jest.mocked(getClassificationByName).mockResolvedValue(classification);
853+
jest
854+
.mocked(patchClassification)
855+
.mockResolvedValue({ ...classification, domains: [] });
856+
857+
await act(async () => {
858+
render(
859+
<MemoryRouter>
860+
<ClassificationDetails
861+
{...defaultProps}
862+
currentClassification={classification}
863+
/>
864+
</MemoryRouter>
865+
);
866+
});
867+
868+
expect(screen.getByText('Finance')).toBeInTheDocument();
869+
870+
fireEvent.click(screen.getByRole('button', { name: 'Apply' }));
871+
872+
await waitFor(() => {
873+
expect(getClassificationByName).toHaveBeenCalledWith(
874+
classification.fullyQualifiedName,
875+
{ fields: 'domains' }
876+
);
877+
expect(patchClassification).toHaveBeenCalledWith(classification.id, [
878+
{ op: 'remove', path: '/domains/0' },
879+
]);
880+
expect(screen.queryByText('Finance')).not.toBeInTheDocument();
881+
});
882+
});
883+
834884
it('should pass currentClassification directly to GenericProvider', async () => {
835885
const { GenericProvider } = jest.requireMock(
836886
'../../Customization/GenericProvider/GenericProvider'

‎openmetadata-ui/src/main/resources/ui/src/components/Classifications/ClassificationDetails/ClassificationDetails.tsx‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ import tagClassBase from '../../../utils/TagClassBase';
8686
import { showErrorToast } from '../../../utils/ToastUtils';
8787
import AppBadge from '../../common/Badge/Badge.component';
8888
import { DomainLabel } from '../../common/DomainLabel/DomainLabel.component';
89-
import { useGenericDomainLabel } from '../../common/DomainLabel/useGenericDomainLabel';
9089
import NoDataPlaceholder from '../../common/EmptyPlaceholder/NoDataPlaceholder';
9190
import Description from '../../common/EntityDescription/Description';
9291
import ManageButton from '../../common/EntityPageInfos/ManageButton/ManageButton';
@@ -175,6 +174,7 @@ const ClassificationDetails = forwardRef(
175174
handleAfterDeleteAction,
176175
classificationPermissions,
177176
handleUpdateClassification,
177+
handleClassificationDomainsUpdate,
178178
handleEditTagClick,
179179
deleteTags,
180180
isAddingTag,
@@ -196,7 +196,6 @@ const ClassificationDetails = forwardRef(
196196
const { fqn: tagCategoryName } = useFqn();
197197
const navigate = useNavigate();
198198
const { entityRules } = useEntityRules(EntityType.CLASSIFICATION);
199-
const domainProps = useGenericDomainLabel();
200199
const [tags, setTags] = useState<Tag[]>([]);
201200
const [isTagsLoading, setIsTagsLoading] = useState(true);
202201
const isLoading = isTagsLoading || isClassificationLoading;
@@ -726,7 +725,8 @@ const ClassificationDetails = forwardRef(
726725
}
727726

728727
function renderTagsPanel() {
729-
return isEmpty(tags) && !isLoading ? (
728+
return isEmpty(tags) &&
729+
(!isLoading || currentClassification?.termCount === 0) ? (
730730
<Box className="tw:relative tw:min-h-[360px]">
731731
<NoDataPlaceholder
732732
actions={
@@ -807,10 +807,20 @@ const ClassificationDetails = forwardRef(
807807
</div>
808808
<div className="tw:flex tw:min-w-0 tw:flex-1 tw:flex-col tw:gap-5">
809809
<DomainLabel
810-
{...domainProps}
811810
multiple
812811
showDomainHeading
813-
hasPermission={editDomainPermission}
812+
afterDomainUpdateAction={(updated) =>
813+
handleClassificationDomainsUpdate?.(
814+
updated.id,
815+
updated.domains
816+
)
817+
}
818+
domains={currentClassification.domains}
819+
entityFqn={currentClassification.fullyQualifiedName ?? ''}
820+
entityId={currentClassification.id}
821+
entityType={EntityType.CLASSIFICATION}
822+
hasPermission={!isVersionView && editDomainPermission}
823+
key={currentClassification.id}
814824
variant="widget"
815825
/>
816826
<WidgetCard

‎openmetadata-ui/src/main/resources/ui/src/pages/TagsPage/TagsPage.tsx‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import { ProviderType } from '../../generated/entity/bot';
5151
import { Classification } from '../../generated/entity/classification/classification';
5252
import { Tag } from '../../generated/entity/classification/tag';
5353
import { Operation } from '../../generated/entity/policies/accessControl/rule';
54+
import { EntityReference } from '../../generated/entity/type';
5455
import { withPageLayout } from '../../hoc/withPageLayout';
5556
import { useEntityPermissions } from '../../hooks/useEntityPermissions/useEntityPermissions';
5657
import { useFqn } from '../../hooks/useFqn';
@@ -227,6 +228,7 @@ const TagsPage = () => {
227228
try {
228229
const res = await createClassification(data);
229230
await fetchClassifications();
231+
setCurrentClassification({ ...res, termCount: 0 });
230232
navigate(getTagPath(res.fullyQualifiedName));
231233
} catch (error) {
232234
if (
@@ -399,6 +401,14 @@ const TagsPage = () => {
399401
[updateClassification]
400402
);
401403

404+
const handleClassificationDomainsUpdate = useCallback(
405+
(id: string, domains?: EntityReference[]) =>
406+
setCurrentClassification((prev) =>
407+
prev?.id === id ? { ...prev, domains } : prev
408+
),
409+
[]
410+
);
411+
402412
const handleCreatePrimaryTag = async (data: CreateTag) => {
403413
try {
404414
await createTag({
@@ -894,6 +904,9 @@ const TagsPage = () => {
894904
handleActionDeleteTag={handleActionDeleteTag}
895905
handleAddNewTagClick={handleAddNewTagClick}
896906
handleAfterDeleteAction={handleAfterDeleteAction}
907+
handleClassificationDomainsUpdate={
908+
handleClassificationDomainsUpdate
909+
}
897910
handleEditClassificationClick={handleEditClassificationClick}
898911
handleEditTagClick={handleEditTagClick}
899912
handleToggleDisable={handleToggleDisable}

0 commit comments

Comments
 (0)