Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: manage groups from deployment settings for single-org deployments#14016

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
aslilac merged 8 commits intomainfromnon-org-groups
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from1 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
NextNext commit
feat: manage non-multi-org groups from deployment settings
  • Loading branch information
@aslilac
aslilac committedJul 25, 2024
commit4c840c73362f35117e587d974df2097c0fc97d90
12 changes: 8 additions & 4 deletionssite/src/api/queries/groups.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,18 +6,18 @@ import type {
PatchGroupRequest,
} from "api/typesGenerated";

const GROUPS_QUERY_KEY = ["groups"];
type GroupSortOrder = "asc" | "desc";

const getGroupQueryKey = (organizationId: string, groupName: string) => [
"organization",
organizationId,
"group",
groupName,
];

export const groups = (organizationId: string) => {
return {
queryKey:GROUPS_QUERY_KEY,
queryKey:["organization", organizationId, "groups"],
queryFn: () => API.getGroups(organizationId),
} satisfies UseQueryOptions<Group[]>;
};
Expand DownExpand Up@@ -97,7 +97,11 @@ export const createGroup = (
mutationFn: (request: CreateGroupRequest) =>
API.createGroup(organizationId, request),
onSuccess: async () => {
await queryClient.invalidateQueries(GROUPS_QUERY_KEY);
await queryClient.invalidateQueries([
"organization",
organizationId,
"groups",
]);
},
};
};
Expand DownExpand Up@@ -146,7 +150,7 @@ export const invalidateGroup = (
groupId: string,
) =>
Promise.all([
queryClient.invalidateQueries(GROUPS_QUERY_KEY),
queryClient.invalidateQueries(["organization", organizationId, "groups"]),
queryClient.invalidateQueries(getGroupQueryKey(organizationId, groupId)),
]);

Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,7 @@ import CreateGroupPageView from "./CreateGroupPageView";
export const CreateGroupPage: FC = () => {
const queryClient = useQueryClient();
const navigate = useNavigate();
const { organization } = useParams() as { organization: string };
const { organization= "default"} = useParams() as { organization: string };
const createGroupMutation = useMutation(
createGroup(queryClient, organization),
);
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -50,7 +50,7 @@ import { isEveryoneGroup } from "utils/groups";
import { pageTitle } from "utils/page";

export const GroupPage: FC = () => {
const { organization, groupName } = useParams() as {
const { organization = "default", groupName } = useParams() as {
Copy link
Contributor

Choose a reason for hiding this comment

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

I see the constant "default" used in multiple places. We should define it in aconst.ts file for consistency. Makes sense?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

personally, I really dread adding imports like that which end up being more typing that the thing you could just say directly

BrunoQuaresma reacted with thumbs up emoji
organization: string;
groupName: string;
};
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,7 +11,7 @@ import { pageTitle } from "utils/page";
import GroupSettingsPageView from "./GroupSettingsPageView";

export const GroupSettingsPage: FC = () => {
const { organization, groupName } = useParams() as {
const { organization = "default", groupName } = useParams() as {
organization: string;
groupName: string;
};
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,23 +3,22 @@ import Button from "@mui/material/Button";
import { type FC, useEffect } from "react";
import { Helmet } from "react-helmet-async";
import { useQuery } from "react-query";
import { Link as RouterLink } from "react-router-dom";
import { Link as RouterLink, 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 { useFeatureVisibility } from "modules/dashboard/useFeatureVisibility";
import { pageTitle } from "utils/page";
import { useOrganizationSettings } from "../ManagementSettingsLayout";
import GroupsPageView from "./GroupsPageView";

export const GroupsPage: FC = () => {
const { permissions } = useAuthenticated();
const { currentOrganizationId } = useOrganizationSettings();
const { createGroup: canCreateGroup } = permissions;
const { template_rbac: isTemplateRBACEnabled } = useFeatureVisibility();
const groupsQuery = useQuery(groups(currentOrganizationId!));
const { organization = "default" } = useParams() as { organization: string };
const groupsQuery = useQuery(groups(organization));

useEffect(() => {
if (groupsQuery.error) {
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,7 +15,7 @@ import { DeploySettingsContext } from "../DeploySettingsPage/DeploySettingsLayou
import { Sidebar } from "./Sidebar";

type OrganizationSettingsContextValue = {
currentOrganizationId?: string;
//currentOrganizationId?: string;
organizations: Organization[];
};

Expand DownExpand Up@@ -58,14 +58,14 @@ export const ManagementSettingsLayout: FC = () => {
{organizationsQuery.data ? (
<OrganizationSettingsContext.Provider
value={{
currentOrganizationId: !inOrganizationSettings
? undefined
: !organization
? getOrganizationIdByDefault(organizationsQuery.data)
: getOrganizationIdByName(
organizationsQuery.data,
organization,
),
//currentOrganizationId: !inOrganizationSettings
// ? undefined
// : !organization
// ? getOrganizationIdByDefault(organizationsQuery.data)
// : getOrganizationIdByName(
// organizationsQuery.data,
// organization,
// ),
organizations: organizationsQuery.data,
}}
>
Expand DownExpand Up@@ -94,9 +94,3 @@ export const ManagementSettingsLayout: FC = () => {
</RequirePermission>
);
};

const getOrganizationIdByName = (organizations: Organization[], name: string) =>
organizations.find((org) => org.name === name)?.id;

const getOrganizationIdByDefault = (organizations: Organization[]) =>
organizations.find((org) => org.is_default)?.id;
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
import type { FC } from "react";
import { useMutation, useQueryClient } from "react-query";
import { useNavigate } from "react-router-dom";
import { useNavigate, useParams } from "react-router-dom";
import {
updateOrganization,
deleteOrganization,
} from "api/queries/organizations";
import type { Organization } from "api/typesGenerated";
import { EmptyState } from "components/EmptyState/EmptyState";
import { displaySuccess } from "components/GlobalSnackbar/utils";
import { useOrganizationSettings } from "./ManagementSettingsLayout";
import { OrganizationSettingsPageView } from "./OrganizationSettingsPageView";

const OrganizationSettingsPage: FC = () => {
const navigate = useNavigate();
const { organization: organizationName } = useParams() as {
organization?: string;
};
const { organizations } = useOrganizationSettings();

const navigate = useNavigate();
const queryClient = useQueryClient();
const updateOrganizationMutation = useMutation(
updateOrganization(queryClient),
Expand All@@ -21,14 +26,14 @@ const OrganizationSettingsPage: FC = () => {
deleteOrganization(queryClient),
);

const{ currentOrganizationId, organizations } = useOrganizationSettings();

const org = organizations.find((org) => org.id === currentOrganizationId);
constorg = organizationName
? getOrganizationIdByName(organizations, organizationName)
: getOrganizationIdByDefault(organizations);

const error =
updateOrganizationMutation.error ?? deleteOrganizationMutation.error;

if (!currentOrganizationId || !org) {
if (!org) {
return <EmptyState message="Organization not found" />;
}

Expand All@@ -55,3 +60,9 @@ const OrganizationSettingsPage: FC = () => {
};

export default OrganizationSettingsPage;

const getOrganizationIdByDefault = (organizations: Organization[]) =>
organizations.find((org) => org.is_default);

const getOrganizationIdByName = (organizations: Organization[], name: string) =>
organizations.find((org) => org.name === name);
View file
Open in desktop

This file was deleted.

63 changes: 43 additions & 20 deletionssite/src/pages/ManagementSettingsPage/Sidebar.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,44 +3,64 @@ import type { Interpolation, Theme } from "@emotion/react";
import AddIcon from "@mui/icons-material/Add";
import SettingsIcon from "@mui/icons-material/Settings";
import type { FC, ReactNode } from "react";
import { Link, NavLink, useLocation } from "react-router-dom";
import { Link, NavLink, useLocation, useParams } from "react-router-dom";
import type { Organization } from "api/typesGenerated";
import { Sidebar as BaseSidebar } from "components/Sidebar/Sidebar";
import { Stack } from "components/Stack/Stack";
import { UserAvatar } from "components/UserAvatar/UserAvatar";
import { type ClassName, useClassName } from "hooks/useClassName";
import { USERS_LINK } from "modules/navigation";
import { useOrganizationSettings } from "./ManagementSettingsLayout";
import { useFeatureVisibility } from "modules/dashboard/useFeatureVisibility";

export const Sidebar: FC = () => {
const { currentOrganizationId, organizations } = useOrganizationSettings();
const { organization: organizationName = "default" } = useParams() as {
organization: string;
};
const { organizations } = useOrganizationSettings();
const { multiple_organizations: organizationsEnabled } =
useFeatureVisibility();

// TODO: Do something nice to scroll to the active org.

return (
<BaseSidebar>
<header css={styles.sidebarHeader}>Deployment</header>
<DeploymentSettingsNavigation />
<header css={styles.sidebarHeader}>Organizations</header>
<SidebarNavItem
active="auto"
href="/organizations/new"
icon={<AddIcon />}
>
New organization
</SidebarNavItem>
{organizations.map((organization) => (
<OrganizationSettingsNavigation
key={organization.id}
organization={organization}
active={organization.id === currentOrganizationId}
/>
))}
{organizationsEnabled && (
<header css={styles.sidebarHeader}>Deployment</header>
)}
<DeploymentSettingsNavigation
organizationsEnabled={organizationsEnabled}
/>
{organizationsEnabled && (
<>
<header css={styles.sidebarHeader}>Organizations</header>
<SidebarNavItem
active="auto"
href="/organizations/new"
icon={<AddIcon />}
>
New organization
</SidebarNavItem>
{organizations.map((organization) => (
<OrganizationSettingsNavigation
key={organization.id}
organization={organization}
active={organization.name === organizationName}
/>
))}
</>
)}
</BaseSidebar>
);
};

const DeploymentSettingsNavigation: FC = () => {
interface DeploymentSettingsNavigationProps {
organizationsEnabled?: boolean;
}

const DeploymentSettingsNavigation: FC<DeploymentSettingsNavigationProps> = ({
organizationsEnabled,
}) => {
const location = useLocation();
const active = location.pathname.startsWith("/deployment");

Expand DownExpand Up@@ -81,6 +101,9 @@ const DeploymentSettingsNavigation: FC = () => {
<SidebarNavSubItem href={USERS_LINK.slice(1)}>
Users
</SidebarNavSubItem>
{!organizationsEnabled && (
<SidebarNavSubItem href="groups">Groups</SidebarNavSubItem>
)}
</Stack>
)}
</div>
Expand Down
39 changes: 18 additions & 21 deletionssite/src/router.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -242,10 +242,6 @@ const OrganizationGroupSettingsPage = lazy(
const OrganizationMembersPage = lazy(
() => import("./pages/ManagementSettingsPage/OrganizationMembersPage"),
);
const OrganizationSettingsPlaceholder = lazy(
() =>
import("./pages/ManagementSettingsPage/OrganizationSettingsPlaceholder"),
);
const TemplateEmbedPage = lazy(
() => import("./pages/TemplatePage/TemplateEmbedPage/TemplateEmbedPage"),
);
Expand DownExpand Up@@ -275,6 +271,21 @@ const RoutesWithSuspense = () => {
);
};

const groupsRouter = () => {
return (
<Route path="groups">
<Route index element={<OrganizationGroupsPage />} />

<Route path="create" element={<CreateOrganizationGroupPage />} />
<Route path=":groupName" element={<OrganizationGroupPage />} />
<Route
path=":groupName/settings"
element={<OrganizationGroupSettingsPage />}
/>
</Route>
);
};

export const router = createBrowserRouter(
createRoutesFromChildren(
<Route element={<RoutesWithSuspense />}>
Expand DownExpand Up@@ -360,23 +371,8 @@ export const router = createBrowserRouter(
<Route path=":organization">
<Route index element={<OrganizationSettingsPage />} />
<Route path="members" element={<OrganizationMembersPage />} />
<Route path="groups">
<Route index element={<OrganizationGroupsPage />} />

<Route
path="create"
element={<CreateOrganizationGroupPage />}
/>
<Route path=":groupName" element={<OrganizationGroupPage />} />
<Route
path=":groupName/settings"
element={<OrganizationGroupSettingsPage />}
/>
</Route>
<Route
path="auditing"
element={<OrganizationSettingsPlaceholder />}
/>
{groupsRouter()}
<Route path="auditing" element={<></>} />
</Route>
</Route>

Expand DownExpand Up@@ -409,6 +405,7 @@ export const router = createBrowserRouter(
<Route path="workspace-proxies" element={<WorkspaceProxyPage />} />
<Route path="users" element={<UsersPage />} />
<Route path="users/create" element={<CreateUserPage />} />
{groupsRouter()}
</Route>

<Route path="/settings" element={<UserSettingsLayout />}>
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp