feat(mysql): support safe grouped result editing

This commit is contained in:
zipg authored and GitHub committed 2026-08-19 11:03:17 +08:00
1 parent 533c7a9633
commit 21af5cf600
10 files changed
+507 -36

No files matched your search

@@ -26,7 +26,7 @@ vi.mock("@/stores/productionSafetyStore", () => ({
useProductionSafetyStore: () => ({}),
}));
function createEditor(sourceColumns?: Array<string | undefined>, confirmDangerousRowDeletion = true, cacheKey?: string) {
function createEditor(sourceColumns?: Array<string | undefined>, confirmDangerousRowDeletion = true, cacheKey?: string, readonlyColumnIndexes?: number[]) {
let editor: ReturnType<typeof useDataGridEditor>;
const result = ref<{ columns: string[]; rows: CellValue[][] }>({
columns: ["first", "hidden", "last"],
@@ -49,6 +49,7 @@ function createEditor(sourceColumns?: Array<string | undefined>, confirmDangerou
primaryKeys: [],
})),
sourceColumns: computed(() => sourceColumns),
readonlyColumnIndexes: computed(() => (readonlyColumnIndexes ? new Set(readonlyColumnIndexes) : undefined)),
onExecuteSql: computed(() => undefined),
sql: computed(() => undefined),
searchText: ref(""),
@@ -180,6 +181,14 @@ describe("useDataGridEditor appendPastedRowsToNewRow", () => {
expect(editor.hasPendingChanges.value).toBe(true);
});
it("keeps explicitly read-only mapped columns out of editing and paste", () => {
const editor = createEditor(["first", "hidden", "last"], true, undefined, [0]);
expect(editor.canEditColumn(0)).toBe(false);
expect(editor.canEditColumn(2)).toBe(true);
expect(editor.appendPastedRowsToNewRow(-1, [["Ada"]], [0])).toEqual({ ok: false, reason: "readonly-column" });
});
it("fills following blank new rows before adding more rows", () => {
const editor = createEditor();
editor.newRows.value = [
@@ -86,6 +86,7 @@ export interface UseDataGridEditorOptions {
| undefined
>;
sourceColumns?: ComputedRef<Array<string | undefined> | undefined>;
readonlyColumnIndexes?: ComputedRef<ReadonlySet<number> | undefined>;
canEditExistingRows?: ComputedRef<boolean>;
onExecuteSql: ComputedRef<((sql: string) => Promise<void>) | undefined>;
customSaveHandler?: ComputedRef<CustomSaveHandler | undefined>;
@@ -201,6 +202,7 @@ export function useDataGridEditor(options: UseDataGridEditorOptions) {
database,
tableMeta,
sourceColumns = computed(() => undefined),
readonlyColumnIndexes = computed(() => undefined),
canEditExistingRows = computed(() => true),
onExecuteSql,
customSaveHandler,
@@ -607,7 +609,7 @@ export function useDataGridEditor(options: UseDataGridEditorOptions) {
function canEditColumn(columnIndex: number): boolean {
const sources = sourceColumns.value;
return !sources || sources[columnIndex] !== undefined;
return (!sources || sources[columnIndex] !== undefined) && !readonlyColumnIndexes.value?.has(columnIndex);
}
// --- Row data helpers ---