-
Notifications
You must be signed in to change notification settings - Fork 943
fix: push create workspace UX to templates page #2142
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
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
0e00ca7
fix: push create workspace UX to templates page
f0ssel b774c50
remove template selector
f0ssel 7467669
make fmt
f0ssel 0cbd765
move loader
f0ssel 94d02b2
just text mock up
f0ssel 64bc02b
make fmt
f0ssel e74f27d
fit loop
f0ssel 4ec519e
fix storybook
f0ssel cbfc0f8
make fmt
f0ssel 2a191ba
change url path
f0ssel 8ee04b8
fix tst
f0ssel 61dfc97
make fmt
f0ssel 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
remove template selector
- Loading branch information
commit b774c50e790b7e4ae14c10a30c0c5bf2fb28af79
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
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
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 |
---|---|---|
|
@@ -4,22 +4,15 @@ import { CreateWorkspaceRequest, ParameterSchema, Template, Workspace } from ".. | |
|
||
type CreateWorkspaceContext = { | ||
organizationId: string | ||
templateName: string | ||
templates?: Template[] | ||
selectedTemplate?: Template | ||
templateSchema?: ParameterSchema[] | ||
createWorkspaceRequest?: CreateWorkspaceRequest | ||
createdWorkspace?: Workspace | ||
// This is useful when the user wants to create a workspace from the template | ||
// page having it pre selected. It is string or null because of the | ||
// useSearchQuery | ||
preSelectedTemplateName: string | null | ||
} | ||
|
||
type CreateWorkspaceEvent = | ||
| { | ||
type: "SELECT_TEMPLATE" | ||
template: Template | ||
} | ||
| { | ||
type: "CREATE_WORKSPACE" | ||
request: CreateWorkspaceRequest | ||
|
@@ -45,64 +38,25 @@ export const createWorkspaceMachine = createMachine( | |
}, | ||
}, | ||
tsTypes: {} as import("./createWorkspaceXService.typegen").Typegen0, | ||
on: { | ||
SELECT_TEMPLATE: { | ||
actions: ["assignSelectedTemplate"], | ||
target: "gettingTemplateSchema", | ||
}, | ||
}, | ||
states: { | ||
gettingTemplates: { | ||
invoke: { | ||
src: "getTemplates", | ||
onDone: [ | ||
{ | ||
actions: ["assignTemplates"], | ||
target: "waitingForTemplateGetCreated", | ||
cond: "areTemplatesEmpty", | ||
}, | ||
{ | ||
actions: ["assignTemplates", "assignPreSelectedTemplate"], | ||
actions: ["assignTemplates", "assignSelectedTemplate"], | ||
target: "gettingTemplateSchema", | ||
cond: "hasValidPreSelectedTemplate", | ||
}, | ||
{ | ||
actions: ["assignTemplates"], | ||
target: "selectingTemplate", | ||
}, | ||
], | ||
onError: { | ||
target: "error", | ||
}, | ||
}, | ||
}, | ||
waitingForTemplateGetCreated: { | ||
initial: "refreshingTemplates", | ||
states: { | ||
refreshingTemplates: { | ||
invoke: { | ||
src: "getTemplates", | ||
onDone: [ | ||
{ target: "waiting", cond: "areTemplatesEmpty" }, | ||
{ target: "#createWorkspaceState.selectingTemplate", actions: ["assignTemplates"] }, | ||
], | ||
}, | ||
}, | ||
waiting: { | ||
after: { | ||
2_000: "refreshingTemplates", | ||
}, | ||
}, | ||
}, | ||
}, | ||
selectingTemplate: { | ||
on: { | ||
SELECT_TEMPLATE: { | ||
actions: ["assignSelectedTemplate"], | ||
target: "gettingTemplateSchema", | ||
}, | ||
}, | ||
}, | ||
gettingTemplateSchema: { | ||
invoke: { | ||
src: "getTemplateSchema", | ||
|
@@ -164,21 +118,20 @@ export const createWorkspaceMachine = createMachine( | |
}, | ||
}, | ||
guards: { | ||
hasValidPreSelectedTemplate: (ctx, event) => { | ||
if (!ctx.preSelectedTemplateName) { | ||
return false | ||
} | ||
const template = event.data.find((template) => template.name === ctx.preSelectedTemplateName) | ||
return !!template | ||
}, | ||
areTemplatesEmpty: (_, event) => event.data.length === 0, | ||
}, | ||
actions: { | ||
assignTemplates: assign({ | ||
templates: (_, event) => event.data, | ||
}), | ||
assignSelectedTemplate: assign({ | ||
selectedTemplate: (_, event) => event.template, | ||
selectedTemplate: (ctx, event) => { | ||
for (const template of event.data) { | ||
if (template.name === ctx.templateName) { | ||
return template | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use Array's filter here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, for loops are gonna die hard for me lol |
||
} | ||
}, | ||
}), | ||
assignTemplateSchema: assign({ | ||
// Only show parameters that are allowed to be overridden. | ||
|
@@ -188,17 +141,6 @@ export const createWorkspaceMachine = createMachine( | |
assignCreateWorkspaceRequest: assign({ | ||
createWorkspaceRequest: (_, event) => event.request, | ||
}), | ||
assignPreSelectedTemplate: assign({ | ||
selectedTemplate: (ctx, event) => { | ||
const selectedTemplate = event.data.find((template) => template.name === ctx.preSelectedTemplateName) | ||
// The proper validation happens on hasValidPreSelectedTemplate | ||
if (!selectedTemplate) { | ||
throw new Error("Invalid template selected") | ||
} | ||
|
||
return selectedTemplate | ||
}, | ||
}), | ||
}, | ||
}, | ||
) |
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.