Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add redirects and such
  • Loading branch information
aslilac committed Jul 26, 2024
commit 01371eca7d8cf2cab01a1ee2065b0208517e1865
31 changes: 29 additions & 2 deletions site/src/pages/ManagementSettingsPage/GroupsPage/GroupsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,36 @@
import { type FC, useEffect } from "react";
import { Helmet } from "react-helmet-async";
import { useQuery } from "react-query";
import { Link as RouterLink, useParams } from "react-router-dom";
import {
Navigate,
Link as RouterLink,
useLocation,
useParams,
} from "react-router-dom";
import { getErrorMessage } from "api/errors";
import { groups } from "api/queries/groups";
import { displayError } from "components/GlobalSnackbar/utils";
import { PageHeader, PageHeaderTitle } from "components/PageHeader/PageHeader";
import { useAuthenticated } from "contexts/auth/RequireAuth";
import { useDashboard } from "modules/dashboard/useDashboard";
import { useFeatureVisibility } from "modules/dashboard/useFeatureVisibility";
import { pageTitle } from "utils/page";
import GroupsPageView from "./GroupsPageView";
import { useOrganizationSettings } from "../ManagementSettingsLayout";

Check failure on line 21 in site/src/pages/ManagementSettingsPage/GroupsPage/GroupsPage.tsx

View workflow job for this annotation

GitHub Actions / lint

`../ManagementSettingsLayout` import should occur before import of `./GroupsPageView`

Check failure on line 21 in site/src/pages/ManagementSettingsPage/GroupsPage/GroupsPage.tsx

View workflow job for this annotation

GitHub Actions / lint

`../ManagementSettingsLayout` import should occur before import of `./GroupsPageView`
import { Organization } from "api/typesGenerated";

Check failure on line 22 in site/src/pages/ManagementSettingsPage/GroupsPage/GroupsPage.tsx

View workflow job for this annotation

GitHub Actions / lint

All imports in the declaration are only used as types. Use `import type`

Check failure on line 22 in site/src/pages/ManagementSettingsPage/GroupsPage/GroupsPage.tsx

View workflow job for this annotation

GitHub Actions / lint

`api/typesGenerated` import should occur before import of `components/GlobalSnackbar/utils`

Check failure on line 22 in site/src/pages/ManagementSettingsPage/GroupsPage/GroupsPage.tsx

View workflow job for this annotation

GitHub Actions / lint

All imports in the declaration are only used as types. Use `import type`

Check failure on line 22 in site/src/pages/ManagementSettingsPage/GroupsPage/GroupsPage.tsx

View workflow job for this annotation

GitHub Actions / lint

`api/typesGenerated` import should occur before import of `components/GlobalSnackbar/utils`

export const GroupsPage: FC = () => {
const { permissions } = useAuthenticated();
const { createGroup: canCreateGroup } = permissions;
const { template_rbac: isTemplateRBACEnabled } = useFeatureVisibility();
const {
multiple_organizations: organizationsEnabled,
template_rbac: isTemplateRBACEnabled,
} = useFeatureVisibility();
const { experiments } = useDashboard();
const location = useLocation();
const { organization = "default" } = useParams() as { organization: string };
const groupsQuery = useQuery(groups(organization));
const { organizations } = useOrganizationSettings();

useEffect(() => {
if (groupsQuery.error) {
Expand All @@ -28,6 +42,16 @@
}
}, [groupsQuery.error]);

if (
organizationsEnabled &&
experiments.includes("multi-organization") &&
location.pathname === "/deployment/groups"
) {
const defaultName =
getOrganizationNameByDefault(organizations) ?? "default";
return <Navigate to={`/organizations/${defaultName}/groups`} replace />;
}

return (
<>
<Helmet>
Expand Down Expand Up @@ -62,3 +86,6 @@
};

export default GroupsPage;

export const getOrganizationNameByDefault = (organizations: Organization[]) =>
organizations.find((org) => org.is_default)?.name;
4 changes: 4 additions & 0 deletions site/src/pages/UsersPage/UsersPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { isNonInitialPage } from "components/PaginationWidget/utils";
import { useAuthenticated } from "contexts/auth/RequireAuth";
import { usePaginatedQuery } from "hooks/usePaginatedQuery";
import { useDashboard } from "modules/dashboard/useDashboard";
import { useFeatureVisibility } from "modules/dashboard/useFeatureVisibility";
import { pageTitle } from "utils/page";
import { generateRandomString } from "utils/random";
import { ResetPasswordDialog } from "./ResetPasswordDialog";
Expand All @@ -43,6 +44,8 @@ const UsersPage: FC = () => {
const { entitlements, experiments, organizationId } = useDashboard();
const [searchParams] = searchParamsResult;
const isMultiOrg = experiments.includes("multi-organization");
const { multiple_organizations: organizationsEnabled } =
useFeatureVisibility();

const groupsByUserIdQuery = useQuery(groupsByUserId(organizationId));
const authMethodsQuery = useQuery(authMethods());
Expand Down Expand Up @@ -104,6 +107,7 @@ const UsersPage: FC = () => {
groupsByUserIdQuery.isLoading;

if (
organizationsEnabled &&
experiments.includes("multi-organization") &&
location.pathname !== "/deployment/users"
) {
Expand Down
Loading