diff --git a/api.planx.uk/modules/flows/publish/service.ts b/api.planx.uk/modules/flows/publish/service.ts index d1e440f6f1..cf2d4c41be 100644 --- a/api.planx.uk/modules/flows/publish/service.ts +++ b/api.planx.uk/modules/flows/publish/service.ts @@ -4,6 +4,7 @@ import { gql } from "graphql-request"; import type { FlowGraph, Node } from "@opensystemslab/planx-core/types"; import { userContext } from "../../auth/middleware.js"; import { getClient } from "../../../client/index.js"; +import { getApplicationTypeVals } from "../validate/service/projectTypes.js"; interface PublishFlow { publishedFlow: { diff --git a/api.planx.uk/modules/flows/validate/service/index.ts b/api.planx.uk/modules/flows/validate/service/index.ts index 7b77f595e7..79b5ba64c5 100644 --- a/api.planx.uk/modules/flows/validate/service/index.ts +++ b/api.planx.uk/modules/flows/validate/service/index.ts @@ -9,8 +9,9 @@ import { dataMerged, getMostRecentPublishedFlow } from "../../../../helpers.js"; import { validateFileTypes } from "./fileTypes.js"; import { validateInviteToPay } from "./inviteToPay.js"; import { validatePlanningConstraints } from "./planningConstraints.js"; -import { validateProjectTypes } from "./projectTypes.js"; +import { getApplicationTypeVals, validateProjectTypes } from "./projectTypes.js"; import { validateSections } from "./sections.js"; +import { getValidSchemaValues } from "@opensystemslab/planx-core"; type AlteredNode = { id: string; @@ -29,12 +30,24 @@ interface FlowValidateAndDiffResponse { alteredNodes: AlteredNode[] | null; message: string; validationChecks?: FlowValidationResponse[]; + applicationTypes?: any; + isStatutoryApplication?:boolean; + trackerArray?: any; } const validateAndDiffFlow = async ( flowId: string, ): Promise => { const flattenedFlow = await dataMerged(flowId); + const applicationTypes = getApplicationTypeVals(flattenedFlow) + const validApplicationTypes = getValidSchemaValues("ApplicationType"); + const trackerArray: {value:string, result: boolean | undefined}[] = [] + // What I want is, for the array of app types in the flow, + // do they all match with schema application type values? + const isStatutoryApplication = applicationTypes.some((value)=> { + const result = validApplicationTypes?.includes(value) + trackerArray.push({value: value, result: result}) + return result }) const mostRecent = await getMostRecentPublishedFlow(flowId); const delta = jsondiffpatch.diff(mostRecent, flattenedFlow); @@ -80,6 +93,9 @@ const validateAndDiffFlow = async ( alteredNodes, message: "Changes queued to publish", validationChecks: sortedValidationChecks, + applicationTypes: applicationTypes, + isStatutoryApplication: isStatutoryApplication, + trackerArray: trackerArray }; }; diff --git a/api.planx.uk/modules/flows/validate/service/projectTypes.ts b/api.planx.uk/modules/flows/validate/service/projectTypes.ts index 240165fd0f..2df2dffee8 100644 --- a/api.planx.uk/modules/flows/validate/service/projectTypes.ts +++ b/api.planx.uk/modules/flows/validate/service/projectTypes.ts @@ -67,4 +67,22 @@ const getProjectTypeVals = (flowGraph: FlowGraph): string[] => { return answerVals; }; -export { validateProjectTypes }; +const getApplicationTypeVals = (flowGraph: FlowGraph): string[] => { + const applicationTypeChecklistNodes = Object.entries(flowGraph).filter( + (entry) => + entry[1].data?.fn === "application.type", + ); + + const answerVals: string[] = []; + applicationTypeChecklistNodes.map(([_nodeId, node]) => + node.edges?.map((edgeId) => { + if (typeof flowGraph[edgeId]?.data?.val === "string") { + answerVals.push(flowGraph[edgeId]?.data?.val); + } + }), + ); + + return answerVals; +}; + +export { validateProjectTypes, getApplicationTypeVals }; diff --git a/editor.planx.uk/src/pages/Filters.tsx b/editor.planx.uk/src/pages/Filters.tsx index afd1066111..7298af4bb1 100644 --- a/editor.planx.uk/src/pages/Filters.tsx +++ b/editor.planx.uk/src/pages/Filters.tsx @@ -97,6 +97,7 @@ interface FiltersProps { flows: FlowSummary[]; setFilteredFlows: React.Dispatch>; formik: FormikProps<{ pattern: string; keys: string[] }>; + clearFilters: boolean; } interface FilterState { @@ -112,6 +113,7 @@ export const Filters: React.FC = ({ flows, setFilteredFlows, formik, + clearFilters, }) => { const [filters, setFilters] = useState(); const [selectedFilters, setSelectedFilters] = useState< @@ -144,6 +146,7 @@ export const Filters: React.FC = ({ if (value) { searchParams.set(key, value); } else { + console.log("hitting delete"); searchParams.delete(key); } }); @@ -159,10 +162,28 @@ export const Filters: React.FC = ({ ); }; + const clearSearchParams = () => { + const searchParams = new URLSearchParams(route.url.search); + searchParams.delete("status"); + searchParams.delete("applicationType"); + searchParams.delete("serviceType"); + navigation.navigate( + { + pathname: window.location.pathname, + search: searchParams.toString(), // Use the complete searchParams object + }, + { + replace: true, + }, + ); + }; + const clearAllFilters = () => { setFilters({}); setSelectedFilters([]); formik.setFieldValue("pattern", ""); + clearSearchParams(); + window.location.reload(); }; const handleFiltering = (filtersArg: FilterState | undefined) => { @@ -218,6 +239,12 @@ export const Filters: React.FC = ({ selectedFilters, ]); + useEffect(() => { + if (clearFilters) { + clearAllFilters(); + } + }, [clearFilters]); + const getSearchResults = () => { const searchResults = results.map((result) => result.item); return { diff --git a/editor.planx.uk/src/pages/FlowEditor/components/Sidebar/Publish/PublishFlowButton.tsx b/editor.planx.uk/src/pages/FlowEditor/components/Sidebar/Publish/PublishFlowButton.tsx index a6266bdf5d..74c0d29ffe 100644 --- a/editor.planx.uk/src/pages/FlowEditor/components/Sidebar/Publish/PublishFlowButton.tsx +++ b/editor.planx.uk/src/pages/FlowEditor/components/Sidebar/Publish/PublishFlowButton.tsx @@ -52,6 +52,7 @@ export const PublishFlowButton: React.FC<{ previewURL: string }> = ({ try { setLastPublishedTitle("Checking for changes..."); const alteredFlow = await validateAndDiffFlow(flowId); + console.log(alteredFlow); setAlteredNodes( alteredFlow?.data.alteredNodes ? alteredFlow.data.alteredNodes : [], ); diff --git a/editor.planx.uk/src/pages/Team.tsx b/editor.planx.uk/src/pages/Team.tsx index 3787ac9003..706335d43e 100644 --- a/editor.planx.uk/src/pages/Team.tsx +++ b/editor.planx.uk/src/pages/Team.tsx @@ -395,6 +395,8 @@ const Team: React.FC = () => { const [filteredFlows, setFilteredFlows] = useState( null, ); + const [triggerClearFilters, setTriggerClearFilters] = + useState(false); const formik = useFormik({ initialValues: { pattern: "", keys: ["name"] }, @@ -518,6 +520,7 @@ const Team: React.FC = () => { flows={flows} setFilteredFlows={setFilteredFlows} formik={formik} + clearFilters={triggerClearFilters} /> )} {teamHasFlows ? ( @@ -545,6 +548,10 @@ const Team: React.FC = () => { )} +