Skip to content
This repository has been archived by the owner on Dec 26, 2023. It is now read-only.

Commit

Permalink
fix(ui): allow variable to be updated from hcl to non-hcl
Browse files Browse the repository at this point in the history
  • Loading branch information
leg100 committed Oct 28, 2023
1 parent 224081c commit ac0ff5a
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 6 deletions.
82 changes: 80 additions & 2 deletions internal/http/html/static/css/output.css
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,10 @@ th, td {
margin: 0px;
}

.m-1 {
margin: 0.25rem;
}

.m-auto {
margin: auto;
}
Expand Down Expand Up @@ -860,6 +864,14 @@ th, td {
margin-top: 1rem;
}

.ml-4 {
margin-left: 1rem;
}

.ml-2 {
margin-left: 0.5rem;
}

.block {
display: block;
}
Expand All @@ -872,6 +884,10 @@ th, td {
display: flex;
}

.inline-flex {
display: inline-flex;
}

.table {
display: table;
}
Expand All @@ -880,6 +896,10 @@ th, td {
display: none;
}

.h-3 {
height: 0.75rem;
}

.h-4 {
height: 1rem;
}
Expand All @@ -888,12 +908,16 @@ th, td {
height: 1.25rem;
}

.h-full {
height: 100%;
}

.min-h-screen {
min-height: 100vh;
}

.w-20 {
width: 5rem;
.w-3 {
width: 0.75rem;
}

.w-32 {
Expand Down Expand Up @@ -960,6 +984,10 @@ th, td {
max-width: 16rem;
}

.max-w-\[66\%\] {
max-width: 66%;
}

.grow {
flex-grow: 1;
}
Expand Down Expand Up @@ -1131,6 +1159,11 @@ th, td {
background-color: rgb(30 64 175 / var(--tw-bg-opacity));
}

.bg-cyan-200 {
--tw-bg-opacity: 1;
background-color: rgb(165 243 252 / var(--tw-bg-opacity));
}

.bg-gray-100 {
--tw-bg-opacity: 1;
background-color: rgb(243 244 246 / var(--tw-bg-opacity));
Expand Down Expand Up @@ -1171,11 +1204,31 @@ th, td {
background-color: rgb(254 226 226 / var(--tw-bg-opacity));
}

.bg-violet-100 {
--tw-bg-opacity: 1;
background-color: rgb(237 233 254 / var(--tw-bg-opacity));
}

.bg-violet-400 {
--tw-bg-opacity: 1;
background-color: rgb(167 139 250 / var(--tw-bg-opacity));
}

.bg-white {
--tw-bg-opacity: 1;
background-color: rgb(255 255 255 / var(--tw-bg-opacity));
}

.bg-yellow-200 {
--tw-bg-opacity: 1;
background-color: rgb(254 240 138 / var(--tw-bg-opacity));
}

.bg-yellow-50 {
--tw-bg-opacity: 1;
background-color: rgb(254 252 232 / var(--tw-bg-opacity));
}

.bg-\[size\:14px\] {
background-size: 14px;
}
Expand Down Expand Up @@ -1268,6 +1321,10 @@ th, td {
text-align: right;
}

.align-middle {
vertical-align: middle;
}

.font-mono {
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}
Expand Down Expand Up @@ -1360,6 +1417,18 @@ th, td {
text-decoration-line: underline;
}

.shadow-xl {
--tw-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
--tw-shadow-colored: 0 20px 25px -5px var(--tw-shadow-color), 0 8px 10px -6px var(--tw-shadow-color);
box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);
}

.shadow-2xl {
--tw-shadow: 0 25px 50px -12px rgb(0 0 0 / 0.25);
--tw-shadow-colored: 0 25px 50px -12px var(--tw-shadow-color);
box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);
}

.shadow-transparent {
--tw-shadow-color: transparent;
--tw-shadow: var(--tw-shadow-colored);
Expand All @@ -1370,6 +1439,11 @@ th, td {
filter: var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow);
}

.drop-shadow-xl {
--tw-drop-shadow: drop-shadow(0 20px 13px rgb(0 0 0 / 0.03)) drop-shadow(0 8px 5px rgb(0 0 0 / 0.08));
filter: var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow);
}

.even\:bg-gray-100:nth-child(even) {
--tw-bg-opacity: 1;
background-color: rgb(243 244 246 / var(--tw-bg-opacity));
Expand Down Expand Up @@ -1400,6 +1474,10 @@ th, td {
background-color: rgb(229 231 235 / var(--tw-bg-opacity));
}

.group:hover .group-hover\:block {
display: block;
}

.group:hover .group-hover\:bg-gray-400 {
--tw-bg-opacity: 1;
background-color: rgb(156 163 175 / var(--tw-bg-opacity));
Expand Down
3 changes: 2 additions & 1 deletion internal/variable/variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ func (v *Variable) update(collection []*Variable, opts UpdateVariableOptions) er
}
}
if opts.HCL != nil {
if v.Sensitive {
changed := v.HCL != *opts.HCL
if changed && v.Sensitive {
return errors.New("changing HCL mode on a sensitive variable is not allowed")
}
v.HCL = *opts.HCL
Expand Down
6 changes: 3 additions & 3 deletions internal/variable/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type (
Description *string
Category *VariableCategory
Sensitive *bool
HCL *bool
HCL bool
VariableID string `schema:"variable_id,required"`
}

Expand Down Expand Up @@ -247,7 +247,7 @@ func (h *web) updateWorkspaceVariable(w http.ResponseWriter, r *http.Request) {
Description: params.Description,
Category: params.Category,
Sensitive: params.Sensitive,
HCL: params.HCL,
HCL: &params.HCL,
})
if err != nil {
html.FlashError(w, err.Error())
Expand Down Expand Up @@ -598,7 +598,7 @@ func (h *web) updateVariableSetVariable(w http.ResponseWriter, r *http.Request)
Description: params.Description,
Category: params.Category,
Sensitive: params.Sensitive,
HCL: params.HCL,
HCL: &params.HCL,
})
if err != nil {
html.FlashError(w, err.Error())
Expand Down
17 changes: 17 additions & 0 deletions internal/variable/web_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,23 @@ func TestVariable_UpdateHandler(t *testing.T) {
assert.True(t, got.HCL)
},
},
{
name: "disable hcl",
existing: CreateVariableOptions{
Key: internal.String("foo"),
Value: internal.String("bar"),
Category: VariableCategoryPtr(CategoryTerraform),
HCL: internal.Bool(true),
generateVersion: func() string { return "" },
},
// If the user unchecks the HCL checkbox then no form value is sent
// but the handler should interpret the absence of the value as
// 'false'.
updated: url.Values{},
want: func(t *testing.T, got *Variable) {
assert.False(t, got.HCL)
},
},
{
name: "update sensitive value",
existing: CreateVariableOptions{
Expand Down

0 comments on commit ac0ff5a

Please sign in to comment.