From d39f88a7545177f6cad7bc1377c6273b28b3f370 Mon Sep 17 00:00:00 2001 From: Chris Kruining Date: Fri, 3 Jan 2025 04:57:05 +0100 Subject: [PATCH] refactor 'rows' -> 'data' --- src/components/grid/grid.tsx | 16 ++++++++-------- src/components/table/dataset.ts | 5 ++--- src/components/table/table.tsx | 6 +++--- src/features/file/grid.tsx | 2 +- src/routes/(editor)/experimental/grid.tsx | 2 +- 5 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/components/grid/grid.tsx b/src/components/grid/grid.tsx index ad3f036..8d127bc 100644 --- a/src/components/grid/grid.tsx +++ b/src/components/grid/grid.tsx @@ -31,30 +31,30 @@ const GridContext = createContext>(); const useGrid = () => useContext(GridContext)!; -type GridProps> = { class?: string, groupBy?: keyof T, columns: Column[], rows: DataSet, api?: (api: GridApi) => any }; +type GridProps> = { class?: string, groupBy?: keyof T, columns: Column[], data: DataSet, api?: (api: GridApi) => any }; export function Grid>(props: GridProps) { const [table, setTable] = createSignal>(); - const rows = createMemo(() => props.rows); + const data = createMemo(() => props.data); const columns = createMemo(() => props.columns as TableColumn[]); - const mutations = createMemo(() => rows().mutations()); + const mutations = createMemo(() => data().mutations()); const ctx: GridContextType = { mutations, selection: createMemo(() => table()?.selection() ?? []), mutate(row: number, column: K, value: T[K]) { - rows().mutate(row, column, value); + data().mutate(row, column, value); }, remove(indices: number[]) { - rows().remove(indices); + data().remove(indices); table()?.clear(); }, insert(row: T, at?: number) { - rows().insert(row, at); + data().insert(row, at); }, addColumn(column: keyof T, value: T[keyof T]): void { @@ -81,7 +81,7 @@ export function Grid>(props: GridProps) { return - { +
{ cellRenderers() }
; @@ -107,7 +107,7 @@ function Api>(props: { api: undefined | ((api: Gri gridContext.insert(row, at); }, addColumn(column: keyof T): void { - // gridContext.addColumn(column, value); + gridContext.addColumn(column, value); }, }; }); diff --git a/src/components/table/dataset.ts b/src/components/table/dataset.ts index 86082b6..e2bb17d 100644 --- a/src/components/table/dataset.ts +++ b/src/components/table/dataset.ts @@ -91,6 +91,8 @@ export const createDataSet = >(data: T[], initialO value = implementation(value as DataSetRowNode[]); } + console.log('dataset => nodes', value); + return value as DataSetNode[]; }); @@ -101,9 +103,6 @@ export const createDataSet = >(data: T[], initialO return deepDiff(state.snapshot, state.value).toArray(); }); - const sorting = createMemo(() => state.sorting); - const grouping = createMemo(() => state.grouping); - const set: DataSet = { data, nodes, diff --git a/src/components/table/table.tsx b/src/components/table/table.tsx index 4a35881..1a4ad48 100644 --- a/src/components/table/table.tsx +++ b/src/components/table/table.tsx @@ -73,12 +73,12 @@ export function Table>(props: TableProps) { - + ; }; -type InnerTableProps> = { class?: string, summary?: string, rows: DataSet }; +type InnerTableProps> = { class?: string, summary?: string, data: DataSet }; function InnerTable>(props: InnerTableProps) { const table = useTable(); @@ -97,7 +97,7 @@ function InnerTable>(props: InnerTableProps) { - []}>{ + []}>{ node => } diff --git a/src/features/file/grid.tsx b/src/features/file/grid.tsx index fc32a3e..4d8ec7e 100644 --- a/src/features/file/grid.tsx +++ b/src/features/file/grid.tsx @@ -71,7 +71,7 @@ export function Grid(props: { class?: string, rows: Entry[], locales: string[], }); }); - return ; + return ; }; const TextArea: Component<{ row: number, key: string, lang: string, value: string, oninput?: (event: InputEvent) => any }> = (props) => { diff --git a/src/routes/(editor)/experimental/grid.tsx b/src/routes/(editor)/experimental/grid.tsx index d92addd..1b425bd 100644 --- a/src/routes/(editor)/experimental/grid.tsx +++ b/src/routes/(editor)/experimental/grid.tsx @@ -90,7 +90,7 @@ export default function GridExperiment() {
- +
Mutations ({mutations().length})