Skip to content

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Mar 10, 2025
Next Next commit
fix: default org selection in template form if only one
  • Loading branch information
Kira-Pilot committed Feb 20, 2025
commit a656cb84b4c47ed91da389e42c03494e39145bbc
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
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: {
value: null,
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: { viewDeploymentValues: 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: { viewDeploymentValues: true },
queries: [
{
key: ["organizations"],
data: [MockOrganization],
},
],
},
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
const button = canvas.getByRole("button");
await userEvent.click(button);
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ export const OrganizationAutocomplete: FC<OrganizationAutocompleteProps> = ({
className={className}
options={options}
loading={organizationsQuery.isLoading}
value={value}
value={options.length === 1 ? options[0] : value}
disabled={options.length === 1}
data-testid="organization-autocomplete"
open={autoComplete.open}
isOptionEqualToValue={(a, b) => a.name === b.name}
Expand Down Expand Up @@ -154,6 +155,6 @@ export const OrganizationAutocomplete: FC<OrganizationAutocompleteProps> = ({
};

const root = css`
padding-left: 14px !important; // Same padding left as input
gap: 4px;
padding-left: 14px !important; // Same padding left as input
gap: 4px;
`;
Loading