Skip to content

Commit

Permalink
Merge pull request #1086 from merico-dev/1083-id_field-error-appears-…
Browse files Browse the repository at this point in the history
…during-initial-rendering-of-viz-table

1083 id field error appears during initial rendering of viz table
  • Loading branch information
GerilLeto authored Jul 31, 2023
2 parents 2fd8bb6 + b173e09 commit f268433
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 31 deletions.
2 changes: 1 addition & 1 deletion api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@devtable/api",
"version": "10.9.7",
"version": "10.9.8",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion dashboard/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@devtable/dashboard",
"version": "10.9.7",
"version": "10.9.8",
"license": "Apache-2.0",
"publishConfig": {
"access": "public",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { ClickBoxplotSeries } from './triggers';
import { DEFAULT_CONFIG, IBoxplotChartConf, IBoxplotDataItem } from './type';
import { parseDataKey } from '~/utils/data';
import { useRowDataMap } from '~/plugins/hooks/use-row-data-map';
import { Box } from '@mantine/core';

echarts.use([
DataZoomComponent,
Expand Down Expand Up @@ -79,13 +80,15 @@ export function VizBoxplotChart({ context, instance }: VizViewProps) {
return null;
}
return (
<ReactEChartsCore
echarts={echarts}
option={option}
style={{ width, height }}
onEvents={onEvents}
notMerge
theme="merico-light"
/>
<Box sx={{ width, height, overflow: 'hidden' }}>
<ReactEChartsCore
echarts={echarts}
option={option}
style={{ width, height }}
onEvents={onEvents}
notMerge
theme="merico-light"
/>
</Box>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export function VizCartesianChart({ context, instance }: VizViewProps) {

const finalHeight = Math.max(0, height - topStatsHeight - bottomStatsHeight);
return (
<Box>
<Box sx={{ width, height, overflow: 'hidden' }}>
<Text
ref={topStatsRef}
align="left"
Expand Down
56 changes: 39 additions & 17 deletions dashboard/src/plugins/viz-components/table/viz-table.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { Box, Table, TableProps, Text } from '@mantine/core';
import {
Cell,
Row,
SortingState,
createColumnHelper,
flexRender,
getCoreRowModel,
getSortedRowModel,
Row,
SortingState,
useReactTable,
} from '@tanstack/react-table';
import _ from 'lodash';
import React, { useCallback, useContext, useMemo, useState } from 'react';
import { useVirtual } from 'react-virtual';
import { useCurrentInteractionManager } from '~/interactions/hooks/use-current-interaction-manager';
Expand All @@ -18,12 +17,12 @@ import { HeadCell } from '~/plugins/viz-components/table/components/head-cell';
import { ClickCellContent } from '~/plugins/viz-components/table/triggers/click-cell-content';
import { baseTableSX, useTableStyles } from '~/plugins/viz-components/table/viz-table.styles';
import { AnyObject } from '~/types';
import { VizInstance, VizViewProps } from '~/types/plugin';
import { VizInstance, VizViewContext, VizViewProps } from '~/types/plugin';
import { parseDataKey } from '~/utils/data';
import { IVizManager, PluginContext, useStorageData } from '../..';
import { TableCellContext } from './table-cell-context';
import { DEFAULT_CONFIG, IColumnConf, ITableConf, TriggerConfigType, ValueType } from './type';
import { IColumnConf, ITableConf, TriggerConfigType, ValueType } from './type';
import { CellValue } from './value';
import { parseDataKey } from '~/utils/data';

const useGetCellContext = (context: {
vizManager: IVizManager;
Expand All @@ -40,10 +39,16 @@ const useGetCellContext = (context: {
);
};

export function VizTable({ context, instance }: VizViewProps) {
const data = context.data;
const { height, width } = context.viewport;
const { value: conf = DEFAULT_CONFIG } = useStorageData<ITableConf>(context.instanceData, 'config');
type IVizTableComponent = {
data: TPanelData;
width: number;
height: number;
conf: ITableConf;
instance: VizInstance;
context: VizViewContext;
};

function VizTableComponent({ data, width, height, conf, context, instance }: IVizTableComponent) {
const { id_field, use_raw_columns, columns, ...rest } = conf;

const { classes, cx } = useTableStyles();
Expand Down Expand Up @@ -126,13 +131,6 @@ export function VizTable({ context, instance }: VizViewProps) {
const showInfoBar = totalRows > 0;
const tableHeight = showInfoBar ? height - 22 : height;
const theadTop = showInfoBar ? 22 : 0;
if (!id_field) {
return (
<Text color="red" align="center">
ID Field is not set, can't render a table without it
</Text>
);
}
if (!Array.isArray(queryData) || queryData.length === 0) {
return (
<Text color="gray" align="center">
Expand Down Expand Up @@ -194,3 +192,27 @@ export function VizTable({ context, instance }: VizViewProps) {
</div>
);
}
export function VizTable({ context, instance }: VizViewProps) {
const data = context.data;
const { height, width } = context.viewport;
const { value: conf } = useStorageData<ITableConf>(context.instanceData, 'config');

if (!conf) {
return null;
}

if (!conf.id_field) {
console.group('🔴 what the fuck');
console.log(conf);
console.groupEnd();
return (
<Text color="red" align="center">
ID Field is not set, can't render a table without it
</Text>
);
}

return (
<VizTableComponent data={data} width={width} height={height} conf={conf} context={context} instance={instance} />
);
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@devtable/root",
"version": "10.9.7",
"version": "10.9.8",
"private": true,
"workspaces": [
"api",
Expand Down
2 changes: 1 addition & 1 deletion settings-form/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@devtable/settings-form",
"version": "10.9.7",
"version": "10.9.8",
"license": "Apache-2.0",
"publishConfig": {
"access": "public",
Expand Down
2 changes: 1 addition & 1 deletion website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@devtable/website",
"private": true,
"license": "Apache-2.0",
"version": "10.9.7",
"version": "10.9.8",
"scripts": {
"dev": "vite",
"preview": "vite preview"
Expand Down

0 comments on commit f268433

Please sign in to comment.