Skip to content

Commit da1326d

Browse files
authored
fix(ui): Improve Model/Model Group description handling (truncate + editableProperties) (#14595)
1 parent f8a95b0 commit da1326d

File tree

3 files changed

+78
-4
lines changed

3 files changed

+78
-4
lines changed

datahub-web-react/src/app/entityV2/mlModel/profile/MLModelGroupsTab.tsx

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Space, Table, Typography } from 'antd';
22
import { ColumnsType } from 'antd/es/table';
33
import Link from 'antd/lib/typography/Link';
4-
import React from 'react';
4+
import React, { useState } from 'react';
55
import styled from 'styled-components';
66

77
import { useBaseEntity } from '@app/entity/shared/EntityContext';
@@ -14,11 +14,18 @@ const TabContent = styled.div`
1414
padding: 16px;
1515
`;
1616

17+
const TruncatedDescription = styled.div<{ isExpanded: boolean }>`
18+
display: -webkit-box;
19+
-webkit-line-clamp: ${({ isExpanded }) => (isExpanded ? 'unset' : '3')};
20+
-webkit-box-orient: vertical;
21+
overflow: hidden;
22+
`;
23+
1724
export default function MLModelGroupsTab() {
1825
const baseEntity = useBaseEntity<GetMlModelQuery>();
1926
const model = baseEntity?.mlModel;
20-
2127
const entityRegistry = useEntityRegistry();
28+
const [expandedRows, setExpandedRows] = useState<Set<string>>(new Set());
2229

2330
const propertyTableColumns: ColumnsType<MlModelGroup> = [
2431
{
@@ -35,6 +42,37 @@ export default function MLModelGroupsTab() {
3542
{
3643
title: 'Description',
3744
dataIndex: 'description',
45+
render: (_, record) => {
46+
const editableDesc = record.editableProperties?.description;
47+
const originalDesc = record.description;
48+
const description = editableDesc || originalDesc;
49+
50+
if (!description) return '-';
51+
52+
const isExpanded = expandedRows.has(record.urn);
53+
const isLong = description.length > 150;
54+
55+
if (!isLong) return description;
56+
57+
return (
58+
<>
59+
<TruncatedDescription isExpanded={isExpanded}>{description}</TruncatedDescription>
60+
<Typography.Link
61+
onClick={() => {
62+
const newExpanded = new Set(expandedRows);
63+
if (isExpanded) {
64+
newExpanded.delete(record.urn);
65+
} else {
66+
newExpanded.add(record.urn);
67+
}
68+
setExpandedRows(newExpanded);
69+
}}
70+
>
71+
{isExpanded ? 'Show less' : 'Read more'}
72+
</Typography.Link>
73+
</>
74+
);
75+
},
3876
},
3977
];
4078

datahub-web-react/src/app/entityV2/mlModelGroup/profile/ModelGroupModels.tsx

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Table, Typography } from 'antd';
2-
import React from 'react';
2+
import React, { useState } from 'react';
33
import styled from 'styled-components';
44

55
import { useBaseEntity } from '@app/entity/shared/EntityContext';
@@ -67,10 +67,18 @@ const VersionContainer = styled.div`
6767
align-items: center;
6868
`;
6969

70+
const TruncatedDescription = styled.div<{ isExpanded: boolean }>`
71+
display: -webkit-box;
72+
-webkit-line-clamp: ${({ isExpanded }) => (isExpanded ? 'unset' : '3')};
73+
-webkit-box-orient: vertical;
74+
overflow: hidden;
75+
`;
76+
7077
export default function MLGroupModels() {
7178
const baseEntity = useBaseEntity<GetMlModelGroupQuery>();
7279
const entityRegistry = useEntityRegistry();
7380
const modelGroup = baseEntity?.mlModelGroup;
81+
const [expandedRows, setExpandedRows] = useState<Set<string>>(new Set());
7482

7583
const models =
7684
baseEntity?.mlModelGroup?.incoming?.relationships
@@ -149,8 +157,33 @@ export default function MLGroupModels() {
149157
render: (_: any, record: any) => {
150158
const editableDesc = record.editableProperties?.description;
151159
const originalDesc = record.description;
160+
const description = editableDesc || originalDesc;
161+
162+
if (!description) return '-';
163+
164+
const isExpanded = expandedRows.has(record.urn);
165+
const isLong = description.length > 150;
152166

153-
return <Typography.Text>{editableDesc || originalDesc || '-'}</Typography.Text>;
167+
if (!isLong) return <Typography.Text>{description}</Typography.Text>;
168+
169+
return (
170+
<>
171+
<TruncatedDescription isExpanded={isExpanded}>{description}</TruncatedDescription>
172+
<Typography.Link
173+
onClick={() => {
174+
const newExpanded = new Set(expandedRows);
175+
if (isExpanded) {
176+
newExpanded.delete(record.urn);
177+
} else {
178+
newExpanded.add(record.urn);
179+
}
180+
setExpandedRows(newExpanded);
181+
}}
182+
>
183+
{isExpanded ? 'Show less' : 'Read more'}
184+
</Typography.Link>
185+
</>
186+
);
154187
},
155188
},
156189
];

datahub-web-react/src/graphql/fragments.graphql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,6 +1105,9 @@ fragment nonRecursiveMLModel on MLModel {
11051105
properties {
11061106
name
11071107
}
1108+
editableProperties {
1109+
description
1110+
}
11081111
}
11091112
customProperties {
11101113
key

0 commit comments

Comments
 (0)