Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(fix #13822):Support for Custom Properties for various entities #14781

Merged
merged 4 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -26,6 +26,7 @@ import {
deleteCustomPropertyForEntity,
generateCustomProperty,
setValueForProperty,
validateValueForProperty,
} from '../Utils/CustomProperty';
import { addDomainToEntity, removeDomainFromEntity } from '../Utils/Domain';
import {
Expand Down Expand Up @@ -483,9 +484,12 @@ class EntityClass {

setCustomProperty(propertydetails: CustomProperty, value: string) {
setValueForProperty(propertydetails.name, value);
validateValueForProperty(propertydetails.name, value);
}

updateCustomProperty(propertydetails: CustomProperty, value: string) {
setValueForProperty(propertydetails.name, value);
validateValueForProperty(propertydetails.name, value);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,16 @@ export const setValueForProperty = (propertyName, value: string) => {
value.replace(/\*|_/gi, '')
);
};
export const validateValueForProperty = (propertyName, value: string) => {
cy.get('.ant-tabs-tab').first().click();
cy.get(
'[data-testid="entity-right-panel"] [data-testid="custom-properties-table"]',
{
timeout: 10000,
}
).scrollIntoView();
cy.get(`[data-row-key="${propertyName}"]`).should(
'contain',
value.replace(/\*|_/gi, '')
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ entities.forEach((entity) => {

it(`Set ${properties} Custom Property `, () => {
Object.values(CustomPropertyType).forEach((type) => {
// set and validate
harsh-vador marked this conversation as resolved.
Show resolved Hide resolved
entity.setCustomProperty(
entity.customPropertyValue[type].property,
entity.customPropertyValue[type].value
Expand All @@ -122,6 +123,7 @@ entities.forEach((entity) => {

it(`Update ${properties} Custom Property`, () => {
Object.values(CustomPropertyType).forEach((type) => {
// update and validate
harsh-vador marked this conversation as resolved.
Show resolved Hide resolved
entity.updateCustomProperty(
entity.customPropertyValue[type].property,
entity.customPropertyValue[type].newValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -621,13 +621,15 @@ const DashboardDetails = ({
data-testid="entity-right-panel"
flex="320px">
<EntityRightPanel
customProperties={dashboardDetails}
dataProducts={dashboardDetails?.dataProducts ?? []}
domain={dashboardDetails?.domain}
editTagPermission={editTagsPermission}
entityFQN={decodedDashboardFQN}
entityId={dashboardDetails.id}
entityType={EntityType.DASHBOARD}
selectedTags={dashboardTags}
viewAllPermission={viewAllPermission}
onTagSelectionChange={handleTagSelection}
onThreadLinkSelect={onThreadLinkSelect}
/>
Expand Down Expand Up @@ -678,6 +680,7 @@ const DashboardDetails = ({
key: EntityTabs.CUSTOM_PROPERTIES,
children: (
<CustomPropertyTable
entityDetails={dashboardDetails}
entityType={EntityType.DASHBOARD}
handleExtensionUpdate={onExtensionUpdate}
hasEditAccess={editCustomAttributePermission}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,45 @@ jest.mock('../../Tag/TagsContainerV2/TagsContainerV2', () => {
return jest.fn().mockImplementation(() => <div>TagsContainerV2</div>);
});

jest.mock('../../common/CustomPropertyTable/CustomPropertyTable', () => ({
CustomPropertyTable: jest
.fn()
.mockImplementation(() => (
<div data-testid="CustomPropertyTable">CustomPropertyTable</div>
)),
}));

jest.mock('../../../utils/EntityRightPanelClassBase');

jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useParams: jest.fn().mockImplementation(() => ({
fqn: 'fqn',
tab: 'tab',
version: 'version',
})),
Link: jest
.fn()
.mockImplementation(({ children, ...rest }) => <a {...rest}>{children}</a>),
}));

describe('EntityRightPanel component test', () => {
const mockDataProducts: EntityReference[] = [];
const mockSelectedTags: EntityTags[] = [];
const mockOnTagSelectionChange = jest.fn();
const mockOnThreadLinkSelect = jest.fn();
const mockCustomProperties = {
extension: {
test1: 'test',
test2: '',
},
};

it('Component should render', () => {
render(
<EntityRightPanel
editTagPermission
customProperties={mockCustomProperties}
dataProducts={mockDataProducts}
entityFQN="testEntityFQN"
entityId="testEntityId"
Expand All @@ -56,6 +83,7 @@ describe('EntityRightPanel component test', () => {
render(
<EntityRightPanel
editTagPermission
customProperties={mockCustomProperties}
dataProducts={mockDataProducts}
entityFQN="testEntityFQN"
entityId="testEntityId"
Expand All @@ -76,6 +104,7 @@ describe('EntityRightPanel component test', () => {
editTagPermission
afterSlot={<div>afterSlot</div>}
beforeSlot={<div>beforeSlot</div>}
customProperties={mockCustomProperties}
dataProducts={mockDataProducts}
entityFQN="testEntityFQN"
entityId="testEntityId"
Expand All @@ -95,6 +124,7 @@ describe('EntityRightPanel component test', () => {
render(
<EntityRightPanel
editTagPermission
customProperties={mockCustomProperties}
dataProducts={mockDataProducts}
entityFQN="testEntityFQN"
entityId="testEntityId"
Expand All @@ -120,6 +150,7 @@ describe('EntityRightPanel component test', () => {
render(
<EntityRightPanel
editTagPermission
customProperties={mockCustomProperties}
dataProducts={mockDataProducts}
entityFQN="testEntityFQN"
entityId="testEntityId"
Expand All @@ -143,6 +174,7 @@ describe('EntityRightPanel component test', () => {
render(
<EntityRightPanel
editTagPermission
customProperties={mockCustomProperties}
dataProducts={mockDataProducts}
entityFQN="testEntityFQN"
entityId="testEntityId"
Expand All @@ -158,4 +190,49 @@ describe('EntityRightPanel component test', () => {

expect(screen.queryByText('KnowledgeArticles')).not.toBeInTheDocument();
});

it('should render CustomPropertyTable when mockCustomProperties is not null', () => {
render(
<EntityRightPanel
editTagPermission
viewAllPermission
customProperties={mockCustomProperties}
dataProducts={mockDataProducts}
entityFQN="testEntityFQN"
entityId="testEntityId"
entityType={EntityType.TABLE}
selectedTags={mockSelectedTags}
showDataProductContainer={false}
onTagSelectionChange={mockOnTagSelectionChange}
onThreadLinkSelect={mockOnThreadLinkSelect}
/>
);

expect(
screen.getByText('label.custom-property-plural')
).toBeInTheDocument();
expect(
screen.queryByText('message.no-access-placeholder')
).not.toBeInTheDocument();
});

it('should not render CustomPropertyTable when no custom properties', () => {
render(
<EntityRightPanel
editTagPermission
viewAllPermission
customProperties={{}}
dataProducts={mockDataProducts}
entityFQN="testEntityFQN"
entityId="testEntityId"
entityType={EntityType.TABLE}
selectedTags={mockSelectedTags}
showDataProductContainer={false}
onTagSelectionChange={mockOnTagSelectionChange}
onThreadLinkSelect={mockOnThreadLinkSelect}
/>
);

expect(screen.queryByText('CustomPropertyTable')).not.toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Space } from 'antd';
import { Space, Typography } from 'antd';
import { t } from 'i18next';
import { EntityTags } from 'Models';
import React, { FC } from 'react';
import { EntityType } from '../../../enums/entity.enum';
import { Link } from 'react-router-dom';
import { EntityTabs, EntityType } from '../../../enums/entity.enum';
import { Table } from '../../../generated/entity/data/table';
import { ThreadType } from '../../../generated/entity/feed/thread';
import { EntityReference } from '../../../generated/entity/type';
import { TagSource } from '../../../generated/type/tagLabel';
import { getEntityDetailLink } from '../../../utils/CommonUtils';
import entityRightPanelClassBase from '../../../utils/EntityRightPanelClassBase';
import { CustomPropertyTable } from '../../common/CustomPropertyTable/CustomPropertyTable';
import type { ExtentionEntitiesKeys as ExtensionEntitiesKeys } from '../../common/CustomPropertyTable/CustomPropertyTable.interface';
import DataProductsContainer from '../../DataProductsContainer/DataProductsContainer.component';
import TagsContainerV2 from '../../Tag/TagsContainerV2/TagsContainerV2';
import { DisplayType } from '../../Tag/TagsViewer/TagsViewer.interface';
Expand All @@ -36,6 +42,8 @@ interface EntityRightPanelProps {
domain?: EntityReference;
onTagSelectionChange?: (selectedTags: EntityTags[]) => Promise<void>;
onThreadLinkSelect?: (value: string, threadType?: ThreadType) => void;
viewAllPermission?: boolean;
customProperties?: Table['extension'];
harsh-vador marked this conversation as resolved.
Show resolved Hide resolved
}

const EntityRightPanel: FC<EntityRightPanelProps> = ({
Expand All @@ -52,6 +60,8 @@ const EntityRightPanel: FC<EntityRightPanelProps> = ({
entityId,
showTaskHandler = true,
showDataProductContainer = true,
viewAllPermission,
customProperties,
}) => {
const KnowledgeArticles =
entityRightPanelClassBase.getKnowLedgeArticlesWidget();
Expand Down Expand Up @@ -94,6 +104,30 @@ const EntityRightPanel: FC<EntityRightPanelProps> = ({
{KnowledgeArticles && (
<KnowledgeArticles entityId={entityId} entityType={entityType} />
)}
{customProperties?.extension && (
harsh-vador marked this conversation as resolved.
Show resolved Hide resolved
<>
<div className="d-flex justify-between">
<Typography.Text className="right-panel-label">
{t('label.custom-property-plural')}
</Typography.Text>
<Link
to={getEntityDetailLink(
entityType,
entityFQN,
EntityTabs.CUSTOM_PROPERTIES
)}>
{t('label.view-all')}
</Link>
</div>
<CustomPropertyTable
isInRightPanel
entityDetails={customProperties}
entityType={entityType as ExtensionEntitiesKeys}
hasEditAccess={false}
hasPermission={viewAllPermission ?? false}
/>
</>
)}
</Space>
{afterSlot}
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,13 +419,15 @@ const MlModelDetail: FC<MlModelDetailProp> = ({
data-testid="entity-right-panel"
flex="320px">
<EntityRightPanel
customProperties={mlModelDetail}
dataProducts={mlModelDetail?.dataProducts ?? []}
domain={mlModelDetail?.domain}
editTagPermission={editTagsPermission}
entityFQN={decodedMlModelFqn}
entityId={mlModelDetail.id}
entityType={EntityType.MLMODEL}
selectedTags={mlModelTags}
viewAllPermission={viewAllPermission}
onTagSelectionChange={handleTagSelection}
onThreadLinkSelect={handleThreadLinkSelect}
/>
Expand Down Expand Up @@ -488,6 +490,7 @@ const MlModelDetail: FC<MlModelDetailProp> = ({
key: EntityTabs.CUSTOM_PROPERTIES,
children: (
<CustomPropertyTable
entityDetails={mlModelDetail}
entityType={EntityType.MLMODEL}
handleExtensionUpdate={onExtensionUpdate}
hasEditAccess={editCustomAttributePermission}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -614,13 +614,15 @@ const PipelineDetails = ({
data-testid="entity-right-panel"
flex="320px">
<EntityRightPanel
customProperties={pipelineDetails}
dataProducts={pipelineDetails?.dataProducts ?? []}
domain={pipelineDetails?.domain}
editTagPermission={editTagsPermission}
entityFQN={pipelineFQN}
entityId={pipelineDetails.id}
entityType={EntityType.PIPELINE}
selectedTags={tags}
viewAllPermission={viewAllPermission}
onTagSelectionChange={handleTagSelection}
onThreadLinkSelect={onThreadLinkSelect}
/>
Expand Down Expand Up @@ -686,6 +688,7 @@ const PipelineDetails = ({
key: EntityTabs.CUSTOM_PROPERTIES,
children: (
<CustomPropertyTable
entityDetails={pipelineDetails}
entityType={EntityType.PIPELINE}
handleExtensionUpdate={onExtensionUpdate}
hasEditAccess={editCustomAttributePermission}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,13 +327,15 @@ const TopicDetails: React.FC<TopicDetailsProps> = ({
data-testid="entity-right-panel"
flex="320px">
<EntityRightPanel
customProperties={topicDetails}
dataProducts={topicDetails?.dataProducts ?? []}
domain={topicDetails?.domain}
editTagPermission={editTagsPermission}
entityFQN={decodedTopicFQN}
entityId={topicDetails.id}
entityType={EntityType.TOPIC}
selectedTags={topicTags}
viewAllPermission={viewAllPermission}
onTagSelectionChange={handleTagSelection}
onThreadLinkSelect={onThreadLinkSelect}
/>
Expand Down Expand Up @@ -413,6 +415,7 @@ const TopicDetails: React.FC<TopicDetailsProps> = ({
key: EntityTabs.CUSTOM_PROPERTIES,
children: (
<CustomPropertyTable
entityDetails={topicDetails}
entityType={EntityType.TOPIC}
handleExtensionUpdate={onExtensionUpdate}
hasEditAccess={editCustomAttributePermission}
Expand Down Expand Up @@ -477,7 +480,6 @@ const TopicDetails: React.FC<TopicDetailsProps> = ({
</Col>
<Col span={24}>
<Tabs
destroyInactiveTabPane
activeKey={activeTab ?? EntityTabs.SCHEMA}
className="entity-details-page-tabs"
data-testid="tabs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ export type ExtentionEntitiesKeys = keyof ExtentionEntities;
export interface CustomPropertyProps<T extends ExtentionEntitiesKeys> {
isVersionView?: boolean;
entityType: T;
entityDetails?: ExtentionEntities[T];
handleExtensionUpdate?: (updatedTable: ExtentionEntities[T]) => Promise<void>;
entityDetails: Table['extension'];
handleExtensionUpdate?: (updatedTable: Table['extension']) => Promise<void>;
hasEditAccess: boolean;
className?: string;
hasPermission: boolean;
isInRightPanel?: boolean;
}
Loading
Loading