From 6221a6fd5450692ae27e5602b41fc9ebd9150736 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Sat, 18 Feb 2023 20:17:39 +0100 Subject: Scoped labels (#22585) Add a new "exclusive" option per label. This makes it so that when the label is named `scope/name`, no other label with the same `scope/` prefix can be set on an issue. The scope is determined by the last occurence of `/`, so for example `scope/alpha/name` and `scope/beta/name` are considered to be in different scopes and can coexist. Exclusive scopes are not enforced by any database rules, however they are enforced when editing labels at the models level, automatically removing any existing labels in the same scope when either attaching a new label or replacing all labels. In menus use a circle instead of checkbox to indicate they function as radio buttons per scope. Issue filtering by label ensures that only a single scoped label is selected at a time. Clicking with alt key can be used to remove a scoped label, both when editing individual issues and batch editing. Label rendering refactor for consistency and code simplification: * Labels now consistently have the same shape, emojis and tooltips everywhere. This includes the label list and label assignment menus. * In label list, show description below label same as label menus. * Don't use exactly black/white text colors to look a bit nicer. * Simplify text color computation. There is no point computing luminance in linear color space, as this is a perceptual problem and sRGB is closer to perceptually linear. * Increase height of label assignment menus to show more labels. Showing only 3-4 labels at a time leads to a lot of scrolling. * Render all labels with a new RenderLabel template helper function. Label creation and editing in multiline modal menu: * Change label creation to open a modal menu like label editing. * Change menu layout to place name, description and colors on separate lines. * Don't color cancel button red in label editing modal menu. * Align text to the left in model menu for better readability and consistent with settings layout elsewhere. Custom exclusive scoped label rendering: * Display scoped label prefix and suffix with slightly darker and lighter background color respectively, and a slanted edge between them similar to the `/` symbol. * In menus exclusive labels are grouped with a divider line. --------- Co-authored-by: Yarden Shoham Co-authored-by: Lauris BH --- templates/projects/view.tmpl | 2 +- templates/repo/issue/labels/edit_delete_label.tmpl | 42 ++++++++++------ templates/repo/issue/labels/label.tmpl | 6 +-- templates/repo/issue/labels/label_list.tmpl | 34 +++++-------- templates/repo/issue/labels/label_new.tmpl | 56 +++++++++++++++------- templates/repo/issue/list.tmpl | 16 ++++++- templates/repo/issue/milestone_issues.tmpl | 4 +- templates/repo/issue/new_form.tmpl | 16 ++++++- templates/repo/issue/view_content/sidebar.tmpl | 16 ++++++- templates/repo/projects/view.tmpl | 2 +- templates/shared/issuelist.tmpl | 2 +- templates/swagger/v1_json.tmpl | 18 ++++++- 12 files changed, 145 insertions(+), 69 deletions(-) (limited to 'templates') diff --git a/templates/projects/view.tmpl b/templates/projects/view.tmpl index 112e6be7ce..b25cf2526e 100644 --- a/templates/projects/view.tmpl +++ b/templates/projects/view.tmpl @@ -234,7 +234,7 @@ {{if or .Labels .Assignees}}
{{range .Labels}} - {{.Name | RenderEmoji}} + {{RenderLabel .}} {{end}}
{{range .Assignees}} diff --git a/templates/repo/issue/labels/edit_delete_label.tmpl b/templates/repo/issue/labels/edit_delete_label.tmpl index a0479dde1b..450061e835 100644 --- a/templates/repo/issue/labels/edit_delete_label.tmpl +++ b/templates/repo/issue/labels/edit_delete_label.tmpl @@ -26,31 +26,45 @@
{{.CsrfTokenHtml}} -
-
-
- -
+
+ +
+
-
-
- -
+
+
+
+ +
+
+ {{.locale.Tr "repo.issues.label_exclusive_desc" | Safe}} +
+ {{svg "octicon-alert"}} {{.locale.Tr "repo.issues.label_exclusive_warning" | Safe}} +
+
+
+ +
+ +
+
+
+
-
-
- {{template "repo/issue/label_precolors"}} +
+ {{template "repo/issue/label_precolors"}} +
-
+
{{.locale.Tr "cancel"}}
-
+
{{.locale.Tr "save"}}
diff --git a/templates/repo/issue/labels/label.tmpl b/templates/repo/issue/labels/label.tmpl index 0afe5cb6e7..87d8f0c41c 100644 --- a/templates/repo/issue/labels/label.tmpl +++ b/templates/repo/issue/labels/label.tmpl @@ -1,9 +1,7 @@ - {{.label.Name | RenderEmoji}} + {{RenderLabel .label}} diff --git a/templates/repo/issue/labels/label_list.tmpl b/templates/repo/issue/labels/label_list.tmpl index 464c9fe208..e8f00fa256 100644 --- a/templates/repo/issue/labels/label_list.tmpl +++ b/templates/repo/issue/labels/label_list.tmpl @@ -30,28 +30,24 @@ {{range .Labels}}
  • -
    -
    {{svg "octicon-tag"}} {{.Name | RenderEmoji}}
    +
    + {{RenderLabel .}} + {{if .Description}}
    {{.Description | RenderEmoji}}{{end}}
    -
    -
    - {{.Description | RenderEmoji}} -
    -
    -
    - {{svg "octicon-issue-opened"}} {{$.locale.Tr "repo.issues.label_open_issues" .NumOpenRepoIssues}} +
    diff --git a/templates/repo/issue/labels/label_new.tmpl b/templates/repo/issue/labels/label_new.tmpl index 035a4db800..62f7155b74 100644 --- a/templates/repo/issue/labels/label_new.tmpl +++ b/templates/repo/issue/labels/label_new.tmpl @@ -1,27 +1,47 @@ -
    -
    - {{.CsrfTokenHtml}} -
    -
    +
    @@ -161,7 +161,7 @@ diff --git a/templates/repo/issue/new_form.tmpl b/templates/repo/issue/new_form.tmpl index 8fbd9d256a..2a6fcaa995 100644 --- a/templates/repo/issue/new_form.tmpl +++ b/templates/repo/issue/new_form.tmpl @@ -53,14 +53,26 @@ {{end}}
    {{.locale.Tr "repo.issues.new.clear_labels"}}
    {{if or .Labels .OrgLabels}} + {{$previousExclusiveScope := "_no_scope"}} {{range .Labels}} - {{svg "octicon-check"}} {{.Name | RenderEmoji}} + {{$exclusiveScope := .ExclusiveScope}} + {{if and (ne $previousExclusiveScope "_no_scope") (ne $previousExclusiveScope $exclusiveScope)}} +
    + {{end}} + {{$previousExclusiveScope = $exclusiveScope}} +
    {{if $exclusiveScope}}{{svg "octicon-dot-fill"}}{{else}}{{svg "octicon-check"}}{{end}}  {{RenderLabel .}} {{if .Description}}
    {{.Description | RenderEmoji}}{{end}}
    {{end}}
    + {{$previousExclusiveScope := "_no_scope"}} {{range .OrgLabels}} - {{svg "octicon-check"}} {{.Name | RenderEmoji}} + {{$exclusiveScope := .ExclusiveScope}} + {{if and (ne $previousExclusiveScope "_no_scope") (ne $previousExclusiveScope $exclusiveScope)}} +
    + {{end}} + {{$previousExclusiveScope = $exclusiveScope}} +
    {{if $exclusiveScope}}{{svg "octicon-dot-fill"}}{{else}}{{svg "octicon-check"}}{{end}}  {{RenderLabel .}} {{if .Description}}
    {{.Description | RenderEmoji}}{{end}}
    {{end}} {{else}} diff --git a/templates/repo/issue/view_content/sidebar.tmpl b/templates/repo/issue/view_content/sidebar.tmpl index 9ba46f3715..8cd34ede6e 100644 --- a/templates/repo/issue/view_content/sidebar.tmpl +++ b/templates/repo/issue/view_content/sidebar.tmpl @@ -123,13 +123,25 @@ {{end}}
    {{.locale.Tr "repo.issues.new.clear_labels"}}
    {{if or .Labels .OrgLabels}} + {{$previousExclusiveScope := "_no_scope"}} {{range .Labels}} - {{svg "octicon-check"}} {{.Name | RenderEmoji}} + {{$exclusiveScope := .ExclusiveScope}} + {{if and (ne $previousExclusiveScope "_no_scope") (ne $previousExclusiveScope $exclusiveScope)}} +
    + {{end}} + {{$previousExclusiveScope = $exclusiveScope}} +
    {{if $exclusiveScope}}{{svg "octicon-dot-fill"}}{{else}}{{svg "octicon-check"}}{{end}}  {{RenderLabel .}} {{if .Description}}
    {{.Description | RenderEmoji}}{{end}}
    {{end}}
    + {{$previousExclusiveScope := "_no_scope"}} {{range .OrgLabels}} - {{svg "octicon-check"}} {{.Name | RenderEmoji}} + {{$exclusiveScope := .ExclusiveScope}} + {{if and (ne $previousExclusiveScope "_no_scope") (ne $previousExclusiveScope $exclusiveScope)}} +
    + {{end}} + {{$previousExclusiveScope = $exclusiveScope}} +
    {{if $exclusiveScope}}{{svg "octicon-dot-fill"}}{{else}}{{svg "octicon-check"}}{{end}}  {{RenderLabel .}} {{if .Description}}
    {{.Description | RenderEmoji}}{{end}}
    {{end}} {{else}} diff --git a/templates/repo/projects/view.tmpl b/templates/repo/projects/view.tmpl index de0911e6cd..a4ada87353 100644 --- a/templates/repo/projects/view.tmpl +++ b/templates/repo/projects/view.tmpl @@ -245,7 +245,7 @@ {{if or .Labels .Assignees}}
    {{range .Labels}} - {{.Name | RenderEmoji}} + {{RenderLabel .}} {{end}}
    {{range .Assignees}} diff --git a/templates/shared/issuelist.tmpl b/templates/shared/issuelist.tmpl index a246b70093..a43047c79d 100644 --- a/templates/shared/issuelist.tmpl +++ b/templates/shared/issuelist.tmpl @@ -42,7 +42,7 @@ {{end}} {{range .Labels}} - {{.Name | RenderEmoji}} + {{RenderLabel .}} {{end}}
    diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 00fc3b60c4..2a675766ab 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -15348,6 +15348,11 @@ "type": "string", "x-go-name": "Description" }, + "exclusive": { + "type": "boolean", + "x-go-name": "Exclusive", + "example": false + }, "name": { "type": "string", "x-go-name": "Name" @@ -16283,12 +16288,18 @@ "properties": { "color": { "type": "string", - "x-go-name": "Color" + "x-go-name": "Color", + "example": "#00aabb" }, "description": { "type": "string", "x-go-name": "Description" }, + "exclusive": { + "type": "boolean", + "x-go-name": "Exclusive", + "example": false + }, "name": { "type": "string", "x-go-name": "Name" @@ -17615,6 +17626,11 @@ "type": "string", "x-go-name": "Description" }, + "exclusive": { + "type": "boolean", + "x-go-name": "Exclusive", + "example": false + }, "id": { "type": "integer", "format": "int64", -- cgit v1.2.3