Skip to content

Commit

Permalink
[FIX] Menus: Show Insert col/row menu when full sheet selected
Browse files Browse the repository at this point in the history
Revision a7d7c0e was too drastic in the visibility limitation of some
menu items. Specifically, a usr should be able to add rows or columns
when they select the entire sheet grid.

closes #3082

Task: 3450188
Signed-off-by: Lucas Lefèvre (lul) <[email protected]>
  • Loading branch information
rrahir committed Nov 7, 2023
1 parent 09607eb commit 4476a51
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 26 deletions.
32 changes: 7 additions & 25 deletions src/actions/insert_actions.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
import { functionRegistry } from "../functions";
import { isConsecutive, isDefined } from "../helpers";
import { isDefined } from "../helpers";
import { _lt } from "../translation";
import { ActionBuilder, ActionSpec } from "./action";
import * as ACTIONS from "./menu_items_actions";

export const insertRow: ActionSpec = {
name: ACTIONS.MENU_INSERT_ROWS_NAME,
isVisible: (env) =>
isConsecutive(env.model.getters.getActiveRows()) &&
ACTIONS.IS_ONLY_ONE_RANGE(env) &&
env.model.getters.getActiveCols().size === 0,
isVisible: (env) => ACTIONS.CAN_INSERT_HEADER(env, "ROW"),
icon: "o-spreadsheet-Icon.INSERT_ROW",
};

export const rowInsertRowBefore: ActionSpec = {
name: ACTIONS.ROW_INSERT_ROWS_BEFORE_NAME,
execute: ACTIONS.INSERT_ROWS_BEFORE_ACTION,
isVisible: (env) =>
isConsecutive(env.model.getters.getActiveRows()) &&
ACTIONS.IS_ONLY_ONE_RANGE(env) &&
env.model.getters.getActiveCols().size === 0,
isVisible: (env) => ACTIONS.CAN_INSERT_HEADER(env, "ROW"),
icon: "o-spreadsheet-Icon.INSERT_ROW_BEFORE",
};

Expand All @@ -38,10 +32,7 @@ export const cellInsertRowsBefore: ActionSpec = {
export const rowInsertRowsAfter: ActionSpec = {
execute: ACTIONS.INSERT_ROWS_AFTER_ACTION,
name: ACTIONS.ROW_INSERT_ROWS_AFTER_NAME,
isVisible: (env) =>
isConsecutive(env.model.getters.getActiveRows()) &&
ACTIONS.IS_ONLY_ONE_RANGE(env) &&
env.model.getters.getActiveCols().size === 0,
isVisible: (env) => ACTIONS.CAN_INSERT_HEADER(env, "ROW"),
icon: "o-spreadsheet-Icon.INSERT_ROW_AFTER",
};

Expand All @@ -52,20 +43,14 @@ export const topBarInsertRowsAfter: ActionSpec = {

export const insertCol: ActionSpec = {
name: ACTIONS.MENU_INSERT_COLUMNS_NAME,
isVisible: (env) =>
isConsecutive(env.model.getters.getActiveCols()) &&
ACTIONS.IS_ONLY_ONE_RANGE(env) &&
env.model.getters.getActiveRows().size === 0,
isVisible: (env) => ACTIONS.CAN_INSERT_HEADER(env, "COL"),
icon: "o-spreadsheet-Icon.INSERT_COL",
};

export const colInsertColsBefore: ActionSpec = {
name: ACTIONS.COLUMN_INSERT_COLUMNS_BEFORE_NAME,
execute: ACTIONS.INSERT_COLUMNS_BEFORE_ACTION,
isVisible: (env) =>
isConsecutive(env.model.getters.getActiveCols()) &&
ACTIONS.IS_ONLY_ONE_RANGE(env) &&
env.model.getters.getActiveRows().size === 0,
isVisible: (env) => ACTIONS.CAN_INSERT_HEADER(env, "COL"),
icon: "o-spreadsheet-Icon.INSERT_COL_BEFORE",
};

Expand All @@ -84,10 +69,7 @@ export const cellInsertColsBefore: ActionSpec = {
export const colInsertColsAfter: ActionSpec = {
name: ACTIONS.COLUMN_INSERT_COLUMNS_AFTER_NAME,
execute: ACTIONS.INSERT_COLUMNS_AFTER_ACTION,
isVisible: (env) =>
isConsecutive(env.model.getters.getActiveCols()) &&
ACTIONS.IS_ONLY_ONE_RANGE(env) &&
env.model.getters.getActiveRows().size === 0,
isVisible: (env) => ACTIONS.CAN_INSERT_HEADER(env, "COL"),
icon: "o-spreadsheet-Icon.INSERT_COL_AFTER",
};

Expand Down
22 changes: 21 additions & 1 deletion src/actions/menu_items_actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import {
getSmartChartDefinition,
} from "../helpers/figures/charts";
import { centerFigurePosition, getMaxFigureSize } from "../helpers/figures/figure/figure";
import { areZonesContinuous, getZoneArea, numberToLetters } from "../helpers/index";
import {
areZonesContinuous,
getZoneArea,
isConsecutive,
isEqual,
numberToLetters,
} from "../helpers/index";
import { interactiveSortSelection } from "../helpers/sort";
import { interactiveCut } from "../helpers/ui/cut_interactive";
import { interactiveAddFilter } from "../helpers/ui/filter_interactive";
Expand Down Expand Up @@ -766,3 +772,17 @@ export const SORT_CELLS_DESCENDING = (env: SpreadsheetChildEnv) => {
export const IS_ONLY_ONE_RANGE = (env: SpreadsheetChildEnv): boolean => {
return env.model.getters.getSelectedZones().length === 1;
};

export const CAN_INSERT_HEADER = (env: SpreadsheetChildEnv, dimension: Dimension): boolean => {
if (!IS_ONLY_ONE_RANGE(env)) {
return false;
}
const activeHeaders =
dimension === "COL" ? env.model.getters.getActiveCols() : env.model.getters.getActiveRows();
const ortogonalActiveHeaders =
dimension === "COL" ? env.model.getters.getActiveRows() : env.model.getters.getActiveCols();
const sheetId = env.model.getters.getActiveSheetId();
const zone = env.model.getters.getSelectedZone();
const allSheetSelected = isEqual(zone, env.model.getters.getSheetZone(sheetId));
return isConsecutive(activeHeaders) && (ortogonalActiveHeaders.size === 0 || allSheetSelected);
};
21 changes: 21 additions & 0 deletions tests/menu_items_registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
freezeRows,
hideColumns,
hideRows,
selectAll,
selectCell,
selectColumn,
selectRow,
Expand Down Expand Up @@ -415,6 +416,11 @@ describe("Menu Item actions", () => {
selectRow(model, 6, "newAnchor");
expect(getNode(addRowBeforePath, rowMenuRegistry).isVisible(env)).toBeFalsy();
});

test("Full sheet selected", () => {
selectAll(model);
expect(getNode(addRowBeforePath, rowMenuRegistry).isVisible(env)).toBeTruthy();
});
});

describe("Insert -> Row below", () => {
Expand Down Expand Up @@ -503,6 +509,11 @@ describe("Menu Item actions", () => {
selectRow(model, 6, "newAnchor");
expect(getNode(addRowAfterPath, rowMenuRegistry).isVisible(env)).toBeFalsy();
});

test("Full sheet selected", () => {
selectAll(model);
expect(getNode(addRowAfterPath, rowMenuRegistry).isVisible(env)).toBeTruthy();
});
});

describe("Insert -> Column left", () => {
Expand Down Expand Up @@ -591,6 +602,11 @@ describe("Menu Item actions", () => {
selectColumn(model, 6, "newAnchor");
expect(getNode(addColBeforePath, colMenuRegistry).isVisible(env)).toBeFalsy();
});

test("Full sheet selected", () => {
selectAll(model);
expect(getNode(addColBeforePath, colMenuRegistry).isVisible(env)).toBeTruthy();
});
});

describe("Insert -> Column right", () => {
Expand Down Expand Up @@ -679,6 +695,11 @@ describe("Menu Item actions", () => {
selectColumn(model, 6, "newAnchor");
expect(getNode(addColAfterPath, colMenuRegistry).isVisible(env)).toBeFalsy();
});

test("Full sheet selected", () => {
selectAll(model);
expect(getNode(addColAfterPath, colMenuRegistry).isVisible(env)).toBeTruthy();
});
});

describe("Insert -> Insert cells and shift down", () => {
Expand Down

0 comments on commit 4476a51

Please sign in to comment.