Skip to content

Commit 900526f

Browse files
committed
poc
1 parent c093c6a commit 900526f

File tree

22 files changed

+223
-335
lines changed

22 files changed

+223
-335
lines changed

packages/o-spreadsheet-engine/src/components/icons/icons.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,20 @@ export function getHoveredCaretDownSvg(color: Style): ImageSVG {
133133
};
134134
}
135135

136+
export function getPivotSortSvg(style: Style): ImageSVG {
137+
return {
138+
name: "PIVOT_SORT_ICON",
139+
width: 512,
140+
height: 512,
141+
paths: [
142+
{
143+
fillColor: style.textColor || TEXT_BODY_MUTED,
144+
path: "M120 216 h270 l-135 -130 M120 296 h270 l-135 130",
145+
},
146+
],
147+
};
148+
}
149+
136150
const CHIP_CARET_DOWN_PATH = "M40 185 h270 l-135 128";
137151

138152
export function getChipSvg(chipStyle: Style): ImageSVG {

packages/o-spreadsheet-engine/src/plugins/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import { CarouselUIPlugin } from "./ui_stateful/carousel_ui";
5555
import { ClipboardPlugin } from "./ui_stateful/clipboard";
5656
import { FilterEvaluationPlugin } from "./ui_stateful/filter_evaluation";
5757
import { HeaderPositionsUIPlugin } from "./ui_stateful/header_positions";
58+
import { HoveredCellPlugin } from "./ui_stateful/hovered_cell_plugin";
5859
import { GridSelectionPlugin } from "./ui_stateful/selection";
5960
import { SheetViewPlugin } from "./ui_stateful/sheetview";
6061

@@ -110,7 +111,9 @@ export const statefulUIPluginRegistry = new Registry<UIPluginConstructor>()
110111
.add("header_positions", HeaderPositionsUIPlugin)
111112
.add("viewport", SheetViewPlugin)
112113
.add("clipboard", ClipboardPlugin)
113-
.add("carousel_ui", CarouselUIPlugin);
114+
.add("carousel_ui", CarouselUIPlugin)
115+
.add("hovered_cell", HoveredCellPlugin)
116+
.add("cell_icon", CellIconPlugin);
114117

115118
// Plugins which have a derived state from core data
116119
export const coreViewsPluginRegistry = new Registry<CoreViewPluginConstructor>()
@@ -121,5 +124,4 @@ export const coreViewsPluginRegistry = new Registry<CoreViewPluginConstructor>()
121124
.add("data_validation_ui", EvaluationDataValidationPlugin)
122125
.add("dynamic_tables", DynamicTablesPlugin)
123126
.add("custom_colors", CustomColorsPlugin)
124-
.add("pivot_ui", PivotUIPlugin)
125-
.add("cell_icon", CellIconPlugin);
127+
.add("pivot_ui", PivotUIPlugin);

packages/o-spreadsheet-engine/src/plugins/ui_core_views/cell_icon_plugin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import {
77
import { Command } from "../../types/commands";
88
import { Align, CellPosition } from "../../types/misc";
99
import { Rect } from "../../types/rendering";
10-
import { CoreViewPlugin } from "../core_view_plugin";
10+
import { UIPlugin } from "../ui_plugin";
1111

12-
export class CellIconPlugin extends CoreViewPlugin {
12+
export class CellIconPlugin extends UIPlugin {
1313
static getters = ["doesCellHaveGridIcon", "getCellIcons", "getCellIconRect"] as const;
1414

1515
private cellIconsCache: Record<string, Record<number, Record<number, GridIcon[]>>> = {};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Command } from "../../types/commands";
2+
import { CellPosition } from "../../types/misc";
3+
import { UIPlugin } from "../ui_plugin";
4+
5+
export class HoveredCellPlugin extends UIPlugin {
6+
static getters = ["getHoveredCell"] as const;
7+
8+
private hoveredCell: CellPosition | undefined = undefined;
9+
10+
handle(cmd: Command) {
11+
switch (cmd.type) {
12+
case "SET_HOVERED_CELL":
13+
this.hoveredCell = cmd.cellPosition || undefined;
14+
break;
15+
}
16+
}
17+
getHoveredCell(): CellPosition | undefined {
18+
return this.hoveredCell;
19+
}
20+
}

packages/o-spreadsheet-engine/src/registries/icons_on_cell_registry.ts

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
getHoveredCaretDownSvg,
99
getHoveredChipSvg,
1010
getPivotIconSvg,
11+
getPivotSortSvg,
1112
ICONS,
1213
} from "../components/icons/icons";
1314
import {
@@ -38,6 +39,7 @@ export interface GridIcon {
3839
hoverSvg?: ImageSVG;
3940
priority: number;
4041
onClick?: (position: CellPosition, env: SpreadsheetChildEnv) => void;
42+
preventIconAnimation?: boolean;
4143
}
4244

4345
type ImageSvgCallback = (getters: Getters, position: CellPosition) => GridIcon | undefined;
@@ -175,9 +177,9 @@ iconsOnCellRegistry.add("pivot_collapse", (getters, position) => {
175177
});
176178

177179
iconsOnCellRegistry.add("pivot_dashboard_sorting", (getters, position) => {
178-
if (!getters.isDashboard()) {
179-
return undefined;
180-
}
180+
// if (!getters.isDashboard()) {
181+
// return undefined;
182+
// }
181183
const pivotCell = getters.getPivotCellFromPosition(position);
182184
if (pivotCell.type !== "MEASURE_HEADER") {
183185
return undefined;
@@ -195,6 +197,33 @@ iconsOnCellRegistry.add("pivot_dashboard_sorting", (getters, position) => {
195197
margin: GRID_ICON_MARGIN,
196198
svg: sortDirection === "asc" ? getCaretUpSvg(cellStyle) : getCaretDownSvg(cellStyle),
197199
position,
198-
onClick: undefined, // click is managed by ClickableCellSortIcon
200+
preventIconAnimation: true,
201+
onClick: undefined, // click is managed by clickable cell
202+
};
203+
});
204+
205+
iconsOnCellRegistry.add("pivot_dashboard_sorting_none", (getters, position) => {
206+
if (!deepEquals(position, getters.getHoveredCell())) {
207+
return undefined;
208+
}
209+
const pivotCell = getters.getPivotCellFromPosition(position);
210+
if (pivotCell.type !== "MEASURE_HEADER") {
211+
return undefined;
212+
}
213+
214+
// if( !getters.isDashboard()) {
215+
// return undefined;
216+
// }
217+
const cellStyle = getters.getCellComputedStyle(position);
218+
return {
219+
type: `pivot_dashboard_sorting_none`,
220+
priority: 5,
221+
horizontalAlign: "right",
222+
size: 17,
223+
margin: GRID_ICON_MARGIN,
224+
svg: getPivotSortSvg(cellStyle),
225+
position,
226+
preventIconAnimation: true,
227+
onClick: undefined, // click is managed by clickable cell
199228
};
200229
});

packages/o-spreadsheet-engine/src/types/commands.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ export const readonlyAllowedCommands = new Set<CommandTypes>([
219219
"UPDATE_CAROUSEL_ACTIVE_ITEM",
220220

221221
"UPDATE_PIVOT",
222+
"SET_HOVERED_CELL",
222223
]);
223224

224225
export const coreTypes = new Set<CoreCommandTypes>([
@@ -1126,6 +1127,11 @@ export interface ToggleCheckboxCommand extends TargetDependentCommand {
11261127
type: "TOGGLE_CHECKBOX";
11271128
}
11281129

1130+
export interface SetHoveredCellCommand {
1131+
type: "SET_HOVERED_CELL";
1132+
cellPosition: CellPosition | null;
1133+
}
1134+
11291135
export type CoreCommand =
11301136
// /** History */
11311137
// | SelectiveUndoCommand
@@ -1288,7 +1294,8 @@ export type LocalCommand =
12881294
| AddNewChartToCarouselCommand
12891295
| AddFigureChartToCarouselCommand
12901296
| UpdateCarouselActiveItemCommand
1291-
| PopOutChartFromCarouselCommand;
1297+
| PopOutChartFromCarouselCommand
1298+
| SetHoveredCellCommand;
12921299

12931300
export type Command = CoreCommand | LocalCommand;
12941301

packages/o-spreadsheet-engine/src/types/getters.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { CarouselUIPlugin } from "../plugins/ui_stateful/carousel_ui";
2929
import { ClipboardPlugin } from "../plugins/ui_stateful/clipboard";
3030
import { FilterEvaluationPlugin } from "../plugins/ui_stateful/filter_evaluation";
3131
import { HeaderPositionsUIPlugin } from "../plugins/ui_stateful/header_positions";
32+
import { HoveredCellPlugin } from "../plugins/ui_stateful/hovered_cell_plugin";
3233
import { GridSelectionPlugin } from "../plugins/ui_stateful/selection";
3334
import { SheetViewPlugin } from "../plugins/ui_stateful/sheetview";
3435
// -----------------------------------------------------------------------------
@@ -72,4 +73,5 @@ export type Getters = {
7273
PluginGetters<typeof CheckboxTogglePlugin> &
7374
PluginGetters<typeof CellIconPlugin> &
7475
PluginGetters<typeof DynamicTranslate> &
75-
PluginGetters<typeof CarouselUIPlugin>;
76+
PluginGetters<typeof CarouselUIPlugin> &
77+
PluginGetters<typeof HoveredCellPlugin>;

src/components/dashboard/clickable_cell_sort_icon/clickable_cell_sort_icon.css

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/components/dashboard/clickable_cell_sort_icon/clickable_cell_sort_icon.ts

Lines changed: 0 additions & 55 deletions
This file was deleted.

src/components/dashboard/clickable_cell_sort_icon/clickable_cell_sort_icon.xml

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)