[IMP] runbot: improve pull request widget

This commit is contained in:
William Braeckman 2024-12-23 10:34:38 +01:00 committed by William Braeckman (wbr)
parent 5d99d535ec
commit 1fa7e4c0c7

View File

@ -138,15 +138,19 @@ registry.category("fields").add("char_frontend_url", {
// Pull Request URL Widget // Pull Request URL Widget
const pullRequestRegex = /\/([a-zA-Z-_]+\/[a-zA-Z-_]+)\/pull\/(\d+)/;
class PullRequestUrlField extends UrlField { class PullRequestUrlField extends UrlField {
static template = xml` static template = xml`
<a class="o_field_widget o_form_uri" t-on-click.stop="" t-att-href="formattedHref" t-esc="props.record.data[props.name].replace('https://github.com/odoo','').replace('/pull','') || ''" target="_blank"/> <UrlField t-props="fieldProps"/>
`; `;
static components = { UrlField } static components = { UrlField }
setup() { get fieldProps() {
if (!this.props.readonly) { const props = {...this.props};
throw new Error("This widget works only on readonly fields"); const parts = pullRequestRegex.exec(this.props.record.data[props.name])
if (parts) {
props.text = `${parts[1]}#${parts[2]}`;
} }
return props
} }
} }