Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/actions/insert_actions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { functionRegistry } from "../functions/function_registry";
import { isDefined } from "../helpers";
import { isDefined, UuidGenerator } from "../helpers";
import { handlePasteResult } from "../helpers/ui/paste_interactive";
import { _t } from "../translation";
import { ActionBuilder, ActionSpec } from "./action";
Expand Down Expand Up @@ -299,7 +299,7 @@ export const insertCheckbox: ActionSpec = {
ranges,
sheetId,
rule: {
id: env.model.uuidGenerator.smallUuid(),
id: UuidGenerator.smallUuid(),
criterion: {
type: "isBoolean",
values: [],
Expand All @@ -317,7 +317,7 @@ export const insertDropdown: ActionSpec = {
const zones = env.model.getters.getSelectedZones();
const sheetId = env.model.getters.getActiveSheetId();
const ranges = zones.map((zone) => env.model.getters.getRangeDataFromZone(sheetId, zone));
const ruleId = env.model.uuidGenerator.smallUuid();
const ruleId = UuidGenerator.smallUuid();
env.model.dispatch("ADD_DATA_VALIDATION_RULE", {
ranges,
sheetId,
Expand Down Expand Up @@ -351,7 +351,7 @@ export const insertSheet: ActionSpec = {
execute: (env) => {
const activeSheetId = env.model.getters.getActiveSheetId();
const position = env.model.getters.getSheetIds().indexOf(activeSheetId) + 1;
const sheetId = env.model.uuidGenerator.smallUuid();
const sheetId = UuidGenerator.smallUuid();
env.model.dispatch("CREATE_SHEET", {
sheetId,
position,
Expand Down
13 changes: 7 additions & 6 deletions src/actions/menu_items_actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
largeMax,
largeMin,
numberToLetters,
UuidGenerator,
} from "../helpers/index";
import { DEFAULT_TABLE_CONFIG } from "../helpers/table_presets";
import { interactivePaste, interactivePasteFromOS } from "../helpers/ui/paste_interactive";
Expand Down Expand Up @@ -399,7 +400,7 @@ export const HIDE_ROWS_NAME = (env: SpreadsheetChildEnv) => {

export const CREATE_CHART = (env: SpreadsheetChildEnv) => {
const getters = env.model.getters;
const figureId = env.model.uuidGenerator.smallUuid();
const figureId = UuidGenerator.smallUuid();
const sheetId = getters.getActiveSheetId();
let zones = getters.getSelectedZones();

Expand All @@ -414,7 +415,7 @@ export const CREATE_CHART = (env: SpreadsheetChildEnv) => {
const result = env.model.dispatch("CREATE_CHART", {
sheetId,
figureId,
chartId: env.model.uuidGenerator.smallUuid(),
chartId: UuidGenerator.smallUuid(),
col,
row,
offset,
Expand All @@ -429,7 +430,7 @@ export const CREATE_CHART = (env: SpreadsheetChildEnv) => {

export const CREATE_CAROUSEL = (env: SpreadsheetChildEnv) => {
const getters = env.model.getters;
const figureId = env.model.uuidGenerator.smallUuid();
const figureId = UuidGenerator.smallUuid();
const sheetId = getters.getActiveSheetId();

const size = { width: DEFAULT_FIGURE_WIDTH, height: DEFAULT_FIGURE_HEIGHT };
Expand All @@ -455,8 +456,8 @@ export const CREATE_CAROUSEL = (env: SpreadsheetChildEnv) => {
//------------------------------------------------------------------------------

export const CREATE_PIVOT = (env: SpreadsheetChildEnv) => {
const pivotId = env.model.uuidGenerator.smallUuid();
const newSheetId = env.model.uuidGenerator.smallUuid();
const pivotId = UuidGenerator.smallUuid();
const newSheetId = UuidGenerator.smallUuid();
const result = env.model.dispatch("INSERT_NEW_PIVOT", { pivotId, newSheetId });
if (result.isSuccessful) {
env.openSidePanel("PivotSidePanel", { pivotId });
Expand Down Expand Up @@ -520,7 +521,7 @@ export const REINSERT_STATIC_PIVOT_CHILDREN = (env: SpreadsheetChildEnv) =>
export const CREATE_IMAGE = async (env: SpreadsheetChildEnv) => {
if (env.imageProvider) {
const sheetId = env.model.getters.getActiveSheetId();
const figureId = env.model.uuidGenerator.smallUuid();
const figureId = UuidGenerator.smallUuid();
const image = await env.imageProvider.requestImage();
const size = getMaxFigureSize(env.model.getters, image.size);
const { col, row, offset } = centerFigurePosition(env.model.getters, size);
Expand Down
4 changes: 2 additions & 2 deletions src/actions/sheet_actions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { buildSheetLink, markdownLink } from "../helpers";
import { buildSheetLink, markdownLink, UuidGenerator } from "../helpers";
import { _t } from "../translation";
import { ActionSpec } from "./action";

Expand Down Expand Up @@ -39,7 +39,7 @@ export const duplicateSheet: ActionSpec = {
execute: (env) => {
const sheetIdFrom = env.model.getters.getActiveSheetId();
const sheetNameFrom = env.model.getters.getSheetName(sheetIdFrom);
const sheetIdTo = env.model.uuidGenerator.smallUuid();
const sheetIdTo = UuidGenerator.smallUuid();
const sheetNameTo = env.model.getters.getDuplicateSheetName(sheetNameFrom);
env.model.dispatch("DUPLICATE_SHEET", {
sheetId: sheetIdFrom,
Expand Down
5 changes: 2 additions & 3 deletions src/clipboard_handlers/carousel_clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class CarouselClipboardHandler extends AbstractFigureClipboardHandler<Cli
}

getPasteTarget(sheetId: UID): ClipboardPasteTarget {
const newId = new UuidGenerator().smallUuid();
const newId = UuidGenerator.smallUuid();
return { zones: [], figureId: newId, sheetId };
}

Expand Down Expand Up @@ -84,14 +84,13 @@ export class CarouselClipboardHandler extends AbstractFigureClipboardHandler<Cli
size: { height, width },
});

const uuidGenerator = new UuidGenerator();
const items = deepCopy(clippedContent.copiedCarousel.items);
for (const item of items) {
if (item.type !== "chart") {
continue;
}
const chart = clippedContent.copiedCharts[item.chartId];
const newId = uuidGenerator.smallUuid();
const newId = UuidGenerator.smallUuid();
const definition = SpreadsheetChart.fromDefinition(
this.getters,
sheetId,
Expand Down
4 changes: 2 additions & 2 deletions src/clipboard_handlers/chart_clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class ChartClipboardHandler extends AbstractFigureClipboardHandler<Clipbo
content: ClipboardContent,
options?: ClipboardOptions
): ClipboardPasteTarget {
const newId = new UuidGenerator().smallUuid();
const newId = UuidGenerator.smallUuid();
return { zones: [], figureId: newId, sheetId };
}

Expand Down Expand Up @@ -83,7 +83,7 @@ export class ChartClipboardHandler extends AbstractFigureClipboardHandler<Clipbo
}
this.dispatch("CREATE_CHART", {
figureId,
chartId: new UuidGenerator().smallUuid(),
chartId: UuidGenerator.smallUuid(),
sheetId,
definition: copiedDefinition,
col,
Expand Down
3 changes: 1 addition & 2 deletions src/clipboard_handlers/conditional_format_clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export class ConditionalFormatClipboardHandler extends AbstractCellClipboardHand
ClipboardContent,
Maybe<ClipboardConditionalFormat>
> {
private readonly uuidGenerator = new UuidGenerator();
private queuedChanges: Record<UID, { toAdd: Zone[]; toRemove: Zone[]; cf: ConditionalFormat }[]> =
{};

Expand Down Expand Up @@ -169,6 +168,6 @@ export class ConditionalFormatClipboardHandler extends AbstractCellClipboardHand
)?.cf;
}

return targetCF || { ...originCF, id: this.uuidGenerator.smallUuid(), ranges: [] };
return targetCF || { ...originCF, id: UuidGenerator.smallUuid(), ranges: [] };
}
}
3 changes: 1 addition & 2 deletions src/clipboard_handlers/data_validation_clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export class DataValidationClipboardHandler extends AbstractCellClipboardHandler
ClipboardContent,
Maybe<ClipboardDataValidationRule>
> {
private readonly uuidGenerator = new UuidGenerator();
private queuedChanges: Record<
UID,
{ toAdd: Zone[]; toRemove: Zone[]; rule: DataValidationRule }[]
Expand Down Expand Up @@ -146,7 +145,7 @@ export class DataValidationClipboardHandler extends AbstractCellClipboardHandler
return (
targetRule || {
...originRule,
id: newId ? this.uuidGenerator.smallUuid() : originRule.id,
id: newId ? UuidGenerator.smallUuid() : originRule.id,
ranges: [],
}
);
Expand Down
2 changes: 1 addition & 1 deletion src/clipboard_handlers/image_clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class ImageClipboardHandler extends AbstractFigureClipboardHandler<Clipbo
content: ClipboardContent,
options?: ClipboardOptions
): ClipboardPasteTarget {
const newId = new UuidGenerator().smallUuid();
const newId = UuidGenerator.smallUuid();
return { sheetId, zones: [], figureId: newId };
}

Expand Down
9 changes: 4 additions & 5 deletions src/collaborative/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ export class Session extends EventBus<CollaborativeEvent> {
| SnapshotCreatedMessage
| undefined = undefined;

private uuidGenerator = new UuidGenerator();
private lastLocalOperation: Revision | undefined;
/**
* Manages the collaboration between multiple users on the same spreadsheet.
Expand Down Expand Up @@ -102,7 +101,7 @@ export class Session extends EventBus<CollaborativeEvent> {
return;
}
const revision = new Revision(
this.uuidGenerator.uuidv4(),
UuidGenerator.uuidv4(),
this.clientId,
commands,
rootCommand,
Expand Down Expand Up @@ -132,7 +131,7 @@ export class Session extends EventBus<CollaborativeEvent> {
type: "REVISION_UNDONE",
version: MESSAGE_VERSION,
serverRevisionId: this.serverRevisionId,
nextRevisionId: this.uuidGenerator.uuidv4(),
nextRevisionId: UuidGenerator.uuidv4(),
undoneRevisionId: revisionId,
});
}
Expand All @@ -143,7 +142,7 @@ export class Session extends EventBus<CollaborativeEvent> {
type: "REVISION_REDONE",
version: MESSAGE_VERSION,
serverRevisionId: this.serverRevisionId,
nextRevisionId: this.uuidGenerator.uuidv4(),
nextRevisionId: UuidGenerator.uuidv4(),
redoneRevisionId: revisionId,
});
}
Expand Down Expand Up @@ -205,7 +204,7 @@ export class Session extends EventBus<CollaborativeEvent> {
if (this.pendingMessages.length !== 0) {
return;
}
const snapshotId = this.uuidGenerator.uuidv4();
const snapshotId = UuidGenerator.uuidv4();
await this.sendToTransport({
type: "SNAPSHOT",
nextRevisionId: snapshotId,
Expand Down
4 changes: 2 additions & 2 deletions src/components/bottom_bar/bottom_bar.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, onWillUpdateProps, useRef, useState } from "@odoo/owl";
import { deepEquals } from "../../helpers";
import { deepEquals, UuidGenerator } from "../../helpers";
import { MenuItemRegistry } from "../../registries/menu_items_registry";
import { _t } from "../../translation";
import { MenuMouseEvent, Pixel, Rect, UID } from "../../types";
Expand Down Expand Up @@ -72,7 +72,7 @@ export class BottomBar extends Component<Props, SpreadsheetChildEnv> {
const activeSheetId = this.env.model.getters.getActiveSheetId();
const position =
this.env.model.getters.getSheetIds().findIndex((sheetId) => sheetId === activeSheetId) + 1;
const sheetId = this.env.model.uuidGenerator.smallUuid();
const sheetId = UuidGenerator.smallUuid();
const name = this.env.model.getters.getNextSheetName(_t("Sheet"));
this.env.model.dispatch("CREATE_SHEET", { sheetId, position, name });
this.env.model.dispatch("ACTIVATE_SHEET", { sheetIdFrom: activeSheetId, sheetIdTo: sheetId });
Expand Down
4 changes: 2 additions & 2 deletions src/components/side_panel/carousel_panel/carousel_panel.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, onWillUpdateProps, useRef } from "@odoo/owl";
import { ActionSpec } from "../../../actions/action";
import { DEFAULT_CAROUSEL_TITLE_STYLE } from "../../../constants";
import { deepEquals } from "../../../helpers";
import { deepEquals, UuidGenerator } from "../../../helpers";
import { getCarouselItemPreview, getCarouselItemTitle } from "../../../helpers/carousel_helpers";
import { _t } from "../../../translation";
import { CarouselItem, TitleDesign, UID } from "../../../types";
Expand Down Expand Up @@ -133,7 +133,7 @@ export class CarouselPanel extends Component<Props, SpreadsheetChildEnv> {
sheetId: this.carouselSheetId,
carouselId: this.props.figureId,
chartId: item.chartId,
duplicatedChartId: this.env.model.uuidGenerator.smallUuid(),
duplicatedChartId: UuidGenerator.smallUuid(),
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
splitReference,
toUnboundedZone,
toZone,
UuidGenerator,
zoneToXc,
} from "../../../../../helpers";
import { createDataSets } from "../../../../../helpers/figures/charts";
Expand Down Expand Up @@ -244,7 +245,7 @@ export class ChartRangeDataSourceComponent extends Component<Props, SpreadsheetC
*/
onDataSeriesRangesChanged(ranges: string[]) {
this.dataSets = ranges.map((dataRange, i) => ({
dataSetId: this.dataSets?.[i]?.dataSetId ?? this.env.model.uuidGenerator.smallUuid(),
dataSetId: this.dataSets?.[i]?.dataSetId ?? UuidGenerator.smallUuid(),
dataRange,
}));
this.state.datasetDispatchResult = this.props.canUpdateChart(this.props.chartId, {
Expand Down Expand Up @@ -475,12 +476,10 @@ export class ChartRangeDataSourceComponent extends Component<Props, SpreadsheetC
datasetOrientation: ChartDatasetOrientation | undefined
): { dataRange: string; dataSetId: UID }[] {
const getters = this.env.model.getters;
const uuidGenerator = this.env.model.uuidGenerator;
const smallUuid = uuidGenerator.smallUuid.bind(uuidGenerator);
if (datasetOrientation === undefined) {
return dataRanges
.filter(isDefined)
.map((dataRange) => ({ dataRange, dataSetId: smallUuid() }));
.map((dataRange) => ({ dataRange, dataSetId: UuidGenerator.smallUuid() }));
}
const zonesBySheetName = {};
const transposedDatasets: ChartRangeDataSourceType<string>["dataSets"] = [];
Expand All @@ -497,7 +496,7 @@ export class ChartRangeDataSourceComponent extends Component<Props, SpreadsheetC
if (!isXcRepresentation(dataRange)) {
return dataRanges
.filter(isDefined)
.map((dataRange) => ({ dataRange, dataSetId: smallUuid() }));
.map((dataRange) => ({ dataRange, dataSetId: UuidGenerator.smallUuid() }));
}
let { sheetName, xc } = splitReference(dataRange);
sheetName = sheetName ?? name;
Expand All @@ -517,7 +516,7 @@ export class ChartRangeDataSourceComponent extends Component<Props, SpreadsheetC
left: col,
right: col,
})}`;
transposedDatasets.push({ dataRange, dataSetId: smallUuid() });
transposedDatasets.push({ dataRange, dataSetId: UuidGenerator.smallUuid() });
}
}
} else {
Expand All @@ -528,7 +527,7 @@ export class ChartRangeDataSourceComponent extends Component<Props, SpreadsheetC
top: row,
bottom: row,
})}`;
transposedDatasets.push({ dataRange, dataSetId: smallUuid() });
transposedDatasets.push({ dataRange, dataSetId: UuidGenerator.smallUuid() });
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component, useRef, useState } from "@odoo/owl";
import { ActionSpec, createActions } from "../../../../actions/action";
import { UuidGenerator } from "../../../../helpers";
import { MenuMouseEvent } from "../../../../types";
import { SpreadsheetChildEnv } from "../../../../types/spreadsheet_env";
import { getBoundingRectAsPOJO } from "../../../helpers/dom_helpers";
Expand All @@ -19,7 +20,7 @@ export class CogWheelMenu extends Component<Props, SpreadsheetChildEnv> {
private buttonRef = useRef("button");
private menuState: MenuState = useState({ isOpen: false, anchorRect: null, menuItems: [] });

private menuId = this.env.model.uuidGenerator.uuidv4();
private menuId = UuidGenerator.uuidv4();

toggleMenu(ev: MenuMouseEvent) {
if (ev.closedMenuId === this.menuId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, useRef } from "@odoo/owl";
import { zoneToXc } from "../../../../helpers";
import { UuidGenerator, zoneToXc } from "../../../../helpers";
import { localizeCFRule } from "../../../../helpers/locale";
import { ConditionalFormat, UID } from "../../../../types";
import { SpreadsheetChildEnv } from "../../../../types/spreadsheet_env";
Expand Down Expand Up @@ -60,7 +60,7 @@ export class ConditionalFormatPreviewList extends Component<Props, SpreadsheetCh
const sheetId = this.env.model.getters.getActiveSheetId();
const zones = this.env.model.getters.getSelectedZones();
const cf: Omit<ConditionalFormat, "ranges"> = {
id: this.env.model.uuidGenerator.smallUuid(),
id: UuidGenerator.smallUuid(),
rule: {
type: "CellIsRule",
operator: "isNotEmpty",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Component } from "@odoo/owl";
import { UuidGenerator } from "../../../helpers";
import { localizeDataValidationRule } from "../../../helpers/locale";
import { DataValidationRule } from "../../../types";
import { SpreadsheetChildEnv } from "../../../types/spreadsheet_env";
Expand All @@ -17,7 +18,7 @@ export class DataValidationPanel extends Component<Props, SpreadsheetChildEnv> {

addDataValidationRule() {
this.env.replaceSidePanel("DataValidationEditor", "DataValidation", {
ruleId: this.env.model.uuidGenerator.smallUuid(),
ruleId: UuidGenerator.smallUuid(),
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component } from "@odoo/owl";
import { ActionSpec } from "../../../../actions/action";
import { UuidGenerator } from "../../../../helpers";
import { _t } from "../../../../translation";
import { CommandResult, UID } from "../../../../types";
import { SpreadsheetChildEnv } from "../../../../types/spreadsheet_env";
Expand Down Expand Up @@ -52,8 +53,8 @@ export class PivotTitleSection extends Component<Props, SpreadsheetChildEnv> {
}

duplicatePivot() {
const newPivotId = this.env.model.uuidGenerator.smallUuid();
const newSheetId = this.env.model.uuidGenerator.smallUuid();
const newPivotId = UuidGenerator.smallUuid();
const newSheetId = UuidGenerator.smallUuid();
const result = this.env.model.dispatch("DUPLICATE_PIVOT_IN_NEW_SHEET", {
pivotId: this.props.pivotId,
newPivotId,
Expand Down
Loading