Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9da6467

Browse files
authored
fix: prefer organization display name for workspaces table (#14617)
* fix: prefer organization display name for workspaces table * fix: update story to account for organization name changes * fix: resolve typo in regex search for test
1 parent eb646f0 commit 9da6467

File tree

4 files changed

+23
-13
lines changed

4 files changed

+23
-13
lines changed

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

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type {
33
DeploymentValues,
44
Experiments,
55
FeatureName,
6+
Organization,
67
SerpentOption,
78
User,
89
} from "api/typesGenerated";
@@ -17,6 +18,7 @@ declare module "@storybook/react" {
1718
features?: FeatureName[];
1819
experiments?: Experiments;
1920
showOrganizations?: boolean;
21+
organizations?: Organization[];
2022
queries?: { key: QueryKey; data: unknown }[];
2123
webSocket?: WebSocketEvent[];
2224
user?: User;

site/src/pages/WorkspacesPage/WorkspacesPageView.stories.tsx

+13-10
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import uniqueId from "lodash/uniqueId";
1515
import type { ComponentProps } from "react";
1616
import {
1717
MockBuildInfo,
18+
MockOrganization,
1819
MockPendingProvisionerJob,
1920
MockTemplate,
2021
MockUser,
@@ -269,25 +270,27 @@ export const InvalidPageNumber: Story = {
269270

270271
export const ShowOrganizations: Story = {
271272
args: {
272-
workspaces: [
273-
{
274-
...MockWorkspace,
275-
organization_name: "Limbus Co.",
276-
},
277-
],
273+
workspaces: [{ ...MockWorkspace, organization_name: "limbus-co" }],
278274
},
279275

280276
parameters: {
281277
showOrganizations: true,
278+
organizations: [
279+
{
280+
...MockOrganization,
281+
name: "limbus-co",
282+
display_name: "Limbus Company, LLC",
283+
},
284+
],
282285
},
283286

284287
play: async ({ canvasElement }) => {
285288
const canvas = within(canvasElement);
286289
const accessibleTableCell = await canvas.findByRole("cell", {
287-
// Need whitespace classes because different parts of the element
288-
// are going in different spans, and Storybook doesn't consolidate
289-
// these
290-
name: /org\s?(?:anization)?\s?:\s?Limbus Co\./i,
290+
// The organization label is always visually hidden, but the test
291+
// makes sure that there's a screen reader hook to give the table
292+
// cell more structured output
293+
name: /organization: Limbus Company, LLC/i,
291294
});
292295

293296
expect(accessibleTableCell).toBeDefined();

site/src/pages/WorkspacesPage/WorkspacesTable.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ export const WorkspacesTable: FC<WorkspacesTableProps> = ({
115115
const checked = checkedWorkspaces.some(
116116
(w) => w.id === workspace.id,
117117
);
118+
const activeOrg = dashboard.organizations.find(
119+
(o) => o.id === workspace.organization_id,
120+
);
121+
118122
return (
119123
<WorkspacesRow
120124
workspace={workspace}
@@ -208,7 +212,7 @@ export const WorkspacesTable: FC<WorkspacesTableProps> = ({
208212
}}
209213
>
210214
<span css={{ ...visuallyHidden }}>Organization: </span>
211-
{workspace.organization_name}
215+
{activeOrg?.display_name || workspace.organization_name}
212216
</div>
213217
)}
214218
</TableCell>

site/src/testHelpers/storybook.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export const withDashboardProvider = (
2424
features = [],
2525
experiments = [],
2626
showOrganizations = false,
27+
organizations = [MockDefaultOrganization],
2728
} = parameters;
2829

2930
const entitlements: Entitlements = {
@@ -44,9 +45,9 @@ export const withDashboardProvider = (
4445
value={{
4546
entitlements,
4647
experiments,
47-
appearance: MockAppearanceConfig,
48-
organizations: [MockDefaultOrganization],
48+
organizations,
4949
showOrganizations,
50+
appearance: MockAppearanceConfig,
5051
}}
5152
>
5253
<Story />

0 commit comments

Comments
 (0)