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

feat(ml model): updating view of ml model feature list #6576

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
@@ -1,163 +1,23 @@
import React, { useState } from 'react';
import { Table, Typography } from 'antd';
import { CheckSquareOutlined } from '@ant-design/icons';
import { AlignType } from 'rc-table/lib/interface';
import styled from 'styled-components';
import { Link } from 'react-router-dom';
import React from 'react';

import MlFeatureDataTypeIcon from './MlFeatureDataTypeIcon';
import { MlFeatureDataType, MlPrimaryKey, MlFeature } from '../../../../../types.generated';
import { MlPrimaryKey, MlFeature } from '../../../../../types.generated';
import { GetMlFeatureTableQuery } from '../../../../../graphql/mlFeatureTable.generated';
import { useBaseEntity, useRefetch } from '../../../shared/EntityContext';
import { useBaseEntity } from '../../../shared/EntityContext';
import { notEmpty } from '../../../shared/utils';
import TagTermGroup from '../../../../shared/tags/TagTermGroup';
import SchemaDescriptionField from '../../../dataset/profile/schema/components/SchemaDescriptionField';
import { useUpdateDescriptionMutation } from '../../../../../graphql/mutations.generated';
import { useEntityRegistry } from '../../../../useEntityRegistry';

const FeaturesContainer = styled.div`
margin-bottom: 100px;
`;

const defaultColumns = [
{
title: 'Type',
dataIndex: 'dataType',
key: 'dataType',
width: 100,
align: 'left' as AlignType,
render: (dataType: MlFeatureDataType) => {
return <MlFeatureDataTypeIcon dataType={dataType} />;
},
},
];
import TableOfMlFeatures from './TableOfMlFeatures';

export default function MlFeatureTableFeatures() {
const baseEntity = useBaseEntity<GetMlFeatureTableQuery>();
const refetch = useRefetch();
const featureTable = baseEntity?.mlFeatureTable;
const [updateDescription] = useUpdateDescriptionMutation();
const entityRegistry = useEntityRegistry();

const [tagHoveredIndex, setTagHoveredIndex] = useState<string | undefined>(undefined);

const features =
const features = (
featureTable?.properties && (featureTable?.properties?.mlFeatures || featureTable?.properties?.mlPrimaryKeys)
? [
...(featureTable?.properties?.mlPrimaryKeys || []),
...(featureTable?.properties?.mlFeatures || []),
].filter(notEmpty)
: [];

const onTagTermCell = (record: any, rowIndex: number | undefined) => ({
onMouseEnter: () => {
setTagHoveredIndex(`${record.urn}-${rowIndex}`);
},
onMouseLeave: () => {
setTagHoveredIndex(undefined);
},
});

const nameColumn = {
title: 'Name',
dataIndex: 'name',
key: 'name',
width: 100,
render: (name: string, feature: MlFeature | MlPrimaryKey) => (
<Link to={entityRegistry.getEntityUrl(feature.type, feature.urn)}>
<Typography.Text strong>{name}</Typography.Text>
</Link>
),
};

const descriptionColumn = {
title: 'Description',
dataIndex: 'description',
key: 'description',
render: (_, feature: MlFeature | MlPrimaryKey) => (
<SchemaDescriptionField
description={feature?.editableProperties?.description || feature?.properties?.description || ''}
original={feature?.properties?.description}
isEdited={!!feature?.editableProperties?.description}
onUpdate={(updatedDescription) =>
updateDescription({
variables: {
input: {
description: updatedDescription,
resourceUrn: feature.urn,
},
},
}).then(refetch)
}
/>
),
width: 300,
};

const tagColumn = {
width: 125,
title: 'Tags',
dataIndex: 'tags',
key: 'tags',
render: (_, feature: MlFeature | MlPrimaryKey, rowIndex: number) => (
<TagTermGroup
editableTags={feature.tags}
canRemove
buttonProps={{ size: 'small' }}
canAddTag={tagHoveredIndex === `${feature.urn}-${rowIndex}`}
onOpenModal={() => setTagHoveredIndex(undefined)}
entityUrn={feature.urn}
entityType={feature.type}
refetch={refetch}
/>
),
onCell: onTagTermCell,
};

const termColumn = {
width: 125,
title: 'Terms',
dataIndex: 'glossaryTerms',
key: 'glossarTerms',
render: (_, feature: MlFeature | MlPrimaryKey, rowIndex: number) => (
<TagTermGroup
editableGlossaryTerms={feature.glossaryTerms}
canRemove
buttonProps={{ size: 'small' }}
canAddTerm={tagHoveredIndex === `${feature.urn}-${rowIndex}`}
onOpenModal={() => setTagHoveredIndex(undefined)}
entityUrn={feature.urn}
entityType={feature.type}
refetch={refetch}
/>
),
onCell: onTagTermCell,
};

const primaryKeyColumn = {
title: 'Primary Key',
dataIndex: 'primaryKey',
key: 'primaryKey',
render: (_: any, record: MlFeature | MlPrimaryKey) =>
record.__typename === 'MLPrimaryKey' ? <CheckSquareOutlined /> : null,
width: 50,
};

const allColumns = [...defaultColumns, nameColumn, descriptionColumn, tagColumn, termColumn, primaryKeyColumn];
: []
) as Array<MlFeature | MlPrimaryKey>;

return (
<FeaturesContainer>
{features && features.length > 0 && (
<Table
columns={allColumns}
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
dataSource={features}
rowKey={(record) => `${record.dataType}-${record.name}`}
expandable={{ defaultExpandAllRows: true, expandRowByClick: true }}
pagination={false}
/>
)}
</FeaturesContainer>
);
return <TableOfMlFeatures features={features} />;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
import React, { useState } from 'react';
import { Table, Typography } from 'antd';
import { CheckSquareOutlined } from '@ant-design/icons';
import { AlignType } from 'rc-table/lib/interface';
import styled from 'styled-components';
import { Link } from 'react-router-dom';

import MlFeatureDataTypeIcon from './MlFeatureDataTypeIcon';
import { MlFeatureDataType, MlPrimaryKey, MlFeature } from '../../../../../types.generated';
import { useRefetch } from '../../../shared/EntityContext';
import TagTermGroup from '../../../../shared/tags/TagTermGroup';
import SchemaDescriptionField from '../../../dataset/profile/schema/components/SchemaDescriptionField';
import { useUpdateDescriptionMutation } from '../../../../../graphql/mutations.generated';
import { useEntityRegistry } from '../../../../useEntityRegistry';

const FeaturesContainer = styled.div`
margin-bottom: 100px;
`;

const defaultColumns = [
{
title: 'Type',
dataIndex: 'dataType',
key: 'dataType',
width: 100,
align: 'left' as AlignType,
render: (dataType: MlFeatureDataType) => {
return <MlFeatureDataTypeIcon dataType={dataType} />;
},
},
];

type Props = {
features: Array<MlFeature | MlPrimaryKey>;
};

export default function TableOfMlFeatures({ features }: Props) {
const refetch = useRefetch();
const [updateDescription] = useUpdateDescriptionMutation();
const entityRegistry = useEntityRegistry();

const [tagHoveredIndex, setTagHoveredIndex] = useState<string | undefined>(undefined);

const onTagTermCell = (record: any, rowIndex: number | undefined) => ({
onMouseEnter: () => {
setTagHoveredIndex(`${record.urn}-${rowIndex}`);
},
onMouseLeave: () => {
setTagHoveredIndex(undefined);
},
});

const nameColumn = {
title: 'Name',
dataIndex: 'name',
key: 'name',
width: 100,
render: (name: string, feature: MlFeature | MlPrimaryKey) => (
<Link to={entityRegistry.getEntityUrl(feature.type, feature.urn)}>
<Typography.Text strong>{name}</Typography.Text>
</Link>
),
};

const descriptionColumn = {
title: 'Description',
dataIndex: 'description',
key: 'description',
render: (_, feature: MlFeature | MlPrimaryKey) => (
<SchemaDescriptionField
description={feature?.editableProperties?.description || feature?.properties?.description || ''}
original={feature?.properties?.description}
isEdited={!!feature?.editableProperties?.description}
onUpdate={(updatedDescription) =>
updateDescription({
variables: {
input: {
description: updatedDescription,
resourceUrn: feature.urn,
},
},
}).then(refetch)
}
/>
),
width: 300,
};

const tagColumn = {
width: 125,
title: 'Tags',
dataIndex: 'tags',
key: 'tags',
render: (_, feature: MlFeature | MlPrimaryKey, rowIndex: number) => (
<TagTermGroup
editableTags={feature.tags}
canRemove
buttonProps={{ size: 'small' }}
canAddTag={tagHoveredIndex === `${feature.urn}-${rowIndex}`}
onOpenModal={() => setTagHoveredIndex(undefined)}
entityUrn={feature.urn}
entityType={feature.type}
refetch={refetch}
/>
),
onCell: onTagTermCell,
};

const termColumn = {
width: 125,
title: 'Terms',
dataIndex: 'glossaryTerms',
key: 'glossaryTerms',
render: (_, feature: MlFeature | MlPrimaryKey, rowIndex: number) => (
<TagTermGroup
editableGlossaryTerms={feature.glossaryTerms}
canRemove
buttonProps={{ size: 'small' }}
canAddTerm={tagHoveredIndex === `${feature.urn}-${rowIndex}`}
onOpenModal={() => setTagHoveredIndex(undefined)}
entityUrn={feature.urn}
entityType={feature.type}
refetch={refetch}
/>
),
onCell: onTagTermCell,
};

const primaryKeyColumn = {
title: 'Primary Key',
dataIndex: 'primaryKey',
key: 'primaryKey',
render: (_: any, record: MlFeature | MlPrimaryKey) =>
record.__typename === 'MLPrimaryKey' ? <CheckSquareOutlined /> : null,
width: 50,
};

const allColumns = [...defaultColumns, nameColumn, descriptionColumn, tagColumn, termColumn, primaryKeyColumn];

return (
<FeaturesContainer>
{features && features.length > 0 && (
<Table
columns={allColumns}
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
dataSource={features}
rowKey={(record) => `${record.dataType}-${record.name}`}
expandable={{ defaultExpandAllRows: true, expandRowByClick: true }}
pagination={false}
/>
)}
</FeaturesContainer>
);
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import React from 'react';

import { EntityType } from '../../../../types.generated';
import { MlPrimaryKey, MlFeature } from '../../../../types.generated';
import { useBaseEntity } from '../../shared/EntityContext';
import { GetMlModelQuery } from '../../../../graphql/mlModel.generated';
import { EntityList } from '../../shared/tabs/Entity/components/EntityList';
import TableOfMlFeatures from '../../mlFeatureTable/profile/features/TableOfMlFeatures';

export default function MlModelFeaturesTab() {
const entity = useBaseEntity() as GetMlModelQuery;

const model = entity && entity.mlModel;
const features = model?.features?.relationships.map((relationship) => relationship.entity);
const features = model?.features?.relationships.map((relationship) => relationship.entity) as Array<
MlFeature | MlPrimaryKey
>;

return <EntityList title="Features used" type={EntityType.Mlfeature} entities={features || []} />;
return <TableOfMlFeatures features={features || []} />;
}
16 changes: 15 additions & 1 deletion datahub-web-react/src/graphql/mlModel.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,21 @@ query getMLModel($urn: String!) {
...partialLineageResults
}
features: relationships(input: { types: ["Consumes"], direction: OUTGOING, start: 0, count: 100 }) {
...fullRelationshipResults
start
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice presumably this reduces latency?

count
total
relationships {
type
direction
entity {
... on MLFeature {
...nonRecursiveMLFeature
}
... on MLPrimaryKey {
...nonRecursiveMLPrimaryKey
}
}
}
}
}
}