-
Notifications
You must be signed in to change notification settings - Fork 3.8k
feat(workflow): deploy workflows from resource panel #6338
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
Open
BillLeoutsakosvl346
wants to merge
11
commits into
staging
Choose a base branch
from
feat/deploy-workflow-resource-panel
base: staging
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+229
−9
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d1e25d3
feat(workflow): deploy workflows from resource panel
e8621e1
fix(workflow): match deploy resource action styling
b8eabc5
Merge remote-tracking branch 'origin/staging' into feat/deploy-workfl…
b923c26
fix(workflow): guard resource deploy metadata loading
d061558
fix(workflow): wait for active workflow hydration before deploy
78171b7
fix(workflow): clarify resource deploy loading states
d3c3137
fix(workflow): retry unavailable resource lock data
c6c7508
test(workflow): focus deploy coverage on behavior
22314f2
refactor(workflow): align resource deploy with editor
8155ebd
fix(workflow): wait for resource lock metadata
1b58be2
Merge remote-tracking branch 'origin/staging' into feat/deploy-workfl…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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
188 changes: 188 additions & 0 deletions
188
...workspace/[workspaceId]/w/[workflowId]/components/panel/components/deploy/deploy.test.tsx
This file contains hidden or 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,188 @@ | ||
| /** | ||
| * @vitest-environment jsdom | ||
| */ | ||
| import { act } from 'react' | ||
| import { createRoot, type Root } from 'react-dom/client' | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' | ||
|
|
||
| const mockState = vi.hoisted(() => ({ | ||
| hydrationPhase: 'ready' as 'idle' | 'state-loading' | 'ready', | ||
| hydrationWorkflowId: 'workflow-1' as string | null, | ||
| registryActiveWorkflowId: 'workflow-1' as string | null, | ||
| hasBlocks: true, | ||
| isDeployed: false, | ||
| changeDetected: false, | ||
| isChangeDetectionSettling: false, | ||
| isDeploying: false, | ||
| readiness: { | ||
| isBlocked: false, | ||
| isSyncing: false, | ||
| tooltip: 'Ready to deploy', | ||
| }, | ||
| handleDeployClick: vi.fn(), | ||
| })) | ||
|
|
||
| vi.mock('@sim/emcn', () => ({ | ||
| Button: ({ children, ...props }: React.ButtonHTMLAttributes<HTMLButtonElement>) => ( | ||
| <button type='button' {...props}> | ||
| {children} | ||
| </button> | ||
| ), | ||
| cn: (...classes: Array<string | undefined>) => classes.filter(Boolean).join(' '), | ||
| Tooltip: { | ||
| Root: ({ children }: { children: React.ReactNode }) => <>{children}</>, | ||
| Trigger: ({ children }: { children: React.ReactNode }) => <>{children}</>, | ||
| Content: ({ children }: { children: React.ReactNode }) => <div>{children}</div>, | ||
| }, | ||
| })) | ||
|
|
||
| vi.mock('@sim/emcn/icons', () => ({ | ||
| Upload: () => <span />, | ||
| })) | ||
|
|
||
| vi.mock( | ||
| '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/deploy/components/deploy-modal/deploy-modal', | ||
| () => ({ | ||
| DeployModal: ({ open }: { open: boolean }) => | ||
| open ? <div role='dialog'>Deploy workflow</div> : null, | ||
| }) | ||
| ) | ||
|
|
||
| vi.mock( | ||
| '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/deploy/hooks', | ||
| () => ({ | ||
| useChangeDetection: () => ({ | ||
| changeDetected: mockState.changeDetected, | ||
| isChangeDetectionSettling: mockState.isChangeDetectionSettling, | ||
| }), | ||
| useDeployment: () => ({ | ||
| isDeploying: mockState.isDeploying, | ||
| handleDeployClick: mockState.handleDeployClick, | ||
| }), | ||
| useDeployReadiness: () => ({ | ||
| ...mockState.readiness, | ||
| status: mockState.readiness.isBlocked ? 'saving' : 'ready', | ||
| isReady: !mockState.readiness.isBlocked, | ||
| waitUntilReady: vi.fn(), | ||
| }), | ||
| }) | ||
| ) | ||
|
|
||
| vi.mock('@/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-current-workflow', () => ({ | ||
| useCurrentWorkflow: () => ({ hasBlocks: () => mockState.hasBlocks }), | ||
| })) | ||
|
|
||
| vi.mock('@/hooks/queries/deployments', () => ({ | ||
| useDeploymentInfo: () => ({ data: { isDeployed: mockState.isDeployed } }), | ||
| useDeployedWorkflowState: () => ({ data: null, isLoading: false, isFetching: false }), | ||
| })) | ||
|
|
||
| vi.mock('@/stores/workflows/registry/store', () => ({ | ||
| useWorkflowRegistry: (selector: (state: unknown) => unknown) => | ||
| selector({ | ||
| activeWorkflowId: mockState.registryActiveWorkflowId, | ||
| hydration: { | ||
| phase: mockState.hydrationPhase, | ||
| workflowId: mockState.hydrationWorkflowId, | ||
| }, | ||
| }), | ||
| })) | ||
|
|
||
| import { Deploy } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/deploy/deploy' | ||
|
|
||
| let container: HTMLDivElement | ||
| let root: Root | ||
|
|
||
| function renderDeploy( | ||
| overrides: Partial<typeof mockState> = {}, | ||
| props: { disabled?: boolean; canAdmin?: boolean } = {} | ||
| ) { | ||
| Object.assign(mockState, overrides) | ||
| act(() => { | ||
| root.render( | ||
| <Deploy | ||
| activeWorkflowId='workflow-1' | ||
| userPermissions={{ | ||
| canRead: true, | ||
| canEdit: true, | ||
| canAdmin: props.canAdmin ?? true, | ||
| userPermissions: props.canAdmin === false ? 'write' : 'admin', | ||
| isLoading: false, | ||
| error: null, | ||
| }} | ||
| compact | ||
| disabled={props.disabled} | ||
| /> | ||
| ) | ||
| }) | ||
| } | ||
|
|
||
| beforeEach(() => { | ||
| container = document.createElement('div') | ||
| document.body.appendChild(container) | ||
| root = createRoot(container) | ||
| mockState.hydrationPhase = 'ready' | ||
| mockState.hydrationWorkflowId = 'workflow-1' | ||
| mockState.registryActiveWorkflowId = 'workflow-1' | ||
| mockState.hasBlocks = true | ||
| mockState.isDeployed = false | ||
| mockState.changeDetected = false | ||
| mockState.isChangeDetectionSettling = false | ||
| mockState.isDeploying = false | ||
| mockState.readiness = { | ||
| isBlocked: false, | ||
| isSyncing: false, | ||
| tooltip: 'Ready to deploy', | ||
| } | ||
| mockState.handleDeployClick.mockReset() | ||
| mockState.handleDeployClick.mockResolvedValue({ success: true, shouldOpenModal: true }) | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| act(() => root.unmount()) | ||
| container.remove() | ||
| }) | ||
|
|
||
| describe('Deploy compact mode', () => { | ||
| it.each([ | ||
| ['Deploy', {}], | ||
| ['Live', { isDeployed: true }], | ||
| ['Update', { isDeployed: true, changeDetected: true }], | ||
| ])('exposes the %s action for its deployment state', (label, overrides) => { | ||
| renderDeploy(overrides) | ||
|
|
||
| expect(container.querySelector('button')?.getAttribute('aria-label')).toBe(label) | ||
| }) | ||
|
|
||
| it.each([ | ||
| ['non-admin users', {}, { canAdmin: false }], | ||
| ['empty workflows', { hasBlocks: false }, {}], | ||
| ['locked workflows', {}, { disabled: true }], | ||
| [ | ||
| 'unsynchronized workflows', | ||
| { | ||
| readiness: { isBlocked: true, isSyncing: false, tooltip: 'Saving workflow changes' }, | ||
| }, | ||
| {}, | ||
| ], | ||
| [ | ||
| 'workflows that are still loading', | ||
| { hydrationWorkflowId: 'workflow-2', registryActiveWorkflowId: 'workflow-2' }, | ||
| {}, | ||
| ], | ||
| ])('disables the action for %s', (_reason, overrides, props) => { | ||
| renderDeploy(overrides, props) | ||
|
|
||
| expect(container.querySelector('button')?.disabled).toBe(true) | ||
| }) | ||
|
|
||
| it('opens the existing deployment modal after a successful deployment action', async () => { | ||
| renderDeploy() | ||
|
|
||
| await act(async () => { | ||
| container.querySelector('button')?.click() | ||
| }) | ||
|
|
||
| expect(container.querySelector('[role="dialog"]')).not.toBeNull() | ||
| }) | ||
| }) |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.