-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use accessorFn to avoid table dot notation case
- Loading branch information
1 parent
e3c683a
commit 10b595c
Showing
5 changed files
with
35 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,44 @@ | ||
import { observer } from 'mobx-react-lite'; | ||
import Box from '@mui/material/Box'; | ||
import { Table } from '@vesoft-inc/ui-components'; | ||
import { MRT_Localization_ZH_HANS } from 'material-react-table/locales/zh-Hans'; | ||
import type { ConsoleResult } from '@/interfaces/console'; | ||
import { useStore } from '@/stores'; | ||
import { JSONBig, transformNebulaResult } from '@/utils'; | ||
|
||
export default function TableResult({ result }: { result: ConsoleResult }) { | ||
export default observer(function TableResult({ result }: { result: ConsoleResult }) { | ||
const { commonStore } = useStore(); | ||
const { headers = [], tables = [] } = result.data || {}; | ||
const columns = headers.map((header) => ({ accessorKey: header, header })); | ||
const columns = headers.map((header) => ({ | ||
accessorFn: (row: Record<string, string>) => row[header], | ||
header, | ||
})); | ||
const data = tables.map((item) => { | ||
const obj = headers.reduce( | ||
(acc, key) => { | ||
acc[key] = JSONBig.stringify(transformNebulaResult(item[key])); | ||
return acc; | ||
}, | ||
{} as Record<string, unknown> | ||
{} as Record<string, string> | ||
); | ||
return obj; | ||
}); | ||
const localization = commonStore.isEnLang ? undefined : MRT_Localization_ZH_HANS; | ||
return ( | ||
<Box m={0} p={1} height="100%" overflow="hidden"> | ||
<Table | ||
columns={columns} | ||
data={data} | ||
renderBottomToolbar={false} | ||
enableStickyHeader | ||
muiTableContainerProps={{ sx: { maxHeight: '280px' } }} | ||
enableSorting | ||
muiPaginationProps={{ | ||
showRowsPerPage: false, | ||
size: 'small', | ||
}} | ||
paginationDisplayMode="pages" | ||
muiTableContainerProps={{ sx: { maxHeight: '286px' } }} | ||
localization={localization} | ||
/> | ||
</Box> | ||
); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters