-
Notifications
You must be signed in to change notification settings - Fork 905
feat: handle update build for dynamic params #18226
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
+431
−132
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
39200b9
feat: handle update build for dynamic params
jaaydenh e7d38cf
feat: pass template version id to workspace parameters page
jaaydenh 561a0eb
feat: check opt-in per template
jaaydenh 67ac3c7
fix: format
jaaydenh 38ae3c7
fix: cleanup logic
jaaydenh 8c50de0
chore: cleanup
jaaydenh 86af69d
fix: cleanup
jaaydenh 6a20a0d
fix: update test calls to match new updateWorkspace signature
blink-so[bot] c82b145
fix: handle missing dynamic-parameters experiment in parameter dialogs
blink-so[bot] 9878ade
fix: format
jaaydenh b8131a5
fix: format
jaaydenh f2876d2
fix: lint error
jaaydenh 962f5fd
fix: remove unnecessary parameters
jaaydenh 80fd236
fix: fix tests
jaaydenh 9117b7f
fix: send existing build parameters for dynamic params
jaaydenh d2856cd
fix: handle multi-select
jaaydenh 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
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
42 changes: 42 additions & 0 deletions
42
site/src/modules/workspaces/DynamicParameter/useDynamicParametersOptOut.ts
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,42 @@ | ||
import { useQuery } from "react-query"; | ||
|
||
export const optOutKey = (id: string): string => `parameters.${id}.optOut`; | ||
|
||
interface UseDynamicParametersOptOutOptions { | ||
templateId: string | undefined; | ||
templateUsesClassicParameters: boolean | undefined; | ||
enabled: boolean; | ||
} | ||
|
||
export const useDynamicParametersOptOut = ({ | ||
templateId, | ||
templateUsesClassicParameters, | ||
enabled, | ||
}: UseDynamicParametersOptOutOptions) => { | ||
return useQuery({ | ||
enabled: !!templateId && enabled, | ||
queryKey: ["dynamicParametersOptOut", templateId], | ||
queryFn: () => { | ||
if (!templateId) { | ||
// This should not happen if enabled is working correctly, | ||
// but as a type guard and sanity check. | ||
throw new Error("templateId is required"); | ||
} | ||
const localStorageKey = optOutKey(templateId); | ||
const storedOptOutString = localStorage.getItem(localStorageKey); | ||
|
||
let optedOut: boolean; | ||
|
||
if (storedOptOutString !== null) { | ||
optedOut = storedOptOutString === "true"; | ||
} else { | ||
optedOut = Boolean(templateUsesClassicParameters); | ||
} | ||
|
||
return { | ||
templateId, | ||
optedOut, | ||
}; | ||
}, | ||
}); | ||
}; |
71 changes: 71 additions & 0 deletions
71
site/src/modules/workspaces/WorkspaceMoreActions/UpdateBuildParametersDialogExperimental.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,71 @@ | ||
import type { TemplateVersionParameter } from "api/typesGenerated"; | ||
import { Button } from "components/Button/Button"; | ||
import { | ||
Dialog, | ||
DialogContent, | ||
DialogDescription, | ||
DialogFooter, | ||
DialogHeader, | ||
DialogTitle, | ||
} from "components/Dialog/Dialog"; | ||
import type { FC } from "react"; | ||
import { useNavigate } from "react-router-dom"; | ||
|
||
type UpdateBuildParametersDialogExperimentalProps = { | ||
open: boolean; | ||
onClose: () => void; | ||
missedParameters: TemplateVersionParameter[]; | ||
workspaceOwnerName: string; | ||
workspaceName: string; | ||
templateVersionId: string | undefined; | ||
}; | ||
|
||
export const UpdateBuildParametersDialogExperimental: FC< | ||
UpdateBuildParametersDialogExperimentalProps | ||
> = ({ | ||
missedParameters, | ||
open, | ||
onClose, | ||
workspaceOwnerName, | ||
workspaceName, | ||
templateVersionId, | ||
}) => { | ||
const navigate = useNavigate(); | ||
|
||
const handleGoToParameters = () => { | ||
onClose(); | ||
navigate( | ||
`/@${workspaceOwnerName}/${workspaceName}/settings/parameters?templateVersionId=${templateVersionId}`, | ||
); | ||
}; | ||
|
||
return ( | ||
<Dialog open={open} onOpenChange={(isOpen) => !isOpen && onClose()}> | ||
<DialogContent> | ||
<DialogHeader> | ||
<DialogTitle>Update workspace parameters</DialogTitle> | ||
<DialogDescription> | ||
This template has{" "} | ||
<strong className="text-content-primary"> | ||
{missedParameters.length} new parameter | ||
{missedParameters.length === 1 ? "" : "s"} | ||
</strong>{" "} | ||
that must be configured to complete the update. | ||
</DialogDescription> | ||
<DialogDescription> | ||
Would you like to go to the workspace parameters page to review and | ||
update these parameters before continuing? | ||
</DialogDescription> | ||
</DialogHeader> | ||
<DialogFooter> | ||
<Button onClick={onClose} variant="outline"> | ||
Cancel | ||
</Button> | ||
<Button onClick={handleGoToParameters}> | ||
Go to workspace parameters | ||
</Button> | ||
</DialogFooter> | ||
</DialogContent> | ||
</Dialog> | ||
); | ||
}; |
Oops, something went wrong.
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.