Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: default-tab in group widget #387

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,11 @@ Preview:

![](images/group-widget-preview.png)

#### Property
| Name | Type | Required | Default |
| ---- | ---- | -------- | ------- |
| default-tab | int | no | 1 |

#### Sharing properties

To avoid repetition you can use [YAML anchors](https://support.atlassian.com/bitbucket-cloud/docs/yaml-anchors/) and share properties between widgets.
Expand Down
2 changes: 1 addition & 1 deletion internal/glance/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ function setupGroups() {
const group = groups[g];
const titles = group.getElementsByClassName("widget-header")[0].children;
const tabs = group.getElementsByClassName("widget-group-contents")[0].children;
let current = 0;
let current = Array.from(titles).findIndex(c => c.classList.contains('widget-group-title-current')) || 0;

for (let t = 0; t < titles.length; t++) {
const title = titles[t];
Expand Down
4 changes: 2 additions & 2 deletions internal/glance/templates/group.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
<div class="widget-group-header">
<div class="widget-header gap-20">
{{ range $i, $widget := .Widgets }}
<button class="widget-group-title{{ if eq $i 0 }} widget-group-title-current{{ end }}"{{ if ne "" .TitleURL }} data-title-url="{{ .TitleURL }}"{{ end }}>{{ $widget.Title }}</button>
<button class="widget-group-title{{ if eq $i $.DefaultTab }} widget-group-title-current{{ end }}"{{ if ne "" .TitleURL }} data-title-url="{{ .TitleURL }}"{{ end }}>{{ $widget.Title }}</button>
{{ end }}
</div>
</div>

<div class="widget-group-contents">
{{ range $i, $widget := .Widgets }}
<div class="widget-group-content{{ if eq $i 0 }} widget-group-content-current{{ end }}">{{ .Render }}</div>
<div class="widget-group-content{{ if eq $i $.DefaultTab }} widget-group-content-current{{ end }}">{{ .Render }}</div>
{{ end }}
</div>

Expand Down
9 changes: 9 additions & 0 deletions internal/glance/widget-group.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,21 @@ var groupWidgetTemplate = mustParseTemplate("group.html", "widget-base.html")
type groupWidget struct {
widgetBase `yaml:",inline"`
containerWidgetBase `yaml:",inline"`
DefaultTab int `yaml:"default-tab"`
}

func (widget *groupWidget) initialize() error {
widget.withError(nil)
widget.HideHeader = true

if widget.DefaultTab > 0 {
widget.DefaultTab = widget.DefaultTab - 1
}

if widget.DefaultTab > (len(widget.Widgets) - 1) {
widget.DefaultTab = len(widget.Widgets) - 1
}

for i := range widget.Widgets {
widget.Widgets[i].setHideHeader(true)

Expand Down