Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit532218e

Browse files
committed
feat: make dynamic parameters opt-in by default for new templates
1 parent0672bf5 commit532218e

File tree

15 files changed

+156
-30
lines changed

15 files changed

+156
-30
lines changed

‎coderd/database/dbgen/dbgen.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func Template(t testing.TB, db database.Store, seed database.Template) database.
147147
DisplayName:takeFirst(seed.DisplayName,testutil.GetRandomName(t)),
148148
AllowUserCancelWorkspaceJobs:seed.AllowUserCancelWorkspaceJobs,
149149
MaxPortSharingLevel:takeFirst(seed.MaxPortSharingLevel,database.AppSharingLevelOwner),
150-
UseClassicParameterFlow:takeFirst(seed.UseClassicParameterFlow,true),
150+
UseClassicParameterFlow:takeFirst(seed.UseClassicParameterFlow,false),
151151
})
152152
require.NoError(t,err,"insert template")
153153

‎coderd/insights_test.go‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -665,10 +665,11 @@ func TestTemplateInsights_Golden(t *testing.T) {
665665
// where we can control the template ID.
666666
// createdTemplate := coderdtest.CreateTemplate(t, client, firstUser.OrganizationID, version.ID)
667667
createdTemplate:=dbgen.Template(t,db, database.Template{
668-
ID:template.id,
669-
ActiveVersionID:version.ID,
670-
OrganizationID:firstUser.OrganizationID,
671-
CreatedBy:firstUser.UserID,
668+
ID:template.id,
669+
ActiveVersionID:version.ID,
670+
OrganizationID:firstUser.OrganizationID,
671+
CreatedBy:firstUser.UserID,
672+
UseClassicParameterFlow:true,
672673
GroupACL: database.TemplateACL{
673674
firstUser.OrganizationID.String():db2sdk.TemplateRoleActions(codersdk.TemplateRoleUse),
674675
},
@@ -1556,10 +1557,11 @@ func TestUserActivityInsights_Golden(t *testing.T) {
15561557
// where we can control the template ID.
15571558
// createdTemplate := coderdtest.CreateTemplate(t, client, firstUser.OrganizationID, version.ID)
15581559
createdTemplate:=dbgen.Template(t,db, database.Template{
1559-
ID:template.id,
1560-
ActiveVersionID:version.ID,
1561-
OrganizationID:firstUser.OrganizationID,
1562-
CreatedBy:firstUser.UserID,
1560+
ID:template.id,
1561+
ActiveVersionID:version.ID,
1562+
OrganizationID:firstUser.OrganizationID,
1563+
CreatedBy:firstUser.UserID,
1564+
UseClassicParameterFlow:true,// Required for parameter usage tracking in this test
15631565
GroupACL: database.TemplateACL{
15641566
firstUser.OrganizationID.String():db2sdk.TemplateRoleActions(codersdk.TemplateRoleUse),
15651567
},

‎coderd/templates.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ func (api *API) postTemplateByOrganization(rw http.ResponseWriter, r *http.Reque
197197
return
198198
}
199199

200-
// Default istrue until dynamic parameters arepromoted to stable.
201-
useClassicParameterFlow:=ptr.NilToDefault(createTemplate.UseClassicParameterFlow,true)
200+
// Default isfalse as dynamic parameters arenow the preferred approach.
201+
useClassicParameterFlow:=ptr.NilToDefault(createTemplate.UseClassicParameterFlow,false)
202202

203203
// Make a temporary struct to represent the template. This is used for
204204
// auditing if any of the following checks fail. It will be overwritten when

‎coderd/templates_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func TestPostTemplateByOrganization(t *testing.T) {
7777
assert.Equal(t,expected.Name,got.Name)
7878
assert.Equal(t,expected.Description,got.Description)
7979
assert.Equal(t,expected.ActivityBumpMillis,got.ActivityBumpMillis)
80-
assert.Equal(t,expected.UseClassicParameterFlow,true)// Current default istrue
80+
assert.Equal(t,expected.UseClassicParameterFlow,false)// Current default isfalse
8181

8282
require.Len(t,auditor.AuditLogs(),3)
8383
assert.Equal(t,database.AuditActionCreate,auditor.AuditLogs()[0].Action)
@@ -1551,7 +1551,7 @@ func TestPatchTemplateMeta(t *testing.T) {
15511551
user:=coderdtest.CreateFirstUser(t,client)
15521552
version:=coderdtest.CreateTemplateVersion(t,client,user.OrganizationID,nil)
15531553
template:=coderdtest.CreateTemplate(t,client,user.OrganizationID,version.ID)
1554-
require.True(t,template.UseClassicParameterFlow,"default istrue")
1554+
require.False(t,template.UseClassicParameterFlow,"default isfalse")
15551555

15561556
bTrue:=true
15571557
bFalse:=false
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import{render,screen}from"@testing-library/react";
2+
import{ClassicParameterFlowDeprecationWarning}from"./ClassicParameterFlowDeprecationWarning";
3+
4+
jest.mock("modules/navigation",()=>({
5+
useLinks:()=>()=>"/mock-link",
6+
linkToTemplate:()=>"/mock-template-link",
7+
}));
8+
9+
describe("ClassicParameterFlowDeprecationWarning",()=>{
10+
constdefaultProps={
11+
enabled:true,
12+
organizationName:"test-org",
13+
templateName:"test-template",
14+
canUpdateTemplate:true,
15+
};
16+
17+
it("renders warning when enabled and user has template update permissions",()=>{
18+
render(<ClassicParameterFlowDeprecationWarning{...defaultProps}isEnabled={true}/>);
19+
20+
expect(screen.getByText("deprecated")).toBeInTheDocument();
21+
expect(screen.getByText("Go to Template Settings")).toBeInTheDocument();
22+
});
23+
24+
it("does not render when enabled is false",()=>{
25+
const{ container}=render(
26+
<ClassicParameterFlowDeprecationWarning
27+
{...defaultProps}
28+
isEnabled={false}
29+
/>
30+
);
31+
32+
expect(container.firstChild).toBeNull();
33+
});
34+
});
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import{Alert}from"components/Alert/Alert";
2+
import{Link}from"components/Link/Link";
3+
import{linkToTemplate,useLinks}from"modules/navigation";
4+
importtype{FC}from"react";
5+
6+
interfaceClassicParameterFlowDeprecationWarningProps{
7+
organizationName:string;
8+
templateName:string;
9+
isEnabled:boolean;
10+
}
11+
12+
exportconstClassicParameterFlowDeprecationWarning:FC<
13+
ClassicParameterFlowDeprecationWarningProps
14+
>=({ organizationName, templateName, isEnabled})=>{
15+
constgetLink=useLinks();
16+
17+
if(!isEnabled){
18+
returnnull;
19+
}
20+
21+
consttemplateSettingsLink=`${getLink(
22+
linkToTemplate(organizationName,templateName),
23+
)}/settings`;
24+
25+
return(
26+
<Alertseverity="warning"className="mb-2">
27+
<div>
28+
This template is using the classic parameter flow, which will be{" "}
29+
<strong>deprecated</strong> in a future release.
30+
Please migrate to dynamic improved functionality.
31+
</div>
32+
<LinkclassName="text-xs"href={templateSettingsLink}>
33+
Go to Template Settings
34+
</Link>
35+
</Alert>
36+
);
37+
};

‎site/src/pages/CreateWorkspacePage/CreateWorkspacePage.tsx‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,20 @@ const CreateWorkspacePage: FC = () => {
7272
}),
7373
enabled:!!templateQuery.data,
7474
});
75+
consttemplatePermissionsQuery=useQuery({
76+
...checkAuthorization({
77+
checks:{
78+
canUpdateTemplate:{
79+
object:{
80+
resource_type:"template",
81+
resource_id:templateQuery.data?.id??"",
82+
},
83+
action:"update",
84+
},
85+
},
86+
}),
87+
enabled:!!templateQuery.data,
88+
});
7589
constrealizedVersionId=
7690
customVersionId??templateQuery.data?.active_version_id;
7791
constorganizationId=templateQuery.data?.organization_id;
@@ -93,9 +107,10 @@ const CreateWorkspacePage: FC = () => {
93107
constisLoadingFormData=
94108
templateQuery.isLoading||
95109
permissionsQuery.isLoading||
110+
templatePermissionsQuery.isLoading||
96111
richParametersQuery.isLoading;
97112
constloadFormDataError=
98-
templateQuery.error??permissionsQuery.error??richParametersQuery.error;
113+
templateQuery.error??permissionsQuery.error??templatePermissionsQuery.error??richParametersQuery.error;
99114

100115
consttitle=autoCreateWorkspaceMutation.isPending
101116
?"Creating workspace..."
@@ -211,7 +226,7 @@ const CreateWorkspacePage: FC = () => {
211226
startPollingExternalAuth={startPollingExternalAuth}
212227
hasAllRequiredExternalAuth={hasAllRequiredExternalAuth}
213228
permissions={permissionsQuery.dataasCreateWorkspacePermissions}
214-
canUpdateTemplate={permissionsQuery.data?.canUpdateTemplate}
229+
templatePermissions={templatePermissionsQuery.dataas{canUpdateTemplate:boolean}}
215230
parameters={realizedParametersasTemplateVersionParameter[]}
216231
presets={templateVersionPresetsQuery.data??[]}
217232
creatingWorkspace={createWorkspaceMutation.isPending}

‎site/src/pages/CreateWorkspacePage/CreateWorkspacePageView.tsx‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { UserAutocomplete } from "components/UserAutocomplete/UserAutocomplete";
2828
import{typeFormikContextType,useFormik}from"formik";
2929
importtype{ExternalAuthPollingState}from"hooks/useExternalAuth";
3030
import{ExternalLinkIcon}from"lucide-react";
31+
import{ClassicParameterFlowDeprecationWarning}from"modules/workspaces/ClassicParameterFlowDeprecationWarning/ClassicParameterFlowDeprecationWarning";
3132
import{generateWorkspaceName}from"modules/workspaces/generateWorkspaceName";
3233
import{typeFC,useCallback,useEffect,useMemo,useState}from"react";
3334
import{Link}from"react-router-dom";
@@ -68,6 +69,7 @@ interface CreateWorkspacePageViewProps {
6869
autofillParameters:AutofillBuildParameter[];
6970
presets:TypesGen.Preset[];
7071
permissions:CreateWorkspacePermissions;
72+
templatePermissions:{canUpdateTemplate:boolean};
7173
creatingWorkspace:boolean;
7274
canUpdateTemplate?:boolean;
7375
onCancel:()=>void;
@@ -94,6 +96,7 @@ export const CreateWorkspacePageView: FC<CreateWorkspacePageViewProps> = ({
9496
autofillParameters,
9597
presets=[],
9698
permissions,
99+
templatePermissions,
97100
creatingWorkspace,
98101
canUpdateTemplate,
99102
onSubmit,
@@ -261,6 +264,12 @@ export const CreateWorkspacePageView: FC<CreateWorkspacePageViewProps> = ({
261264
</Stack>
262265
</PageHeader>
263266

267+
<ClassicParameterFlowDeprecationWarning
268+
organizationName={template.organization_name}
269+
templateName={template.name}
270+
isEnabled={templatePermissions.canUpdateTemplate}
271+
/>
272+
264273
<HorizontalForm
265274
name="create-workspace-form"
266275
onSubmit={form.handleSubmit}

‎site/src/pages/CreateWorkspacePage/CreateWorkspacePageViewExperimental.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ export const CreateWorkspacePageViewExperimental: FC<
407407
<br/>
408408
<Link
409409
href={docs(
410-
"/admin/templates/extending-templates/parameters#enable-dynamic-parameters-early-access",
410+
"/admin/templates/extending-templates/dynamic-parameters",
411411
)}
412412
>
413413
View docs
@@ -555,7 +555,7 @@ export const CreateWorkspacePageViewExperimental: FC<
555555
parameters cannot be modified once the workspace is created.
556556
<Link
557557
href={docs(
558-
"/admin/templates/extending-templates/parameters#enable-dynamic-parameters-early-access",
558+
"/admin/templates/extending-templates/dynamic-parameters",
559559
)}
560560
>
561561
View docs

‎site/src/pages/TemplateSettingsPage/TemplateGeneralSettingsPage/TemplateSettingsForm.tsx‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,19 +245,20 @@ export const TemplateSettingsForm: FC<TemplateSettingsForm> = ({
245245
label={
246246
<StackLabel>
247247
<spanclassName="flex flex-row gap-2">
248-
Enable dynamic parameters for workspace creation
248+
Enable dynamic parameters for workspace creation (recommended)
249249
</span>
250250
<StackLabelHelperText>
251251
<div>
252-
The new workspace form allows you to design your template
253-
with new form types and identity-aware conditional
254-
parameters. The form will only present options that are
255-
compatible and available.
252+
The dynamic workspace form allows you to design your
253+
template with additional form types and identity-aware
254+
conditional parameters. This is the default option for new
255+
templates. The classic workspace creation flow will be
256+
deprecated in a future release.
256257
</div>
257258
<Link
258259
className="text-xs"
259260
href={docs(
260-
"/admin/templates/extending-templates/parameters#dynamic-parameters-beta",
261+
"/admin/templates/extending-templates/dynamic-parameters",
261262
)}
262263
>
263264
Learn more

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp