Harden API token policy button state
This commit is contained in:
@@ -69,6 +69,20 @@ func (u *ui) selectedAPIToken() (apitokens.Token, bool) {
|
||||
return apitokens.Token{}, false
|
||||
}
|
||||
|
||||
func (u *ui) ensureAPIPolicyRemoveClickables(count int) []widget.Clickable {
|
||||
if count <= 0 {
|
||||
u.apiPolicyRemoves = nil
|
||||
return nil
|
||||
}
|
||||
if len(u.apiPolicyRemoves) == count {
|
||||
return u.apiPolicyRemoves
|
||||
}
|
||||
clicks := make([]widget.Clickable, count)
|
||||
copy(clicks, u.apiPolicyRemoves)
|
||||
u.apiPolicyRemoves = clicks
|
||||
return clicks
|
||||
}
|
||||
|
||||
func (u *ui) loadSelectedAPITokenIntoEditor() {
|
||||
token, ok := u.selectedAPIToken()
|
||||
if !ok {
|
||||
@@ -83,7 +97,7 @@ func (u *ui) loadSelectedAPITokenIntoEditor() {
|
||||
u.apiPolicyAllow.Value = true
|
||||
u.apiPolicyGroupScope = true
|
||||
u.apiPolicyGroupScopeW.Value = true
|
||||
u.apiPolicyRemoves = nil
|
||||
u.ensureAPIPolicyRemoveClickables(0)
|
||||
return
|
||||
}
|
||||
u.apiTokenName.SetText(token.Name)
|
||||
@@ -94,9 +108,7 @@ func (u *ui) loadSelectedAPITokenIntoEditor() {
|
||||
u.apiTokenExpiresAt.SetText("")
|
||||
}
|
||||
u.apiTokenDisabled.Value = token.Disabled
|
||||
if len(u.apiPolicyRemoves) < len(token.Policies) {
|
||||
u.apiPolicyRemoves = make([]widget.Clickable, len(token.Policies))
|
||||
}
|
||||
u.ensureAPIPolicyRemoveClickables(len(token.Policies))
|
||||
}
|
||||
|
||||
func (u *ui) issueAPITokenAction() error {
|
||||
@@ -444,8 +456,9 @@ func (u *ui) apiAuditListPanel(gtx layout.Context) layout.Dimensions {
|
||||
|
||||
func (u *ui) apiTokenDetailPanel(gtx layout.Context) layout.Dimensions {
|
||||
token, ok := u.selectedAPIToken()
|
||||
if ok && len(u.apiPolicyRemoves) < len(token.Policies) {
|
||||
u.apiPolicyRemoves = make([]widget.Clickable, len(token.Policies))
|
||||
removeClicks := u.ensureAPIPolicyRemoveClickables(0)
|
||||
if ok {
|
||||
removeClicks = u.ensureAPIPolicyRemoveClickables(len(token.Policies))
|
||||
}
|
||||
rows := []layout.Widget{
|
||||
func(gtx layout.Context) layout.Dimensions {
|
||||
@@ -548,13 +561,13 @@ func (u *ui) apiTokenDetailPanel(gtx layout.Context) layout.Dimensions {
|
||||
lbl := material.Label(u.theme, unit.Sp(13), ruleText)
|
||||
lbl.Color = mutedColor
|
||||
return lbl.Layout(gtx)
|
||||
}),
|
||||
layout.Rigid(layout.Spacer{Width: unit.Dp(8)}.Layout),
|
||||
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
||||
return tonedButton(gtx, u.theme, &u.apiPolicyRemoves[index], "Remove")
|
||||
}),
|
||||
)
|
||||
},
|
||||
}),
|
||||
layout.Rigid(layout.Spacer{Width: unit.Dp(8)}.Layout),
|
||||
layout.Rigid(func(gtx layout.Context) layout.Dimensions {
|
||||
return tonedButton(gtx, u.theme, &removeClicks[index], "Remove")
|
||||
}),
|
||||
)
|
||||
},
|
||||
layout.Spacer{Height: unit.Dp(6)}.Layout,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user