fix(grid): keep save actions visible
This commit is contained in:
1 parent
b6bf3009f8
commit
cf86d7f3b4
3 files changed
+87
-5
No files matched your search
@@ -103,7 +103,7 @@ import {
|
||||
} from "@/lib/columnFormatter";
|
||||
import { isCancelSearchShortcut, isFocusSearchShortcut } from "@/lib/keyboardShortcuts";
|
||||
import { dataGridHeaderContentWidth, scrollbarGutterWidth } from "@/lib/dataGridScrollGutter";
|
||||
import { dataGridSaveActionMode } from "@/lib/dataGridSaveUi";
|
||||
import { dataGridSaveActionMode, dataGridSaveToolbarState } from "@/lib/dataGridSaveUi";
|
||||
import { appendColumnValueFilterCondition, buildColumnValueFilterCondition } from "@/lib/dataGridColumnFilter";
|
||||
import {
|
||||
filterColumnVisibilityOptions,
|
||||
@@ -1335,6 +1335,14 @@ const saveActionMode = computed(() =>
|
||||
useTransaction: !!useTransaction.value,
|
||||
}),
|
||||
);
|
||||
const saveToolbarState = computed(() =>
|
||||
dataGridSaveToolbarState({
|
||||
editable: props.editable,
|
||||
hasSaveTarget: !!props.tableMeta || !!props.customSave,
|
||||
hasPendingChanges: hasPendingChanges.value,
|
||||
isSaving: isSaving.value,
|
||||
}),
|
||||
);
|
||||
|
||||
function canEditRowItem(item: RowItem | undefined): boolean {
|
||||
return !!props.editable && !!item && !item.isDeleted && (item.isNew || canEditExistingRows.value);
|
||||
@@ -2711,14 +2719,14 @@ defineExpose({
|
||||
<span class="h-1.5 w-1.5 rounded-full bg-emerald-500 animate-pulse" />
|
||||
{{ t("grid.transactionActive") }}
|
||||
</span>
|
||||
<template v-if="editable && (tableMeta || customSave) && hasPendingChanges">
|
||||
<template v-if="saveToolbarState.showActions">
|
||||
<Tooltip>
|
||||
<TooltipTrigger as-child>
|
||||
<Button
|
||||
variant="default"
|
||||
size="sm"
|
||||
class="h-5 text-xs px-1.5 shrink-0"
|
||||
:disabled="isSaving"
|
||||
:disabled="saveToolbarState.actionsDisabled"
|
||||
@click="onToolbarCommit"
|
||||
>
|
||||
<Loader2 v-if="isSaving" class="w-3 h-3 mr-1 animate-spin" />
|
||||
@@ -2734,7 +2742,7 @@ defineExpose({
|
||||
variant="outline"
|
||||
size="sm"
|
||||
class="h-5 text-xs px-1.5 shrink-0"
|
||||
:disabled="isSaving"
|
||||
:disabled="saveToolbarState.actionsDisabled"
|
||||
@click="useTransaction ? onToolbarRollback() : discardChanges()"
|
||||
>
|
||||
<RotateCcw class="w-3 h-3 mr-1" />
|
||||
|
||||
@@ -14,3 +14,21 @@ export function dataGridSaveActionMode(options: {
|
||||
secondaryActionKey: options.useTransaction ? "grid.rollback" : "grid.discard",
|
||||
};
|
||||
}
|
||||
|
||||
export interface DataGridSaveToolbarState {
|
||||
showActions: boolean;
|
||||
actionsDisabled: boolean;
|
||||
}
|
||||
|
||||
export function dataGridSaveToolbarState(options: {
|
||||
editable: boolean;
|
||||
hasSaveTarget: boolean;
|
||||
hasPendingChanges: boolean;
|
||||
isSaving: boolean;
|
||||
}): DataGridSaveToolbarState {
|
||||
const showActions = options.editable && options.hasSaveTarget;
|
||||
return {
|
||||
showActions,
|
||||
actionsDisabled: !showActions || !options.hasPendingChanges || options.isSaving,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user