mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-08-27 10:26:09 +00:00
fix the glossary-term loading and column size issue (#20536)
* fix the glossary-term loading and column size issue * sonar and playwright fix
This commit is contained in:
parent
eca3770a93
commit
685b5702e8
@ -598,6 +598,21 @@ export const validateGlossaryTerm = async (
|
||||
const termSelector = `[data-row-key="${escapedFqn}"]`;
|
||||
const statusSelector = `[data-testid="${escapedFqn}-status"]`;
|
||||
|
||||
await expect(page.locator('[data-testid="loader"]')).toBeHidden();
|
||||
|
||||
await expect(
|
||||
page.getByTestId('glossary-terms-table').getByText('Terms')
|
||||
).toBeVisible();
|
||||
await expect(
|
||||
page.getByTestId('glossary-terms-table').getByText('Description')
|
||||
).toBeVisible();
|
||||
await expect(
|
||||
page.getByTestId('glossary-terms-table').getByText('Owners')
|
||||
).toBeVisible();
|
||||
await expect(
|
||||
page.getByTestId('glossary-terms-table').getByText('Status')
|
||||
).toBeVisible();
|
||||
|
||||
if (isGlossaryTermPage) {
|
||||
await expect(page.getByTestId(term.name)).toBeVisible();
|
||||
} else {
|
||||
|
@ -116,8 +116,8 @@ import {
|
||||
|
||||
const GlossaryTermTab = ({ isGlossary, className }: GlossaryTermTabProps) => {
|
||||
const { currentUser } = useApplicationStore();
|
||||
const tableRef = useRef<HTMLDivElement>(null);
|
||||
const [tableWidth, setTableWidth] = useState(0);
|
||||
const tableContainerRef = useRef<HTMLDivElement>(null);
|
||||
const [containerWidth, setContainerWidth] = useState(0);
|
||||
const {
|
||||
activeGlossary,
|
||||
glossaryChildTerms,
|
||||
@ -243,8 +243,8 @@ const GlossaryTermTab = ({ isGlossary, className }: GlossaryTermTabProps) => {
|
||||
}, [isGlossary, activeGlossary]);
|
||||
|
||||
const tableColumnsWidth = useMemo(
|
||||
() => glossaryTermTableColumnsWidth(tableWidth, permissions.Create),
|
||||
[permissions.Create, tableWidth]
|
||||
() => glossaryTermTableColumnsWidth(containerWidth, permissions.Create),
|
||||
[permissions.Create, containerWidth]
|
||||
);
|
||||
|
||||
const updateGlossaryTermStatus = (
|
||||
@ -832,10 +832,23 @@ const GlossaryTermTab = ({ isGlossary, className }: GlossaryTermTabProps) => {
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (tableRef.current) {
|
||||
setTableWidth(tableRef.current.offsetWidth);
|
||||
if (!tableContainerRef.current) {
|
||||
return undefined;
|
||||
}
|
||||
}, [tableRef.current]);
|
||||
|
||||
const resizeObserver = new ResizeObserver((entries) => {
|
||||
for (const entry of entries) {
|
||||
const width = entry.contentRect.width;
|
||||
setContainerWidth(width);
|
||||
}
|
||||
});
|
||||
|
||||
resizeObserver.observe(tableContainerRef.current);
|
||||
|
||||
return () => {
|
||||
resizeObserver.disconnect();
|
||||
};
|
||||
}, [tableContainerRef.current]);
|
||||
|
||||
if (termsLoading) {
|
||||
return <Loader />;
|
||||
@ -843,6 +856,8 @@ const GlossaryTermTab = ({ isGlossary, className }: GlossaryTermTabProps) => {
|
||||
|
||||
if (isEmpty(glossaryTerms)) {
|
||||
return (
|
||||
// If there is no terms, the table container ref is not set, so we need to use a div to set the width
|
||||
<div ref={tableContainerRef}>
|
||||
<ErrorPlaceHolder
|
||||
className="m-t-xlg p-md p-b-lg"
|
||||
doc={GLOSSARIES_DOCS}
|
||||
@ -856,6 +871,7 @@ const GlossaryTermTab = ({ isGlossary, className }: GlossaryTermTabProps) => {
|
||||
}
|
||||
onClick={handleAddGlossaryTermClick}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@ -865,7 +881,8 @@ const GlossaryTermTab = ({ isGlossary, className }: GlossaryTermTabProps) => {
|
||||
|
||||
return (
|
||||
<Row className={className} gutter={[0, 16]}>
|
||||
<Col span={24}>
|
||||
{/* Have use the col to set the width of the table, to only use the viewport width for the table columns */}
|
||||
<Col className="w-full" ref={tableContainerRef} span={24}>
|
||||
{glossaryTerms.length > 0 ? (
|
||||
<DndProvider backend={HTML5Backend}>
|
||||
<Table
|
||||
@ -880,11 +897,8 @@ const GlossaryTermTab = ({ isGlossary, className }: GlossaryTermTabProps) => {
|
||||
defaultVisibleColumns={DEFAULT_VISIBLE_COLUMNS}
|
||||
expandable={expandableConfig}
|
||||
extraTableFilters={extraTableFilters}
|
||||
// Loading is set to true if the table is not loaded or the table width is not set,
|
||||
// as we are using the table width to calculate the column width
|
||||
loading={isTableLoading || !tableRef.current?.offsetWidth}
|
||||
loading={isTableLoading}
|
||||
pagination={false}
|
||||
ref={tableRef}
|
||||
rowKey="fullyQualifiedName"
|
||||
size="small"
|
||||
staticVisibleColumns={STATIC_VISIBLE_COLUMNS}
|
||||
|
@ -364,7 +364,7 @@ describe('Glossary Utils - glossaryTermTableColumnsWidth', () => {
|
||||
name: 400,
|
||||
owners: 170,
|
||||
reviewers: 330,
|
||||
status: 330,
|
||||
status: 200,
|
||||
synonyms: 330,
|
||||
});
|
||||
});
|
||||
@ -377,21 +377,8 @@ describe('Glossary Utils - glossaryTermTableColumnsWidth', () => {
|
||||
name: 400,
|
||||
owners: 170,
|
||||
reviewers: 330,
|
||||
status: 330,
|
||||
status: 200,
|
||||
synonyms: 330,
|
||||
});
|
||||
});
|
||||
|
||||
it('should return fallback width when table width is 0', () => {
|
||||
const columnWidthObject = glossaryTermTableColumnsWidth(0, false);
|
||||
|
||||
expect(columnWidthObject).toEqual({
|
||||
description: 200,
|
||||
name: 200,
|
||||
owners: 200,
|
||||
reviewers: 200,
|
||||
status: 200,
|
||||
synonyms: 200,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -447,19 +447,16 @@ export const glossaryTermTableColumnsWidth = (
|
||||
tableWidth: number,
|
||||
havingCreatePermission: boolean
|
||||
) => {
|
||||
const fallbackWidth = 200;
|
||||
|
||||
return {
|
||||
name: calculatePercentageFromValue(tableWidth, 40) || fallbackWidth,
|
||||
description:
|
||||
calculatePercentageFromValue(
|
||||
name: calculatePercentageFromValue(tableWidth, 40),
|
||||
description: calculatePercentageFromValue(
|
||||
tableWidth,
|
||||
havingCreatePermission ? 21 : 33
|
||||
) || fallbackWidth,
|
||||
reviewers: calculatePercentageFromValue(tableWidth, 33) || fallbackWidth,
|
||||
synonyms: calculatePercentageFromValue(tableWidth, 33) || fallbackWidth,
|
||||
owners: calculatePercentageFromValue(tableWidth, 17) || fallbackWidth,
|
||||
status: calculatePercentageFromValue(tableWidth, 33) || fallbackWidth,
|
||||
),
|
||||
reviewers: calculatePercentageFromValue(tableWidth, 33),
|
||||
synonyms: calculatePercentageFromValue(tableWidth, 33),
|
||||
owners: calculatePercentageFromValue(tableWidth, 17),
|
||||
status: calculatePercentageFromValue(tableWidth, 20),
|
||||
};
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user