Skip to content

Commit

Permalink
feat: added possibility to add, change and remove multiviewers on run…
Browse files Browse the repository at this point in the history
…ning production
  • Loading branch information
malmen237 committed Oct 16, 2024
1 parent 09dbcac commit 0c0831c
Show file tree
Hide file tree
Showing 13 changed files with 247 additions and 107 deletions.
56 changes: 41 additions & 15 deletions src/api/manager/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ export async function startProduction(
{ step: 'pipeline_outputs', success: false },
{ step: 'multiviews', success: false }
],
error: 'Unknown error occured'
error: 'Could not start multiviews'
};
}
return {
Expand Down Expand Up @@ -951,7 +951,8 @@ export async function postMultiviewersOnRunningProduction(
additions: MultiviewSettings[]
) {
try {
if (!production.production_settings.pipelines[0].multiviews) {
const multiview = production.production_settings.pipelines[0].multiviews;
if (!multiview) {
Log().error(
`No multiview settings specified for production: ${production.name}`
);
Expand Down Expand Up @@ -979,11 +980,33 @@ export async function postMultiviewersOnRunningProduction(
throw `Failed to create multiview for pipeline '${productionSettings.pipelines[0].pipeline_name}/${productionSettings.pipelines[0].pipeline_id}': ${error}`;
});

runtimeMultiviews.flatMap((runtimeMultiview, index) => {
const multiview = production.production_settings.pipelines[0].multiviews;
if (multiview && multiview[index]) {
return (multiview[index].multiview_id = runtimeMultiview.id);
const multiviewsWithUpdatedId: MultiviewSettings[] = [
...multiview.slice(0, multiview.length - runtimeMultiviews.length),
...runtimeMultiviews.map((runtimeMultiview, index) => {
return {
...multiview[multiview.length - runtimeMultiviews.length + index],
multiview_id: runtimeMultiview.id
};
})
];

await putProduction(production._id.toString(), {
...production,
production_settings: {
...production.production_settings,
pipelines: production.production_settings.pipelines.map((pipeline) => {
return {
...pipeline,
multiviews: multiviewsWithUpdatedId
};
})
}
}).catch(async (error) => {
Log().error(
`Failed to save multiviews for pipeline '${productionSettings.pipelines[0].pipeline_name}/${productionSettings.pipelines[0].pipeline_id}' to database`,
error
);
throw error;
});

return {
Expand All @@ -999,7 +1022,7 @@ export async function postMultiviewersOnRunningProduction(
}
};
} catch (e) {
Log().error('Could not start multiviews');
Log().error('Could not create multiviews');
Log().error(e);
if (typeof e !== 'string') {
return {
Expand All @@ -1013,7 +1036,7 @@ export async function postMultiviewersOnRunningProduction(
}
]
},
error: 'Unknown error occured'
error: 'Could not create multiviews'
};
}
return {
Expand All @@ -1023,7 +1046,8 @@ export async function postMultiviewersOnRunningProduction(
steps: [
{
step: 'create_multiview',
success: false
success: false,
message: e
}
]
},
Expand Down Expand Up @@ -1065,7 +1089,7 @@ export async function putMultiviewersOnRunningProduction(
}
};
} catch (e) {
Log().error('Could not start multiviews');
Log().error('Could not update multiviews');
Log().error(e);
if (typeof e !== 'string') {
return {
Expand All @@ -1079,7 +1103,7 @@ export async function putMultiviewersOnRunningProduction(
}
]
},
error: 'Unknown error occured'
error: 'Could not update multiviews'
};
}
return {
Expand All @@ -1089,7 +1113,8 @@ export async function putMultiviewersOnRunningProduction(
steps: [
{
step: 'update_multiview',
success: false
success: false,
message: e
}
]
},
Expand Down Expand Up @@ -1149,7 +1174,7 @@ export async function deleteMultiviewersOnRunningProduction(
}
};
} catch (e) {
Log().error('Could not start multiviews');
Log().error('Could not delete multiviews');
Log().error(e);
if (typeof e !== 'string') {
return {
Expand All @@ -1163,7 +1188,7 @@ export async function deleteMultiviewersOnRunningProduction(
}
]
},
error: 'Unknown error occured'
error: 'Could not delete multiviews'
};
}
return {
Expand All @@ -1173,7 +1198,8 @@ export async function deleteMultiviewersOnRunningProduction(
steps: [
{
step: 'delete_multiview',
success: false
success: false,
message: e
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export async function PUT(request: NextRequest): Promise<NextResponse> {
Log().error(error);
const errorResponse = {
ok: false,
error: 'unexpected'
error: 'Could not update multiviewers'
};
return new NextResponse(JSON.stringify(errorResponse), { status: 500 });
});
Expand All @@ -44,7 +44,7 @@ export async function DELETE(request: NextRequest): Promise<NextResponse> {
Log().error(error);
const errorResponse = {
ok: false,
error: 'unexpected'
error: 'Could not remove multiviewers'
};
return new NextResponse(JSON.stringify(errorResponse), { status: 500 });
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export async function POST(request: NextRequest): Promise<NextResponse> {
Log().error(error);
const errorResponse = {
ok: false,
error: 'unexpected'
error: 'Could not add multiviewers'
};
return new NextResponse(JSON.stringify(errorResponse), { status: 500 });
});
Expand Down
36 changes: 29 additions & 7 deletions src/app/production/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ import { ConfigureMultiviewButton } from '../../../components/modal/configureMul
import { useUpdateSourceInputSlotOnMultiviewLayouts } from '../../../hooks/useUpdateSourceInputSlotOnMultiviewLayouts';
import { useCheckProductionPipelines } from '../../../hooks/useCheckProductionPipelines';
import cloneDeep from 'lodash.clonedeep';
import { useUpdateMultiviewersOnRunningProduction } from '../../../hooks/workflow';
import {
useAddMultiviewersOnRunningProduction,
useRemoveMultiviewersOnRunningProduction,
useUpdateMultiviewersOnRunningProduction
} from '../../../hooks/workflow';
import { MultiviewSettings } from '../../../interfaces/multiview';

export default function ProductionConfiguration({ params }: PageProps) {
Expand Down Expand Up @@ -92,8 +96,12 @@ export default function ProductionConfiguration({ params }: PageProps) {
const [updateMultiviewViews] = useMultiviews();
const [updateSourceInputSlotOnMultiviewLayouts] =
useUpdateSourceInputSlotOnMultiviewLayouts();
const [addMultiviewersOnRunningProduction] =
useAddMultiviewersOnRunningProduction();
const [updateMultiviewersOnRunningProduction] =
useUpdateMultiviewersOnRunningProduction();
const [removeMultiviewersOnRunningProduction] =
useRemoveMultiviewersOnRunningProduction();

//FROM LIVE API
const [pipelines, loadingPipelines, , refreshPipelines] = usePipelines();
Expand Down Expand Up @@ -309,12 +317,26 @@ export default function ProductionConfiguration({ params }: PageProps) {
(oldItem) => !presetMultiviewsMap.has(oldItem.multiview_id)
);

updateMultiviewersOnRunningProduction(
(productionSetup?._id.toString(), updatedPreset),
additions,
updates,
removals
);
if (additions.length > 0) {
addMultiviewersOnRunningProduction(
(productionSetup?._id.toString(), updatedPreset),
additions
);
}

if (updates.length > 0) {
updateMultiviewersOnRunningProduction(
(productionSetup?._id.toString(), updatedPreset),
updates
);
}

if (removals.length > 0) {
removeMultiviewersOnRunningProduction(
(productionSetup?._id.toString(), updatedPreset),
removals
);
}
}

putProduction(productionSetup?._id.toString(), updatedPreset).then(() => {
Expand Down
25 changes: 15 additions & 10 deletions src/components/modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Modal as BaseModal } from '@mui/base';
type BaseModalProps = {
open: boolean;
forwardRef?: LegacyRef<HTMLDivElement> | null;
outsideClick: () => void;
outsideClick?: () => void;
className?: string;
};

Expand All @@ -16,16 +16,21 @@ export function Modal({ open, children, outsideClick, className }: ModalProps) {
const element = useRef<HTMLDivElement | null>(null);

useEffect(() => {
const handleClickOutside = (event: MouseEvent) => {
if (element.current && !element.current.contains(event.target as Node)) {
outsideClick();
}
};
if (outsideClick) {
const handleClickOutside = (event: MouseEvent) => {
if (
element.current &&
!element.current.contains(event.target as Node)
) {
outsideClick();
}
};

document.addEventListener('click', handleClickOutside, true);
return () => {
document.removeEventListener('click', handleClickOutside, true);
};
document.addEventListener('click', handleClickOutside, true);
return () => {
document.removeEventListener('click', handleClickOutside, true);
};
}
}, [outsideClick]);

return (
Expand Down
37 changes: 37 additions & 0 deletions src/components/modal/UpdateMultiviewersModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { useTranslate } from '../../i18n/useTranslate';
import { Button } from '../button/Button';
import { Modal } from './Modal';

type UpdateMultiviewersModalProps = {
open: boolean;
onAbort: () => void;
onConfirm: () => void;
};

export function UpdateMultiviewersModal({
open,
onAbort,
onConfirm
}: UpdateMultiviewersModalProps) {
const t = useTranslate();
return (
<Modal open={open} outsideClick={onAbort}>
<div className="text-center flex flex-col items-center">
<h1 className="text-xl">{t('preset.confirm_update_multiviewers')}</h1>

<div className="flex gap-8 mt-4">
<Button
onClick={onAbort}
className="bg-button-delete hover:bg-button-hover-red-bg"
>
{t('abort')}
</Button>

<Button onClick={onConfirm} className={'min-w-fit'}>
{t('preset.confirm_update')}
</Button>
</div>
</div>
</Modal>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { usePutMultiviewLayout } from '../../../hooks/multiviewLayout';
import Decision from '../configureOutputModal/Decision';
import MultiviewLayoutSettings from './MultiviewLayoutSettings/MultiviewLayoutSettings';
import { IconSettings } from '@tabler/icons-react';
import { UpdateMultiviewersModal } from '../UpdateMultiviewersModal';

type ConfigureMultiviewModalProps = {
open: boolean;
Expand All @@ -33,6 +34,7 @@ export function ConfigureMultiviewModal({
[]
);
const [layoutModalOpen, setLayoutModalOpen] = useState(false);
const [confirmUpdateModalOpen, setConfirmUpdateModalOpen] = useState(false);
const [newMultiviewLayout, setNewMultiviewLayout] =
useState<TMultiviewLayout | null>(null);
const addNewLayout = usePutMultiviewLayout();
Expand All @@ -59,6 +61,14 @@ export function ConfigureMultiviewModal({
}, [multiviews]);

const onSave = () => {
if (production?.isActive && !confirmUpdateModalOpen) {
setConfirmUpdateModalOpen(true);
return;
}
if (production?.isActive && confirmUpdateModalOpen) {
setConfirmUpdateModalOpen(false);
}

const presetToUpdate = deepclone(preset);

if (!multiviews) {
Expand Down Expand Up @@ -162,7 +172,7 @@ export function ConfigureMultiviewModal({
};

return (
<Modal open={open} outsideClick={() => clearInputs()}>
<Modal open={open}>
{!layoutModalOpen && (
<div className="flex gap-3">
{multiviews &&
Expand Down Expand Up @@ -245,6 +255,14 @@ export function ConfigureMultiviewModal({
onClose={() => (layoutModalOpen ? closeLayoutModal() : clearInputs())}
onSave={() => (layoutModalOpen ? onUpdateLayoutPreset() : onSave())}
/>

{confirmUpdateModalOpen && (
<UpdateMultiviewersModal
open={confirmUpdateModalOpen}
onAbort={() => setConfirmUpdateModalOpen(false)}
onConfirm={() => onSave()}
/>
)}
</Modal>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export default function MultiviewSettingsConfig({
}
handleUpdateMultiview({
...multiviewLayouts[0],
_id: multiviewLayouts[0]._id?.toString(),
for_pipeline_idx: 0
});
}
Expand All @@ -80,7 +81,11 @@ export default function MultiviewSettingsConfig({
output: multiview?.output || selected.output
};
setSelectedMultiviewLayout(updatedMultiview);
handleUpdateMultiview({ ...updatedMultiview, for_pipeline_idx: 0 });
handleUpdateMultiview({
...updatedMultiview,
_id: updatedMultiview._id?.toString(),
for_pipeline_idx: 0
});
};

const getNumber = (val: string, prev: number) => {
Expand Down
8 changes: 7 additions & 1 deletion src/components/startProduction/StartProductionButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,13 @@ export function StartProductionButton({
),
{
...pipelineToUpdateMultiview,
multiviews: [{ ...multiviewLayouts[0], for_pipeline_idx: 0 }]
multiviews: [
{
...multiviewLayouts[0],
for_pipeline_idx: 0,
_id: multiviewLayouts[0]._id?.toString()
}
]
}
]
}
Expand Down
Loading

0 comments on commit 0c0831c

Please sign in to comment.