- Notifications
You must be signed in to change notification settings - Fork907
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
16 commits Select commitHold shift + click to select a range
39200b9
feat: handle update build for dynamic params
jaaydenhe7d38cf
feat: pass template version id to workspace parameters page
jaaydenh561a0eb
feat: check opt-in per template
jaaydenh67ac3c7
fix: format
jaaydenh38ae3c7
fix: cleanup logic
jaaydenh8c50de0
chore: cleanup
jaaydenh86af69d
fix: cleanup
jaaydenh6a20a0d
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
jaaydenhb8131a5
fix: format
jaaydenhf2876d2
fix: lint error
jaaydenh962f5fd
fix: remove unnecessary parameters
jaaydenh80fd236
fix: fix tests
jaaydenh9117b7f
fix: send existing build parameters for dynamic params
jaaydenhd2856cd
fix: handle multi-select
jaaydenhFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
92 changes: 82 additions & 10 deletionssite/src/api/api.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 |
---|---|---|
@@ -24,7 +24,10 @@ import type dayjs from "dayjs"; | ||
import userAgentParser from "ua-parser-js"; | ||
import { OneWayWebSocket } from "../utils/OneWayWebSocket"; | ||
import { delay } from "../utils/delay"; | ||
import type { | ||
DynamicParametersRequest, | ||
PostWorkspaceUsageRequest, | ||
} from "./typesGenerated"; | ||
import * as TypesGen from "./typesGenerated"; | ||
const getMissingParameters = ( | ||
@@ -73,8 +76,10 @@ const getMissingParameters = ( | ||
if (templateParameter.options.length === 0) { | ||
continue; | ||
} | ||
// For multi-select, extra steps are necessary to JSON parse the value. | ||
if (templateParameter.form_type === "multi-select") { | ||
continue; | ||
} | ||
let buildParameter = newBuildParameters.find( | ||
(p) => p.name === templateParameter.name, | ||
); | ||
@@ -231,7 +236,7 @@ export const watchWorkspaceAgentLogs = ( | ||
/** | ||
* WebSocket compression in Safari (confirmed in 16.5) is broken when | ||
* the server sends large messages. The following error is seen: | ||
* WebSocket connection to 'wss://...' failed: The operation couldn't be completed. | ||
*/ | ||
if (userAgentParser(navigator.userAgent).browser.name === "Safari") { | ||
searchParams.set("no_compression", ""); | ||
@@ -990,6 +995,17 @@ class ApiMethods { | ||
return response.data; | ||
}; | ||
getTemplateVersionDynamicParameters = async ( | ||
versionId: string, | ||
data: TypesGen.DynamicParametersRequest, | ||
): Promise<TypesGen.DynamicParametersResponse> => { | ||
const response = await this.axios.post( | ||
`/api/v2/templateversions/${versionId}/dynamic-parameters/evaluate`, | ||
data, | ||
); | ||
return response.data; | ||
}; | ||
getTemplateVersionRichParameters = async ( | ||
versionId: string, | ||
): Promise<TypesGen.TemplateVersionParameter[]> => { | ||
@@ -2132,6 +2148,38 @@ class ApiMethods { | ||
await this.axios.delete(`/api/v2/licenses/${licenseId}`); | ||
}; | ||
getDynamicParameters = async ( | ||
templateVersionId: string, | ||
ownerId: string, | ||
oldBuildParameters: TypesGen.WorkspaceBuildParameter[], | ||
) => { | ||
const request: DynamicParametersRequest = { | ||
id: 1, | ||
jaaydenh marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
owner_id: ownerId, | ||
inputs: Object.fromEntries( | ||
new Map(oldBuildParameters.map((param) => [param.name, param.value])), | ||
), | ||
}; | ||
const dynamicParametersResponse = | ||
await this.getTemplateVersionDynamicParameters( | ||
templateVersionId, | ||
request, | ||
); | ||
return dynamicParametersResponse.parameters.map((p) => ({ | ||
...p, | ||
description_plaintext: p.description || "", | ||
default_value: p.default_value?.valid ? p.default_value.value : "", | ||
options: p.options | ||
? p.options.map((opt) => ({ | ||
...opt, | ||
value: opt.value?.valid ? opt.value.value : "", | ||
})) | ||
: [], | ||
})); | ||
}; | ||
/** Steps to change the workspace version | ||
* - Get the latest template to access the latest active version | ||
* - Get the current build parameters | ||
@@ -2145,11 +2193,23 @@ class ApiMethods { | ||
workspace: TypesGen.Workspace, | ||
templateVersionId: string, | ||
newBuildParameters: TypesGen.WorkspaceBuildParameter[] = [], | ||
isDynamicParametersEnabled = false, | ||
): Promise<TypesGen.WorkspaceBuild> => { | ||
const currentBuildParameters = await this.getWorkspaceBuildParameters( | ||
workspace.latest_build.id, | ||
); | ||
let templateParameters: TypesGen.TemplateVersionParameter[] = []; | ||
if (isDynamicParametersEnabled) { | ||
templateParameters = await this.getDynamicParameters( | ||
templateVersionId, | ||
workspace.owner_id, | ||
currentBuildParameters, | ||
); | ||
} else { | ||
templateParameters = | ||
await this.getTemplateVersionRichParameters(templateVersionId); | ||
} | ||
const missingParameters = getMissingParameters( | ||
currentBuildParameters, | ||
@@ -2180,15 +2240,27 @@ class ApiMethods { | ||
updateWorkspace = async ( | ||
workspace: TypesGen.Workspace, | ||
newBuildParameters: TypesGen.WorkspaceBuildParameter[] = [], | ||
isDynamicParametersEnabled = false, | ||
): Promise<TypesGen.WorkspaceBuild> => { | ||
const [template, oldBuildParameters] = await Promise.all([ | ||
this.getTemplate(workspace.template_id), | ||
this.getWorkspaceBuildParameters(workspace.latest_build.id), | ||
]); | ||
const activeVersionId = template.active_version_id; | ||
let templateParameters: TypesGen.TemplateVersionParameter[] = []; | ||
if (isDynamicParametersEnabled) { | ||
templateParameters = await this.getDynamicParameters( | ||
activeVersionId, | ||
workspace.owner_id, | ||
oldBuildParameters, | ||
); | ||
} else { | ||
templateParameters = | ||
await this.getTemplateVersionRichParameters(activeVersionId); | ||
} | ||
const missingParameters = getMissingParameters( | ||
oldBuildParameters, | ||
22 changes: 19 additions & 3 deletionssite/src/api/queries/workspaces.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
6 changes: 3 additions & 3 deletionssite/src/components/Dialog/Dialog.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
42 changes: 42 additions & 0 deletionssite/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 deletionssite/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.
Uh oh!
There was an error while loading.Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
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.