Skip to content

Commit fe5345e

Browse files
committed
[IMP] topbar: improve toolbar and topbar composer
This commits improves the usability of the toolbar: - The composer is now in a new line to have more space for tools - Tools button have a bit more padding/margin - Added Insert Chart/Pivot/Function buttons in the toolbar Task: 5231006
1 parent 6fefc9c commit fe5345e

File tree

19 files changed

+2394
-2012
lines changed

19 files changed

+2394
-2012
lines changed

src/actions/insert_actions.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,37 +211,38 @@ export const insertTable: ActionSpec = {
211211
icon: "o-spreadsheet-Icon.PAINT_TABLE",
212212
};
213213

214-
export const insertFunction: ActionSpec = {
215-
name: _t("Function"),
216-
icon: "o-spreadsheet-Icon.FORMULA",
217-
};
218-
219214
export const insertFunctionSum: ActionSpec = {
215+
id: "insert_function_sum",
220216
name: _t("SUM"),
221217
execute: (env) => env.startCellEdition(`=SUM(`),
222218
};
223219

224220
export const insertFunctionAverage: ActionSpec = {
221+
id: "insert_function_average",
225222
name: _t("AVERAGE"),
226223
execute: (env) => env.startCellEdition(`=AVERAGE(`),
227224
};
228225

229226
export const insertFunctionCount: ActionSpec = {
227+
id: "insert_function_count",
230228
name: _t("COUNT"),
231229
execute: (env) => env.startCellEdition(`=COUNT(`),
232230
};
233231

234232
export const insertFunctionMax: ActionSpec = {
233+
id: "insert_function_max",
235234
name: _t("MAX"),
236235
execute: (env) => env.startCellEdition(`=MAX(`),
237236
};
238237

239238
export const insertFunctionMin: ActionSpec = {
239+
id: "insert_function_min",
240240
name: _t("MIN"),
241241
execute: (env) => env.startCellEdition(`=MIN(`),
242242
};
243243

244-
export const categorieFunctionAll: ActionSpec = {
244+
export const categoryFunctionAll: ActionSpec = {
245+
id: "category_function_all",
245246
name: _t("All"),
246247
children: [allFunctionListMenuBuilder],
247248
};
@@ -273,6 +274,20 @@ export const categoriesFunctionListMenuBuilder: ActionBuilder = () => {
273274
});
274275
};
275276

277+
export const insertFunction: ActionSpec = {
278+
name: _t("Function"),
279+
icon: "o-spreadsheet-Icon.FORMULA",
280+
children: [
281+
insertFunctionSum,
282+
insertFunctionAverage,
283+
insertFunctionCount,
284+
insertFunctionMax,
285+
{ ...insertFunctionMin, separator: true },
286+
categoryFunctionAll,
287+
categoriesFunctionListMenuBuilder,
288+
],
289+
};
290+
276291
export const insertLink: ActionSpec = {
277292
name: _t("Link"),
278293
execute: ACTIONS.INSERT_LINK,

src/components/action_button/action_button.css

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@
33
display: flex;
44
justify-content: center;
55
align-items: center;
6-
margin: 2px 1px;
7-
padding: 0px 1px;
6+
margin: 2px 2px;
7+
padding: 0px 4px;
88
border-radius: 2px;
99
min-width: 22px;
10+
11+
.o-caret-down {
12+
margin-left: 4px;
13+
width: fit-content;
14+
}
1015
}
16+
1117
.o-disabled {
1218
opacity: 0.6;
1319
cursor: default;

src/components/icons/icons.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@
587587
</div>
588588
</t>
589589
<t t-name="o-spreadsheet-Icon.CARET_DOWN">
590-
<div class="o-icon fa-small">
590+
<div class="o-icon fa-small o-caret-down">
591591
<i class="fa fa-caret-down"/>
592592
</div>
593593
</t>

src/components/top_bar/number_formats_tool/number_formats_tool.ts renamed to src/components/top_bar/menu_button_tool/menu_button_tool.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { SpreadsheetChildEnv } from "@odoo/o-spreadsheet-engine/types/spreadsheet_env";
22
import { Component, useRef, useState } from "@odoo/owl";
3-
import { Action, createAction } from "../../../actions/action";
4-
import { formatNumberMenuItemSpec } from "../../../registries/menus";
3+
import { Action, ActionSpec, createAction } from "../../../actions/action";
54
import { Rect } from "../../../types";
65
import { ActionButton } from "../../action_button/action_button";
76
import { getBoundingRectAsPOJO } from "../../helpers/dom_helpers";
@@ -10,18 +9,18 @@ import { MenuPopover } from "../../menu_popover/menu_popover";
109

1110
interface Props {
1211
class: string;
12+
action: ActionSpec;
1313
}
1414

1515
interface State {
1616
menuItems: Action[];
1717
anchorRect: Rect;
1818
}
1919

20-
export class NumberFormatsTool extends Component<Props, SpreadsheetChildEnv> {
21-
static template = "o-spreadsheet-NumberFormatsTool";
20+
export class MenuButtonTool extends Component<Props, SpreadsheetChildEnv> {
21+
static template = "o-spreadsheet-MenuButtonTool";
2222
static components = { MenuPopover, ActionButton };
23-
static props = { class: String };
24-
formatNumberMenuItemSpec = formatNumberMenuItemSpec;
23+
static props = { class: String, action: Object };
2524
topBarToolStore!: ToolBarDropdownStore;
2625

2726
buttonRef = useRef("buttonRef");
@@ -38,7 +37,7 @@ export class NumberFormatsTool extends Component<Props, SpreadsheetChildEnv> {
3837
if (this.isActive) {
3938
this.topBarToolStore.closeDropdowns();
4039
} else {
41-
const menu = createAction(this.formatNumberMenuItemSpec);
40+
const menu = createAction(this.props.action);
4241
this.state.menuItems = menu.children(this.env).sort((a, b) => a.sequence - b.sequence);
4342
this.state.anchorRect = getBoundingRectAsPOJO(this.buttonRef.el!);
4443
this.topBarToolStore.openDropdown();
@@ -48,4 +47,8 @@ export class NumberFormatsTool extends Component<Props, SpreadsheetChildEnv> {
4847
get isActive() {
4948
return this.topBarToolStore.isActive;
5049
}
50+
51+
onClose() {
52+
this.topBarToolStore.closeDropdowns();
53+
}
5154
}

src/components/top_bar/number_formats_tool/number_formats_tool.xml renamed to src/components/top_bar/menu_button_tool/menu_button_tool.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<templates>
2-
<div t-name="o-spreadsheet-NumberFormatsTool" t-ref="buttonRef" t-on-click.stop="">
2+
<div t-name="o-spreadsheet-MenuButtonTool" t-ref="buttonRef" t-on-click.stop="">
33
<ActionButton
4-
action="formatNumberMenuItemSpec"
4+
action="props.action"
55
hasTriangleDownIcon="true"
66
onClick.bind="toggleMenu"
77
class="props.class"
@@ -10,7 +10,7 @@
1010
t-if="isActive"
1111
anchorRect="state.anchorRect"
1212
menuItems="state.menuItems"
13-
onClose="() => {}"
13+
onClose.bind="onClose"
1414
popoverPositioning="'bottom-left'"
1515
/>
1616
</div>

src/components/top_bar/top_bar.css

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
.o-spreadsheet {
2-
@media (max-width: 1200px) {
3-
.o-topbar-responsive {
4-
flex-direction: column !important;
5-
}
6-
}
7-
82
@media (max-width: 768px) {
93
.topbar-banner span {
104
overflow: auto;
@@ -21,8 +15,8 @@
2115
.o-topbar-divider {
2216
border-right: 1px solid var(--os-separator-color);
2317
width: 0;
24-
margin: 0 6px;
25-
height: 30px;
18+
margin: 0 4px;
19+
height: 100%;
2620
}
2721

2822
.o-toolbar-button {
@@ -93,11 +87,17 @@
9387

9488
.o-toolbar-button {
9589
height: 35px;
96-
width: 31px;
90+
min-width: 31px;
9791
.o-toolbar-button.o-mobile-disabled * {
9892
color: var(--os-disabled-text-color);
9993
cursor: not-allowed;
10094
}
10195
}
10296
}
97+
98+
.o-topbar-tools-popover {
99+
.o-topbar-divider {
100+
height: 30px;
101+
}
102+
}
103103
}

src/components/top_bar/top_bar.xml

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,19 @@
2525
</div>
2626
</div>
2727
<!-- Toolbar and Cell Content -->
28-
<div
29-
class="d-flex o-topbar-responsive"
30-
t-att-class="{'o-topbar-responsive': !env.model.getters.isReadonly()}"
31-
t-ref="toolBarContainer">
32-
<div
33-
class="o-topbar-toolbar d-flex"
34-
t-att-class="{'flex-shrink-0': env.model.getters.isReadonly()}">
28+
<div class="d-flex" t-if="env.model.getters.isReadonly()">
29+
<div class="o-readonly-toolbar d-flex align-items-center flex-shrink-0 text-muted px-3">
30+
<span>
31+
<i class="fa fa-eye"/>
32+
Readonly Access
33+
</span>
34+
</div>
35+
<TopBarComposer t-if="!env.isSmall"/>
36+
</div>
37+
<t t-else="">
38+
<div class="o-topbar-toolbar d-flex" t-ref="toolBarContainer">
3539
<!-- Toolbar -->
36-
<div
37-
t-if="env.model.getters.isReadonly()"
38-
class="o-readonly-toolbar d-flex align-items-center text-muted">
39-
<span>
40-
<i class="fa fa-eye"/>
41-
Readonly Access
42-
</span>
43-
</div>
44-
<div t-else="" class="o-toolbar-tools d-flex ms-4 flex-grow-1" t-ref="toolBar">
40+
<div class="o-toolbar-tools d-flex ms-3 flex-grow-1" t-ref="toolBar">
4541
<div
4642
class="d-flex tool-container"
4743
t-foreach="toolsCategories"
@@ -69,7 +65,7 @@
6965
</div>
7066
</div>
7167
<TopBarComposer t-if="!env.isSmall"/>
72-
</div>
68+
</t>
7369
<div
7470
t-if="this.fingerprints.isEnabled"
7571
class="topbar-banner irregularity-map d-flex align-items-center justify-content-between">
@@ -104,7 +100,7 @@
104100
popoverPositioning="'bottom-left'"
105101
/>
106102
<Popover t-if="state.toolsPopoverState.isOpen" t-props="toolsPopoverProps">
107-
<div class="d-flex px-2 py-1 flex-wrap align-items-center bg-white">
103+
<div class="o-topbar-tools-popover d-flex px-2 py-1 flex-wrap align-items-center bg-white">
108104
<t
109105
t-foreach="state.invisibleToolsCategories"
110106
t-as="category"

0 commit comments

Comments
 (0)