-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[UI v2] feat: Adds AutomationsTriggerTemplateSelect component (#16597)
- Loading branch information
1 parent
c94289d
commit e004d6a
Showing
6 changed files
with
131 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
26 changes: 26 additions & 0 deletions
26
...izard/automations-trigger-template-select/automations-trigger-template-select.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import { fn } from "@storybook/test"; | ||
import { useState } from "react"; | ||
import { | ||
AutomationsTriggerTemplateSelect, | ||
type TemplateTriggers, | ||
} from "./automations-trigger-template-select"; | ||
|
||
const meta = { | ||
title: "Components/Automations/Wizard/AutomationsTriggerTemplateSelect", | ||
component: AutomationsTriggerTemplateSelect, | ||
args: { onValueChange: fn() }, | ||
render: function ComponentExmaple() { | ||
const [template, setTemplate] = useState<TemplateTriggers>(); | ||
return ( | ||
<AutomationsTriggerTemplateSelect | ||
onValueChange={setTemplate} | ||
value={template} | ||
/> | ||
); | ||
}, | ||
} satisfies Meta<typeof AutomationsTriggerTemplateSelect>; | ||
|
||
export default meta; | ||
|
||
export const story: StoryObj = { name: "AutomationsTriggerTemplateSelect" }; |
47 changes: 47 additions & 0 deletions
47
...s-wizard/automations-trigger-template-select/automations-trigger-template-select.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import userEvent from "@testing-library/user-event"; | ||
import { expect, test, vi } from "vitest"; | ||
|
||
import { AutomationsTriggerTemplateSelect } from "./automations-trigger-template-select"; | ||
|
||
test("AutomationsTriggerTemplateSelect can select an option", async () => { | ||
/** | ||
* JSDOM doesn't implement PointerEvent so we need to mock our own implementation | ||
* Default to mouse left click interaction | ||
* https://github.com/radix-ui/primitives/issues/1822 | ||
* https://github.com/jsdom/jsdom/pull/2666 | ||
*/ | ||
class MockPointerEvent extends Event { | ||
button: number; | ||
ctrlKey: boolean; | ||
pointerType: string; | ||
|
||
constructor(type: string, props: PointerEventInit) { | ||
super(type, props); | ||
this.button = props.button || 0; | ||
this.ctrlKey = props.ctrlKey || false; | ||
this.pointerType = props.pointerType || "mouse"; | ||
} | ||
} | ||
window.PointerEvent = MockPointerEvent as never; | ||
window.HTMLElement.prototype.scrollIntoView = vi.fn(); | ||
window.HTMLElement.prototype.releasePointerCapture = vi.fn(); | ||
window.HTMLElement.prototype.hasPointerCapture = vi.fn(); | ||
|
||
const user = userEvent.setup(); | ||
|
||
// ------------ Setup | ||
const mockOnValueChangeFn = vi.fn(); | ||
|
||
render( | ||
<AutomationsTriggerTemplateSelect onValueChange={mockOnValueChangeFn} />, | ||
); | ||
|
||
// ------------ Act | ||
await user.click(screen.getByLabelText("Trigger Template")); | ||
await user.click(screen.getByRole("option", { name: "Deployment status" })); | ||
|
||
// ------------ Assert | ||
expect(screen.getByText("Deployment status")).toBeVisible(); | ||
expect(mockOnValueChangeFn).toBeCalledWith("deployment-status"); | ||
}); |
53 changes: 53 additions & 0 deletions
53
...ations-wizard/automations-trigger-template-select/automations-trigger-template-select.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { Label } from "@/components/ui/label"; | ||
import { | ||
Select, | ||
SelectContent, | ||
SelectGroup, | ||
SelectItem, | ||
SelectLabel, | ||
SelectTrigger, | ||
SelectValue, | ||
} from "@/components/ui/select"; | ||
|
||
const TEMPLATE_TRIGGERS = { | ||
"deployment-status": "Deployment status", | ||
"flow-run-state": "Flow run state", | ||
"work-pool-status": "Work pool status", | ||
"work-queue-status": "Work queue status", | ||
custom: "Custom", | ||
} as const; | ||
|
||
export type TemplateTriggers = keyof typeof TEMPLATE_TRIGGERS; | ||
|
||
type AutomationsTriggerTemplateSelectProps = { | ||
onValueChange: (value: TemplateTriggers) => void; | ||
value?: TemplateTriggers; | ||
}; | ||
|
||
export const AutomationsTriggerTemplateSelect = ({ | ||
onValueChange, | ||
value, | ||
}: AutomationsTriggerTemplateSelectProps) => { | ||
return ( | ||
<div> | ||
<Label htmlFor="automations-trigger-template-select"> | ||
Trigger Template | ||
</Label> | ||
<Select value={value} onValueChange={onValueChange}> | ||
<SelectTrigger id="automations-trigger-template-select"> | ||
<SelectValue placeholder="Select template" /> | ||
</SelectTrigger> | ||
<SelectContent> | ||
<SelectGroup> | ||
<SelectLabel>Trigger templates</SelectLabel> | ||
{Object.keys(TEMPLATE_TRIGGERS).map((key) => ( | ||
<SelectItem key={key} value={key}> | ||
{TEMPLATE_TRIGGERS[key as TemplateTriggers]} | ||
</SelectItem> | ||
))} | ||
</SelectGroup> | ||
</SelectContent> | ||
</Select> | ||
</div> | ||
); | ||
}; |
4 changes: 4 additions & 0 deletions
4
...rc/components/automations/automations-wizard/automations-trigger-template-select/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export { | ||
AutomationsTriggerTemplateSelect, | ||
type TemplateTriggers, | ||
} from "./automations-trigger-template-select"; |