Skip to content

Commit

Permalink
init work on Stat app types and clearfilters
Browse files Browse the repository at this point in the history
  • Loading branch information
RODO94 committed Jan 20, 2025
1 parent e7d45da commit c78a06a
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 2 deletions.
1 change: 1 addition & 0 deletions api.planx.uk/modules/flows/publish/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
18 changes: 17 additions & 1 deletion api.planx.uk/modules/flows/validate/service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<FlowValidateAndDiffResponse> => {
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);
Expand Down Expand Up @@ -80,6 +93,9 @@ const validateAndDiffFlow = async (
alteredNodes,
message: "Changes queued to publish",
validationChecks: sortedValidationChecks,
applicationTypes: applicationTypes,
isStatutoryApplication: isStatutoryApplication,
trackerArray: trackerArray
};
};

Expand Down
20 changes: 19 additions & 1 deletion api.planx.uk/modules/flows/validate/service/projectTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
27 changes: 27 additions & 0 deletions editor.planx.uk/src/pages/Filters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ interface FiltersProps {
flows: FlowSummary[];
setFilteredFlows: React.Dispatch<React.SetStateAction<FlowSummary[] | null>>;
formik: FormikProps<{ pattern: string; keys: string[] }>;
clearFilters: boolean;
}

interface FilterState {
Expand All @@ -112,6 +113,7 @@ export const Filters: React.FC<FiltersProps> = ({
flows,
setFilteredFlows,
formik,
clearFilters,
}) => {
const [filters, setFilters] = useState<FilterState>();
const [selectedFilters, setSelectedFilters] = useState<
Expand Down Expand Up @@ -144,6 +146,7 @@ export const Filters: React.FC<FiltersProps> = ({
if (value) {
searchParams.set(key, value);
} else {
console.log("hitting delete");
searchParams.delete(key);
}
});
Expand All @@ -159,10 +162,28 @@ export const Filters: React.FC<FiltersProps> = ({
);
};

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) => {
Expand Down Expand Up @@ -218,6 +239,12 @@ export const Filters: React.FC<FiltersProps> = ({
selectedFilters,
]);

useEffect(() => {
if (clearFilters) {
clearAllFilters();
}
}, [clearFilters]);

const getSearchResults = () => {
const searchResults = results.map((result) => result.item);
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 : [],
);
Expand Down
7 changes: 7 additions & 0 deletions editor.planx.uk/src/pages/Team.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,8 @@ const Team: React.FC = () => {
const [filteredFlows, setFilteredFlows] = useState<FlowSummary[] | null>(
null,
);
const [triggerClearFilters, setTriggerClearFilters] =
useState<boolean>(false);

const formik = useFormik({
initialValues: { pattern: "", keys: ["name"] },
Expand Down Expand Up @@ -518,6 +520,7 @@ const Team: React.FC = () => {
flows={flows}
setFilteredFlows={setFilteredFlows}
formik={formik}
clearFilters={triggerClearFilters}
/>
)}
{teamHasFlows ? (
Expand Down Expand Up @@ -545,6 +548,10 @@ const Team: React.FC = () => {
<Button variant="link">Clear filters</Button>
)}
</Box>
<Button
title="Clear"
onClick={() => setTriggerClearFilters(true)}
/>
{hasFeatureFlag("SORT_FLOWS") && flows && (
<Box sx={{ display: "flex", alignItems: "center", gap: 1.5 }}>
<Typography variant="body2">
Expand Down

0 comments on commit c78a06a

Please sign in to comment.