Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
import { OperationPermission } from '../../../context/PermissionProvider/PermissionProvider.interface';
import { Classification } from '../../../generated/entity/classification/classification';
import { Tag } from '../../../generated/entity/classification/tag';
import { EntityReference } from '../../../generated/entity/type';
import { DeleteTagsType } from '../../../pages/TagsPage/TagsPage.interface';

Check warning on line 17 in openmetadata-ui/src/main/resources/ui/src/components/Classifications/ClassificationDetails/ClassificationDetails.interface.ts

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

export interface ClassificationDetailsProps {
classificationPermissions: OperationPermission;
Expand All @@ -30,6 +31,10 @@
handleUpdateClassification?: (
updatedClassification: Classification
) => Promise<void>;
handleClassificationDomainsUpdate?: (
id: string,
domains?: EntityReference[]
) => void;
handleToggleDisable?: (tag: Tag) => void;
handleEditClassificationClick?: () => void;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ import { Classification } from '../../../generated/entity/classification/classif
import { Tag } from '../../../generated/entity/classification/tag';
import { ENTITY_PERMISSIONS } from '../../../mocks/Permissions.mock';
import { postExactAggregateFieldOptions } from '../../../rest/miscAPI';
import { getTags } from '../../../rest/tagAPI';
import {
getClassificationByName,
getTags,
patchClassification,
} from '../../../rest/tagAPI';
import { renderWithQueryClient as render } from '../../../test/unit/test-utils';
import ClassificationDetails from './ClassificationDetails';

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

jest.mock('../../../rest/tagAPI', () => ({
getClassificationByName: jest.fn(),
patchClassification: jest.fn(),
getTags: jest.fn().mockResolvedValue({
data: [],
paging: { total: 0 },
Expand Down Expand Up @@ -244,22 +250,25 @@ jest.mock('../../Customization/GenericProvider/GenericProvider', () => ({
}));

jest.mock('../../common/WidgetCard/WidgetCard', () =>
jest
.fn()
.mockImplementation(
({ children, title }: { children?: React.ReactNode; title?: string }) => (
<div data-testid="widget-card">
{title && <div>{title}</div>}
{children}
</div>
)
)
jest.fn().mockImplementation(({ children, headerExtra, title }) => (
<div data-testid="widget-card">
{title && <div>{title}</div>}
{headerExtra}
{children}
</div>
))
);

jest.mock('../../common/DomainLabel/DomainLabel.component', () => ({
DomainLabel: jest
.fn()
.mockImplementation(() => <div data-testid="domain-label">Domain</div>),
jest.mock('../../common/DomainSelect/DomainSelect', () =>
jest.fn().mockImplementation(({ onUpdate }) => (
<button type="button" onClick={() => onUpdate([])}>
Apply
</button>
))
);

jest.mock('../../../rest/domainAPI', () => ({
getDomainStyles: jest.fn().mockResolvedValue({ data: [] }),
}));

jest.mock('../../common/Badge/Badge.component', () =>
Expand Down Expand Up @@ -470,7 +479,7 @@ describe('ClassificationDetails', () => {
'TestClassification'
);
expect(screen.getByTestId('tag-row-Tag2')).toBeInTheDocument();
expect(screen.getByTestId('domain-label')).toBeInTheDocument();
expect(screen.getByText('label.domain-plural')).toBeInTheDocument();
expect(screen.getByTestId('owner-label')).toBeInTheDocument();
});

Expand Down Expand Up @@ -692,6 +701,10 @@ describe('ClassificationDetails', () => {
);

expect(screen.queryByTestId('add-new-tag-button')).not.toBeInTheDocument();
expect(screen.getByText('label.domain-plural')).toBeInTheDocument();
expect(
screen.queryByRole('button', { name: 'Apply' })
).not.toBeInTheDocument();

unmount();

Expand Down Expand Up @@ -793,7 +806,7 @@ describe('ClassificationDetails', () => {
expect(screen.getByTestId('loader')).toBeInTheDocument();
expect(screen.queryByTestId('header')).not.toBeInTheDocument();
expect(screen.queryByTestId('tags-table')).not.toBeInTheDocument();
expect(screen.queryByTestId('domain-label')).not.toBeInTheDocument();
expect(screen.queryByText('label.domain-plural')).not.toBeInTheDocument();
expect(screen.queryByTestId('owner-label')).not.toBeInTheDocument();
});

Expand Down Expand Up @@ -827,10 +840,47 @@ describe('ClassificationDetails', () => {
expect(screen.queryByTestId('loader')).not.toBeInTheDocument();
expect(screen.getByTestId('header')).toBeInTheDocument();
expect(screen.getByTestId('tags-table')).toBeInTheDocument();
expect(screen.getByTestId('domain-label')).toBeInTheDocument();
expect(screen.getByText('label.domain-plural')).toBeInTheDocument();
expect(screen.getByTestId('owner-label')).toBeInTheDocument();
});

it('should show the assigned domain and apply domain changes to the classification', async () => {
const classification = {
...mockClassification,
domains: [{ id: 'domain-id', type: 'domain', name: 'Finance' }],
};
jest.mocked(getClassificationByName).mockResolvedValue(classification);
jest
.mocked(patchClassification)
.mockResolvedValue({ ...classification, domains: [] });

await act(async () => {
render(
<MemoryRouter>
<ClassificationDetails
{...defaultProps}
currentClassification={classification}
/>
</MemoryRouter>
);
});

expect(screen.getByText('Finance')).toBeInTheDocument();

fireEvent.click(screen.getByRole('button', { name: 'Apply' }));

await waitFor(() => {
expect(getClassificationByName).toHaveBeenCalledWith(
classification.fullyQualifiedName,
{ fields: 'domains' }
);
expect(patchClassification).toHaveBeenCalledWith(classification.id, [
{ op: 'remove', path: '/domains/0' },
]);
expect(screen.queryByText('Finance')).not.toBeInTheDocument();
});
});

it('should pass currentClassification directly to GenericProvider', async () => {
const { GenericProvider } = jest.requireMock(
'../../Customization/GenericProvider/GenericProvider'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@
import { showErrorToast } from '../../../utils/ToastUtils';
import AppBadge from '../../common/Badge/Badge.component';
import { DomainLabel } from '../../common/DomainLabel/DomainLabel.component';
import { useGenericDomainLabel } from '../../common/DomainLabel/useGenericDomainLabel';
import NoDataPlaceholder from '../../common/EmptyPlaceholder/NoDataPlaceholder';
import Description from '../../common/EntityDescription/Description';
import ManageButton from '../../common/EntityPageInfos/ManageButton/ManageButton';
Expand Down Expand Up @@ -175,6 +174,7 @@
handleAfterDeleteAction,
classificationPermissions,
handleUpdateClassification,
handleClassificationDomainsUpdate,
handleEditTagClick,
deleteTags,
isAddingTag,
Expand All @@ -196,7 +196,6 @@
const { fqn: tagCategoryName } = useFqn();
const navigate = useNavigate();
const { entityRules } = useEntityRules(EntityType.CLASSIFICATION);
const domainProps = useGenericDomainLabel();
const [tags, setTags] = useState<Tag[]>([]);
const [isTagsLoading, setIsTagsLoading] = useState(true);
const isLoading = isTagsLoading || isClassificationLoading;
Expand Down Expand Up @@ -286,7 +285,7 @@
)
);
}
}, [currentVersion, tagCategoryName]);

Check warning on line 288 in openmetadata-ui/src/main/resources/ui/src/components/Classifications/ClassificationDetails/ClassificationDetails.tsx

View workflow job for this annotation

GitHub Actions / checkstyle

React Hook useCallback has missing dependencies: 'isVersionView' and 'navigate'. Either include them or remove the dependency array

// Prop stays raw (OperationPermission) — ClassificationUtils.tsx's getTagsTableColumn
// (out of this batch's scope: src/utils/**, not src/components/**) also consumes this
Expand Down Expand Up @@ -450,7 +449,7 @@
}

return null;
}, [createPermission, isClassificationDisabled]);

Check warning on line 452 in openmetadata-ui/src/main/resources/ui/src/components/Classifications/ClassificationDetails/ClassificationDetails.tsx

View workflow job for this annotation

GitHub Actions / checkstyle

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

const tableColumn: ColumnsType<Tag> = useMemo(
() =>
Expand Down Expand Up @@ -526,7 +525,7 @@
]
: []),
],
[

Check warning on line 528 in openmetadata-ui/src/main/resources/ui/src/components/Classifications/ClassificationDetails/ClassificationDetails.tsx

View workflow job for this annotation

GitHub Actions / checkstyle

React Hook useMemo has a missing dependency: 't'. Either include it or remove the dependency array
isClassificationDisabled,
showDisableOption,
handleEnableDisableClassificationClick,
Expand Down Expand Up @@ -580,7 +579,7 @@
fetchClassificationChildren(currentClassification.fullyQualifiedName);
}
}
}, [currentClassification?.fullyQualifiedName, pageSize, pagingCursor]);

