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; +}