Skip to content

Commit

Permalink
🐛 Switch sidebar type based on routes (#1889)
Browse files Browse the repository at this point in the history
Linked changes:
1. fix incorrect handling of Paths.assessment and Paths.questionnaire -
both were incorrectly handled as dev routes
2. split Paths enum into type safe specialized read-only objects -
DevPaths, AdminPaths and GeneralPaths

Resolves: #954

---------

Signed-off-by: Radoslaw Szwajkowski <[email protected]>
  • Loading branch information
rszwajko authored May 9, 2024
1 parent e44cc09 commit fa5fff2
Show file tree
Hide file tree
Showing 5 changed files with 284 additions and 235 deletions.
108 changes: 61 additions & 47 deletions client/src/app/Paths.ts
Original file line number Diff line number Diff line change
@@ -1,54 +1,68 @@
export enum Paths {
base = "/",
notFound = "/not-found",

export const DevPaths = {
// Developer perspective
applications = "/applications",
applicationsAnalysisTab = "/applications/analysis-tab",
applicationsAssessmentTab = "/applications/assessment-tab",
applicationsImports = "/applications/application-imports",
applicationsImportsDetails = "/applications/application-imports/:importId",
archetypesAssessment = "/archetypes/assessment/:assessmentId",
applicationsAssessment = "/applications/assessment/:assessmentId",
applicationAssessmentActions = "/applications/assessment-actions/:applicationId",
viewArchetypes = "/applications/view-archetypes/:applicationId/archetypes/:archetypeId",
archetypeAssessmentActions = "/archetypes/assessment-actions/:archetypeId",
applicationAssessmentSummary = "/applications/assessment-summary/:assessmentId",
archetypeAssessmentSummary = "/archetypes/assessment-summary/:assessmentId",
applicationsReview = "/applications/:applicationId/review",
archetypeReview = "/archetypes/:archetypeId/review",
applicationsAnalysis = "/applications/analysis",
archetypes = "/archetypes",
controls = "/controls",
controlsBusinessServices = "/controls/business-services",
controlsStakeholders = "/controls/stakeholders",
controlsStakeholderGroups = "/controls/stakeholder-groups",
controlsJobFunctions = "/controls/job-functions",
controlsTags = "/controls/tags",
reports = "/reports",
migrationWaves = "/migration-waves",
waves = "/waves",
issues = "/issues",
issuesAllTab = "/issues/all",
issuesAllAffectedApplications = "/issues/all/:ruleset/:rule/affected-applications",
issuesSingleAppTab = "/issues/single-app",
issuesSingleAppSelected = "/issues/single-app/:applicationId",
applications: "/applications",
applicationsAnalysisTab: "/applications/analysis-tab",
applicationsAssessmentTab: "/applications/assessment-tab",
applicationsImports: "/applications/application-imports",
applicationsImportsDetails: "/applications/application-imports/:importId",
archetypesAssessment: "/archetypes/assessment/:assessmentId",
applicationsAssessment: "/applications/assessment/:assessmentId",
applicationAssessmentActions:
"/applications/assessment-actions/:applicationId",
viewArchetypes:
"/applications/view-archetypes/:applicationId/archetypes/:archetypeId",
archetypeAssessmentActions: "/archetypes/assessment-actions/:archetypeId",
applicationAssessmentSummary:
"/applications/assessment-summary/:assessmentId",
archetypeAssessmentSummary: "/archetypes/assessment-summary/:assessmentId",
applicationsReview: "/applications/:applicationId/review",
archetypeReview: "/archetypes/:archetypeId/review",
applicationsAnalysis: "/applications/analysis",
archetypes: "/archetypes",
controls: "/controls",
controlsBusinessServices: "/controls/business-services",
controlsStakeholders: "/controls/stakeholders",
controlsStakeholderGroups: "/controls/stakeholder-groups",
controlsJobFunctions: "/controls/job-functions",
controlsTags: "/controls/tags",
reports: "/reports",
migrationWaves: "/migration-waves",
waves: "/waves",
issues: "/issues",
issuesAllTab: "/issues/all",
issuesAllAffectedApplications:
"/issues/all/:ruleset/:rule/affected-applications",
issuesSingleAppTab: "/issues/single-app",
issuesSingleAppSelected: "/issues/single-app/:applicationId",

dependencies: "/dependencies",
} as const;

dependencies = "/dependencies",
export type DevPathValues = (typeof DevPaths)[keyof typeof DevPaths];

export const AdminPaths = {
// Administrator perspective
general = "/general",
identities = "/identities",
repositories = "/repositories",
repositoriesGit = "/repositories/git",
repositoriesSvn = "/repositories/svn",
repositoriesMvn = "/repositories/maven",
proxies = "/proxies",
migrationTargets = "/migration-targets",
assessment = "/assessment",
questionnaire = "/questionnaire/:questionnaireId",
jira = "/jira",
}
general: "/general",
identities: "/identities",
repositories: "/repositories",
repositoriesGit: "/repositories/git",
repositoriesSvn: "/repositories/svn",
repositoriesMvn: "/repositories/maven",
proxies: "/proxies",
migrationTargets: "/migration-targets",
assessment: "/assessment",
questionnaire: "/questionnaire/:questionnaireId",
jira: "/jira",
} as const;

export type AdminPathValues = (typeof AdminPaths)[keyof typeof AdminPaths];

export const GeneralPaths = {
base: "/",
notFound: "/not-found",
} as const;

export const Paths = { ...GeneralPaths, ...AdminPaths, ...DevPaths } as const;

export interface AssessmentRoute {
assessmentId: string;
Expand Down
30 changes: 15 additions & 15 deletions client/src/app/Routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { AppPlaceholder } from "@app/components/AppPlaceholder";
import { RepositoriesGit } from "./pages/repositories/Git";
import { RepositoriesMvn } from "./pages/repositories/Mvn";
import { RepositoriesSvn } from "./pages/repositories/Svn";
import { Paths } from "@app/Paths";
import { Paths, DevPathValues, AdminPathValues } from "@app/Paths";
import { RouteWrapper } from "./components/RouteWrapper";
import { adminRoles, devRoles } from "./rbac";
import { ErrorBoundary } from "react-error-boundary";
Expand Down Expand Up @@ -61,14 +61,14 @@ const AssessmentSummary = lazy(
"./pages/assessment/components/assessment-summary/assessment-summary-page"
)
);
export interface IRoute {
path: string;
export interface IRoute<T> {
path: T;
comp: React.ComponentType<any>;
exact?: boolean;
routes?: undefined;
}

export const devRoutes: IRoute[] = [
export const devRoutes: IRoute<DevPathValues>[] = [
{
path: Paths.applicationsImportsDetails,
comp: ImportDetails,
Expand Down Expand Up @@ -172,24 +172,14 @@ export const devRoutes: IRoute[] = [
},
]
: []),
{
path: Paths.assessment,
comp: AssessmentSettings,
exact: false,
},
{
path: Paths.questionnaire,
comp: Questionnaire,
exact: false,
},
{
path: Paths.archetypes,
comp: Archetypes,
exact: false,
},
];

export const adminRoutes: IRoute[] = [
export const adminRoutes: IRoute<AdminPathValues>[] = [
{
comp: General,
path: Paths.general,
Expand All @@ -215,6 +205,16 @@ export const adminRoutes: IRoute[] = [
path: Paths.repositoriesMvn,
exact: false,
},
{
path: Paths.assessment,
comp: AssessmentSettings,
exact: false,
},
{
path: Paths.questionnaire,
comp: Questionnaire,
exact: false,
},
{ comp: Proxies, path: Paths.proxies, exact: false },
{ comp: MigrationTargets, path: Paths.migrationTargets, exact: false },
...(FEATURES_ENABLED.migrationWaves
Expand Down
Loading

0 comments on commit fa5fff2

Please sign in to comment.