Check warning on line 582 in openmetadata-ui/src/main/resources/ui/src/components/Classifications/ClassificationDetails/ClassificationDetails.tsx

View workflow job for this annotation

GitHub Actions / checkstyle

React Hook useEffect has missing dependencies: 'fetchClassificationChildren', 'handlePageChange', 'isAddingTag', and 'isPagedPastFirstPage'. Either include them or remove the dependency array

useImperativeHandle(ref, () => ({
refreshClassificationTags() {
Expand Down Expand Up @@ -726,7 +725,8 @@
}

function renderTagsPanel() {
return isEmpty(tags) && !isLoading ? (
return isEmpty(tags) &&
(!isLoading || currentClassification?.termCount === 0) ? (
<Box className="tw:relative tw:min-h-[360px]">
<NoDataPlaceholder
actions={
Expand Down Expand Up @@ -807,10 +807,20 @@
</div>
<div className="tw:flex tw:min-w-0 tw:flex-1 tw:flex-col tw:gap-5">
<DomainLabel
{...domainProps}
multiple
showDomainHeading
hasPermission={editDomainPermission}
afterDomainUpdateAction={(updated) =>
handleClassificationDomainsUpdate?.(
updated.id,
updated.domains
)
}
domains={currentClassification.domains}
entityFqn={currentClassification.fullyQualifiedName ?? ''}
entityId={currentClassification.id}
entityType={EntityType.CLASSIFICATION}
hasPermission={!isVersionView && editDomainPermission}
key={currentClassification.id}
variant="widget"
/>
<WidgetCard
Expand Down
Loading