diff --git a/packages/datalib/src/GridDisplay.ts b/packages/datalib/src/GridDisplay.ts index ddc2ef07..b22010ed 100644 --- a/packages/datalib/src/GridDisplay.ts +++ b/packages/datalib/src/GridDisplay.ts @@ -110,11 +110,7 @@ export abstract class GridDisplay { } reload() { - this.setCache(cache => ({ - // ...cache, - ...createGridCache(), - refreshTime: new Date().getTime(), - })); + this.setCache(reloadDataCacheFunc); } includeInColumnSet(field: keyof GridConfigColumns, uniqueName: string, isIncluded: boolean) { @@ -586,3 +582,11 @@ export abstract class GridDisplay { })); } } + +export function reloadDataCacheFunc(cache: GridCache): GridCache { + return { + // ...cache, + ...createGridCache(), + refreshTime: new Date().getTime(), + }; +} diff --git a/packages/web/src/datagrid/CollectionDataGridCore.svelte b/packages/web/src/datagrid/CollectionDataGridCore.svelte index 2fcb6895..8cdd1fdf 100644 --- a/packages/web/src/datagrid/CollectionDataGridCore.svelte +++ b/packages/web/src/datagrid/CollectionDataGridCore.svelte @@ -128,34 +128,6 @@ // $: console.log('GRIDER', grider); // $: if (onChangeGrider) onChangeGrider(grider); - async function handleConfirmChange(changeSet) { - const resp = await axiosInstance.request({ - url: 'database-connections/update-collection', - method: 'post', - params: { - conid, - database, - }, - data: { changeSet }, - }); - const { errorMessage } = resp.data || {}; - if (errorMessage) { - showModal(ErrorMessageModal, { title: 'Error when saving', message: errorMessage }); - } else { - dispatchChangeSet({ type: 'reset', value: createChangeSet() }); - display.reload(); - } - } - - function handleSave() { - const json = changeSetState && changeSetState.value; - showModal(ConfirmNoSqlModal, { - json, - onConfirm: () => handleConfirmChange(json), - engine: display.engine, - }); - } - function exportGrid() { const initialValues: any = {}; initialValues.sourceStorageType = 'query'; @@ -219,5 +191,4 @@ bind:loadedRows frameSelection={!!macroPreview} {grider} - onSave={handleSave} /> diff --git a/packages/web/src/datagrid/DataGridCore.svelte b/packages/web/src/datagrid/DataGridCore.svelte index 50562a84..6169ab57 100644 --- a/packages/web/src/datagrid/DataGridCore.svelte +++ b/packages/web/src/datagrid/DataGridCore.svelte @@ -12,18 +12,6 @@ onClick: () => getCurrentDataGrid().refresh(), }); - registerCommand({ - id: 'dataGrid.save', - group: 'save', - category: 'Data grid', - name: 'Save', - // keyText: 'Ctrl+S', - toolbar: true, - icon: 'icon save', - testEnabled: () => getCurrentDataGrid()?.getGrider()?.allowSave, - onClick: () => getCurrentDataGrid().save(), - }); - registerCommand({ id: 'dataGrid.revertRowChanges', category: 'Data grid', @@ -261,7 +249,6 @@ export let onReferenceSourceChanged = undefined; export let onReferenceClick = undefined; // export let onSelectedCellsPublishedChanged = undefined; - export let onSave; export let focusOnVisible = false; export let onExportGrid = null; export let onOpenQuery = null; @@ -303,10 +290,6 @@ display.reload(); } - export function save() { - if (onSave) onSave(); - } - export function getGrider() { return grider; } @@ -491,10 +474,6 @@ editJsonRowDocument(grider, rowIndex); } - // export function getGeneralAllowSave() { - // return generalAllowSave; - // } - $: autofillMarkerCell = selectedCells && selectedCells.length > 0 && _.uniq(selectedCells.map(x => x[0])).length == 1 ? [_.max(selectedCells.map(x => x[0])), _.max(selectedCells.map(x => x[1]))] @@ -994,12 +973,12 @@ // if (action.mode == 'save') setTimeout(handleSave, 0); return {}; } - case 'shouldSave': { - return { - ...state, - shouldSave: true, - }; - } + // case 'shouldSave': { + // return { + // ...state, + // shouldSave: true, + // }; + // } } return {}; }, {}); @@ -1019,7 +998,7 @@ { command: 'dataGrid.switchToJson', hideDisabled: true }, { command: 'dataGrid.editJsonDocument', hideDisabled: true }, { divider: true }, - { command: 'dataGrid.save' }, + { placeTag: 'save' }, { command: 'dataGrid.revertRowChanges' }, { command: 'dataGrid.revertAllChanges' }, { command: 'dataGrid.deleteSelectedRows' }, diff --git a/packages/web/src/datagrid/SqlDataGridCore.svelte b/packages/web/src/datagrid/SqlDataGridCore.svelte index 1ac7fb36..64565a4d 100644 --- a/packages/web/src/datagrid/SqlDataGridCore.svelte +++ b/packages/web/src/datagrid/SqlDataGridCore.svelte @@ -102,35 +102,6 @@ // $: console.log('GRIDER', grider); // $: if (onChangeGrider) onChangeGrider(grider); - async function handleConfirmSql(sql) { - const resp = await axiosInstance.request({ - url: 'database-connections/query-data', - method: 'post', - params: { - conid, - database, - }, - data: { sql }, - }); - const { errorMessage } = resp.data || {}; - if (errorMessage) { - showModal(ErrorMessageModal, { title: 'Error when saving', message: errorMessage }); - } else { - dispatchChangeSet({ type: 'reset', value: createChangeSet() }); - display.reload(); - } - } - - function handleSave() { - const script = changeSetToSql(changeSetState && changeSetState.value, display.dbinfo); - const sql = scriptToSql(display.driver, script); - showModal(ConfirmSqlModal, { - sql, - onConfirm: () => handleConfirmSql(sql), - engine: display.engine, - }); - } - function exportGrid() { const initialValues: any = {}; initialValues.sourceStorageType = 'query'; @@ -196,5 +167,4 @@ bind:selectedCellsPublished frameSelection={!!macroPreview} {grider} - onSave={handleSave} /> diff --git a/packages/web/src/formview/FormView.svelte b/packages/web/src/formview/FormView.svelte index b6558335..193ea990 100644 --- a/packages/web/src/formview/FormView.svelte +++ b/packages/web/src/formview/FormView.svelte @@ -10,16 +10,16 @@ onClick: () => getCurrentDataForm().switchToTable(), }); - registerCommand({ - id: 'dataForm.save', - group: 'save', - category: 'Data form', - name: 'Save', - toolbar: true, - icon: 'icon save', - testEnabled: () => getCurrentDataForm()?.getFormer()?.allowSave, - onClick: () => getCurrentDataForm().save(), - }); + // registerCommand({ + // id: 'dataForm.save', + // group: 'save', + // category: 'Data form', + // name: 'Save', + // toolbar: true, + // icon: 'icon save', + // testEnabled: () => getCurrentDataForm()?.getFormer()?.allowSave, + // onClick: () => getCurrentDataForm().save(), + // }); registerCommand({ id: 'dataForm.copyToClipboard', @@ -164,7 +164,7 @@ import axiosInstance from '../utility/axiosInstance'; import { copyTextToClipboard } from '../utility/clipboard'; - import contextMenu from '../utility/contextMenu'; + import contextMenu, { getContextMenu, registerMenu } from '../utility/contextMenu'; import createActivator, { getActiveComponent } from '../utility/createActivator'; import createReducer from '../utility/createReducer'; import keycodes from '../utility/keycodes'; @@ -181,7 +181,6 @@ export let isLoading; export let former; export let formDisplay; - export let onSave; export let onNavigate; let wrapperHeight = 1; @@ -228,14 +227,14 @@ })); } - export function save() { - if ($inplaceEditorState.cell) { - // @ts-ignore - dispatchInsplaceEditor({ type: 'shouldSave' }); - return; - } - if (onSave) onSave(); - } + // export function save() { + // if ($inplaceEditorState.cell) { + // // @ts-ignore + // dispatchInsplaceEditor({ type: 'shouldSave' }); + // return; + // } + // if (onSave) onSave(); + // } export function setNull() { if (isDataCell(currentCell)) { @@ -332,36 +331,35 @@ // if (action.mode == 'save') setTimeout(handleSave, 0); return {}; } - case 'shouldSave': { - return { - ...state, - shouldSave: true, - }; - } + // case 'shouldSave': { + // return { + // ...state, + // shouldSave: true, + // }; + // } } return {}; }, {}); - function createMenu() { - return [ - { command: 'dataForm.switchToTable' }, - { command: 'dataForm.copyToClipboard' }, - { divider: true }, - { command: 'dataForm.filterSelected' }, - { command: 'dataForm.addToFilter' }, - { divider: true }, - { command: 'dataForm.save' }, - { command: 'dataForm.revertRowChanges' }, - { command: 'dataForm.setNull' }, - { divider: true }, - { command: 'dataForm.undo' }, - { command: 'dataForm.redo' }, - { divider: true }, - { command: 'dataForm.goToFirst' }, - { command: 'dataForm.goToPrevious' }, - { command: 'dataForm.goToNext' }, - { command: 'dataForm.goToLast' }, - ]; - } + registerMenu( + { command: 'dataForm.switchToTable' }, + { command: 'dataForm.copyToClipboard' }, + { divider: true }, + { command: 'dataForm.filterSelected' }, + { command: 'dataForm.addToFilter' }, + { divider: true }, + { placeTag: 'save' }, + { command: 'dataForm.revertRowChanges' }, + { command: 'dataForm.setNull' }, + { divider: true }, + { command: 'dataForm.undo' }, + { command: 'dataForm.redo' }, + { divider: true }, + { command: 'dataForm.goToFirst' }, + { command: 'dataForm.goToPrevious' }, + { command: 'dataForm.goToNext' }, + { command: 'dataForm.goToLast' } + ); + const menu = getContextMenu(); function handleKeyDown(event) { if ($inplaceEditorState.cell) return; @@ -437,7 +435,7 @@