@adecore/database 0.0.1 → 0.16.0-beta.0
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/LICENSE +21 -0
- package/README.md +152 -1
- package/dist/DatabaseProvider.d.ts +13 -0
- package/dist/DatabaseProvider.js +17 -0
- package/dist/actions.d.ts +40 -0
- package/dist/actions.js +1 -0
- package/dist/client/client.d.ts +5 -0
- package/dist/client/client.js +245 -0
- package/dist/client/index.d.ts +2 -0
- package/dist/client/index.js +2 -0
- package/dist/client/types.d.ts +97 -0
- package/dist/client/types.js +13 -0
- package/dist/client-context.d.ts +16 -0
- package/dist/client-context.js +17 -0
- package/dist/connections/ConnectionForm.d.ts +10 -0
- package/dist/connections/ConnectionForm.js +145 -0
- package/dist/connections/ConnectionManager.d.ts +12 -0
- package/dist/connections/ConnectionManager.js +93 -0
- package/dist/connections/EngineIcon.d.ts +9 -0
- package/dist/connections/EngineIcon.js +7 -0
- package/dist/connections/connection-config.d.ts +16 -0
- package/dist/connections/connection-config.js +107 -0
- package/dist/connections/docker.d.ts +9 -0
- package/dist/connections/docker.js +38 -0
- package/dist/connections/engine-icons.d.ts +3 -0
- package/dist/connections/engine-icons.js +3 -0
- package/dist/connections/use-docker-containers.d.ts +17 -0
- package/dist/connections/use-docker-containers.js +26 -0
- package/dist/console/DestructiveDialog.d.ts +9 -0
- package/dist/console/DestructiveDialog.js +9 -0
- package/dist/console/HistoryPanel.d.ts +10 -0
- package/dist/console/HistoryPanel.js +15 -0
- package/dist/console/QueryConsole.d.ts +14 -0
- package/dist/console/QueryConsole.js +261 -0
- package/dist/console/SchemaPicker.d.ts +11 -0
- package/dist/console/SchemaPicker.js +8 -0
- package/dist/console/SqlEditor.d.ts +12 -0
- package/dist/console/SqlEditor.js +61 -0
- package/dist/console/StatementResultView.d.ts +18 -0
- package/dist/console/StatementResultView.js +32 -0
- package/dist/console/TransactionControls.d.ts +13 -0
- package/dist/console/TransactionControls.js +12 -0
- package/dist/console/destructive.d.ts +7 -0
- package/dist/console/destructive.js +43 -0
- package/dist/console/editing.d.ts +12 -0
- package/dist/console/editing.js +60 -0
- package/dist/console/history.d.ts +13 -0
- package/dist/console/history.js +43 -0
- package/dist/console/labels.d.ts +1 -0
- package/dist/console/labels.js +6 -0
- package/dist/console/outcome.d.ts +6 -0
- package/dist/console/outcome.js +11 -0
- package/dist/console/schemas.d.ts +2 -0
- package/dist/console/schemas.js +5 -0
- package/dist/console/shortcuts.d.ts +2 -0
- package/dist/console/shortcuts.js +3 -0
- package/dist/console/useConsoleHistory.d.ts +7 -0
- package/dist/console/useConsoleHistory.js +22 -0
- package/dist/ddl/alter-mysql.d.ts +4 -0
- package/dist/ddl/alter-mysql.js +79 -0
- package/dist/ddl/alter-sqlite.d.ts +4 -0
- package/dist/ddl/alter-sqlite.js +80 -0
- package/dist/ddl/alter.d.ts +4 -0
- package/dist/ddl/alter.js +24 -0
- package/dist/ddl/column.d.ts +9 -0
- package/dist/ddl/column.js +62 -0
- package/dist/ddl/create.d.ts +12 -0
- package/dist/ddl/create.js +74 -0
- package/dist/ddl/dialect.d.ts +12 -0
- package/dist/ddl/dialect.js +34 -0
- package/dist/ddl/diff.d.ts +34 -0
- package/dist/ddl/diff.js +111 -0
- package/dist/ddl/draft.d.ts +46 -0
- package/dist/ddl/draft.js +70 -0
- package/dist/ddl/index.d.ts +10 -0
- package/dist/ddl/index.js +10 -0
- package/dist/ddl/parse.d.ts +17 -0
- package/dist/ddl/parse.js +131 -0
- package/dist/ddl/statements.d.ts +6 -0
- package/dist/ddl/statements.js +12 -0
- package/dist/ddl/types.d.ts +6 -0
- package/dist/ddl/types.js +52 -0
- package/dist/ddl/validate.d.ts +7 -0
- package/dist/ddl/validate.js +38 -0
- package/dist/designer/ColumnsEditor.d.ts +2 -0
- package/dist/designer/ColumnsEditor.js +24 -0
- package/dist/designer/DesignerView.d.ts +25 -0
- package/dist/designer/DesignerView.js +33 -0
- package/dist/designer/ForeignKeysEditor.d.ts +7 -0
- package/dist/designer/ForeignKeysEditor.js +24 -0
- package/dist/designer/IndexesEditor.d.ts +2 -0
- package/dist/designer/IndexesEditor.js +13 -0
- package/dist/designer/NamePicker.d.ts +11 -0
- package/dist/designer/NamePicker.js +13 -0
- package/dist/designer/OptionsEditor.d.ts +2 -0
- package/dist/designer/OptionsEditor.js +17 -0
- package/dist/designer/SqlPreview.d.ts +12 -0
- package/dist/designer/SqlPreview.js +17 -0
- package/dist/designer/TableDesigner.d.ts +10 -0
- package/dist/designer/TableDesigner.js +103 -0
- package/dist/designer/edit.d.ts +17 -0
- package/dist/designer/edit.js +115 -0
- package/dist/designer/editor-props.d.ts +10 -0
- package/dist/designer/editor-props.js +1 -0
- package/dist/designer/plan.d.ts +9 -0
- package/dist/designer/plan.js +13 -0
- package/dist/designer/recover.d.ts +2 -0
- package/dist/designer/recover.js +18 -0
- package/dist/designer/useReferenceColumns.d.ts +3 -0
- package/dist/designer/useReferenceColumns.js +36 -0
- package/dist/explorer/DatabaseExplorer.d.ts +13 -0
- package/dist/explorer/DatabaseExplorer.js +264 -0
- package/dist/explorer/RowMenu.d.ts +11 -0
- package/dist/explorer/RowMenu.js +89 -0
- package/dist/explorer/TableDialog.d.ts +15 -0
- package/dist/explorer/TableDialog.js +50 -0
- package/dist/explorer/expansion.d.ts +7 -0
- package/dist/explorer/expansion.js +31 -0
- package/dist/explorer/table-statements.d.ts +5 -0
- package/dist/explorer/table-statements.js +12 -0
- package/dist/explorer/tree.d.ts +125 -0
- package/dist/explorer/tree.js +295 -0
- package/dist/explorer/use-explorer-loads.d.ts +12 -0
- package/dist/explorer/use-explorer-loads.js +109 -0
- package/dist/explorer/use-stored-expansion.d.ts +9 -0
- package/dist/explorer/use-stored-expansion.js +47 -0
- package/dist/grid/CellEditor.d.ts +9 -0
- package/dist/grid/CellEditor.js +29 -0
- package/dist/grid/CopyAsMenu.d.ts +7 -0
- package/dist/grid/CopyAsMenu.js +10 -0
- package/dist/grid/DataGrid.d.ts +36 -0
- package/dist/grid/DataGrid.js +512 -0
- package/dist/grid/EnumPicker.d.ts +17 -0
- package/dist/grid/EnumPicker.js +53 -0
- package/dist/grid/GridHeaderCell.d.ts +36 -0
- package/dist/grid/GridHeaderCell.js +69 -0
- package/dist/grid/RecordView.d.ts +20 -0
- package/dist/grid/RecordView.js +126 -0
- package/dist/grid/ValueDock.d.ts +11 -0
- package/dist/grid/ValueDock.js +28 -0
- package/dist/grid/aggregates.d.ts +22 -0
- package/dist/grid/aggregates.js +62 -0
- package/dist/grid/cell-range.d.ts +14 -0
- package/dist/grid/cell-range.js +11 -0
- package/dist/grid/column-layout.d.ts +18 -0
- package/dist/grid/column-layout.js +49 -0
- package/dist/grid/column-selection.d.ts +11 -0
- package/dist/grid/column-selection.js +28 -0
- package/dist/grid/column-view.d.ts +10 -0
- package/dist/grid/column-view.js +23 -0
- package/dist/grid/copy-formats.d.ts +15 -0
- package/dist/grid/copy-formats.js +80 -0
- package/dist/grid/display.d.ts +20 -0
- package/dist/grid/display.js +81 -0
- package/dist/grid/edit-value.d.ts +5 -0
- package/dist/grid/edit-value.js +55 -0
- package/dist/grid/enum-type.d.ts +7 -0
- package/dist/grid/enum-type.js +52 -0
- package/dist/grid/focused-value.d.ts +4 -0
- package/dist/grid/focused-value.js +19 -0
- package/dist/grid/layout.d.ts +22 -0
- package/dist/grid/layout.js +74 -0
- package/dist/grid/navigation.d.ts +15 -0
- package/dist/grid/navigation.js +52 -0
- package/dist/grid/row-selection.d.ts +9 -0
- package/dist/grid/row-selection.js +24 -0
- package/dist/grid/sort.d.ts +7 -0
- package/dist/grid/sort.js +7 -0
- package/dist/grid/types.d.ts +30 -0
- package/dist/grid/types.js +9 -0
- package/dist/host/helper-path.d.ts +7 -0
- package/dist/host/helper-path.js +15 -0
- package/dist/host/host.d.ts +2 -0
- package/dist/host/host.js +343 -0
- package/dist/host/index.d.ts +5 -0
- package/dist/host/index.js +4 -0
- package/dist/host/spawn.d.ts +7 -0
- package/dist/host/spawn.js +98 -0
- package/dist/host/types.d.ts +19 -0
- package/dist/host/types.js +1 -0
- package/dist/host/validate.d.ts +10 -0
- package/dist/host/validate.js +339 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +13 -0
- package/dist/locales/en.json +577 -0
- package/dist/locales/nl.json +577 -0
- package/dist/locales.d.ts +4 -0
- package/dist/locales.js +14 -0
- package/dist/protocol/connection.d.ts +56 -0
- package/dist/protocol/connection.js +1 -0
- package/dist/protocol/errors.d.ts +7 -0
- package/dist/protocol/errors.js +1 -0
- package/dist/protocol/index.d.ts +5 -0
- package/dist/protocol/index.js +3 -0
- package/dist/protocol/messages.d.ts +250 -0
- package/dist/protocol/messages.js +2 -0
- package/dist/protocol/schema.d.ts +53 -0
- package/dist/protocol/schema.js +1 -0
- package/dist/protocol/values.d.ts +21 -0
- package/dist/protocol/values.js +15 -0
- package/dist/sql-split.d.ts +15 -0
- package/dist/sql-split.js +201 -0
- package/dist/sql.d.ts +29 -0
- package/dist/sql.js +104 -0
- package/dist/structure/StructureView.d.ts +14 -0
- package/dist/structure/StructureView.js +99 -0
- package/dist/structure/structure-text.d.ts +2 -0
- package/dist/structure/structure-text.js +2 -0
- package/dist/table/CommandField.d.ts +14 -0
- package/dist/table/CommandField.js +157 -0
- package/dist/table/ImportDialog.d.ts +27 -0
- package/dist/table/ImportDialog.js +28 -0
- package/dist/table/TableStatusBar.d.ts +19 -0
- package/dist/table/TableStatusBar.js +22 -0
- package/dist/table/TableToolbar.d.ts +43 -0
- package/dist/table/TableToolbar.js +16 -0
- package/dist/table/TableView.d.ts +13 -0
- package/dist/table/TableView.js +508 -0
- package/dist/table/command-field.d.ts +57 -0
- package/dist/table/command-field.js +203 -0
- package/dist/table/grid-rows.d.ts +23 -0
- package/dist/table/grid-rows.js +55 -0
- package/dist/table/import-mapping.d.ts +7 -0
- package/dist/table/import-mapping.js +28 -0
- package/dist/table/layout-store.d.ts +13 -0
- package/dist/table/layout-store.js +43 -0
- package/dist/table/paging.d.ts +12 -0
- package/dist/table/paging.js +20 -0
- package/dist/table/pending.d.ts +32 -0
- package/dist/table/pending.js +94 -0
- package/dist/table/references.d.ts +12 -0
- package/dist/table/references.js +21 -0
- package/dist/table/useLoaded.d.ts +7 -0
- package/dist/table/useLoaded.js +36 -0
- package/dist/table/useStoredLayout.d.ts +8 -0
- package/dist/table/useStoredLayout.js +39 -0
- package/dist/table/useTableTransfer.d.ts +51 -0
- package/dist/table/useTableTransfer.js +125 -0
- package/dist/testing/fake.d.ts +21 -0
- package/dist/testing/fake.js +372 -0
- package/dist/testing/index.d.ts +1 -0
- package/dist/testing/index.js +1 -0
- package/dist/use-popup-press.d.ts +1 -0
- package/dist/use-popup-press.js +24 -0
- package/dist/use-schema-change.d.ts +1 -0
- package/dist/use-schema-change.js +13 -0
- package/dist/use-stable-callback.d.ts +1 -0
- package/dist/use-stable-callback.js +9 -0
- package/dist/value/ValuePanel.d.ts +14 -0
- package/dist/value/ValuePanel.js +103 -0
- package/dist/value/draft.d.ts +33 -0
- package/dist/value/draft.js +44 -0
- package/dist/value/hex.d.ts +14 -0
- package/dist/value/hex.js +46 -0
- package/dist/value/json.d.ts +9 -0
- package/dist/value/json.js +71 -0
- package/dist/value/views.d.ts +22 -0
- package/dist/value/views.js +54 -0
- package/dist/workbench/DatabaseWorkbench.d.ts +9 -0
- package/dist/workbench/DatabaseWorkbench.js +179 -0
- package/dist/workbench/DesignerTab.d.ts +10 -0
- package/dist/workbench/DesignerTab.js +22 -0
- package/dist/workbench/TableTab.d.ts +10 -0
- package/dist/workbench/TableTab.js +8 -0
- package/dist/workbench/tabs.d.ts +42 -0
- package/dist/workbench/tabs.js +139 -0
- package/package.json +79 -3
- package/src/DatabaseProvider.tsx +37 -0
- package/src/actions.ts +34 -0
- package/src/client/client.ts +324 -0
- package/src/client/index.ts +18 -0
- package/src/client/types.ts +161 -0
- package/src/client-context.ts +35 -0
- package/src/connections/ConnectionForm.tsx +474 -0
- package/src/connections/ConnectionManager.tsx +224 -0
- package/src/connections/EngineIcon.tsx +18 -0
- package/src/connections/connection-config.ts +143 -0
- package/src/connections/docker.ts +50 -0
- package/src/connections/engine-icons.ts +5 -0
- package/src/connections/use-docker-containers.ts +41 -0
- package/src/console/DestructiveDialog.tsx +40 -0
- package/src/console/HistoryPanel.tsx +67 -0
- package/src/console/QueryConsole.tsx +439 -0
- package/src/console/SchemaPicker.tsx +32 -0
- package/src/console/SqlEditor.tsx +95 -0
- package/src/console/StatementResultView.tsx +176 -0
- package/src/console/TransactionControls.tsx +53 -0
- package/src/console/destructive.ts +60 -0
- package/src/console/editing.ts +77 -0
- package/src/console/history.ts +62 -0
- package/src/console/labels.ts +7 -0
- package/src/console/outcome.ts +14 -0
- package/src/console/schemas.ts +7 -0
- package/src/console/shortcuts.ts +4 -0
- package/src/console/useConsoleHistory.ts +39 -0
- package/src/ddl/alter-mysql.ts +90 -0
- package/src/ddl/alter-sqlite.ts +93 -0
- package/src/ddl/alter.ts +29 -0
- package/src/ddl/column.ts +74 -0
- package/src/ddl/create.ts +92 -0
- package/src/ddl/dialect.ts +53 -0
- package/src/ddl/diff.ts +164 -0
- package/src/ddl/draft.ts +136 -0
- package/src/ddl/index.ts +10 -0
- package/src/ddl/parse.ts +161 -0
- package/src/ddl/statements.ts +20 -0
- package/src/ddl/types.ts +60 -0
- package/src/ddl/validate.ts +47 -0
- package/src/designer/ColumnsEditor.tsx +204 -0
- package/src/designer/DesignerView.tsx +184 -0
- package/src/designer/ForeignKeysEditor.tsx +132 -0
- package/src/designer/IndexesEditor.tsx +63 -0
- package/src/designer/NamePicker.tsx +44 -0
- package/src/designer/OptionsEditor.tsx +101 -0
- package/src/designer/SqlPreview.tsx +56 -0
- package/src/designer/TableDesigner.tsx +186 -0
- package/src/designer/edit.ts +137 -0
- package/src/designer/editor-props.ts +13 -0
- package/src/designer/plan.ts +25 -0
- package/src/designer/recover.ts +20 -0
- package/src/designer/useReferenceColumns.ts +54 -0
- package/src/explorer/DatabaseExplorer.tsx +450 -0
- package/src/explorer/RowMenu.tsx +134 -0
- package/src/explorer/TableDialog.tsx +80 -0
- package/src/explorer/expansion.ts +47 -0
- package/src/explorer/table-statements.ts +18 -0
- package/src/explorer/tree.ts +453 -0
- package/src/explorer/use-explorer-loads.ts +157 -0
- package/src/explorer/use-stored-expansion.ts +66 -0
- package/src/grid/CellEditor.tsx +53 -0
- package/src/grid/CopyAsMenu.tsx +33 -0
- package/src/grid/DataGrid.tsx +871 -0
- package/src/grid/EnumPicker.tsx +108 -0
- package/src/grid/GridHeaderCell.tsx +243 -0
- package/src/grid/RecordView.tsx +293 -0
- package/src/grid/ValueDock.tsx +52 -0
- package/src/grid/aggregates.ts +94 -0
- package/src/grid/cell-range.ts +26 -0
- package/src/grid/column-layout.ts +71 -0
- package/src/grid/column-selection.ts +42 -0
- package/src/grid/column-view.ts +35 -0
- package/src/grid/copy-formats.ts +108 -0
- package/src/grid/display.ts +109 -0
- package/src/grid/edit-value.ts +60 -0
- package/src/grid/enum-type.ts +62 -0
- package/src/grid/focused-value.ts +23 -0
- package/src/grid/layout.ts +91 -0
- package/src/grid/navigation.ts +74 -0
- package/src/grid/row-selection.ts +35 -0
- package/src/grid/sort.ts +12 -0
- package/src/grid/types.ts +59 -0
- package/src/host/helper-path.ts +41 -0
- package/src/host/host.ts +456 -0
- package/src/host/index.ts +5 -0
- package/src/host/spawn.ts +124 -0
- package/src/host/types.ts +46 -0
- package/src/host/validate.ts +402 -0
- package/src/index.ts +37 -0
- package/src/locales/en.json +577 -0
- package/src/locales/nl.json +577 -0
- package/src/locales.ts +18 -0
- package/src/protocol/connection.ts +86 -0
- package/src/protocol/errors.ts +38 -0
- package/src/protocol/index.ts +33 -0
- package/src/protocol/messages.ts +168 -0
- package/src/protocol/schema.ts +76 -0
- package/src/protocol/values.ts +52 -0
- package/src/sql-split.ts +220 -0
- package/src/sql.ts +152 -0
- package/src/structure/StructureView.tsx +269 -0
- package/src/structure/structure-text.ts +4 -0
- package/src/table/CommandField.tsx +318 -0
- package/src/table/ImportDialog.tsx +168 -0
- package/src/table/TableStatusBar.tsx +91 -0
- package/src/table/TableToolbar.tsx +217 -0
- package/src/table/TableView.tsx +880 -0
- package/src/table/command-field.ts +285 -0
- package/src/table/grid-rows.ts +80 -0
- package/src/table/import-mapping.ts +37 -0
- package/src/table/layout-store.ts +62 -0
- package/src/table/paging.ts +33 -0
- package/src/table/pending.ts +143 -0
- package/src/table/references.ts +38 -0
- package/src/table/useLoaded.ts +58 -0
- package/src/table/useStoredLayout.ts +53 -0
- package/src/table/useTableTransfer.ts +187 -0
- package/src/testing/fake.ts +533 -0
- package/src/testing/index.ts +1 -0
- package/src/use-popup-press.ts +27 -0
- package/src/use-schema-change.ts +19 -0
- package/src/use-stable-callback.ts +12 -0
- package/src/value/ValuePanel.tsx +254 -0
- package/src/value/draft.ts +72 -0
- package/src/value/hex.ts +62 -0
- package/src/value/json.ts +74 -0
- package/src/value/views.ts +68 -0
- package/src/workbench/DatabaseWorkbench.tsx +348 -0
- package/src/workbench/DesignerTab.tsx +37 -0
- package/src/workbench/TableTab.tsx +27 -0
- package/src/workbench/tabs.ts +184 -0
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import type { Ref } from 'react';
|
|
2
|
+
import clsx from 'clsx';
|
|
3
|
+
import {
|
|
4
|
+
ChevronsLeft,
|
|
5
|
+
ChevronsRight,
|
|
6
|
+
CopyPlus,
|
|
7
|
+
Download,
|
|
8
|
+
Ellipsis,
|
|
9
|
+
FileInput,
|
|
10
|
+
PanelRight,
|
|
11
|
+
Plus,
|
|
12
|
+
RefreshCw,
|
|
13
|
+
Rows3,
|
|
14
|
+
TableProperties,
|
|
15
|
+
Trash2,
|
|
16
|
+
Undo2
|
|
17
|
+
} from 'lucide-react';
|
|
18
|
+
import { useTranslation } from 'react-i18next';
|
|
19
|
+
import { Button, Icon, IconButton, Menu } from '@adecore/ui';
|
|
20
|
+
import { formatNumber } from '@adecore/ui/format';
|
|
21
|
+
import type { Engine, FileFormat } from '../protocol/index.ts';
|
|
22
|
+
import { CommandField } from './CommandField.tsx';
|
|
23
|
+
import type { Chip, CommandColumn } from './command-field.ts';
|
|
24
|
+
import { PAGE_SIZES, type PageBounds } from './paging.ts';
|
|
25
|
+
|
|
26
|
+
/* The menu of export and import; present only when the app can show file dialogs. */
|
|
27
|
+
export interface TransferMenu {
|
|
28
|
+
/* An export is running. */
|
|
29
|
+
busy: boolean;
|
|
30
|
+
onExport(format: FileFormat): void;
|
|
31
|
+
/* Left out where rows cannot be added. */
|
|
32
|
+
onImport?(): void;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const EXPORT_FORMATS: readonly FileFormat[] = ['csv', 'tsv', 'json', 'sql'];
|
|
36
|
+
|
|
37
|
+
export interface TableToolbarProps {
|
|
38
|
+
refreshing: boolean;
|
|
39
|
+
/* Why rows cannot be added, changed or deleted, or `null` when they can. */
|
|
40
|
+
readOnlyReason: string | null;
|
|
41
|
+
hasSelection: boolean;
|
|
42
|
+
/* Whether any selected row has a change to take back. */
|
|
43
|
+
canRevertSelection: boolean;
|
|
44
|
+
valuePanelOpen: boolean;
|
|
45
|
+
/* The record view replaces the grid with the focused row as a list of fields. */
|
|
46
|
+
recordViewOpen?: boolean;
|
|
47
|
+
transfer?: TransferMenu;
|
|
48
|
+
pendingCount: number;
|
|
49
|
+
submitting: boolean;
|
|
50
|
+
engine: Engine;
|
|
51
|
+
chips: readonly Chip[];
|
|
52
|
+
/* The columns the command field suggests. */
|
|
53
|
+
columns: readonly CommandColumn[];
|
|
54
|
+
pageSize: number;
|
|
55
|
+
bounds: PageBounds;
|
|
56
|
+
/* The text input of the command field, for the owner to focus. */
|
|
57
|
+
commandRef?: Ref<HTMLInputElement>;
|
|
58
|
+
onChipsChange(next: Chip[]): void;
|
|
59
|
+
onJumpToColumn(name: string): void;
|
|
60
|
+
onRefresh(): void;
|
|
61
|
+
onAddRow(): void;
|
|
62
|
+
onDeleteRows(): void;
|
|
63
|
+
onCloneRows(): void;
|
|
64
|
+
onRevertRows(): void;
|
|
65
|
+
onToggleValuePanel(): void;
|
|
66
|
+
onToggleRecordView?(): void;
|
|
67
|
+
onPageSizeChange(size: number): void;
|
|
68
|
+
onFirstPage(): void;
|
|
69
|
+
/* Counts the rows first when they are not counted yet. */
|
|
70
|
+
onLastPage(): void;
|
|
71
|
+
onSubmit(): void;
|
|
72
|
+
onRevert(): void;
|
|
73
|
+
className?: string;
|
|
74
|
+
ref?: Ref<HTMLDivElement>;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/* The command field for filtering, sorting and jumping to a column, refresh, add row, the submit of pending changes, and a menu of the rest. */
|
|
78
|
+
export function TableToolbar({
|
|
79
|
+
refreshing,
|
|
80
|
+
readOnlyReason,
|
|
81
|
+
hasSelection,
|
|
82
|
+
canRevertSelection,
|
|
83
|
+
valuePanelOpen,
|
|
84
|
+
recordViewOpen = false,
|
|
85
|
+
transfer,
|
|
86
|
+
pendingCount,
|
|
87
|
+
submitting,
|
|
88
|
+
engine,
|
|
89
|
+
chips,
|
|
90
|
+
columns,
|
|
91
|
+
pageSize,
|
|
92
|
+
bounds,
|
|
93
|
+
commandRef,
|
|
94
|
+
onChipsChange,
|
|
95
|
+
onJumpToColumn,
|
|
96
|
+
onRefresh,
|
|
97
|
+
onAddRow,
|
|
98
|
+
onDeleteRows,
|
|
99
|
+
onCloneRows,
|
|
100
|
+
onRevertRows,
|
|
101
|
+
onToggleValuePanel,
|
|
102
|
+
onToggleRecordView,
|
|
103
|
+
onPageSizeChange,
|
|
104
|
+
onFirstPage,
|
|
105
|
+
onLastPage,
|
|
106
|
+
onSubmit,
|
|
107
|
+
onRevert,
|
|
108
|
+
className,
|
|
109
|
+
ref
|
|
110
|
+
}: TableToolbarProps) {
|
|
111
|
+
const { t } = useTranslation('database');
|
|
112
|
+
const readOnly = readOnlyReason !== null;
|
|
113
|
+
const tooltipOf = (label: string): string => (readOnly ? t('table.unavailable', { action: label, reason: readOnlyReason }) : label);
|
|
114
|
+
|
|
115
|
+
return (
|
|
116
|
+
<div ref={ref} className={clsx('flex shrink-0 items-center gap-2 border-b border-border px-3 py-2', className)}>
|
|
117
|
+
<CommandField chips={chips} columns={columns} engine={engine} inputRef={commandRef} onChipsChange={onChipsChange} onJumpToColumn={onJumpToColumn} />
|
|
118
|
+
{pendingCount > 0 && (
|
|
119
|
+
<>
|
|
120
|
+
<Button variant="primary" size="sm" disabled={submitting} onClick={onSubmit}>
|
|
121
|
+
{t('table.submit', { changes: formatNumber(pendingCount) })}
|
|
122
|
+
</Button>
|
|
123
|
+
<Button size="sm" disabled={submitting} onClick={onRevert}>
|
|
124
|
+
{t('table.revert')}
|
|
125
|
+
</Button>
|
|
126
|
+
</>
|
|
127
|
+
)}
|
|
128
|
+
<IconButton icon={RefreshCw} size="sm" label={t('table.refresh')} busy={refreshing} onClick={onRefresh} />
|
|
129
|
+
<IconButton
|
|
130
|
+
icon={Plus}
|
|
131
|
+
size="sm"
|
|
132
|
+
label={t('table.addRow')}
|
|
133
|
+
tooltip={tooltipOf(t('table.addRow'))}
|
|
134
|
+
aria-disabled={readOnly || undefined}
|
|
135
|
+
onClick={() => !readOnly && onAddRow()}
|
|
136
|
+
/>
|
|
137
|
+
<Menu.Root>
|
|
138
|
+
<IconButton icon={Ellipsis} size="sm" label={t('table.more')} render={<Menu.Trigger />} />
|
|
139
|
+
<Menu.Popup align="end">
|
|
140
|
+
<Menu.SubmenuRoot>
|
|
141
|
+
<Menu.SubmenuTrigger>
|
|
142
|
+
<Icon icon={Rows3} size={14} />
|
|
143
|
+
{t('table.pageSize')}
|
|
144
|
+
</Menu.SubmenuTrigger>
|
|
145
|
+
<Menu.Popup>
|
|
146
|
+
<Menu.RadioGroup value={String(pageSize)} onValueChange={(value) => onPageSizeChange(Number(value))}>
|
|
147
|
+
{PAGE_SIZES.map((size) => (
|
|
148
|
+
<Menu.RadioItem key={size} value={String(size)}>
|
|
149
|
+
{t('table.perPage', { size: formatNumber(size) })}
|
|
150
|
+
</Menu.RadioItem>
|
|
151
|
+
))}
|
|
152
|
+
</Menu.RadioGroup>
|
|
153
|
+
</Menu.Popup>
|
|
154
|
+
</Menu.SubmenuRoot>
|
|
155
|
+
<Menu.Item disabled={!bounds.hasPrevious} onClick={onFirstPage}>
|
|
156
|
+
<Icon icon={ChevronsLeft} size={14} />
|
|
157
|
+
{t('table.firstPage')}
|
|
158
|
+
</Menu.Item>
|
|
159
|
+
<Menu.Item disabled={!bounds.hasNext} onClick={onLastPage}>
|
|
160
|
+
<Icon icon={ChevronsRight} size={14} />
|
|
161
|
+
{t('table.lastPage')}
|
|
162
|
+
{!bounds.exact && <Menu.Hint>{t('table.lastPageCounts')}</Menu.Hint>}
|
|
163
|
+
</Menu.Item>
|
|
164
|
+
<Menu.Separator />
|
|
165
|
+
{onToggleRecordView !== undefined && (
|
|
166
|
+
<Menu.CheckboxItem checked={recordViewOpen} onCheckedChange={onToggleRecordView}>
|
|
167
|
+
<Icon icon={TableProperties} size={14} />
|
|
168
|
+
{t('table.recordView')}
|
|
169
|
+
</Menu.CheckboxItem>
|
|
170
|
+
)}
|
|
171
|
+
<Menu.CheckboxItem checked={valuePanelOpen} onCheckedChange={onToggleValuePanel}>
|
|
172
|
+
<Icon icon={PanelRight} size={14} />
|
|
173
|
+
{t('table.valuePanel')}
|
|
174
|
+
</Menu.CheckboxItem>
|
|
175
|
+
<Menu.Separator />
|
|
176
|
+
{readOnly && <Menu.Label>{readOnlyReason}</Menu.Label>}
|
|
177
|
+
<Menu.Item disabled={readOnly || !hasSelection} onClick={onCloneRows}>
|
|
178
|
+
<Icon icon={CopyPlus} size={14} />
|
|
179
|
+
{t('table.cloneRows')}
|
|
180
|
+
</Menu.Item>
|
|
181
|
+
<Menu.Item disabled={!canRevertSelection} onClick={onRevertRows}>
|
|
182
|
+
<Icon icon={Undo2} size={14} />
|
|
183
|
+
{t('table.revertRows')}
|
|
184
|
+
</Menu.Item>
|
|
185
|
+
<Menu.Item disabled={readOnly || !hasSelection} onClick={onDeleteRows}>
|
|
186
|
+
<Icon icon={Trash2} size={14} />
|
|
187
|
+
{t('table.deleteRows')}
|
|
188
|
+
</Menu.Item>
|
|
189
|
+
{transfer !== undefined && (
|
|
190
|
+
<>
|
|
191
|
+
<Menu.Separator />
|
|
192
|
+
<Menu.SubmenuRoot>
|
|
193
|
+
<Menu.SubmenuTrigger disabled={transfer.busy}>
|
|
194
|
+
<Icon icon={Download} size={14} />
|
|
195
|
+
{t('table.export.label')}
|
|
196
|
+
</Menu.SubmenuTrigger>
|
|
197
|
+
<Menu.Popup>
|
|
198
|
+
{EXPORT_FORMATS.map((format) => (
|
|
199
|
+
<Menu.Item key={format} onClick={() => transfer.onExport(format)}>
|
|
200
|
+
{t('table.export.as', { format: format.toUpperCase() })}
|
|
201
|
+
</Menu.Item>
|
|
202
|
+
))}
|
|
203
|
+
</Menu.Popup>
|
|
204
|
+
</Menu.SubmenuRoot>
|
|
205
|
+
{transfer.onImport !== undefined && (
|
|
206
|
+
<Menu.Item onClick={transfer.onImport}>
|
|
207
|
+
<Icon icon={FileInput} size={14} />
|
|
208
|
+
{t('table.import.menu')}
|
|
209
|
+
</Menu.Item>
|
|
210
|
+
)}
|
|
211
|
+
</>
|
|
212
|
+
)}
|
|
213
|
+
</Menu.Popup>
|
|
214
|
+
</Menu.Root>
|
|
215
|
+
</div>
|
|
216
|
+
);
|
|
217
|
+
}
|