Skip to content

Commit

Permalink
fixes #36, #997 respect workflow displayOrder, add filter workflows b…
Browse files Browse the repository at this point in the history
…y displayOrder

UoM: MAT-477, MAT-478
  • Loading branch information
JamesUoM committed Jul 6, 2023
1 parent 897d4f5 commit ce95d99
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 2 deletions.
9 changes: 9 additions & 0 deletions editor-settings.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
17 changes: 17 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down Expand Up @@ -92,6 +96,10 @@ const defaultSettings: iSettings = {
languages: {},
icons: undefined,
defaultVideoFlavor: undefined,
},
workflow: {
min: undefined,
max: undefined
}
}
let configFileSettings: iSettings
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -373,6 +386,10 @@ const SCHEMA = {
thumbnail: {
show: types.boolean,
simpleMode: types.boolean,
},
workflow: {
min: types.number,
max: types.number
}
}

Expand Down
31 changes: 29 additions & 2 deletions src/main/WorkflowSelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ 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";

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
Expand All @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,8 @@ export interface httpRequestState {
error: string | undefined,
errorReason: 'unknown' | 'workflowActive'
}

export interface IWorkflowConfiguration {
min: number | undefined;
max: number | undefined;
}

0 comments on commit ce95d99

Please sign in to comment.