From 9a2520a10a77694985e489a91274caca1686656e Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Thu, 19 Nov 2020 12:42:13 +0100 Subject: [PATCH] datagrid context menu --- packages/datalib/src/GridDisplay.ts | 1 + packages/datalib/src/TableGridDisplay.ts | 1 + packages/datalib/src/ViewGridDisplay.ts | 1 + .../web/src/datagrid/DataGridContextMenu.js | 50 ++++++++++++------- packages/web/src/datagrid/DataGridCore.js | 12 ++--- 5 files changed, 40 insertions(+), 25 deletions(-) diff --git a/packages/datalib/src/GridDisplay.ts b/packages/datalib/src/GridDisplay.ts index db92e426..6aada156 100644 --- a/packages/datalib/src/GridDisplay.ts +++ b/packages/datalib/src/GridDisplay.ts @@ -58,6 +58,7 @@ export abstract class GridDisplay { filterable = false; editable = false; isLoadedCorrectly = true; + supportsReload = false; setColumnVisibility(uniquePath: string[], isVisible: boolean) { const uniqueName = uniquePath.join('.'); diff --git a/packages/datalib/src/TableGridDisplay.ts b/packages/datalib/src/TableGridDisplay.ts index f002ee50..692c92f3 100644 --- a/packages/datalib/src/TableGridDisplay.ts +++ b/packages/datalib/src/TableGridDisplay.ts @@ -32,6 +32,7 @@ export class TableGridDisplay extends GridDisplay { this.filterable = true; this.sortable = true; this.editable = true; + this.supportsReload = true; this.baseTable = this.table; if (this.table && this.table.columns) { this.changeSetKeyFields = this.table.primaryKey diff --git a/packages/datalib/src/ViewGridDisplay.ts b/packages/datalib/src/ViewGridDisplay.ts index c9a5758c..26b957fd 100644 --- a/packages/datalib/src/ViewGridDisplay.ts +++ b/packages/datalib/src/ViewGridDisplay.ts @@ -17,6 +17,7 @@ export class ViewGridDisplay extends GridDisplay { this.filterable = true; this.sortable = true; this.editable = false; + this.supportsReload = true; } getDisplayColumns(view: ViewInfo) { diff --git a/packages/web/src/datagrid/DataGridContextMenu.js b/packages/web/src/datagrid/DataGridContextMenu.js index bdd89e6d..76b76ec6 100644 --- a/packages/web/src/datagrid/DataGridContextMenu.js +++ b/packages/web/src/datagrid/DataGridContextMenu.js @@ -15,30 +15,42 @@ export default function DataGridContextMenu({ }) { return ( <> - - Reload - - + {!!reload && ( + + Reload + + )} + {!!reload && } Copy - - Revert row changes - - - Delete selected rows - - - Insert new row - + {revertRowChanges && ( + + Revert row changes + + )} + {deleteSelectedRows && ( + + Delete selected rows + + )} + {insertNewRow && ( + + Insert new row + + )} - - Set NULL - + {setNull && ( + + Set NULL + + )} {exportGrid && Export} - - Filter selected value - + {filterSelectedValue && ( + + Filter selected value + + )} {openQuery && Open query} Open selection in free table editor diff --git a/packages/web/src/datagrid/DataGridCore.js b/packages/web/src/datagrid/DataGridCore.js index dd661325..853cbc02 100644 --- a/packages/web/src/datagrid/DataGridCore.js +++ b/packages/web/src/datagrid/DataGridCore.js @@ -345,13 +345,13 @@ export default function DataGridCore(props) { event.pageY, display.reload()} - setNull={setNull} + revertRowChanges={grider.containsChanges ? revertRowChanges : null} + deleteSelectedRows={grider.editable ? deleteSelectedRows : null} + insertNewRow={grider.editable ? insertNewRow : null} + reload={display.supportsReload ? () => display.reload() : null} + setNull={grider.editable ? setNull : null} exportGrid={exportGrid} - filterSelectedValue={filterSelectedValue} + filterSelectedValue={display.filterable ? filterSelectedValue : null} openQuery={openQuery} openFreeTable={handleOpenFreeTable} />