Fix: rundown import (#1795)

* fix: patch in the active rundown id and title

* fix: send a ALL refetch on project patch

* fix: load the last used rundown on project patch and not just the first one

* chore: lint

* chore: clean up and let rundown service send the refetch request

* chore: dont destructure rundown
This commit is contained in:
Alex Christoffer Rasmussen
2025-09-25 10:49:16 +02:00
parent bc0b83aa14
commit 80e4dc0941
3 changed files with 12 additions and 6 deletions
@@ -2,6 +2,7 @@ import { useState } from 'react';
import { CustomFields, Rundown } from 'ontime-types';
import Button from '../../../../../common/components/buttons/Button';
import useRundown from '../../../../../common/hooks-query/useRundown';
import * as Panel from '../../../panel-utils/PanelUtils';
import PreviewSpreadsheet from './preview/PreviewRundown';
@@ -17,7 +18,7 @@ interface ImportReviewProps {
export default function ImportReview(props: ImportReviewProps) {
const { rundown, customFields, onFinished, onCancel } = props;
const { data: currentRundown } = useRundown();
const [loading, setLoading] = useState(false);
const { importRundown } = useGoogleSheet();
const resetPreview = useSheetStore((state) => state.resetPreview);
@@ -29,9 +30,12 @@ export default function ImportReview(props: ImportReviewProps) {
const applyImport = async () => {
setLoading(true);
// we need to import on-top of the currently loaded rundown
// so the id needs to match
await importRundown(
{
[rundown.id]: rundown,
[currentRundown.id]: { ...rundown, id: currentRundown.id, title: currentRundown.title },
},
customFields,
);
@@ -31,7 +31,6 @@ export async function patchPartialProjectFile(req: Request, res: Response<Databa
};
const newData = await projectService.patchCurrentProject(patchDb);
res.status(200).send(newData);
} catch (error) {
const message = getErrorMessage(error);
@@ -323,11 +323,14 @@ export async function patchCurrentProject(data: Partial<DatabaseModel>) {
/**
* The user may have multiple rundowns
* We currently ignore all other rundowns
* so attempt to get the one that was used last
* otherwise just pick the first
*/
const firstRundown = getFirstRundown(result);
const last = await getLastLoaded();
const rundownToLoad =
last?.rundownId && last.rundownId in result ? result[last.rundownId] : getFirstRundown(result);
await initRundown(firstRundown, customFields);
await initRundown(rundownToLoad, customFields, true);
}
const updatedData = await getDataProvider().getData();