Skip to content

Commit 71e0931

Browse files
committed
Remove react-data-table from file connection preview
1 parent f3d019c commit 71e0931

File tree

19 files changed

+297
-234
lines changed

19 files changed

+297
-234
lines changed

src/shared/types/chartkit/table.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type {ReactElement} from 'react';
2+
13
import type {Column} from '@gravity-ui/react-data-table';
24

35
import type {WrappedHTML} from '../charts';
@@ -32,6 +34,7 @@ export interface TableCommonCell {
3234
// formatted number from Wizard
3335
formattedValue?: string;
3436
css?: ChartKitCss;
37+
contentCss?: ChartKitCss;
3538
// if the column type: 'text'
3639
link?: {
3740
href: string;
@@ -55,9 +58,9 @@ export type TableCellsRow = {
5558
cells: TableCell[];
5659
};
5760
export type TableRow = TableValuesRow | TableCellsRow;
58-
export type CommonTableColumn = {
61+
export type CommonTableColumn<CT extends Record<string, unknown> = Record<string, unknown>> = {
5962
id?: string;
60-
name: string;
63+
name: string | ReactElement;
6164
formattedName?: WrappedHTML | string;
6265
type: TableCommonCellType;
6366
group?: boolean;
@@ -67,10 +70,11 @@ export type CommonTableColumn = {
6770
width?: Column<unknown>['width'];
6871
/** @deprecated seems like only for type=grid */
6972
contentCss?: ChartKitCss;
73+
innerContentCss?: ChartKitCss;
7074
sortable?: boolean;
7175
allowGroupSort?: boolean;
7276
/** Reserved subspace to store options and values for customized functionality */
73-
custom?: Record<string, any>;
77+
custom?: CT;
7478
pinned?: boolean;
7579
hint?: string;
7680
};
@@ -133,9 +137,10 @@ export type TableColumn =
133137
| BarTableColumn;
134138
type TableSubColumn = {
135139
id?: string;
136-
name: string;
140+
name: string | ReactElement;
137141
formattedName?: WrappedHTML | string;
138142
css?: ChartKitCss;
143+
innerContentCss?: ChartKitCss;
139144
markup: MarkupItem;
140145
sub: (TableColumn | TableSubColumn)[];
141146
width?: string;

src/ui/libs/DatalensChartkit/ChartKit/components/Widget/components/Table/utils/render.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ export const getColumnsAndNames = ({
386386
});
387387
const columnName = generateName({
388388
id: column.id,
389-
name: column.name,
389+
...(typeof column.name === 'string' ? {name: column.name} : null),
390390
level,
391391
shift,
392392
index,
@@ -423,7 +423,13 @@ export const getColumnsAndNames = ({
423423
} else {
424424
const {id, name, type, css: columnCss, group, autogroup, ...options} = column;
425425
const columnWidth = topLevelWidth || column.width;
426-
const columnName = generateName({id, name, level, shift, index});
426+
const columnName = generateName({
427+
id,
428+
...(typeof name === 'string' ? {name} : null),
429+
level,
430+
shift,
431+
index,
432+
});
427433

428434
const isColumnSortable =
429435
typeof column.sortable === 'undefined' ? true : column.sortable;

src/ui/libs/DatalensChartkit/ChartKit/plugins/Table/renderer/TableWidget.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ const TableWidget = React.forwardRef<ChartKitWidgetRef | undefined, TableWidgetP
2828
backgroundColor,
2929
isQlPreviewTable = false,
3030
qa = ChartKitTableQa.Widget,
31+
emptyDataMessage,
32+
className,
3133
} = props;
3234

3335
const generatedId = React.useMemo(
@@ -91,11 +93,12 @@ const TableWidget = React.forwardRef<ChartKitWidgetRef | undefined, TableWidgetP
9193
);
9294

9395
return (
94-
<div className={b()} data-qa={qa} ref={ref}>
96+
<div className={b({}, className)} data-qa={qa} ref={ref}>
9597
{dimensions ? (
9698
<Table
9799
widgetData={props.data}
98100
dimensions={dimensions}
101+
emptyDataMessage={emptyDataMessage}
99102
onChangeParams={handleChangeParams}
100103
onReady={handleTableReady}
101104
backgroundColor={backgroundColor}

src/ui/libs/DatalensChartkit/ChartKit/plugins/Table/renderer/components/Table/Table.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type Props = {
4747
onReady?: () => void;
4848
backgroundColor?: string;
4949
disableCellFormatting?: boolean;
50+
emptyDataMessage?: string;
5051
};
5152

5253
export const Table = React.memo<Props>((props: Props) => {
@@ -57,6 +58,7 @@ export const Table = React.memo<Props>((props: Props) => {
5758
onReady,
5859
backgroundColor,
5960
disableCellFormatting = false,
61+
emptyDataMessage,
6062
} = props;
6163
const {config, data: originalData, unresolvedParams, params: currentParams} = widgetData;
6264
const title = getTableTitle(config);
@@ -273,7 +275,7 @@ export const Table = React.memo<Props>((props: Props) => {
273275
<div className={b('table-wrapper', {'highlight-rows': highlightRows, size})}>
274276
{noData && (
275277
<div className={b('no-data')}>
276-
{i18n('chartkit-table', 'message-no-data')}
278+
{emptyDataMessage || i18n('chartkit-table', 'message-no-data')}
277279
</div>
278280
)}
279281
{!noData && (

src/ui/libs/DatalensChartkit/ChartKit/plugins/Table/renderer/components/Table/TableHead.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export const TableHead = React.memo<Props>((props: Props) => {
4949
className={b('th-content', {
5050
sortable: th.sortable,
5151
})}
52+
style={th.contentStyle}
5253
>
5354
{th.content}
5455
<SortIcon className={b('sort-icon')} sorting={th.sorting} />

src/ui/libs/DatalensChartkit/ChartKit/plugins/Table/renderer/components/Table/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export type HeadCellViewData = {
8181
sortable: boolean;
8282
pinned: boolean;
8383
style?: React.CSSProperties;
84+
contentStyle?: React.CSSProperties;
8485
sorting: 'asc' | 'desc' | false;
8586
content: JSX.Element | React.ReactNode;
8687
onClick: () => void;

src/ui/libs/DatalensChartkit/ChartKit/plugins/Table/renderer/components/Table/usePreparedTableData.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import type {
3434
} from './types';
3535
import {
3636
createTableColumns,
37+
getCellCustomContentStyle,
3738
getCellCustomStyle,
3839
getColumnId,
3940
getElementBackgroundColor,
@@ -361,6 +362,7 @@ export const usePreparedTableData = (props: {
361362
originalCellData,
362363
tableBgColor,
363364
);
365+
const cellContentStyle = getCellCustomContentStyle(originalCellData);
364366

365367
if (pinned) {
366368
cellStyle.left = leftPositions[originalCellData?.index ?? -1];
@@ -383,6 +385,7 @@ export const usePreparedTableData = (props: {
383385
sortable,
384386
pinned,
385387
style: cellStyle,
388+
contentStyle: cellContentStyle,
386389
sorting: header.column.getIsSorted(),
387390
content: flexRender(
388391
header.column.columnDef.header,
@@ -477,7 +480,8 @@ export const usePreparedTableData = (props: {
477480
cellStyle.wordBreak = 'break-word';
478481
}
479482

480-
const contentStyle: React.CSSProperties = {};
483+
const contentStyle: React.CSSProperties =
484+
getCellCustomContentStyle(originalHeadData);
481485
if (typeof originalHeadData?.width !== 'undefined') {
482486
contentStyle.width = originalHeadData.width;
483487
}

src/ui/libs/DatalensChartkit/ChartKit/plugins/Table/renderer/components/Table/utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,3 +329,7 @@ export function getCellCustomStyle(cellData: unknown, tableBgColor?: string) {
329329

330330
return css;
331331
}
332+
333+
export function getCellCustomContentStyle(cellData: unknown) {
334+
return {...camelCaseCss(get(cellData, 'contentCss', {}))} as React.CSSProperties;
335+
}

src/ui/libs/DatalensChartkit/ChartKit/plugins/Table/renderer/utils/renderer.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import {calculateNumericProperty} from './math';
3333
const b = block('chartkit-table-widget');
3434

3535
export type HeadCell = THead & {
36-
name: string;
36+
name: string | React.ReactElement;
3737
formattedName?: WrappedHTML | string;
3838
fieldId?: string;
3939
custom?: unknown;
@@ -60,7 +60,7 @@ export function mapHeadCell(args: {
6060
type: th.markup ? 'markup' : columnType,
6161
} as TableCommonCell;
6262
return (
63-
<span data-qa={ChartKitTableQa.HeadCellContent}>
63+
<span style={th.innerContentCss} data-qa={ChartKitTableQa.HeadCellContent}>
6464
{renderCellContent({cell, column: th, header: true, onRender: onRenderCell})}
6565
{hint && <MarkdownHelpPopover markdown={hint} />}
6666
</span>
@@ -127,6 +127,10 @@ export function renderCellContent(args: {
127127
const cellView = get(cell, 'view', get(column, 'view'));
128128
const cellType = cell.type ?? get(column, 'type');
129129

130+
if (React.isValidElement(cell.value)) {
131+
return cell.value;
132+
}
133+
130134
if (cellType === 'markup' || isMarkupItem(cell.value)) {
131135
return <MarkupCell cell={cell} />;
132136
}

src/ui/libs/DatalensChartkit/ChartKit/plugins/Table/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@ export type TableWidgetProps = {
1616
backgroundColor?: string;
1717
isQlPreviewTable?: boolean;
1818
qa?: string;
19+
emptyDataMessage?: string;
20+
className?: string;
1921
};

0 commit comments

Comments
 (0)