-
Notifications
You must be signed in to change notification settings - Fork 47
/
pivot_menu_items.ts
52 lines (50 loc) · 1.7 KB
/
pivot_menu_items.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { ActionSpec } from "../../actions/action";
import { _t } from "../../translation";
export const pivotProperties: ActionSpec = {
name: _t("Edit Pivot"),
execute(env) {
const position = env.model.getters.getActivePosition();
const pivotId = env.model.getters.getPivotIdFromPosition(position);
env.openSidePanel("PivotSidePanel", { pivotId });
},
isVisible: (env) => {
const position = env.model.getters.getActivePosition();
const pivotId = env.model.getters.getPivotIdFromPosition(position);
return (pivotId && env.model.getters.isExistingPivot(pivotId)) || false;
},
icon: "o-spreadsheet-Icon.PIVOT",
};
export const FIX_FORMULAS: ActionSpec = {
name: _t("Convert to individual formulas"),
execute(env) {
const position = env.model.getters.getActivePosition();
const cell = env.model.getters.getCorrespondingFormulaCell(position);
const pivotId = env.model.getters.getPivotIdFromPosition(position);
if (!cell || !pivotId) {
return;
}
const { sheetId, col, row } = env.model.getters.getCellPosition(cell.id);
const pivot = env.model.getters.getPivot(pivotId);
pivot.init();
if (!pivot.isValid()) {
return;
}
env.model.dispatch("INSERT_PIVOT", {
sheetId,
col,
row,
pivotId,
table: pivot.getTableStructure().export(),
});
},
isVisible: (env) => {
const position = env.model.getters.getActivePosition();
const pivotId = env.model.getters.getPivotIdFromPosition(position);
if (!pivotId) {
return false;
}
const pivot = env.model.getters.getPivot(pivotId);
return pivot.isValid() && env.model.getters.isSpillPivotFormula(position);
},
icon: "o-spreadsheet-Icon.PIVOT",
};