Skip to content

Commit

Permalink
add path match logic
Browse files Browse the repository at this point in the history
  • Loading branch information
lucechal14 committed Sep 10, 2024
1 parent cfc7479 commit c79a29a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Alert } from "../Feedback";
import Grid from "../grid";
import { Link as LinkComponent } from "../link";
import type { AppBanners } from "../Types";
import { checkPathMatchList } from "../utils";
import { findPathMatchList } from "../utils";

interface LayoutWithNotificationsProps {
bannersData: AppBanners;
Expand All @@ -26,12 +26,13 @@ const LayoutWithNotifications = ({

const location = useLocation();

checkPathMatchList(location?.pathname, perWorkflowData[workflow]?.paths);
const pathMatches = findPathMatchList(location?.pathname, perWorkflowData[workflow]?.paths);

const hasPerWorkflowAlert =
workflow && perWorkflowData[workflow] && !perWorkflowData[workflow]?.dismissed;
const showAlertPerWorkflow = !isEmpty(perWorkflowData[workflow]?.paths)
? hasPerWorkflowAlert && perWorkflowData[workflow]?.paths?.includes(location.pathname)
? hasPerWorkflowAlert &&
(perWorkflowData[workflow]?.paths?.includes(location.pathname) || pathMatches)
: hasPerWorkflowAlert;

const showAlertMultiWorkflow =
Expand Down
2 changes: 1 addition & 1 deletion frontend/packages/core/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// eslint-disable-next-line import/prefer-default-export
export { default as getDisplayName } from "./getDisplayName";
export { default as checkPathMatchList } from "./pathMatching";
export { default as findPathMatchList } from "./pathMatching";
14 changes: 10 additions & 4 deletions frontend/packages/core/src/utils/pathMatching.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { matchPath } from "react-router";

const checkPathMatchList = (locationPathname: string, pathstoMatch: string[]) => {
pathstoMatch.forEach(path => {
const findPathMatchList = (locationPathname: string, pathstoMatch: string[]) => {
let pathFound = false;

pathstoMatch?.forEach((path: string) => {
const match = matchPath({ path }, locationPathname);

console.log("match: ", match);
if (match) {
pathFound = true;
}
});

return pathFound;
};

export default checkPathMatchList;
export default findPathMatchList;

0 comments on commit c79a29a

Please sign in to comment.