From e6ec32126fa6131dd296754e23d915e75d42bd95 Mon Sep 17 00:00:00 2001 From: samunohito <46447427+samunohito@users.noreply.github.com> Date: Sat, 3 Feb 2024 13:17:26 +0900 Subject: [PATCH] fix validation --- .../frontend/src/components/grid/MkGrid.vue | 33 ++++++++++--------- .../src/components/grid/grid-event.ts | 1 + .../admin/custom-emojis-grid.register.vue | 16 +++++---- 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/packages/frontend/src/components/grid/MkGrid.vue b/packages/frontend/src/components/grid/MkGrid.vue index cf69834751..f25d846b23 100644 --- a/packages/frontend/src/components/grid/MkGrid.vue +++ b/packages/frontend/src/components/grid/MkGrid.vue @@ -756,22 +756,25 @@ function emitCellValue(sender: GridCell | CellAddress, newValue: CellValue) { const cellAddress = 'address' in sender ? sender.address : sender; const cell = cells.value[cellAddress.row].cells[cellAddress.col]; - const violation = cellValidation(cell, newValue); - cell.violation = violation; - emitGridEvent({ - type: 'cell-validation', - violation: violation, - }); + if (cell.column.setting.editable) { + const violation = cellValidation(cell, newValue); + cell.violation = violation; + emitGridEvent({ + type: 'cell-validation', + violation: violation, + all: cells.value.flatMap(it => it.cells).map(it => it.violation), + }); - cell.value = newValue; - emitGridEvent({ - type: 'cell-value-change', - column: cell.column, - row: cell.row, - violation: violation, - oldValue: cell.value, - newValue: newValue, - }); + cell.value = newValue; + emitGridEvent({ + type: 'cell-value-change', + column: cell.column, + row: cell.row, + violation: violation, + oldValue: cell.value, + newValue: newValue, + }); + } } /** diff --git a/packages/frontend/src/components/grid/grid-event.ts b/packages/frontend/src/components/grid/grid-event.ts index fd724f5132..6a34f19e5f 100644 --- a/packages/frontend/src/components/grid/grid-event.ts +++ b/packages/frontend/src/components/grid/grid-event.ts @@ -44,6 +44,7 @@ export type GridCellValueChangeEvent = { export type GridCellValidationEvent = { type: 'cell-validation'; violation: ValidateViolation; + all: ValidateViolation[]; }; export type GridKeyDownEvent = { diff --git a/packages/frontend/src/pages/admin/custom-emojis-grid.register.vue b/packages/frontend/src/pages/admin/custom-emojis-grid.register.vue index 5e9e2fb7a9..ac9705cf09 100644 --- a/packages/frontend/src/pages/admin/custom-emojis-grid.register.vue +++ b/packages/frontend/src/pages/admin/custom-emojis-grid.register.vue @@ -79,7 +79,9 @@ {{ i18n.ts.registration }} - {{ i18n.ts.clear }} + + {{ i18n.ts.clear }} + @@ -147,7 +149,7 @@ type DroppedDirectory = { } const columnSettings: ColumnSetting[] = [ - { bindTo: 'url', icon: 'ti-icons', type: 'image', editable: true, width: 'auto', validators: [required] }, + { bindTo: 'url', icon: 'ti-icons', type: 'image', editable: false, width: 'auto', validators: [required] }, { bindTo: 'name', title: 'name', type: 'text', editable: true, width: 140, validators: [required] }, { bindTo: 'category', title: 'category', type: 'text', editable: true, width: 140 }, { bindTo: 'aliases', title: 'aliases', type: 'text', editable: true, width: 140 }, @@ -328,7 +330,7 @@ function onRowDeleting(rows: GridRow[]) { function onGridEvent(event: GridEvent, currentState: GridCurrentState) { switch (event.type) { case 'cell-validation': - onGridCellValidation(event, currentState); + onGridCellValidation(event); break; case 'row-context-menu': onGridRowContextMenu(event, currentState); @@ -342,8 +344,8 @@ function onGridEvent(event: GridEvent, currentState: GridCurrentState) { } } -function onGridCellValidation(event: GridCellValidationEvent, _: GridCurrentState) { - registerButtonDisabled.value = !event.violation.valid; +function onGridCellValidation(event: GridCellValidationEvent) { + registerButtonDisabled.value = event.all.filter(it => !it.valid).length > 0; } function onGridRowContextMenu(event: GridRowContextMenuEvent, currentState: GridCurrentState) { @@ -377,7 +379,9 @@ function onGridKeyDown(event: GridKeyDownEvent, currentState: GridCurrentState) } else { const ranges = currentState.rangedCells; for (const cell of ranges) { - gridItems.value[cell.row.index][cell.column.setting.bindTo] = undefined; + if (cell.column.setting.editable) { + gridItems.value[cell.row.index][cell.column.setting.bindTo] = undefined; + } } } break;