Skip to content

Commit d2a22c5

Browse files
authored
chore: add more stories and use new groups query for user settings page (#14481)
1 parent 6bc9352 commit d2a22c5

File tree

6 files changed

+39
-14
lines changed

6 files changed

+39
-14
lines changed

site/src/@types/storybook.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ declare module "@storybook/react" {
1616
interface Parameters {
1717
features?: FeatureName[];
1818
experiments?: Experiments;
19+
showOrganizations?: boolean;
1920
queries?: { key: QueryKey; data: unknown }[];
2021
webSocket?: WebSocketEvent[];
2122
user?: User;

site/src/api/api.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1603,8 +1603,15 @@ class ApiMethods {
16031603
return response.data;
16041604
};
16051605

1606-
getGroups = async (): Promise<TypesGen.Group[]> => {
1607-
const response = await this.axios.get("/api/v2/groups");
1606+
getGroups = async (
1607+
options: { userId?: string } = {},
1608+
): Promise<TypesGen.Group[]> => {
1609+
const params: Record<string, string> = {};
1610+
if (options.userId !== undefined) {
1611+
params.has_member = options.userId;
1612+
}
1613+
1614+
const response = await this.axios.get("/api/v2/groups", { params });
16081615
return response.data;
16091616
};
16101617

site/src/api/queries/groups.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,9 @@ export function groupsByUserId() {
7474

7575
export function groupsForUser(userId: string) {
7676
return {
77-
...groups(),
78-
select: (allGroups) => {
79-
const groupsForUser = allGroups.filter((group) =>
80-
group.members.some((member) => member.id === userId),
81-
);
82-
83-
return sortGroupsByName(groupsForUser, "asc");
84-
},
85-
} as const satisfies UseQueryOptions<Group[], unknown, readonly Group[]>;
77+
queryKey: groupsQueryKey,
78+
queryFn: () => API.getGroups({ userId }),
79+
} as const satisfies UseQueryOptions<Group[]>;
8680
}
8781

8882
export const groupPermissionsKey = (groupId: string) => [

site/src/pages/UserSettingsPage/AccountPage/AccountUserGroups.stories.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
MockUser,
55
mockApiError,
66
} from "testHelpers/entities";
7+
import { withDashboardProvider } from "testHelpers/storybook";
78
import { AccountUserGroups } from "./AccountUserGroups";
89

910
const MockGroup2 = {
@@ -24,13 +25,20 @@ const meta: Meta<typeof AccountUserGroups> = {
2425
groups: [MockGroup1, MockGroup2],
2526
loading: false,
2627
},
28+
decorators: [withDashboardProvider],
2729
};
2830

2931
export default meta;
3032
type Story = StoryObj<typeof AccountUserGroups>;
3133

3234
export const Example: Story = {};
3335

36+
export const ExampleWithOrganizations: Story = {
37+
parameters: {
38+
showOrganizations: true,
39+
},
40+
};
41+
3442
export const NoGroups: Story = {
3543
args: {
3644
groups: [],

site/src/pages/UserSettingsPage/AccountPage/AccountUserGroups.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { Group } from "api/typesGenerated";
55
import { ErrorAlert } from "components/Alert/ErrorAlert";
66
import { AvatarCard } from "components/AvatarCard/AvatarCard";
77
import { Loader } from "components/Loader/Loader";
8+
import { useDashboard } from "modules/dashboard/useDashboard";
89
import type { FC } from "react";
910
import { Section } from "../Section";
1011

@@ -20,6 +21,7 @@ export const AccountUserGroups: FC<AccountGroupsProps> = ({
2021
loading,
2122
}) => {
2223
const theme = useTheme();
24+
const { showOrganizations } = useDashboard();
2325

2426
return (
2527
<Section
@@ -55,7 +57,16 @@ export const AccountUserGroups: FC<AccountGroupsProps> = ({
5557
imgUrl={group.avatar_url}
5658
altText={group.display_name || group.name}
5759
header={group.display_name || group.name}
58-
subtitle={group.organization_display_name}
60+
subtitle={
61+
showOrganizations ? (
62+
group.organization_display_name
63+
) : (
64+
<>
65+
{group.total_member_count} member
66+
{group.total_member_count !== 1 && "s"}
67+
</>
68+
)
69+
}
5970
/>
6071
</Grid>
6172
))}

site/src/testHelpers/storybook.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ export const withDashboardProvider = (
2020
Story: FC,
2121
{ parameters }: StoryContext,
2222
) => {
23-
const { features = [], experiments = [] } = parameters;
23+
const {
24+
features = [],
25+
experiments = [],
26+
showOrganizations = false,
27+
} = parameters;
2428

2529
const entitlements: Entitlements = {
2630
...MockEntitlements,
@@ -42,7 +46,7 @@ export const withDashboardProvider = (
4246
experiments,
4347
appearance: MockAppearanceConfig,
4448
organizations: [MockDefaultOrganization],
45-
showOrganizations: false,
49+
showOrganizations,
4650
}}
4751
>
4852
<Story />

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy