Skip to content

Commit 13c62d9

Browse files
[IMP] runbot: diffable error contents
Adds the ability to make a diff between error contents in the error form view.
1 parent cc39949 commit 13c62d9

File tree

3 files changed

+110
-2
lines changed

3 files changed

+110
-2
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import { Component, useEffect, useState } from '@odoo/owl';
2+
3+
import { registry } from '@web/core/registry';
4+
import { useBus } from '@web/core/utils/hooks';
5+
import { standardFieldProps } from "@web/views/fields/standard_field_props";
6+
import { TextField } from '@web/views/fields/text/text_field';
7+
import { X2ManyField, x2ManyField } from "@web/views/fields/x2many/x2many_field";
8+
import { CheckBox } from "@web/core/checkbox/checkbox";
9+
10+
import { diff_match_patch } from "@runbot/libs/diff_match_patch/diff_match_patch";
11+
import { DiffDisplay } from './diff_display';
12+
13+
14+
export class ErrorContentOne2ManyList extends X2ManyField {
15+
static template = 'runbot.ErrorContentOne2ManyList';
16+
static components = {...X2ManyField.components, CheckBox};
17+
18+
setup() {
19+
super.setup(...arguments);
20+
this.creates = [];
21+
this.state = useState({
22+
useDiff: localStorage.getItem('runbot.error_content_diff_mode') === 'true',
23+
});
24+
25+
useEffect(() => {
26+
localStorage.setItem('runbot.error_content_diff_mode', this.state.useDiff);
27+
this.env.bus.trigger(
28+
'RUNBOT.TOGGLE-DIFF-MODE', {
29+
mode: this.state.useDiff,
30+
},
31+
);
32+
}, () => [this.state.useDiff]);
33+
}
34+
35+
get displayControlPanelButtons() {
36+
return true;
37+
}
38+
39+
onToggle(state) {
40+
this.state.useDiff = state;
41+
}
42+
}
43+
44+
export const errorContentOne2ManyList = {
45+
...x2ManyField,
46+
component: ErrorContentOne2ManyList,
47+
};
48+
49+
export class FieldErrorContentContent extends Component {
50+
static template = 'runbot.FieldErrorContentContent';
51+
static components = { TextField, DiffDisplay };
52+
static props = {...standardFieldProps};
53+
54+
setup() {
55+
// We assume that the content is readonly here
56+
this.otherRecords = this.props.record.model.root.data.error_content_ids.records;
57+
this.state = useState({
58+
useDiff: localStorage.getItem('runbot.error_content_diff_mode') === 'true',
59+
});
60+
61+
useBus(
62+
this.env.bus, 'RUNBOT.TOGGLE-DIFF-MODE',
63+
({detail: {mode}}) => this.state.useDiff = mode,
64+
);
65+
}
66+
67+
get isParent() {
68+
return this.otherRecords[0] === this.props.record;
69+
}
70+
71+
get parent() {
72+
return this.otherRecords[0];
73+
}
74+
}
75+
76+
export const fieldErrorContentContent = {
77+
component: FieldErrorContentContent,
78+
displayName: "Error Content diffable (list)",
79+
supportedTypes: ["html", "text", "char"],
80+
};
81+
82+
83+
registry.category('fields').add('error_content_list', errorContentOne2ManyList);
84+
registry.category('fields').add('list.error_content_content', fieldErrorContentContent);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<templates>
3+
<t t-name="runbot.ErrorContentOne2ManyList" t-inherit="web.X2ManyField" t-inherit-mode="primary">
4+
<div class="o_x2m_control_panel d-empty-none mt-1 mb-4" position="attributes">
5+
<attribute name="class">o_x2m_control_panel d-empty-none mt-1</attribute>
6+
</div>
7+
<div role="toolbar" position="inside">
8+
<CheckBox
9+
className="'o_boolean_toggle form-switch'"
10+
value="state.useDiff"
11+
onChange.bind="onToggle"
12+
>
13+
Toggle diff mode
14+
</CheckBox>
15+
</div>
16+
</t>
17+
18+
<t t-name="runbot.FieldErrorContentContent">
19+
<t t-if="isParent || !this.state.useDiff">
20+
<TextField t-props="this.props"/>
21+
</t>
22+
<DiffDisplay t-else="" fromValue="parent.data.content" toValue="props.record.data.content"/>
23+
</t>
24+
</templates>

runbot/views/build_error_views.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
<button name="action_view_errors" string="See all linked errors" type="object" class="oe_highlight"/>
1616
<group string="Base info">
1717
<field name="name"/>
18-
<field name="error_content_ids" readonly="1">
18+
<field name="error_content_ids" readonly="1" widget="error_content_list">
1919
<list limit="5">
20-
<field name="content" readonly="1"/>
20+
<field name="content" readonly="1" widget="error_content_content"/>
2121
<!--field name="module_name" readonly="1"/-->
2222
<!--field name="function" readonly="1"/-->
2323
<!--field name="file_path" readonly="1"/-->

0 commit comments

Comments
 (0)