Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(coral): Add route filter and updated navigtion for superadmin behind feature flag #2303

Merged
merged 12 commits into from
Feb 19, 2024

Conversation

programmiri
Copy link
Contributor

@programmiri programmiri commented Feb 14, 2024

Description

This PR enables user with the role SUPERADMIN to access coral. It's behind a feature flag!

This is part of #2307

Description

  • adds a feature flag
  • (when feature flag is enabled) adds function to filter routes based on a SuperAdminRouteMap to add redirects to some routes and remove others. The filter is not super optimised, as it's a temporary solution.
  • (when feature flag is enabled) Hides or shows navigation links based on the role

Additionally:

  • moving and renaming of router related helper functions.

What kind of change does this PR introduce?

  • Bug fix
  • New feature
  • Refactor
  • Docs update
  • CI update

Requirements (all must be checked before review)

  • The pull request title follows our guidelines
  • Tests for the changes have been added (if relevant)
  • The latest changes from the main branch have been pulled
  • pnpm lint has been run successfully

@programmiri programmiri force-pushed the add-helper-for-redirect-admin branch 7 times, most recently from cad163b to deaecb0 Compare February 15, 2024 14:13
@programmiri programmiri changed the title POC routes filters. feat(coral): Add route filter and updated navigtion for superadmin behind feature flag Feb 15, 2024
@@ -349,7 +356,118 @@ const routes: Array<RouteObject> = [
},
];

const router = createBrowserRouter(routes, {
/** `superadminRouteMap` is used as in-between-solution
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to leave the map itself here in router.tsx because it's similar to our routes map and I thought it's good to keep them together? 🤔

} from "src/services/router-utils/route-utils";
import { isFeatureFlagActive } from "src/services/feature-flags/utils";

const superAdminAccessCoralEnabled = isFeatureFlagActive(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to run the filter when the feature isn't enabled anyway, so I added it here, too.

@@ -0,0 +1,279 @@
import { useToast } from "@aivenio/aquarium";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

route-utils.tsx was located in /services/feature-flag before, because it only contained the createRouteBehindFeatureFlag function before.

Now that we have more util functions related to router, I moved this to a separate directory.

@@ -1,5 +1,3 @@
import isString from "lodash/isString";

enum Routes {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved route-utils.ts in the new directory in services and renamed it to types.ts. All functions are moved to router-utils.tsx. So now type definition are separated from functions and there is only one route-utils file :D

…ole.

Signed-off-by: Mirjam Aulbach <mirjam.aulbach@aiven.io>
Signed-off-by: Mirjam Aulbach <mirjam.aulbach@aiven.io>
Signed-off-by: Mirjam Aulbach <mirjam.aulbach@aiven.io>
Signed-off-by: Mirjam Aulbach <mirjam.aulbach@aiven.io>
Signed-off-by: Mirjam Aulbach <mirjam.aulbach@aiven.io>
Signed-off-by: Mirjam Aulbach <mirjam.aulbach@aiven.io>
Signed-off-by: Mirjam Aulbach <mirjam.aulbach@aiven.io>
Signed-off-by: Mirjam Aulbach <mirjam.aulbach@aiven.io>
});
});

describe("filteredRoutesForSuperAdmin", () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the new tests case I added, rest was only moved with the file.

The tests are a bit rough and superficial, I didn't want to start adding rendering etc. pp. here, because it's only for a temporary time.

@programmiri programmiri marked this pull request as ready for review February 16, 2024 12:07
Copy link
Contributor

@mathieu-anderson mathieu-anderson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few comments ^^

coral/src/app/router.tsx Show resolved Hide resolved
coral/src/services/router-utils/route-utils.tsx Outdated Show resolved Hide resolved
coral/src/services/router-utils/route-utils.tsx Outdated Show resolved Hide resolved
coral/src/services/router-utils/route-utils.tsx Outdated Show resolved Hide resolved
Signed-off-by: Mirjam Aulbach <mirjam.aulbach@aiven.io>
Signed-off-by: Mirjam Aulbach <mirjam.aulbach@aiven.io>
Signed-off-by: Mirjam Aulbach <mirjam.aulbach@aiven.io>
Copy link
Contributor

@mathieu-anderson mathieu-anderson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@mathieu-anderson mathieu-anderson merged commit f2321f1 into main Feb 19, 2024
26 checks passed
@mathieu-anderson mathieu-anderson deleted the add-helper-for-redirect-admin branch February 19, 2024 08:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants