Skip to content

An open source alternative to Tableau. Embeddable visual analytic

optimize: dataTable optimize (#223)

islxyqwee544712f784f
diff --git a/packages/graphic-walker/src/Table.tsx b/packages/graphic-walker/src/Table.tsx
index 2972d20d..90ecdd32 100644
--- a/packages/graphic-walker/src/Table.tsx
+++ b/packages/graphic-walker/src/Table.tsx
@@ -11,6 +11,7 @@ import { guardDataKeys } from './utils/dataPrep';
import { getComputation } from './computation/clientComputation';
import DatasetTable from './components/dataTable';
import { useCurrentMediaTheme } from './utils/media';
+import { toJS } from 'mobx';
export type BaseTableProps = IAppI18nProps &
IErrorHandlerProps &
@@ -55,13 +56,16 @@ export const TableApp = observer(function VizApp(props: BaseTableProps) {
() => (computation ? withErrorReport(withTimeout(computation, computationTimeout), (err) => reportError(parseErrorMessage(err), 501)) : async () => []),
[reportError, computation, computationTimeout]
);
+
+ const metas = React.useMemo(() => toJS(vizStore.meta), [vizStore.meta])
+
return (
<ErrorContext value={{ reportError }}>
<ErrorBoundary fallback={<div>Something went wrong</div>} onError={props.onError}>
<ComputationContext.Provider value={wrappedComputation}>
<div className={`${darkMode === 'dark' ? 'dark' : ''} App font-sans bg-white dark:bg-zinc-900 dark:text-white m-0 p-0`}>
<div className="bg-white dark:bg-zinc-900 dark:text-white">
- <DatasetTable size={pageSize} metas={vizStore.meta} computation={wrappedComputation} />
+ <DatasetTable size={pageSize} metas={metas} computation={wrappedComputation} />
</div>
</div>
</ComputationContext.Provider>
diff --git a/packages/graphic-walker/src/components/dataTable/index.tsx b/packages/graphic-walker/src/components/dataTable/index.tsx
index dfd54f07..2c2be5cc 100644
--- a/packages/graphic-walker/src/components/dataTable/index.tsx
+++ b/packages/graphic-walker/src/components/dataTable/index.tsx
@@ -292,17 +292,17 @@ const DataTable: React.FC<DataTableProps> = (props) => {
</nav>
<div className="overflow-y-auto" style={{ maxHeight: '600px' }}>
- <table className="min-w-full divide-y relative border-x border-gray-200 dark:border-gray-700">
+ <table className="min-w-full relative border-x border-gray-200 dark:border-gray-700">
<thead className="">
{headers.map((row) => (
<tr className="divide-x divide-gray-200 dark:divide-gray-700" key={`row_${getHeaderKey(row[0])}`}>
- {row.map((f) => (
+ {row.map((f, i) => (
<th
colSpan={f.colSpan}
rowSpan={f.rowSpan}
key={getHeaderKey(f)}
- className="align-top sticky top-0 bg-white dark:bg-zinc-900"
- // style={{ zIndex: -100 }}
+ className="align-top sticky top-0 bg-white dark:bg-zinc-900 p-0"
+ style={{ zIndex: row.length - i }}
>
<div className="border-b border-gray-200 dark:border-gray-700">
{f.type === 'name' && (
@@ -329,7 +329,6 @@ const DataTable: React.FC<DataTableProps> = (props) => {
)}
{onMetaChange && (
<DropdownContext
- position="right-0"
options={semanticTypeList}
onSelect={(value) => {
onMetaChange(f.value.fid, f.fIndex, {
diff --git a/packages/graphic-walker/src/components/dataTable/pagination.tsx b/packages/graphic-walker/src/components/dataTable/pagination.tsx
index dfd4c809..a982a22f 100644
--- a/packages/graphic-walker/src/components/dataTable/pagination.tsx
+++ b/packages/graphic-walker/src/components/dataTable/pagination.tsx
@@ -15,9 +15,12 @@ interface PaginationProps {
pageSize?: number;
extendPageNumber?: number;
}
-function btnStylePrefix(className?: string) {
- return `rounded-md border border-gray-300 bg-white dark:bg-zinc-900 px-2.5 py-1.5 text-xs font-medium text-gray-700 dark:text-gray-200 hover:bg-gray-50 dark:hover:bg-gray-800 ${className}`;
+function btnStylePrefix(...className: string[]) {
+ return `rounded-md px-2.5 py-1.5 text-xs font-medium ${className?.join(' ')}`;
}
+
+const defaultColor = 'ring-1 ring-inset ring-gray-300 bg-white dark:bg-zinc-900 text-gray-700 dark:text-gray-200 hover:bg-gray-50 dark:hover:bg-gray-800';
+
export default function Pagination(props: PaginationProps) {
const { total, onNext, onPrev, pageIndex, onPageChange, pageSize = 100, extendPageNumber = 1 } = props;
const { t } = useTranslation();
@@ -50,55 +53,44 @@ export default function Pagination(props: PaginationProps) {
}
return pagesUnique;
}, [pageIndex, pageSize, extendPageNumber, total, pageIndex]);
- return showIndices.length > 0 ? (
- <div className="flex flex-1 justify-between sm:justify-end gap-2">
+
+ const pageButton = (index: number) => {
+ return (
<button
+ key={index}
+ className={btnStylePrefix('inline-block', index === pageIndex ? 'bg-indigo-600 text-white' : defaultColor)}
onClick={() => {
- onPrev();
+ onPageChange && onPageChange(index);
}}
- className="relative inline-flex items-center rounded-md border border-gray-300 bg-white dark:bg-zinc-900 px-2.5 py-1.5 text-xs font-medium text-gray-700 dark:text-gray-200 hover:bg-gray-50 dark:hover:bg-gray-800"
>
- {t('actions.prev')}
+ {index + 1}
</button>
+ );
+ };
+
+ return showIndices.length > 0 ? (
+ <div className="flex flex-1 justify-between sm:justify-end gap-2">
<button
- className={btnStylePrefix('inline-block')}
onClick={() => {
- onPageChange && onPageChange(showIndices[0].index);
+ onPrev();
}}
+ className="relative inline-flex items-center rounded-md border border-gray-300 bg-white dark:bg-zinc-900 px-2.5 py-1.5 text-xs font-medium text-gray-700 dark:text-gray-200 hover:bg-gray-50 dark:hover:bg-gray-800"
>
- {showIndices[0].index + 1}
+ {t('actions.prev')}
</button>
+ {pageButton(showIndices[0].index)}
{showIndices.length > 2 && showIndices[1].index > showIndices[0].index + 1 && (
- <div className={btnStylePrefix('inline-block')} aria-hidden>
+ <div className={btnStylePrefix('inline-block', defaultColor)} aria-hidden>
...
</div>
)}
- {showIndices.slice(1, -1).map((page) => (
- <button
- key={page.index}
- className={btnStylePrefix('inline-block')}
- onClick={() => {
- onPageChange && onPageChange(page.index);
- }}
- >
- {page.index + 1}
- </button>
- ))}
+ {showIndices.slice(1, -1).map((page) => pageButton(page.index))}
{showIndices.length > 2 && showIndices[showIndices.length - 1].index > showIndices[showIndices.length - 2].index + 1 && (
- <div className={btnStylePrefix('inline-block')} aria-hidden>
+ <div className={btnStylePrefix('inline-block', defaultColor)} aria-hidden>
...
</div>
)}
- {showIndices.length > 2 && (
- <button
- className={btnStylePrefix('inline-block')}
- onClick={() => {
- onPageChange && onPageChange(showIndices[showIndices.length - 1].index);
- }}
- >
- {showIndices[showIndices.length - 1].index + 1}
- </button>
- )}
+ {showIndices.length > 2 && pageButton(showIndices[showIndices.length - 1].index)}
<button
onClick={() => {
onNext();
diff --git a/packages/graphic-walker/src/dataSource/datasetConfig/index.tsx b/packages/graphic-walker/src/dataSource/datasetConfig/index.tsx
index 9340d6a5..a2cc28c2 100644
--- a/packages/graphic-walker/src/dataSource/datasetConfig/index.tsx
+++ b/packages/graphic-walker/src/dataSource/datasetConfig/index.tsx
@@ -2,16 +2,18 @@ import React from 'react';
import DatasetTable from '../../components/dataTable';
import { observer } from 'mobx-react-lite';
import { useCompututaion, useVizStore } from '../../store';
+import { toJS } from 'mobx';
const DatasetConfig: React.FC = () => {
const vizStore = useVizStore();
const computation = useCompututaion();
+ const metas = React.useMemo(() => toJS(vizStore.meta), [vizStore.meta]);
return (
<div className="relative">
<DatasetTable
size={100}
- metas={vizStore.meta}
+ metas={metas}
computation={computation}
onMetaChange={(fid, fIndex, diffMeta) => {
vizStore.updateCurrentDatasetMetas(fid, diffMeta);