Skip to content

Commit 43a79a7

Browse files
committed
feat(visualizer): avoid table name being truncated
1 parent 8108b75 commit 43a79a7

File tree

6 files changed

+23
-11
lines changed

6 files changed

+23
-11
lines changed

packages/json-table-schema-visualizer/src/components/TableHeader.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const TableHeader = ({ title }: TableHeaderProps) => {
4747
align="center"
4848
strokeWidth={PADDINGS.xs}
4949
padding={PADDINGS.xs}
50-
fontSize={FONT_SIZES.lg}
50+
fontSize={FONT_SIZES.tableTitle}
5151
/>
5252
</Group>
5353
);

packages/json-table-schema-visualizer/src/constants/sizing.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export const TABLE_FIELD_TYPE_PADDING = PADDINGS.sm;
2323
export const FONT_SIZES = {
2424
md: 15,
2525
lg: 18,
26+
tableTitle: 18,
2627
};
2728

2829
export const FIELD_DETAILS_CARET = {

packages/json-table-schema-visualizer/src/hooks/table.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ export const useTableDefaultPosition = (tableName: string): XYPosition => {
5050
};
5151

5252
export const useGetTableMinWidth = (table: JSONTableTable): number => {
53-
const tableLinesTexts = getTableLinesText(table.fields, table.name);
53+
const tableLinesTexts = getTableLinesText(table.fields);
5454
const minWidth = useMemo(() => {
55-
const minW = computeTablePreferredWidth(tableLinesTexts);
55+
const minW = computeTablePreferredWidth(tableLinesTexts, table.name);
5656
tableWidthStore.setWidth(table.name, minW);
5757
return minW;
5858
}, [tableLinesTexts]);

packages/json-table-schema-visualizer/src/utils/computeTableDimension.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import { COLUMN_HEIGHT, TABLE_HEADER_HEIGHT } from "@/constants/sizing";
77
import { type Dimension } from "@/types/dimension";
88

99
export const computeTableDimension = (table: JSONTableTable): Dimension => {
10-
const tableTexts = getTableLinesText(table.fields, table.name);
11-
const width = computeTablePreferredWidth(tableTexts);
10+
const tableTexts = getTableLinesText(table.fields);
11+
const width = computeTablePreferredWidth(tableTexts, table.name);
1212
const height = TABLE_HEADER_HEIGHT + COLUMN_HEIGHT * table.fields.length;
1313

1414
return { width, height };
Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
1+
import { computeTextSize } from "../computeTextSize";
12
import { computeTextsMaxWidth } from "../computeTextsMaxWidth";
23

34
import {
5+
FONT_SIZES,
46
TABLE_DEFAULT_MIN_WIDTH,
57
TABLE_FIELD_TYPE_PADDING,
68
} from "@/constants/sizing";
79

8-
export const computeTablePreferredWidth = (tableTexts: string[]): number => {
9-
const minW = computeTextsMaxWidth(tableTexts);
10+
export const computeTablePreferredWidth = (
11+
tableTexts: string[],
12+
tableName: string,
13+
): number => {
14+
const minColsW = computeTextsMaxWidth(tableTexts);
15+
const { width: tableNameW } = computeTextSize(tableName, {
16+
fontSize: FONT_SIZES.tableTitle,
17+
});
1018

11-
return Math.max(minW + TABLE_FIELD_TYPE_PADDING * 2, TABLE_DEFAULT_MIN_WIDTH);
19+
const maxOnColsAndTableName = Math.max(minColsW, tableNameW);
20+
21+
return Math.max(
22+
maxOnColsAndTableName + TABLE_FIELD_TYPE_PADDING * 2,
23+
TABLE_DEFAULT_MIN_WIDTH,
24+
);
1225
};

packages/json-table-schema-visualizer/src/utils/tableWComputation/getTableLinesText.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ import { type JSONTableTable } from "shared/types/tableSchema";
22

33
export const getTableLinesText = (
44
fields: JSONTableTable["fields"],
5-
name: string,
65
): string[] => {
76
const stringColsNames = fields.map(
87
(field) => `${field.name} ${field.type.type_name}`,
98
);
10-
const tableLinesTexts = [name, ...stringColsNames];
119

12-
return tableLinesTexts;
10+
return stringColsNames;
1311
};

0 commit comments

Comments
 (0)