@@ -808,6 +829,17 @@ function ManualItemsView({
onClose={() => setPickerOpen(false)}
open={pickerOpen}
/>
+
+ setConflictOpen(false)}
+ onConfirm={reloadAfterConflict}
+ open={conflictOpen}
+ title="Order changed elsewhere"
+ tone="danger"
+ />
);
}
diff --git a/web/src/screens/MultiCollectionsScreen.test.tsx b/web/src/screens/MultiCollectionsScreen.test.tsx
index 28083bf7f..3b104e2aa 100644
--- a/web/src/screens/MultiCollectionsScreen.test.tsx
+++ b/web/src/screens/MultiCollectionsScreen.test.tsx
@@ -47,6 +47,14 @@ function mockApi(options: MockOptions = {}) {
}
}
+ // Single-record GET (the editor loads it on open for the #253 concurrency ETag) — must be
+ // matched before the list handler, which would otherwise swallow it with the paged shape.
+ const multiById = url.match(/^\/api\/multi-collections\/(\d+)$/);
+ if (multiById && method === 'GET') {
+ const found = (multi as Array<{ id: number }>).find((m) => String(m.id) === multiById[1]) ?? multi[0];
+ return Promise.resolve(jsonResponse(found));
+ }
+
if (url.startsWith('/api/multi-collections') && method === 'GET') {
return Promise.resolve(jsonResponse({ page: multi, totalCount: multi.length }));
}
diff --git a/web/src/screens/MultiCollectionsScreen.tsx b/web/src/screens/MultiCollectionsScreen.tsx
index 89170f6f8..d7a92c31a 100644
--- a/web/src/screens/MultiCollectionsScreen.tsx
+++ b/web/src/screens/MultiCollectionsScreen.tsx
@@ -2,9 +2,11 @@ import { useCallback, useEffect, useRef, useState } from 'react';
import { ArrowLeft, Check, Layers, Plus, Trash2, TriangleAlert } from 'lucide-react';
import { Badge, Button, Card, ConfirmDialog, IconButton, Input, Select, Spinner, Switch } from '../components';
import {
+ ApiError,
createMultiCollection,
deleteMultiCollection,
getCollections,
+ getMultiCollectionWithMeta,
getMultiCollections,
getSmartCollections,
messageFromMultiCollectionError,
@@ -111,15 +113,30 @@ function MultiCollectionEditor({
const [loadError, setLoadError] = useState
(null);
const [saveError, setSaveError] = useState(null);
const [saving, setSaving] = useState(false);
+ const [conflictOpen, setConflictOpen] = useState(false);
+ const [reloadKey, setReloadKey] = useState(0);
const activeRef = useRef(true);
+ // Concurrency ETag (issue #253): captured from the single-record GET when editing an existing
+ // multi-collection, sent as If-Match on save. There's no rotation-on-save because the editor
+ // always returns to the list after a successful save (see onSaved below).
+ const etagRef = useRef(null);
useEffect(() => {
activeRef.current = true;
- Promise.all([getCollections(), getSmartCollections()])
- .then(([manual, smart]) => {
+ Promise.all([
+ getCollections(),
+ getSmartCollections(),
+ initial ? getMultiCollectionWithMeta(initial.id) : Promise.resolve(null)
+ ])
+ .then(([manual, smart, mcMeta]) => {
if (activeRef.current) {
setCollections(manual);
setSmartCollections(smart);
+ if (mcMeta) {
+ etagRef.current = mcMeta.etag;
+ setName(mcMeta.data.name ?? '');
+ setItems(itemsFromMultiCollection(mcMeta.data));
+ }
setLoadError(null);
}
})
@@ -132,7 +149,7 @@ function MultiCollectionEditor({
return () => {
activeRef.current = false;
};
- }, []);
+ }, [initial, reloadKey]);
const hasManual = (id: number) => items.some((item) => item.kind === 'manual' && item.id === id);
const hasSmart = (id: number) => items.some((item) => item.kind === 'smart' && item.id === id);
@@ -182,19 +199,30 @@ function MultiCollectionEditor({
try {
const body = { items: items.map(toItemRequest), name: trimmedName };
if (initial) {
- await updateMultiCollection(initial.id, body);
+ await updateMultiCollection(initial.id, body, etagRef.current);
} else {
await createMultiCollection(body);
}
onSaved();
} catch (error) {
- setSaveError(messageFromMultiCollectionError(error, 'Unable to save multi-collection'));
+ if (error instanceof ApiError && error.status === 412) {
+ // Another edit landed since we loaded — force a reload rather than overwriting it (#253).
+ setConflictOpen(true);
+ } else {
+ setSaveError(messageFromMultiCollectionError(error, 'Unable to save multi-collection'));
+ }
} finally {
setSaving(false);
}
};
+ const reloadAfterConflict = () => {
+ setConflictOpen(false);
+ setSaveError(null);
+ setReloadKey((key) => key + 1);
+ };
+
const collectionOptions = [
{ label: 'Select a collection…', value: '' },
...collections
@@ -316,6 +344,17 @@ function MultiCollectionEditor({
))
)}
+
+ setConflictOpen(false)}
+ onConfirm={reloadAfterConflict}
+ open={conflictOpen}
+ title="Multi-collection changed elsewhere"
+ tone="danger"
+ />
);
}
diff --git a/web/src/screens/PlayoutScheduleEditors.tsx b/web/src/screens/PlayoutScheduleEditors.tsx
index 546e28f5b..d87287e85 100644
--- a/web/src/screens/PlayoutScheduleEditors.tsx
+++ b/web/src/screens/PlayoutScheduleEditors.tsx
@@ -1,14 +1,15 @@
import { useEffect, useRef, useState } from 'react';
import { ArrowDown, ArrowLeft, ArrowRight, ArrowUp, CalendarDays, Check, Plus, Trash2, TriangleAlert } from 'lucide-react';
import { navigateToPath } from '../routing';
-import { Badge, Button, Card, Checkbox, IconButton, Select, Spinner } from '../components';
+import { Badge, Button, Card, Checkbox, ConfirmDialog, IconButton, Select, Spinner } from '../components';
import { daysInMonth, firstMatchingIndex } from './playoutTemplateCalendar';
import {
+ ApiError,
DAYS_OF_WEEK,
- getAlternateSchedules,
+ getAlternateSchedulesWithMeta,
getDecoTemplates,
getPlayout,
- getPlayoutTemplates,
+ getPlayoutTemplatesWithMeta,
getSchedules,
getTemplates,
messageFromPlayoutClientError,
@@ -428,18 +429,24 @@ export function PlayoutAlternateSchedulesScreen({ playoutId }: { playoutId: numb
const [loadError, setLoadError] = useState