From ce95d99f27f5461d487763c7731e8ce4614c7e36 Mon Sep 17 00:00:00 2001 From: James Perrin Date: Thu, 6 Jul 2023 12:19:00 +0100 Subject: [PATCH 1/2] fixes #36, #997 respect workflow displayOrder, add filter workflows by displayOrder UoM: MAT-477, MAT-478 --- editor-settings.toml | 9 +++++++++ src/config.ts | 17 +++++++++++++++++ src/main/WorkflowSelection.tsx | 31 +++++++++++++++++++++++++++++-- src/types.ts | 5 +++++ 4 files changed, 60 insertions(+), 2 deletions(-) diff --git a/editor-settings.toml b/editor-settings.toml index d79e3463c..b7fc4fd4b 100644 --- a/editor-settings.toml +++ b/editor-settings.toml @@ -165,3 +165,12 @@ # Type: boolean # Default: true #local = + +[workflow] + +# Filter the publishing workflows by their displayOrder value +# min <= displayOrder <= max +# Type: number +# Default: undefined (unbound) +#min = +#max = \ No newline at end of file diff --git a/src/config.ts b/src/config.ts index 4c5b3c9ae..b5c116676 100644 --- a/src/config.ts +++ b/src/config.ts @@ -57,6 +57,10 @@ interface iSettings { languages: { [key: string]: string } | undefined, icons: { [key: string]: string } | undefined, defaultVideoFlavor: Flavor | undefined, + }, + workflow: { + min: number | undefined, + max: number | undefined, } } @@ -92,6 +96,10 @@ const defaultSettings: iSettings = { languages: {}, icons: undefined, defaultVideoFlavor: undefined, + }, + workflow: { + min: undefined, + max: undefined } } let configFileSettings: iSettings @@ -287,6 +295,11 @@ const types = { throw new Error("is not a string, but should be"); } }, + 'number': (v: any, _allowParse: any) => { + if (isNaN(v)) { + throw new Error('is not a number, but should be'); + } + }, 'boolean': (v: string, allowParse: any) => { if (typeof v === 'boolean') { return; @@ -373,6 +386,10 @@ const SCHEMA = { thumbnail: { show: types.boolean, simpleMode: types.boolean, + }, + workflow: { + min: types.number, + max: types.number } } diff --git a/src/main/WorkflowSelection.tsx b/src/main/WorkflowSelection.tsx index ccc8debca..35d4e7acb 100644 --- a/src/main/WorkflowSelection.tsx +++ b/src/main/WorkflowSelection.tsx @@ -12,7 +12,7 @@ import { faChevronLeft } from "@fortawesome/free-solid-svg-icons"; import { SaveAndProcessButton } from "./WorkflowConfiguration"; import { selectStatus, selectError } from "../redux/workflowPostAndProcessSlice"; import { selectStatus as saveSelectStatus, selectError as saveSelectError } from "../redux/workflowPostSlice"; -import { httpRequestState, Workflow } from "../types"; +import { httpRequestState, IWorkflowConfiguration, Workflow } from "../types"; import { SaveButton } from "./Save"; import { EmotionJSX } from "@emotion/react/types/jsx-namespace"; @@ -20,6 +20,7 @@ import { useTranslation } from 'react-i18next'; import { Trans } from "react-i18next"; import { FormControlLabel, Radio, RadioGroup } from "@mui/material"; import { selectTheme } from "../redux/themeSlice"; +import { settings } from "../config"; /** * Allows the user to select a workflow @@ -30,8 +31,34 @@ const WorkflowSelection : React.FC = () => { const dispatch = useDispatch(); + const filterWorkflows = (workflowFilter: IWorkflowConfiguration | undefined, workflows: Workflow[]) => { + if (workflowFilter) { + let filterWorkflows : Workflow[] = [] + + workflows.forEach((workflow: Workflow) => { + if ((!workflowFilter.min || workflow.displayOrder >= workflowFilter.min) && + (!workflowFilter.max || workflow.displayOrder <= workflowFilter.max)) { + filterWorkflows.push(workflow) + } + }) + + if (filterWorkflows.length === 0) { + console.warn('Filtering removed all workflows, ignoring') + filterWorkflows = workflows + } + + return (filterWorkflows) + } + + return (workflows) + } + // Initialite redux states - const workflows = useSelector(selectWorkflows) + const workflowFilter: IWorkflowConfiguration | undefined = settings.workflow; + const workflows = filterWorkflows(workflowFilter, useSelector(selectWorkflows)).sort((a, b) => { + return (b.displayOrder - a.displayOrder) + }) + const finishState = useSelector(selectFinishState) const pageNumber = useSelector(selectPageNumber) const theme = useSelector(selectTheme) diff --git a/src/types.ts b/src/types.ts index c0dca9610..21af154f3 100644 --- a/src/types.ts +++ b/src/types.ts @@ -83,3 +83,8 @@ export interface httpRequestState { error: string | undefined, errorReason: 'unknown' | 'workflowActive' } + +export interface IWorkflowConfiguration { + min: number | undefined; + max: number | undefined; +} From de0833709509bdd02ec06ea263a68a4bb71e1a8a Mon Sep 17 00:00:00 2001 From: James S Perrin Date: Mon, 10 Jul 2023 15:53:22 +0100 Subject: [PATCH 2/2] fix #997, sorting when displayOrder undefined --- src/main/WorkflowSelection.tsx | 4 +++- src/redux/videoSlice.ts | 4 +--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/WorkflowSelection.tsx b/src/main/WorkflowSelection.tsx index 35d4e7acb..5513a8a70 100644 --- a/src/main/WorkflowSelection.tsx +++ b/src/main/WorkflowSelection.tsx @@ -55,7 +55,9 @@ const WorkflowSelection : React.FC = () => { // Initialite redux states const workflowFilter: IWorkflowConfiguration | undefined = settings.workflow; - const workflows = filterWorkflows(workflowFilter, useSelector(selectWorkflows)).sort((a, b) => { + let workflows = filterWorkflows(workflowFilter, useSelector(selectWorkflows)) + // Need to make copy to handle undefined displayOrder values + workflows = [...workflows].sort((a, b) => { return (b.displayOrder - a.displayOrder) }) diff --git a/src/redux/videoSlice.ts b/src/redux/videoSlice.ts index 4bb612a3d..ab65ab8bd 100644 --- a/src/redux/videoSlice.ts +++ b/src/redux/videoSlice.ts @@ -212,9 +212,7 @@ const videoSlice = createSlice({ state.duration = action.payload.duration state.title = action.payload.title state.segments = parseSegments(action.payload.segments, action.payload.duration) - state.workflows = action.payload.workflows.sort((n1: { displayOrder: number; }, n2: { displayOrder: number; }) => { - return n1.displayOrder - n2.displayOrder; - }); + state.workflows = action.payload.workflows state.waveformImages = action.payload.waveformURIs ? action.payload.waveformURIs : state.waveformImages state.originalThumbnails = state.tracks.map((track: Track) => { return {id: track.id, uri: track.thumbnailUri} })