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

fix: select default org in template form if only one exists#16639

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
Kira-Pilot merged 10 commits intomainfromorg-picker-default/kira-pilot
Mar 10, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
10 commits
Select commitHold shift + click to select a range
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
9 changes: 7 additions & 2 deletionssite/e2e/helpers.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -267,8 +267,13 @@ export const createTemplate = async (
);
}

await orgPicker.click();
await page.getByText(orgName, { exact: true }).click();
// picker is disabled if only one org is available
const pickerIsDisabled = await orgPicker.isDisabled();

if (!pickerIsDisabled) {
await orgPicker.click();
await page.getByText(orgName, { exact: true }).click();
}
}

const name = randomName();
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
import { action } from "@storybook/addon-actions";
import type { Meta, StoryObj } from "@storybook/react";
import { userEvent, within } from "@storybook/test";
import {
MockOrganization,
MockOrganization2,
MockUser,
} from "testHelpers/entities";
import { OrganizationAutocomplete } from "./OrganizationAutocomplete";

const meta: Meta<typeof OrganizationAutocomplete> = {
title: "components/OrganizationAutocomplete",
component: OrganizationAutocomplete,
args: {
onChange: action("Selected organization"),
},
};

export default meta;
type Story = StoryObj<typeof OrganizationAutocomplete>;

export const ManyOrgs: Story = {
parameters: {
showOrganizations: true,
user: MockUser,
features: ["multiple_organizations"],
permissions: { viewDeploymentConfig: true },
queries: [
{
key: ["organizations"],
data: [MockOrganization, MockOrganization2],
},
],
},
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
const button = canvas.getByRole("button");
await userEvent.click(button);
},
};

export const OneOrg: Story = {
parameters: {
showOrganizations: true,
user: MockUser,
features: ["multiple_organizations"],
permissions: { viewDeploymentConfig: true },
queries: [
{
key: ["organizations"],
data: [MockOrganization],
},
],
},
};
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,7 +7,7 @@ import { organizations } from "api/queries/organizations";
import type { AuthorizationCheck, Organization } from "api/typesGenerated";
import { Avatar } from "components/Avatar/Avatar";
import { AvatarData } from "components/Avatar/AvatarData";
import { type ComponentProps, type FC, useState } from "react";
import { type ComponentProps, type FC,useEffect,useState } from "react";
import { useQuery } from "react-query";

export type OrganizationAutocompleteProps = {
Expand DownExpand Up@@ -57,11 +57,26 @@ export const OrganizationAutocomplete: FC<OrganizationAutocompleteProps> = ({
: [];
}

// Unfortunate: this useEffect sets a default org value
// if only one is available and is necessary as the autocomplete loads
// its own data. Until we refactor, proceed cautiously!
useEffect(() => {
const org = options[0];
if (options.length !== 1 || org === selected) {
return;
}

setSelected(org);
onChange(org);
}, [options, selected, onChange]);

return (
<Autocomplete
noOptionsText="No organizations found"
className={className}
options={options}
disabled={options.length === 1}
value={selected}
Copy link
MemberAuthor

@Kira-PilotKira-PilotMar 7, 2025
edited
Loading

Choose a reason for hiding this comment

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

Populatingvalue is necessary so that the selected org shows in the Autocomplete.

aslilac reacted with thumbs up emoji
loading={organizationsQuery.isLoading}
data-testid="organization-autocomplete"
open={open}
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp