diff --git a/.changeset/35685-list-state-confirm.md b/.changeset/35685-list-state-confirm.md new file mode 100644 index 00000000000..4048d84092e --- /dev/null +++ b/.changeset/35685-list-state-confirm.md @@ -0,0 +1,18 @@ +--- +'@object-ui/components': patch +'@object-ui/plugin-grid': patch +'@object-ui/plugin-detail': patch +'@object-ui/i18n': patch +--- + +feat(list): confirm a state-machine move before a list cell saves it; the drawer's save bar says when the record changed elsewhere + +Clause-②: yes (widening) — `GridCellSelection` in `@object-ui/components` takes an optional `confirmCommit(row, columnKey, value)` member; nothing removed or renamed +Metadata-protocol: none + +In a grid that mounts `GridCellSelection` (the select-first grid every `ListView` draws): + +- **A move of a state-machine field asks first.** When an active `state_machine` validation rule of the object governs the field on update, a new value committed into its cell (picked in the editor, or pasted) opens a confirm naming the field and both values and saying saving may trigger related automation. Cancel writes nothing and the cell keeps what it showed; Change saves the value as any commit is saved. Focus goes back to the cell either way. +- **The generic seam:** `GridCellSelection.confirmCommit` is asked before a value that changes what a cell shows is staged or saved. A promise holds the write until it settles (`true` writes, `false` or a rejection writes nothing); `null` or `undefined` means no question, as before. + +On a record page or in a record drawer, `InlineEditSaveBar` now says so when the record is read again at another version while an inline edit session is open (a list cell beside the drawer saved it, say). The draft stays as typed, and Save writes it over the version now read, as it did before; only the note is new. diff --git a/content/docs/frontend/plugins/plugin-grid.mdx b/content/docs/frontend/plugins/plugin-grid.mdx index 1a28789396c..058c36f2fa8 100644 --- a/content/docs/frontend/plugins/plugin-grid.mdx +++ b/content/docs/frontend/plugins/plugin-grid.mdx @@ -427,6 +427,18 @@ row whose new value would sort it elsewhere stays in place until the next load takes back that toast's save, while Ctrl+Z always goes newest first. Inside an open editor Ctrl+Z stays the editor's own text undo. A save of a field the row did not read offers no Undo. +- **A state-machine field asks first.** When the object's `state_machine` + validation rule governs the field (an active rule whose events cover an + update), picking a new value — in the cell's editor, or by pasting — opens a + confirm that names the field and both values and says saving may trigger + related automation ("Status changes from On Hold to Active. Saving may + trigger related automation."). Cancel writes nothing and the cell keeps the + value it had; Change saves it as any commit is saved. The confirm does not + list the flows. A host asks this through `GridCellSelection.confirmCommit`. +- **The record drawer follows.** A record open in the list's drawer is read + again when a list cell saves it. If the drawer holds unsaved edits of its own, + those stay as typed, the drawer's save bar says the record was changed + elsewhere, and Save writes the drawer's edits over the latest version. ### Footer calculations diff --git a/ui/packages/components/src/__tests__/data-table-autosave-35685.test.tsx b/ui/packages/components/src/__tests__/data-table-autosave-35685.test.tsx index 36b4510b61d..bf088cc00ef 100644 --- a/ui/packages/components/src/__tests__/data-table-autosave-35685.test.tsx +++ b/ui/packages/components/src/__tests__/data-table-autosave-35685.test.tsx @@ -21,6 +21,9 @@ * 5. A refusal naming a field the list cannot edit offers to open the record. * 6. A client-sorted row a save updated stays where it is until the rows load. * 7. Control: without the provider the save bar model is unchanged. + * 8. A commit the host asks to confirm (`confirmCommit`, slice S3) is held + * with nothing staged: No leaves the cell as it was, Yes writes it; a + * paste is asked too, an unchanged value is not. */ import React from 'react'; import { describe, it, expect, afterEach, vi } from 'vitest'; @@ -310,3 +313,93 @@ describe('data-table autosave — Esc in the editor while the row is saving', () expect(onRowSave.mock.calls[0][1]).toEqual({ name: 'Alpha 2' }); }); }); + +describe('data-table autosave — a commit the host asks to confirm first (objectstack#35685)', () => { + /** A table whose host asks about every commit into `Stage`, each answer settled by hand. */ + function renderConfirming(onRowSave: Save) { + const asks: Array<{ row: any; columnKey: string; value: unknown; answer: (yes: boolean) => void }> = []; + const confirmCommit = vi.fn((row: any, columnKey: string, value: unknown) => { + if (columnKey !== 'stage') return null; + return new Promise((resolve) => { asks.push({ row, columnKey, value, answer: resolve }); }); + }); + const DataTable = ComponentRegistry.get('data-table')!; + const utils = render( + + + , + ); + const cell = (row: number, col: number) => + utils.container.querySelectorAll('tbody tr')[row].querySelectorAll('td[data-grid-cell]')[col] as HTMLElement; + const editor = () => utils.container.querySelector('td[data-editing-cell] input'); + const catcher = () => utils.container.querySelector('[data-slot="cell-type-catcher"]'); + const typeAndEnter = (row: number, col: number, value: string) => { + fireEvent.click(cell(row, col)); + fireEvent.change(catcher()!, { target: { value: value.slice(0, 1) } }); + fireEvent.change(editor()!, { target: { value } }); + fireEvent.keyDown(editor()!, { key: 'Enter' }); + }; + return { ...utils, cell, editor, catcher, typeAndEnter, asks, confirmCommit }; + } + + it('No writes nothing: the editor closes, nothing is staged or sent, the cell shows what it had', async () => { + const { onRowSave } = deferredSave(); + const t = renderConfirming(onRowSave); + t.typeAndEnter(0, 1, 'won'); + await act(async () => {}); + expect(t.confirmCommit).toHaveBeenCalledTimes(1); + expect(t.asks[0].row).toBe(ROWS[0]); + expect(t.asks[0].value).toBe('won'); + // While the host asks: the editor is closed, the cell shows the stored + // value with no save state, and nothing went out. + expect(t.editor()).toBeNull(); + expect(t.cell(0, 1).textContent).toContain('open'); + expect(t.cell(0, 1).querySelector('[data-slot="cell-save-state"]')).toBeNull(); + expect(onRowSave).not.toHaveBeenCalled(); + await act(async () => { t.asks[0].answer(false); }); + expect(onRowSave).not.toHaveBeenCalled(); + expect(t.cell(0, 1).textContent).toContain('open'); + expect(t.cell(0, 1).textContent).not.toContain('won'); + // Focus is back on the selected cell, so the keys carry on. + expect(document.activeElement).toBe(t.catcher()); + }); + + it('Yes writes the value as any commit is written: one update of that cell', async () => { + const { onRowSave } = deferredSave(); + const t = renderConfirming(onRowSave); + t.typeAndEnter(0, 1, 'won'); + await act(async () => {}); + expect(onRowSave).not.toHaveBeenCalled(); + await act(async () => { t.asks[0].answer(true); }); + await waitFor(() => expect(onRowSave).toHaveBeenCalledTimes(1)); + expect(onRowSave.mock.calls[0][1]).toEqual({ stage: 'won' }); + expect(t.cell(0, 1).querySelector('[data-slot="cell-save-state"]')).toHaveAttribute('data-state', 'saving'); + }); + + it('a paste is asked about as an editor commit is', async () => { + const { onRowSave } = deferredSave(); + const t = renderConfirming(onRowSave); + fireEvent.click(t.cell(0, 1)); + fireEvent.paste(t.catcher()!, { clipboardData: { getData: () => 'won' } }); + await act(async () => {}); + expect(t.confirmCommit).toHaveBeenCalledTimes(1); + expect(onRowSave).not.toHaveBeenCalled(); + await act(async () => { t.asks[0].answer(false); }); + expect(onRowSave).not.toHaveBeenCalled(); + expect(t.cell(0, 1).textContent).toContain('open'); + }); + + it('a commit that changes nothing, and a cell the host does not ask about, are not held', async () => { + const { onRowSave } = deferredSave(); + const t = renderConfirming(onRowSave); + // The stored value again: nothing to ask, nothing to send. + t.typeAndEnter(0, 1, 'open'); + await act(async () => {}); + expect(t.confirmCommit).not.toHaveBeenCalled(); + expect(onRowSave).not.toHaveBeenCalled(); + // Another column: the host answers no question, and it saves at once. + t.typeAndEnter(0, 0, 'Alpha 2'); + await waitFor(() => expect(onRowSave).toHaveBeenCalledTimes(1)); + expect(t.confirmCommit).toHaveBeenCalledTimes(1); + expect(onRowSave.mock.calls[0][1]).toEqual({ name: 'Alpha 2' }); + }); +}); diff --git a/ui/packages/components/src/context/gridCellSelection.tsx b/ui/packages/components/src/context/gridCellSelection.tsx index 3348d0e9a96..e1d59b23393 100644 --- a/ui/packages/components/src/context/gridCellSelection.tsx +++ b/ui/packages/components/src/context/gridCellSelection.tsx @@ -55,6 +55,18 @@ export interface GridCellSelection { describeCell?: (row: any, columnKey: string) => GridCellFacts | null | undefined; /** Called when a cell becomes the selected one (a host may prefetch what an edit will need). */ onCellSelect?: (row: any, columnKey: string) => void; + /** + * Asked when a value is committed into a cell (an editor's commit, a toggle + * or a paste) that changes what the cell shows, before anything is staged + * or saved. A promise holds the write until it settles: `true` writes the + * value as any commit is written, `false` (or a rejection) writes nothing + * and the cell keeps what it showed. `null` / `undefined` ⇒ no question; + * the value is written at once. Only a table that saves each cell as it is + * committed (one wired with `onRowSave`) asks; a table on `onBatchSave` + * alone never does. A host asks, for example, before a move of a + * state-machine field (objectstack#35685). + */ + confirmCommit?: (row: any, columnKey: string, value: unknown) => Promise | null | undefined; } const GridCellSelectionContext = React.createContext(null); diff --git a/ui/packages/components/src/renderers/complex/data-table.tsx b/ui/packages/components/src/renderers/complex/data-table.tsx index 700c0ef1b7c..19b0f7649e4 100644 --- a/ui/packages/components/src/renderers/complex/data-table.tsx +++ b/ui/packages/components/src/renderers/complex/data-table.tsx @@ -2049,6 +2049,10 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => { const autosaveDueRef = useRef>(new Set()); const [autosaveTick, setAutosaveTick] = useState(0); const savedTimersRef = useRef>>(new Set()); + // A commit the host confirmed is written by the newest `commitCellValue`, + // and its answer re-renders so focus goes back to the selected cell. + const commitCellValueRef = useRef<(row: any, columnKey: string, value: unknown, confirmed?: boolean) => void>(() => {}); + const [, bumpConfirmSettled] = React.useReducer((n: number) => n + 1, 0); useEffect(() => () => { for (const timer of savedTimersRef.current) clearTimeout(timer); savedTimersRef.current.clear(); @@ -2817,6 +2821,20 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => { // (objectui#12664) has not reached state yet either. const valueToStage = explicitValue !== undefined ? explicitValue : editValueRef.current; + // objectstack#35685 — a value the host asks to confirm first: the editor + // closes with nothing of this session staged, and the value is written + // only once the host says yes (a no leaves the cell as it was). + const asked = commitConfirmationOf(rowKey, row, columnKey, valueToStage); + if (asked) { + revertEditSession(editingCell, editRevertRef.current); + editRevertRef.current = null; + editingCellRef.current = null; + setEditingCell(null); + setEditValue(''); + settleCommitConfirmation(asked, row, columnKey, valueToStage); + return; + } + // Update pending changes — or drop this cell's entry when the committed // value is the one the row loaded with (objectui#11816). An updater, so a // save that settled since this render is not undone (objectui#12322). @@ -2844,6 +2862,7 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => { const saveEditRef = useRef(saveEdit); useEffect(() => { saveEditRef.current = saveEdit; + commitCellValueRef.current = commitCellValue; }); // The injected-editor commit contract (objectui#12664): before the table @@ -2874,6 +2893,60 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => { // is what makes Escape/cancel discard an injected widget's staged changes. For // built-in editors (which don't stage until commit) the snapshot equals the // live pending value, so the revert is a no-op. + /** Roll the edit session's cell back to its snapshot (see `editRevertRef`). */ + const revertEditSession = (active: EditingCell, snap: { had: boolean; value: any } | null) => { + if (!snap) return; + const { rowKey, columnKey } = active; + setPendingChanges((prev) => { + const cur = prev.get(rowKey); + const staged = !!cur && columnKey in cur.changes; + if (!staged && !snap.had) return prev; // nothing changed for this cell + const next = new Map(prev); + const rc = { ...(cur?.changes || {}) }; + if (snap.had) rc[columnKey] = snap.value; + else delete rc[columnKey]; + if (Object.keys(rc).length > 0) next.set(rowKey, { row: cur?.row ?? active.row, changes: rc }); + else next.delete(rowKey); + return next; + }); + }; + + /** + * objectstack#35685 — the host's confirmation of a value committed into a + * select-first cell (`GridCellSelection.confirmCommit`), or `null` when it + * asks none. Only a value that changes what the cell shows is asked about. + */ + const commitConfirmationOf = ( + rowKey: PendingRowKey, + row: any, + columnKey: string, + value: unknown, + ): Promise | null => { + if (!autosaves || typeof cellSelection?.confirmCommit !== 'function') return null; + const staged = pendingChanges.get(rowKey)?.changes; + const shown = staged && columnKey in staged ? staged[columnKey] : row?.[columnKey]; + if (isUnchangedCellValue(value, shown)) return null; + return cellSelection.confirmCommit(row, columnKey, value) ?? null; + }; + + /** + * Write a confirmed value once the host's answer comes, and hand focus back + * to the selected cell either way (the host's dialog had it meanwhile). + */ + const settleCommitConfirmation = (asked: Promise, row: any, columnKey: string, value: unknown) => { + void asked.then( + (confirmed) => { + if (confirmed) commitCellValueRef.current(row, columnKey, value, true); + focusSelectionRef.current = true; + bumpConfirmSettled(); + }, + () => { + focusSelectionRef.current = true; + bumpConfirmSettled(); + }, + ); + }; + const exitEdit = (revert: boolean) => { const active = editingCellRef.current; const snap = editRevertRef.current; @@ -2884,20 +2957,8 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => { // wire it only takes back this edit (below), as Esc on the selected cell // leaves a sent value alone. discardCellChange(active.rowKey, active.columnKey); - } else if (revert && active && snap) { - const { rowKey, columnKey } = active; - setPendingChanges((prev) => { - const cur = prev.get(rowKey); - const staged = !!cur && columnKey in cur.changes; - if (!staged && !snap.had) return prev; // nothing changed for this cell - const next = new Map(prev); - const rc = { ...(cur?.changes || {}) }; - if (snap.had) rc[columnKey] = snap.value; - else delete rc[columnKey]; - if (Object.keys(rc).length > 0) next.set(rowKey, { row: cur?.row ?? active.row, changes: rc }); - else next.delete(rowKey); - return next; - }); + } else if (revert && active) { + revertEditSession(active, snap); } editingCellRef.current = null; setEditingCell(null); @@ -3533,9 +3594,15 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => { }; /** Write a value into a cell without an editor: the commit `saveEdit` makes. */ - const commitCellValue = (row: any, columnKey: string, value: unknown) => { + const commitCellValue = (row: any, columnKey: string, value: unknown, confirmed = false) => { const rowKey = pendingRowKeyOf(row); const held = heldRowOf(rowKey) ?? row; + // objectstack#35685 — a toggle or a paste is asked about as an editor's commit is. + const asked = confirmed ? null : commitConfirmationOf(rowKey, held, columnKey, value); + if (asked) { + settleCommitConfirmation(asked, held, columnKey, value); + return; + } const inFlight = inFlightRef.current.get(rowKey); setPendingChanges((prev) => stageCellChange(prev, rowKey, held, columnKey, value, inFlight)); clearCellError(rowKey, columnKey); diff --git a/ui/packages/i18n/src/locales/ar.ts b/ui/packages/i18n/src/locales/ar.ts index c12ab9dff03..d17d45393ca 100644 --- a/ui/packages/i18n/src/locales/ar.ts +++ b/ui/packages/i18n/src/locales/ar.ts @@ -561,6 +561,12 @@ const ar = { approvalLocked: "هذا السجل مقفل أثناء الموافقة عليه.", noRecordPermission: "ليس لديك إذن بتحرير هذا السجل.", }, + stateChange: { + title: "تغيير {{field}}؟", + description: "يتغير {{field}} من {{from}} إلى {{to}}. قد يؤدي الحفظ إلى تشغيل عمليات أتمتة ذات صلة.", + confirm: "تغيير", + cancel: "إلغاء", + }, bulkSelected: "تم تحديد {{count}}", bulkSelected_zero: "تم تحديد {{count}}", bulkSelected_one: "تم تحديد {{count}}", @@ -1646,6 +1652,7 @@ const ar = { pathStageChangeConflict: 'قام شخص آخر بتغيير هذا السجل، ويتم الآن عرض أحدث إصدار. اضغط على المرحلة مرة أخرى إذا كان النقل لا يزال مطلوبًا.', pathStageChangeDenied: 'ليس لديك إذن لتغيير مرحلة هذا السجل.', pathStageChangeFailed: 'تعذر تغيير المرحلة.', + inlineEditRecordChanged: "تم تغيير هذا السجل في مكان آخر أثناء التحرير. يتم الاحتفاظ بتغييراتك غير المحفوظة، ويكتبها الحفظ فوق أحدث إصدار.", stageMenuTrigger: 'المرحلة: {{stage}}. تغيير المرحلة', stageMenuCurrent: 'المرحلة الحالية', stageMenuNotReachable: 'لا يمكن الانتقال إلى هنا من {{stage}}', diff --git a/ui/packages/i18n/src/locales/de.ts b/ui/packages/i18n/src/locales/de.ts index e1672686475..91c8d512df8 100644 --- a/ui/packages/i18n/src/locales/de.ts +++ b/ui/packages/i18n/src/locales/de.ts @@ -531,6 +531,12 @@ const de = { approvalLocked: "Dieser Datensatz ist während der Genehmigung gesperrt.", noRecordPermission: "Sie haben keine Berechtigung, diesen Datensatz zu bearbeiten.", }, + stateChange: { + title: "{{field}} ändern?", + description: "{{field}} wechselt von {{from}} zu {{to}}. Beim Speichern können zugehörige Automatisierungen ausgelöst werden.", + confirm: "Ändern", + cancel: "Abbrechen", + }, bulkSelected: "{{count}} ausgewählt", bulkSelected_one: "{{count}} ausgewählt", bulkSelected_other: "{{count}} ausgewählt", @@ -1472,6 +1478,7 @@ const de = { pathStageChangeConflict: 'Jemand anderes hat diesen Datensatz geändert; die aktuelle Version wird jetzt angezeigt. Klicken Sie erneut auf die Phase, wenn die Verschiebung weiterhin gilt.', pathStageChangeDenied: 'Sie sind nicht berechtigt, die Phase dieses Datensatzes zu ändern.', pathStageChangeFailed: 'Die Phase konnte nicht geändert werden.', + inlineEditRecordChanged: "Dieser Datensatz wurde während Ihrer Bearbeitung an anderer Stelle geändert. Ihre ungespeicherten Änderungen bleiben erhalten, und Speichern schreibt sie über die neueste Version.", stageMenuTrigger: 'Phase: {{stage}}. Phase ändern', stageMenuCurrent: 'aktuelle Phase', stageMenuNotReachable: 'Von {{stage}} nicht hierher verschiebbar', diff --git a/ui/packages/i18n/src/locales/en.ts b/ui/packages/i18n/src/locales/en.ts index da447f467d5..63ea0a29074 100644 --- a/ui/packages/i18n/src/locales/en.ts +++ b/ui/packages/i18n/src/locales/en.ts @@ -794,6 +794,13 @@ const en = { approvalLocked: 'This record is locked while it\'s in approval.', noRecordPermission: 'You don\'t have permission to edit this record.', }, + // objectstack#35685 — the confirm before a list cell moves a state-machine field. + stateChange: { + title: 'Change {{field}}?', + description: '{{field}} changes from {{from}} to {{to}}. Saving may trigger related automation.', + confirm: 'Change', + cancel: 'Cancel', + }, actions: 'Actions', edit: 'Edit', delete: 'Delete', @@ -1611,6 +1618,7 @@ const en = { pathStageChangeConflict: 'Someone else changed this record, and the latest version is now shown. Press the stage again if the move still applies.', pathStageChangeDenied: "You don't have permission to change this record's stage.", pathStageChangeFailed: 'The stage could not be changed.', + inlineEditRecordChanged: 'This record was changed elsewhere while you were editing. Your unsaved changes are kept, and Save writes them over the latest version.', stageMenuTrigger: 'Stage: {{stage}}. Change stage', stageMenuCurrent: 'current stage', stageMenuNotReachable: "Can't move here from {{stage}}", diff --git a/ui/packages/i18n/src/locales/es.ts b/ui/packages/i18n/src/locales/es.ts index 80ff6d3f7f9..390c4573d6e 100644 --- a/ui/packages/i18n/src/locales/es.ts +++ b/ui/packages/i18n/src/locales/es.ts @@ -542,6 +542,12 @@ const es = { approvalLocked: "Este registro está bloqueado mientras está en aprobación.", noRecordPermission: "No tiene permiso para editar este registro.", }, + stateChange: { + title: "¿Cambiar {{field}}?", + description: "{{field}} cambia de {{from}} a {{to}}. Al guardar se pueden activar automatizaciones relacionadas.", + confirm: "Cambiar", + cancel: "Cancelar", + }, bulkSelected: "{{count}} seleccionados", bulkSelected_one: "{{count}} seleccionado", bulkSelected_many: "{{count}} seleccionados", @@ -1517,6 +1523,7 @@ const es = { pathStageChangeConflict: 'Otra persona ha modificado este registro y ahora se muestra la versión más reciente. Vuelve a pulsar la etapa si el cambio sigue siendo válido.', pathStageChangeDenied: 'No tienes permiso para cambiar la etapa de este registro.', pathStageChangeFailed: 'No se ha podido cambiar la etapa.', + inlineEditRecordChanged: "Este registro se modificó en otro lugar mientras lo editaba. Sus cambios sin guardar se conservan, y Guardar los escribe sobre la versión más reciente.", stageMenuTrigger: 'Etapa: {{stage}}. Cambiar etapa', stageMenuCurrent: 'etapa actual', stageMenuNotReachable: 'No se puede pasar aquí desde {{stage}}', diff --git a/ui/packages/i18n/src/locales/fr.ts b/ui/packages/i18n/src/locales/fr.ts index 2f0f8cccab8..4bb460ae33a 100644 --- a/ui/packages/i18n/src/locales/fr.ts +++ b/ui/packages/i18n/src/locales/fr.ts @@ -537,6 +537,12 @@ const fr = { approvalLocked: "Cet enregistrement est verrouillé pendant son approbation.", noRecordPermission: "Vous n'avez pas l'autorisation de modifier cet enregistrement.", }, + stateChange: { + title: "Modifier {{field}} ?", + description: "{{field}} passe de {{from}} à {{to}}. L'enregistrement peut déclencher des automatisations associées.", + confirm: "Modifier", + cancel: "Annuler", + }, bulkSelected: "{{count}} sélectionné(s)", bulkSelected_one: "{{count}} sélectionné", bulkSelected_many: "{{count}} sélectionnés", @@ -1514,6 +1520,7 @@ const fr = { pathStageChangeConflict: "Quelqu'un d'autre a modifié cet enregistrement ; la dernière version est maintenant affichée. Cliquez à nouveau sur l'étape si le changement s'applique toujours.", pathStageChangeDenied: "Vous n'avez pas l'autorisation de modifier l'étape de cet enregistrement.", pathStageChangeFailed: "L'étape n'a pas pu être modifiée.", + inlineEditRecordChanged: "Cet enregistrement a été modifié ailleurs pendant votre modification. Vos modifications non enregistrées sont conservées, et Enregistrer les écrit sur la dernière version.", stageMenuTrigger: "Étape : {{stage}}. Changer d'étape", stageMenuCurrent: 'étape actuelle', stageMenuNotReachable: 'Impossible de passer ici depuis {{stage}}', diff --git a/ui/packages/i18n/src/locales/ja.ts b/ui/packages/i18n/src/locales/ja.ts index 38f2d5894bb..2c0176400e2 100644 --- a/ui/packages/i18n/src/locales/ja.ts +++ b/ui/packages/i18n/src/locales/ja.ts @@ -531,6 +531,12 @@ const ja = { approvalLocked: "このレコードは承認中のためロックされています。", noRecordPermission: "このレコードを編集する権限がありません。", }, + stateChange: { + title: "{{field}}を変更しますか?", + description: "{{field}}を {{from}} から {{to}} に変更します。保存すると関連する自動化が実行される場合があります。", + confirm: "変更", + cancel: "キャンセル", + }, bulkSelected: "{{count}} 件を選択中", bulkSelected_one: "{{count}} 件を選択中", bulkSelected_other: "{{count}} 件を選択中", @@ -1553,6 +1559,7 @@ const ja = { pathStageChangeConflict: '他のユーザーがこのレコードを変更したため、最新の内容を表示しています。移動が必要な場合は、もう一度ステージを押してください。', pathStageChangeDenied: 'このレコードのステージを変更する権限がありません。', pathStageChangeFailed: 'ステージを変更できませんでした。', + inlineEditRecordChanged: "編集中にこのレコードが別の場所で変更されました。未保存の変更はそのまま残り、保存すると最新版に上書きされます。", stageMenuTrigger: 'ステージ:{{stage}}。ステージを変更', stageMenuCurrent: '現在のステージ', stageMenuNotReachable: '{{stage}}からここへは移動できません', diff --git a/ui/packages/i18n/src/locales/ko.ts b/ui/packages/i18n/src/locales/ko.ts index 0812bba2672..e3ac9a12870 100644 --- a/ui/packages/i18n/src/locales/ko.ts +++ b/ui/packages/i18n/src/locales/ko.ts @@ -531,6 +531,12 @@ const ko = { approvalLocked: "이 레코드는 승인 중이라 잠겨 있습니다.", noRecordPermission: "이 레코드를 편집할 권한이 없습니다.", }, + stateChange: { + title: "{{field}}을(를) 변경할까요?", + description: "{{field}}이(가) {{from}}에서 {{to}}(으)로 변경됩니다. 저장하면 관련 자동화가 실행될 수 있습니다.", + confirm: "변경", + cancel: "취소", + }, bulkSelected: "{{count}}건 선택됨", bulkSelected_one: "{{count}}건 선택됨", bulkSelected_other: "{{count}}건 선택됨", @@ -1472,6 +1478,7 @@ const ko = { pathStageChangeConflict: '다른 사용자가 이 레코드를 변경하여 최신 버전을 표시합니다. 이동이 여전히 필요하면 단계를 다시 누르세요.', pathStageChangeDenied: '이 레코드의 단계를 변경할 권한이 없습니다.', pathStageChangeFailed: '단계를 변경할 수 없습니다.', + inlineEditRecordChanged: "편집하는 동안 이 레코드가 다른 곳에서 변경되었습니다. 저장하지 않은 변경 사항은 유지되며, 저장하면 최신 버전에 덮어씁니다.", stageMenuTrigger: '단계: {{stage}}. 단계 변경', stageMenuCurrent: '현재 단계', stageMenuNotReachable: '{{stage}}에서 여기로 이동할 수 없습니다', diff --git a/ui/packages/i18n/src/locales/pt-BR.ts b/ui/packages/i18n/src/locales/pt-BR.ts index c219bc5f495..ba18d2218ea 100644 --- a/ui/packages/i18n/src/locales/pt-BR.ts +++ b/ui/packages/i18n/src/locales/pt-BR.ts @@ -537,6 +537,12 @@ const pt = { approvalLocked: "Este registro está bloqueado enquanto está em aprovação.", noRecordPermission: "Você não tem permissão para editar este registro.", }, + stateChange: { + title: "Alterar {{field}}?", + description: "{{field}} muda de {{from}} para {{to}}. Salvar pode acionar automações relacionadas.", + confirm: "Alterar", + cancel: "Cancelar", + }, bulkSelected: "{{count}} selecionados", bulkSelected_one: "{{count}} selecionado", bulkSelected_many: "{{count}} selecionados", @@ -1514,6 +1520,7 @@ const pt = { pathStageChangeConflict: 'Outra pessoa alterou este registro, e a versão mais recente está sendo exibida. Pressione a etapa novamente se a mudança ainda se aplicar.', pathStageChangeDenied: 'Você não tem permissão para alterar a etapa deste registro.', pathStageChangeFailed: 'Não foi possível alterar a etapa.', + inlineEditRecordChanged: "Este registro foi alterado em outro lugar enquanto você editava. Suas alterações não salvas são mantidas, e Salvar as grava sobre a versão mais recente.", stageMenuTrigger: 'Etapa: {{stage}}. Alterar etapa', stageMenuCurrent: 'etapa atual', stageMenuNotReachable: 'Não é possível ir para cá a partir de {{stage}}', diff --git a/ui/packages/i18n/src/locales/ru.ts b/ui/packages/i18n/src/locales/ru.ts index 024a2762397..f12738dc07e 100644 --- a/ui/packages/i18n/src/locales/ru.ts +++ b/ui/packages/i18n/src/locales/ru.ts @@ -546,6 +546,12 @@ const ru = { approvalLocked: "Эта запись заблокирована, пока находится на согласовании.", noRecordPermission: "У вас нет прав на изменение этой записи.", }, + stateChange: { + title: "Изменить {{field}}?", + description: "{{field}}: {{from}} → {{to}}. При сохранении могут запуститься связанные автоматизации.", + confirm: "Изменить", + cancel: "Отмена", + }, bulkSelected: "Выбрано: {{count}}", bulkSelected_one: "Выбрано: {{count}}", bulkSelected_few: "Выбрано: {{count}}", @@ -1658,6 +1664,7 @@ const ru = { pathStageChangeConflict: 'Запись изменил другой пользователь, теперь показана последняя версия. Нажмите на этап ещё раз, если перевод всё ещё нужен.', pathStageChangeDenied: 'У вас нет прав на смену этапа этой записи.', pathStageChangeFailed: 'Не удалось сменить этап.', + inlineEditRecordChanged: "Пока вы редактировали, эту запись изменили в другом месте. Несохранённые изменения сохранены, и при сохранении они будут записаны поверх последней версии.", stageMenuTrigger: 'Этап: «{{stage}}». Сменить этап', stageMenuCurrent: 'текущий этап', stageMenuNotReachable: 'Сюда нельзя перейти с этапа «{{stage}}»', diff --git a/ui/packages/i18n/src/locales/zh-Hans.ts b/ui/packages/i18n/src/locales/zh-Hans.ts index 23d00805272..39d89b800e0 100644 --- a/ui/packages/i18n/src/locales/zh-Hans.ts +++ b/ui/packages/i18n/src/locales/zh-Hans.ts @@ -544,6 +544,12 @@ const zh = { approvalLocked: '此记录正在审批中,已锁定。', noRecordPermission: '您没有编辑此记录的权限。', }, + stateChange: { + title: '更改{{field}}?', + description: '{{field}}从 {{from}} 改为 {{to}},保存后可能触发相关自动化。', + confirm: '确认更改', + cancel: '取消', + }, actions: '操作', edit: '编辑', delete: '删除', @@ -1338,6 +1344,7 @@ const zh = { pathStageChangeConflict: '其他人已修改此记录,现已显示最新版本。如仍需移动,请再次点击该阶段。', pathStageChangeDenied: '你没有更改此记录阶段的权限。', pathStageChangeFailed: '无法更改阶段。', + inlineEditRecordChanged: '编辑期间,此记录已在别处被修改。你未保存的修改会保留,保存时以你的修改为准,写到最新版本上。', stageMenuTrigger: '阶段:{{stage}},更改阶段', stageMenuCurrent: '当前阶段', stageMenuNotReachable: '流转规则不允许从{{stage}}直接改到这里', diff --git a/ui/packages/i18n/src/locales/zh-Hant.ts b/ui/packages/i18n/src/locales/zh-Hant.ts index ec2fa15cb8f..96dbaa8f19a 100644 --- a/ui/packages/i18n/src/locales/zh-Hant.ts +++ b/ui/packages/i18n/src/locales/zh-Hant.ts @@ -544,6 +544,12 @@ const zhHant = { approvalLocked: '此記錄正在審批中,已鎖定。', noRecordPermission: '您沒有編輯此記錄的權限。', }, + stateChange: { + title: '更改{{field}}?', + description: '{{field}}從 {{from}} 改為 {{to}},儲存後可能觸發相關自動化。', + confirm: '確認更改', + cancel: '取消', + }, actions: '操作', edit: '編輯', delete: '刪除', @@ -1338,6 +1344,7 @@ const zhHant = { pathStageChangeConflict: '其他人已修改此記錄,現已顯示最新版本。如仍需移動,請再次點選該階段。', pathStageChangeDenied: '你沒有更改此記錄階段的權限。', pathStageChangeFailed: '無法更改階段。', + inlineEditRecordChanged: '編輯期間,此記錄已在別處被修改。你未儲存的修改會保留,儲存時以你的修改為準,寫到最新版本上。', stageMenuTrigger: '階段:{{stage}},更改階段', stageMenuCurrent: '當前階段', stageMenuNotReachable: '流轉規則不允許從{{stage}}直接改到這裡', diff --git a/ui/packages/plugin-detail/src/InlineEditSaveBar.tsx b/ui/packages/plugin-detail/src/InlineEditSaveBar.tsx index af5fa0dab05..390900cfb2d 100644 --- a/ui/packages/plugin-detail/src/InlineEditSaveBar.tsx +++ b/ui/packages/plugin-detail/src/InlineEditSaveBar.tsx @@ -554,6 +554,22 @@ export const InlineEditSaveBar: React.FC = ({ return () => window.removeEventListener('keydown', onKeyDown); }, [editing, saving, locked, conflictOpen, handleSave, cancel]); + // objectstack#35685 — the record's version when this edit session began. A + // record read again meanwhile at another version was changed elsewhere (a + // list cell beside the drawer, another tab): the draft stays as typed and + // Save writes it over the record as it is now, so the bar says so. + const dataVersion = typeof data?.updated_at === 'string' ? (data.updated_at as string) : undefined; + const [editBase, setEditBase] = React.useState<{ version: string | undefined } | null>(null); + React.useEffect(() => { + if (!editing) { + setEditBase(null); + return; + } + setEditBase((prev) => prev ?? { version: dataVersion }); + }, [editing, dataVersion]); + const changedWhileEditing = + !saving && editBase !== null && editBase.version !== undefined && dataVersion !== undefined && dataVersion !== editBase.version; + // Render nothing unless a provider is present and the record is being edited. if (!inline || !inline.editing) return null; @@ -609,6 +625,15 @@ export const InlineEditSaveBar: React.FC = ({ )} )} + {changedWhileEditing && ( +
+ {t('detail.inlineEditRecordChanged')} +
+ )} {/* The lock REASON is surfaced by DetailView's approval-lock band; here we only disable Save so a locked record can't be written. */}