Skip to content

Commit

Permalink
[IMP] runbot: allow changing trigger from stat page
Browse files Browse the repository at this point in the history
Adds a new selection field to change trigger directly from the stat
page.
  • Loading branch information
Williambraecky committed Jan 9, 2025
1 parent 5c59229 commit 48233b6
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 1 deletion.
18 changes: 18 additions & 0 deletions runbot/controllers/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import werkzeug
import logging
import functools
import itertools

import werkzeug.utils
import werkzeug.urls
Expand Down Expand Up @@ -620,10 +621,27 @@ def list_config_categories(config):

categories = sorted(categories)

triggers = bundle.project_id.trigger_ids.filtered(
lambda t: t.has_stats and not t.manual
).sorted(
lambda t: (t.category_id.id, t.sequence, t.id)
)
triggers_by_category = defaultdict(list)
slug = request.env['ir.http']._slug
for trig in triggers:
triggers_by_category[trig.category_id.name].append(
{
'id': trig.id,
'slug': slug(trig),
'name': trig.name,
},
)
context = {
'stats_categories': categories,
'bundle': bundle,
'trigger': trigger,
# Category name -> List of trigger name + id
'triggers_by_category': triggers_by_category
}

return request.render("runbot.modules_stats", context)
Expand Down
31 changes: 31 additions & 0 deletions runbot/static/src/stats/stats_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ export class StatsConfig extends Component {
},
},
stats_categories: { type: Array, element: String },
triggers_by_category: {
type: Object,
values: {
type: Array,
element: {
type: Object,
shape: {
id: { type: Number },
slug: { type: String },
name: { type: String },
}
}
}
},
};

setup() {
Expand All @@ -43,4 +57,21 @@ export class StatsConfig extends Component {
onClickNext() {
this.env.bus.trigger('click-next', {});
}

/**
* Called when the trigger selection is changed.
* This changes the config a bit and redirects the user towards the same page with the new trigger.
*
* @param {Event} event the event
*/
onChangeTrigger(event) {
const { origin, pathname, search } = window.location;
const [_, bundle] = /\/runbot\/stats\/(.+)\/.+/.exec(pathname);
const newParams = this.config.asSearchParams();
this.config.getTriggerSpecificKeys().forEach(
(key) => newParams.delete(key)
);
console.log( `${origin}/runbot/stats/${bundle}/${event.target.value}${search}#${newParams.toString()}`);
window.location.href = `${origin}/runbot/stats/${bundle}/${event.target.value}${search}#${newParams.toString()}`;
}
};
7 changes: 6 additions & 1 deletion runbot/static/src/stats/stats_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
<nav class="navbar navbar-light">
<div class="container">
<b>Bundle:</b><t t-out="props.bundle.name"/>
<b>Trigger:</b><t t-out="props.trigger.name"/>
<b>Trigger:</b>
<select class="form-select text-capitalize" aria-label="Select Trigger" t-on-change="(ev) => this.onChangeTrigger(ev)">
<optgroup t-foreach="Object.entries(props.triggers_by_category)" t-as="entry" t-key="entry[0]" t-att-label="entry[0]">
<option t-foreach="entry[1]" t-as="trigger" t-key="trigger.slug" t-out="trigger.name" t-att-value="trigger.slug" t-att-selected="trigger.id === props.trigger.id ? 'selected' : undefined"/>
</optgroup>
</select>
<b>Stat Category:</b>
<select class="form-select text-capitalize" aria-label="Stat Category" t-model="config.key_category">
<option t-foreach="props.stats_categories" t-as="category" t-key="category" t-attf-value="{{category}}">
Expand Down
14 changes: 14 additions & 0 deletions runbot/static/src/stats/stats_root.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ export class StatsRoot extends Component {
},
},
stats_categories: { type: Array, element: String },
triggers_by_category: {
type: Object,
values: {
type: Array,
element: {
type: Object,
shape: {
id: { type: Number },
slug: { type: String },
name: { type: String },
}
}
}
},
};

setup() {
Expand Down
18 changes: 18 additions & 0 deletions runbot/static/src/stats/use_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ export class Config {
return new Config(config);
}

/**
* Returns the config a an URLSearchParams object.
*
* @return {URLSearchParams}
*/
asSearchParams() {
return new URLSearchParams({...this});
}

/**
* Updates the url hash according to the current state of the config.
*/
Expand Down Expand Up @@ -70,6 +79,15 @@ export class Config {
return ['mode', 'nb_dataset', 'display_aggregate', 'visible_keys'];
}

/**
* Gets a set of keys that should not be kept when changing trigger.
*
* @returns {string[]} set of keys to remove when changing trigger.
*/
getTriggerSpecificKeys() {
return ['center_build_id', 'key_category', 'visible_keys'];
}

/**
* Gets the visible keys as an array instead of string.
*
Expand Down
1 change: 1 addition & 0 deletions runbot/templates/build_stats.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
'bundle': {'id': bundle.id, 'name': bundle.name},
'trigger': {'id': trigger.id, 'name': trigger.name},
'stats_categories': stats_categories,
'triggers_by_category': triggers_by_category,
})"/>;
</script>
<div id="wrapwrap">This page requires javascript to load</div>
Expand Down

0 comments on commit 48233b6

Please sign in to comment.