@dxos/react-ui-table 0.8.4-main.f5c0578 → 0.8.4-main.fcfe5033a5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/chunk-BF54SSNL.mjs +70 -0
- package/dist/lib/browser/chunk-BF54SSNL.mjs.map +7 -0
- package/dist/lib/browser/{chunk-ZAOSIG3L.mjs → chunk-F7Y374KL.mjs} +739 -802
- package/dist/lib/browser/chunk-F7Y374KL.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +1208 -1158
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +34 -43
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/browser/types/index.mjs +3 -3
- package/dist/lib/node-esm/{chunk-ZOFFI3JJ.mjs → chunk-CCJ4LOVM.mjs} +739 -801
- package/dist/lib/node-esm/chunk-CCJ4LOVM.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-SIRDIPHZ.mjs +71 -0
- package/dist/lib/node-esm/chunk-SIRDIPHZ.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +1208 -1158
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +34 -43
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/types/index.mjs +3 -3
- package/dist/types/src/components/Table/ColumnActionsMenu.d.ts +1 -2
- package/dist/types/src/components/Table/ColumnActionsMenu.d.ts.map +1 -1
- package/dist/types/src/components/Table/ColumnSettings.d.ts +2 -2
- package/dist/types/src/components/Table/ColumnSettings.d.ts.map +1 -1
- package/dist/types/src/components/Table/DynamicTable.d.ts +7 -7
- package/dist/types/src/components/Table/DynamicTable.d.ts.map +1 -1
- package/dist/types/src/components/Table/DynamicTable.stories.d.ts +35 -3
- package/dist/types/src/components/Table/DynamicTable.stories.d.ts.map +1 -1
- package/dist/types/src/components/Table/Relations.stories.d.ts +106 -5
- package/dist/types/src/components/Table/Relations.stories.d.ts.map +1 -1
- package/dist/types/src/components/Table/RowActionsMenu.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.d.ts +21 -19
- package/dist/types/src/components/Table/Table.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.stories.d.ts +108 -5
- package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
- package/dist/types/src/components/Table/TableContent.d.ts +17 -0
- package/dist/types/src/components/Table/TableContent.d.ts.map +1 -0
- package/dist/types/src/components/Table/TableToolbar.d.ts +21 -0
- package/dist/types/src/components/Table/TableToolbar.d.ts.map +1 -0
- package/dist/types/src/components/TableCellEditor/CellValidationMessage.d.ts +1 -1
- package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts +13 -9
- package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts +7 -14
- package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts +38 -5
- package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/index.d.ts +1 -0
- package/dist/types/src/components/TableCellEditor/index.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +0 -1
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/components/testing.d.ts +23 -16
- package/dist/types/src/components/testing.d.ts.map +1 -1
- package/dist/types/src/hooks/index.d.ts +2 -1
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useAddRow.d.ts +6 -6
- package/dist/types/src/hooks/useAddRow.d.ts.map +1 -1
- package/dist/types/src/hooks/useProjectionModel.d.ts +6 -0
- package/dist/types/src/hooks/useProjectionModel.d.ts.map +1 -0
- package/dist/types/src/hooks/useTableModel.d.ts +9 -9
- package/dist/types/src/hooks/useTableModel.d.ts.map +1 -1
- package/dist/types/src/model/modal-controller.d.ts +5 -8
- package/dist/types/src/model/modal-controller.d.ts.map +1 -1
- package/dist/types/src/model/selection-model.d.ts +17 -8
- package/dist/types/src/model/selection-model.d.ts.map +1 -1
- package/dist/types/src/model/table-model.d.ts +110 -29
- package/dist/types/src/model/table-model.d.ts.map +1 -1
- package/dist/types/src/model/table-presentation.d.ts +4 -2
- package/dist/types/src/model/table-presentation.d.ts.map +1 -1
- package/dist/types/src/playwright/TableManager.d.ts +2 -1
- package/dist/types/src/playwright/TableManager.d.ts.map +1 -1
- package/dist/types/src/testing/useTestTableModel.d.ts +18 -34
- package/dist/types/src/testing/useTestTableModel.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +21 -23
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/Table.d.ts +26 -0
- package/dist/types/src/types/Table.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +1 -1
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/src/util/dynamic-table.d.ts +14 -12
- package/dist/types/src/util/dynamic-table.d.ts.map +1 -1
- package/dist/types/src/util/dynamic-table.test.d.ts +2 -0
- package/dist/types/src/util/dynamic-table.test.d.ts.map +1 -0
- package/dist/types/src/util/index.d.ts +2 -1
- package/dist/types/src/util/index.d.ts.map +1 -1
- package/dist/types/src/util/query-ast.d.ts +7 -0
- package/dist/types/src/util/query-ast.d.ts.map +1 -0
- package/dist/types/src/util/schema.d.ts +1 -1
- package/dist/types/src/util/schema.d.ts.map +1 -1
- package/dist/types/src/util/sort.d.ts +12 -0
- package/dist/types/src/util/sort.d.ts.map +1 -0
- package/dist/types/src/util/table-buttons.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +58 -57
- package/src/components/Table/ColumnActionsMenu.tsx +15 -11
- package/src/components/Table/ColumnSettings.tsx +8 -9
- package/src/components/Table/DynamicTable.stories.tsx +36 -34
- package/src/components/Table/DynamicTable.tsx +33 -36
- package/src/components/Table/Relations.stories.tsx +180 -59
- package/src/components/Table/RowActionsMenu.tsx +24 -15
- package/src/components/Table/Table.stories.tsx +152 -129
- package/src/components/Table/Table.tsx +46 -391
- package/src/components/Table/TableContent.tsx +421 -0
- package/src/components/Table/TableToolbar.tsx +111 -0
- package/src/components/TableCellEditor/CellValidationMessage.tsx +5 -5
- package/src/components/TableCellEditor/FormCellEditor.tsx +134 -40
- package/src/components/TableCellEditor/TableCellEditor.stories.tsx +35 -72
- package/src/components/TableCellEditor/TableCellEditor.tsx +80 -224
- package/src/components/TableCellEditor/index.ts +1 -0
- package/src/components/index.ts +0 -1
- package/src/components/testing.ts +44 -18
- package/src/hooks/index.ts +2 -1
- package/src/hooks/useAddRow.ts +14 -14
- package/src/hooks/useProjectionModel.ts +39 -0
- package/src/hooks/useTableModel.ts +36 -34
- package/src/model/modal-controller.ts +23 -40
- package/src/model/selection-model.ts +75 -44
- package/src/model/table-model.test.ts +91 -56
- package/src/model/table-model.ts +447 -172
- package/src/model/table-presentation.test.ts +68 -58
- package/src/model/table-presentation.ts +97 -73
- package/src/playwright/TableManager.ts +13 -6
- package/src/playwright/playwright.config.ts +1 -1
- package/src/playwright/smoke.spec.ts +92 -46
- package/src/testing/useTestTableModel.ts +50 -40
- package/src/translations.ts +20 -22
- package/src/types/Table.ts +79 -0
- package/src/types/index.ts +1 -1
- package/src/util/dynamic-table.test.ts +70 -0
- package/src/util/dynamic-table.ts +45 -32
- package/src/util/index.ts +2 -1
- package/src/util/query-ast.ts +22 -0
- package/src/util/schema.ts +4 -4
- package/src/util/sort.ts +90 -0
- package/src/util/table-buttons.ts +3 -3
- package/src/util/table-controls.ts +2 -2
- package/dist/lib/browser/chunk-L2LSB6KV.mjs +0 -18
- package/dist/lib/browser/chunk-L2LSB6KV.mjs.map +0 -7
- package/dist/lib/browser/chunk-ZAOSIG3L.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-NXZ4CJYX.mjs +0 -20
- package/dist/lib/node-esm/chunk-NXZ4CJYX.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-ZOFFI3JJ.mjs.map +0 -7
- package/dist/types/src/components/Table/CreateRefPanel.d.ts +0 -9
- package/dist/types/src/components/Table/CreateRefPanel.d.ts.map +0 -1
- package/dist/types/src/components/TableCellEditor/extension.d.ts +0 -13
- package/dist/types/src/components/TableCellEditor/extension.d.ts.map +0 -1
- package/dist/types/src/components/TableToolbar/TableToolbar.d.ts +0 -21
- package/dist/types/src/components/TableToolbar/TableToolbar.d.ts.map +0 -1
- package/dist/types/src/components/TableToolbar/index.d.ts +0 -2
- package/dist/types/src/components/TableToolbar/index.d.ts.map +0 -1
- package/dist/types/src/model/table-sorting.d.ts +0 -53
- package/dist/types/src/model/table-sorting.d.ts.map +0 -1
- package/dist/types/src/types/schema.d.ts +0 -8
- package/dist/types/src/types/schema.d.ts.map +0 -1
- package/dist/types/src/util/table.d.ts +0 -12
- package/dist/types/src/util/table.d.ts.map +0 -1
- package/src/components/Table/CreateRefPanel.tsx +0 -86
- package/src/components/TableCellEditor/extension.ts +0 -61
- package/src/components/TableToolbar/TableToolbar.tsx +0 -102
- package/src/components/TableToolbar/index.ts +0 -5
- package/src/model/table-sorting.ts +0 -216
- package/src/types/schema.ts +0 -16
- package/src/util/table.ts +0 -53
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { Rx } from '@effect-rx/rx-react';
|
|
6
|
-
import React, { useMemo } from 'react';
|
|
7
|
-
|
|
8
|
-
import { live } from '@dxos/live-object';
|
|
9
|
-
import { type ThemedClassName } from '@dxos/react-ui';
|
|
10
|
-
import {
|
|
11
|
-
type ActionGraphEdges,
|
|
12
|
-
type ActionGraphNodes,
|
|
13
|
-
type ActionGraphProps,
|
|
14
|
-
type MenuAction,
|
|
15
|
-
MenuProvider,
|
|
16
|
-
ToolbarMenu,
|
|
17
|
-
createGapSeparator,
|
|
18
|
-
createMenuAction,
|
|
19
|
-
useMenuActions,
|
|
20
|
-
} from '@dxos/react-ui-menu';
|
|
21
|
-
import { rxFromSignal } from '@dxos/react-ui-menu';
|
|
22
|
-
|
|
23
|
-
import { translationKey } from '../../translations';
|
|
24
|
-
|
|
25
|
-
export type TableToolbarActionProperties = { type: TableToolbarActionType };
|
|
26
|
-
|
|
27
|
-
export type TableToolbarAction = MenuAction<TableToolbarActionProperties>;
|
|
28
|
-
|
|
29
|
-
export type TableToolbarActionType = 'add-row' | 'comment' | 'save-view';
|
|
30
|
-
|
|
31
|
-
type TableToolbarState = Partial<{ viewDirty: boolean }>;
|
|
32
|
-
|
|
33
|
-
export type TableToolbarProps = ThemedClassName<
|
|
34
|
-
TableToolbarState & {
|
|
35
|
-
onAdd: () => void;
|
|
36
|
-
onSave: () => void;
|
|
37
|
-
attendableId?: string;
|
|
38
|
-
customActions?: Rx.Rx<ActionGraphProps>;
|
|
39
|
-
}
|
|
40
|
-
>;
|
|
41
|
-
|
|
42
|
-
const createTableToolbarActions = ({
|
|
43
|
-
state,
|
|
44
|
-
onAdd,
|
|
45
|
-
onSave,
|
|
46
|
-
customActions,
|
|
47
|
-
}: {
|
|
48
|
-
state: TableToolbarState;
|
|
49
|
-
onAdd: () => void;
|
|
50
|
-
onSave: () => void;
|
|
51
|
-
customActions?: Rx.Rx<ActionGraphProps>;
|
|
52
|
-
}) =>
|
|
53
|
-
Rx.make((get) => {
|
|
54
|
-
const add = createMenuAction<TableToolbarActionProperties>('add-row', onAdd, {
|
|
55
|
-
type: 'add-row' as const,
|
|
56
|
-
icon: 'ph--plus--regular',
|
|
57
|
-
label: ['add row', { ns: translationKey }],
|
|
58
|
-
testId: 'table.toolbar.add-row',
|
|
59
|
-
});
|
|
60
|
-
const save = createMenuAction<TableToolbarActionProperties>('save-view', onSave, {
|
|
61
|
-
type: 'save-view' as const,
|
|
62
|
-
icon: 'ph--floppy-disk--regular',
|
|
63
|
-
label: ['save view label', { ns: translationKey }],
|
|
64
|
-
testId: 'table.toolbar.save-view',
|
|
65
|
-
iconOnly: false,
|
|
66
|
-
hidden: get(rxFromSignal(() => !state.viewDirty)),
|
|
67
|
-
});
|
|
68
|
-
const gap = createGapSeparator();
|
|
69
|
-
const nodes: ActionGraphNodes = [add, save, ...gap.nodes];
|
|
70
|
-
const edges: ActionGraphEdges = nodes.map(({ id: target }) => ({ source: 'root', target }));
|
|
71
|
-
if (customActions) {
|
|
72
|
-
const custom = get(customActions);
|
|
73
|
-
nodes.push(...custom.nodes);
|
|
74
|
-
edges.push(...custom.edges);
|
|
75
|
-
}
|
|
76
|
-
return {
|
|
77
|
-
nodes,
|
|
78
|
-
edges,
|
|
79
|
-
};
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
export const TableToolbar = ({
|
|
83
|
-
classNames,
|
|
84
|
-
viewDirty,
|
|
85
|
-
attendableId,
|
|
86
|
-
onAdd,
|
|
87
|
-
onSave,
|
|
88
|
-
customActions,
|
|
89
|
-
}: TableToolbarProps) => {
|
|
90
|
-
const state = useMemo(() => live<TableToolbarState>({ viewDirty }), []);
|
|
91
|
-
const actionsCreator = useMemo(
|
|
92
|
-
() => createTableToolbarActions({ state, onAdd, onSave, customActions }),
|
|
93
|
-
[state, onAdd, onSave, customActions],
|
|
94
|
-
);
|
|
95
|
-
const menu = useMenuActions(actionsCreator);
|
|
96
|
-
|
|
97
|
-
return (
|
|
98
|
-
<MenuProvider {...menu} attendableId={attendableId}>
|
|
99
|
-
<ToolbarMenu classNames={classNames} />
|
|
100
|
-
</MenuProvider>
|
|
101
|
-
);
|
|
102
|
-
};
|
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { type ReadonlySignal, type Signal, computed, signal } from '@preact/signals-core';
|
|
6
|
-
import orderBy from 'lodash.orderby';
|
|
7
|
-
|
|
8
|
-
import { type FieldSortType, FormatEnum, type SortDirectionType, TypeEnum, getValue } from '@dxos/echo-schema';
|
|
9
|
-
import { formatForDisplay } from '@dxos/react-ui-form';
|
|
10
|
-
import type { DataType, FieldType, ProjectionModel, PropertyType } from '@dxos/schema';
|
|
11
|
-
|
|
12
|
-
import { type TableRow } from './table-model';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Represents the local sort state.
|
|
16
|
-
* - undefined: No local sort set, fallback to view sort.
|
|
17
|
-
* - cleared: Sort explicitly cleared by user.
|
|
18
|
-
* - active: Active local sort with sort configuration.
|
|
19
|
-
*/
|
|
20
|
-
type LocalSort = { type: 'cleared' } | { type: 'active'; sort: FieldSortType } | undefined;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Manages table sorting functionality through display and data index mapping.
|
|
24
|
-
*
|
|
25
|
-
* When a table is sorted, rows visually reorder but we need to maintain references
|
|
26
|
-
* to the original data positions. This is handled through two types of indices:
|
|
27
|
-
*
|
|
28
|
-
* - Display indices: The visual positions after sorting
|
|
29
|
-
* - Data indices: The original positions in the source data
|
|
30
|
-
*
|
|
31
|
-
* The _displayToDataIndex map maintains these relationships, enabling lookups
|
|
32
|
-
* between visual and source positions.
|
|
33
|
-
*
|
|
34
|
-
* Example mapping between display and data indices:
|
|
35
|
-
*
|
|
36
|
-
* Original Data: Sorted Display: Mapping: (Display → Data)
|
|
37
|
-
* ┌──────────────┐ ┌──────────────┐ ┌────────┐
|
|
38
|
-
* │ 0: "Banana" │ => │ 0: "Apple" │ => │ 0 => 1 │
|
|
39
|
-
* │ 1: "Apple" │ => │ 1: "Banana" │ => │ 1 => 0 │
|
|
40
|
-
* │ 2: "Cherry" │ => │ 2: "Cherry" │ => │ 2 => 2 │
|
|
41
|
-
* └──────────────┘ └──────────────┘ └────────┘
|
|
42
|
-
*/
|
|
43
|
-
export class TableSorting<T extends TableRow> {
|
|
44
|
-
private readonly _displayToDataIndex = new Map<number, number>();
|
|
45
|
-
private readonly _rows: Signal<T[]>;
|
|
46
|
-
private readonly _localSort = signal<LocalSort>(undefined);
|
|
47
|
-
private readonly _isDirty: ReadonlySignal<boolean>;
|
|
48
|
-
public readonly sortedRows: ReadonlySignal<T[]>;
|
|
49
|
-
|
|
50
|
-
constructor(
|
|
51
|
-
rows: Signal<T[]>,
|
|
52
|
-
private readonly _view: DataType.View,
|
|
53
|
-
private readonly _projection: ProjectionModel,
|
|
54
|
-
) {
|
|
55
|
-
this._rows = rows;
|
|
56
|
-
this._isDirty = computed(() => {
|
|
57
|
-
const local = this._localSort.value;
|
|
58
|
-
const viewSort = this._view.query.sort?.[0];
|
|
59
|
-
if (local?.type === 'cleared') {
|
|
60
|
-
return viewSort !== undefined;
|
|
61
|
-
}
|
|
62
|
-
if (local?.type === 'active') {
|
|
63
|
-
if (!viewSort) {
|
|
64
|
-
return true;
|
|
65
|
-
}
|
|
66
|
-
return local.sort.fieldId !== viewSort.fieldId || local.sort.direction !== viewSort.direction;
|
|
67
|
-
}
|
|
68
|
-
return false;
|
|
69
|
-
});
|
|
70
|
-
this.sortedRows = this.initialiseSortedRows();
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* @reactive
|
|
75
|
-
* @returns Local sort if present, falls back to view sort.
|
|
76
|
-
*/
|
|
77
|
-
public get sorting(): FieldSortType | undefined {
|
|
78
|
-
const local = this._localSort.value;
|
|
79
|
-
if (local?.type === 'cleared') {
|
|
80
|
-
return undefined;
|
|
81
|
-
}
|
|
82
|
-
if (local?.type === 'active') {
|
|
83
|
-
return local.sort;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return this._view.query.sort?.[0];
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* @reactive
|
|
91
|
-
* @returns Whether local sort differs from view sort.
|
|
92
|
-
*/
|
|
93
|
-
public get isDirty(): boolean {
|
|
94
|
-
return this._isDirty.value;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
public getDataIndex(displayIndex: number): number {
|
|
98
|
-
return this._displayToDataIndex.get(displayIndex) ?? displayIndex;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
public setSort(fieldId: string, direction: SortDirectionType): void {
|
|
102
|
-
this._localSort.value = {
|
|
103
|
-
type: 'active',
|
|
104
|
-
sort: { fieldId, direction },
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
public toggleSort(fieldId: string): void {
|
|
109
|
-
if (!this.sorting || this.sorting.fieldId !== fieldId) {
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
switch (this.sorting.direction) {
|
|
114
|
-
case 'asc': {
|
|
115
|
-
this.setSort(fieldId, 'desc');
|
|
116
|
-
break;
|
|
117
|
-
}
|
|
118
|
-
case 'desc': {
|
|
119
|
-
this.setSort(fieldId, 'asc');
|
|
120
|
-
break;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
public clearSort(): void {
|
|
126
|
-
this._localSort.value = { type: 'cleared' };
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
public save(): void {
|
|
130
|
-
if (this._localSort.value !== undefined) {
|
|
131
|
-
if (this._localSort.value.type === 'active') {
|
|
132
|
-
this._view.query.sort = [this._localSort.value.sort];
|
|
133
|
-
} else {
|
|
134
|
-
this._view.query.sort = [];
|
|
135
|
-
}
|
|
136
|
-
this._localSort.value = undefined;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
//
|
|
141
|
-
// Initialisation.
|
|
142
|
-
//
|
|
143
|
-
|
|
144
|
-
private initialiseSortedRows(): ReadonlySignal<T[]> {
|
|
145
|
-
return computed(() => {
|
|
146
|
-
this._displayToDataIndex.clear();
|
|
147
|
-
const sort = this.sorting;
|
|
148
|
-
if (!sort) {
|
|
149
|
-
return this._rows.value;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
const field = this._projection.fields.find((f) => f.id === sort.fieldId);
|
|
153
|
-
if (!field) {
|
|
154
|
-
return this._rows.value;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const { props } = this._projection.getFieldProjection(field.id);
|
|
158
|
-
|
|
159
|
-
const dataWithIndices = this._rows.value.map((item, index) => {
|
|
160
|
-
const sortValue = this.getSortValue(props, field, item);
|
|
161
|
-
const isEmpty = !(props.type === TypeEnum.Boolean) && (sortValue == null || sortValue === '');
|
|
162
|
-
|
|
163
|
-
return { item, index, value: sortValue, isEmpty };
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
const ordered = orderBy(dataWithIndices, ['isEmpty', 'value'], ['asc', sort.direction]);
|
|
167
|
-
|
|
168
|
-
ordered.forEach(({ index: dataIndex }, displayIndex) => {
|
|
169
|
-
if (displayIndex !== dataIndex) {
|
|
170
|
-
this._displayToDataIndex.set(displayIndex, dataIndex);
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
return ordered.map(({ item }) => item);
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
private getSortValue(props: PropertyType, field: FieldType, item: T) {
|
|
179
|
-
const { type, format } = props;
|
|
180
|
-
const value = getValue(item, field.path);
|
|
181
|
-
|
|
182
|
-
if (type === TypeEnum.Boolean) {
|
|
183
|
-
return !!value; // Coerce null/undefined to false for booleans.
|
|
184
|
-
}
|
|
185
|
-
if (type === TypeEnum.Number) {
|
|
186
|
-
return value;
|
|
187
|
-
}
|
|
188
|
-
if (value == null) {
|
|
189
|
-
return value;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* For single select fields, the sort value is determined by the index of the option in the
|
|
194
|
-
* options array. This ensures sort order matches the configured option order.
|
|
195
|
-
*/
|
|
196
|
-
if (format === FormatEnum.SingleSelect) {
|
|
197
|
-
const options = props.options;
|
|
198
|
-
if (!options) {
|
|
199
|
-
return undefined;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
const option = options.find((option) => option.id === value);
|
|
203
|
-
return option ? options.indexOf(option) : undefined;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
// TODO(ZaymonFC): Should we format this returned value for display based on the referenced prop format?
|
|
207
|
-
// Right now we're going to be sorting based on the raw values.
|
|
208
|
-
// Maybe we need to recurse this function with the referenced prop format and field?
|
|
209
|
-
if (format === FormatEnum.Ref && field.referencePath) {
|
|
210
|
-
const refValue = getValue(value.target, field.referencePath);
|
|
211
|
-
return refValue;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
return formatForDisplay({ type, format, value });
|
|
215
|
-
}
|
|
216
|
-
}
|
package/src/types/schema.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { Schema } from 'effect';
|
|
6
|
-
|
|
7
|
-
import { Type } from '@dxos/echo';
|
|
8
|
-
import { JsonPath } from '@dxos/effect';
|
|
9
|
-
|
|
10
|
-
export const TableView = Schema.Struct({
|
|
11
|
-
sizes: Schema.Record({
|
|
12
|
-
key: JsonPath,
|
|
13
|
-
value: Schema.Number,
|
|
14
|
-
}).pipe(Schema.mutable),
|
|
15
|
-
}).pipe(Type.Obj({ typename: 'dxos.org/type/TableView', version: '0.1.0' }));
|
|
16
|
-
export type TableView = Schema.Schema.Type<typeof TableView>;
|
package/src/util/table.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { Match } from 'effect';
|
|
6
|
-
|
|
7
|
-
import { Obj } from '@dxos/echo';
|
|
8
|
-
import { type JsonPath, type JsonSchemaType, toEffectSchema } from '@dxos/echo-schema';
|
|
9
|
-
import { type SimpleType } from '@dxos/effect';
|
|
10
|
-
import { type CreateViewFromSpaceProps, type DataType, createViewFromSpace, getSchemaProperties } from '@dxos/schema';
|
|
11
|
-
|
|
12
|
-
import { TableView } from '../types';
|
|
13
|
-
|
|
14
|
-
type CreateTableProps = Omit<CreateViewFromSpaceProps, 'presentation'> & {
|
|
15
|
-
sizes?: Record<string, number>;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export const createTable = async ({
|
|
19
|
-
sizes,
|
|
20
|
-
...props
|
|
21
|
-
}: CreateTableProps): Promise<{
|
|
22
|
-
jsonSchema: JsonSchemaType;
|
|
23
|
-
view: DataType.View;
|
|
24
|
-
schema: ReturnType<typeof toEffectSchema>;
|
|
25
|
-
}> => {
|
|
26
|
-
const table = Obj.make(TableView, { sizes: {} });
|
|
27
|
-
const { jsonSchema, view } = await createViewFromSpace({ ...props, presentation: table });
|
|
28
|
-
|
|
29
|
-
// Preset sizes.
|
|
30
|
-
const schema = toEffectSchema(jsonSchema);
|
|
31
|
-
const shouldIncludeId = props.fields?.find((field) => field === 'id') !== undefined;
|
|
32
|
-
const properties = getSchemaProperties(schema.ast, {}, shouldIncludeId);
|
|
33
|
-
for (const property of properties) {
|
|
34
|
-
if (sizes?.[property.name]) {
|
|
35
|
-
table.sizes[property.name as JsonPath] = sizes[property.name];
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
Match.type<SimpleType>().pipe(
|
|
40
|
-
Match.when('boolean', () => {
|
|
41
|
-
table.sizes[property.name as JsonPath] = 100;
|
|
42
|
-
}),
|
|
43
|
-
Match.when('number', () => {
|
|
44
|
-
table.sizes[property.name as JsonPath] = 100;
|
|
45
|
-
}),
|
|
46
|
-
Match.orElse(() => {
|
|
47
|
-
// Noop.
|
|
48
|
-
}),
|
|
49
|
-
)(property.type);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return { jsonSchema, schema, view };
|
|
53
|
-
};
|