2022-02-07 14:09:23 +00:00
|
|
|
import { allCommands } from 'app/client/components/commands';
|
2022-10-28 16:11:08 +00:00
|
|
|
import { makeT } from 'app/client/lib/localization';
|
2022-02-07 14:09:23 +00:00
|
|
|
import { menuDivider, menuItemCmd } from 'app/client/ui2018/menus';
|
|
|
|
import { IMultiColumnContextMenu } from 'app/client/ui/GridViewMenus';
|
2022-04-19 13:01:08 +00:00
|
|
|
import { IRowContextMenu } from 'app/client/ui/RowContextMenu';
|
2022-10-17 09:47:16 +00:00
|
|
|
import { COMMENTS } from 'app/client/models/features';
|
2022-04-19 13:01:08 +00:00
|
|
|
import { dom } from 'grainjs';
|
2022-02-07 14:09:23 +00:00
|
|
|
|
2022-10-28 16:11:08 +00:00
|
|
|
const t = makeT('CellContextMenu');
|
|
|
|
|
2022-02-07 14:09:23 +00:00
|
|
|
export function CellContextMenu(rowOptions: IRowContextMenu, colOptions: IMultiColumnContextMenu) {
|
|
|
|
|
|
|
|
const { disableInsert, disableDelete, isViewSorted } = rowOptions;
|
|
|
|
const { disableModify, isReadonly } = colOptions;
|
|
|
|
|
2022-10-17 09:47:16 +00:00
|
|
|
// disableModify is true if the column is a summary column or is being transformed.
|
|
|
|
// isReadonly is true for readonly mode.
|
2022-02-07 14:09:23 +00:00
|
|
|
const disableForReadonlyColumn = dom.cls('disabled', Boolean(disableModify) || isReadonly);
|
|
|
|
const disableForReadonlyView = dom.cls('disabled', isReadonly);
|
|
|
|
|
|
|
|
const numCols: number = colOptions.numColumns;
|
2022-10-28 00:23:18 +00:00
|
|
|
const nameClearColumns = colOptions.isFiltered ?
|
2022-12-06 16:43:35 +00:00
|
|
|
t("Reset {{count}} entire columns", {count: numCols}) :
|
|
|
|
t("Reset {{count}} columns", {count: numCols});
|
|
|
|
const nameDeleteColumns = t("Delete {{count}} columns", {count: numCols});
|
2022-02-07 14:09:23 +00:00
|
|
|
|
|
|
|
const numRows: number = rowOptions.numRows;
|
2022-12-06 16:43:35 +00:00
|
|
|
const nameDeleteRows = t("Delete {{count}} rows", {count: numRows});
|
2022-02-07 14:09:23 +00:00
|
|
|
|
2022-12-06 13:57:29 +00:00
|
|
|
const nameClearCells = (numRows > 1 || numCols > 1) ? t("Clear values") : t("Clear cell");
|
2022-02-07 14:09:23 +00:00
|
|
|
|
|
|
|
const result: Array<Element|null> = [];
|
|
|
|
|
|
|
|
result.push(
|
|
|
|
|
|
|
|
// TODO: implement copy/paste actions
|
|
|
|
|
|
|
|
colOptions.isFormula ?
|
|
|
|
null :
|
|
|
|
menuItemCmd(allCommands.clearValues, nameClearCells, disableForReadonlyColumn),
|
2022-10-17 09:47:16 +00:00
|
|
|
menuItemCmd(allCommands.clearColumns, nameClearColumns, disableForReadonlyColumn),
|
2022-02-07 14:09:23 +00:00
|
|
|
|
|
|
|
...(
|
|
|
|
(numCols > 1 || numRows > 1) ? [] : [
|
|
|
|
menuDivider(),
|
2022-12-06 13:57:29 +00:00
|
|
|
menuItemCmd(allCommands.copyLink, t("Copy anchor link")),
|
2022-04-18 14:40:29 +00:00
|
|
|
menuDivider(),
|
2022-12-06 13:57:29 +00:00
|
|
|
menuItemCmd(allCommands.filterByThisCellValue, t("Filter by this value")),
|
2022-10-17 09:47:16 +00:00
|
|
|
menuItemCmd(allCommands.openDiscussion, 'Comment', dom.cls('disabled', (
|
|
|
|
isReadonly || numRows === 0 || numCols === 0
|
2022-10-28 16:11:08 +00:00
|
|
|
)), dom.hide(use => !use(COMMENTS()))) //TODO: i18next
|
2022-02-07 14:09:23 +00:00
|
|
|
]
|
|
|
|
),
|
|
|
|
|
|
|
|
menuDivider(),
|
|
|
|
|
|
|
|
// inserts
|
|
|
|
...(
|
|
|
|
isViewSorted ?
|
|
|
|
// When the view is sorted, any newly added records get shifts instantly at the top or
|
|
|
|
// bottom. It could be very confusing for users who might expect the record to stay above or
|
|
|
|
// below the active row. Thus in this case we show a single `insert row` command.
|
2022-12-06 13:57:29 +00:00
|
|
|
[menuItemCmd(allCommands.insertRecordAfter, t("Insert row"),
|
2022-02-07 14:09:23 +00:00
|
|
|
dom.cls('disabled', disableInsert))] :
|
|
|
|
|
2022-12-06 13:57:29 +00:00
|
|
|
[menuItemCmd(allCommands.insertRecordBefore, t("Insert row above"),
|
2022-02-07 14:09:23 +00:00
|
|
|
dom.cls('disabled', disableInsert)),
|
2022-12-06 13:57:29 +00:00
|
|
|
menuItemCmd(allCommands.insertRecordAfter, t("Insert row below"),
|
2022-02-07 14:09:23 +00:00
|
|
|
dom.cls('disabled', disableInsert))]
|
|
|
|
),
|
2022-12-06 16:43:35 +00:00
|
|
|
menuItemCmd(allCommands.duplicateRows, t("Duplicate rows", {count: numRows}),
|
2022-04-19 13:01:08 +00:00
|
|
|
dom.cls('disabled', disableInsert || numRows === 0)),
|
2022-12-06 13:57:29 +00:00
|
|
|
menuItemCmd(allCommands.insertFieldBefore, t("Insert column to the left"),
|
2022-02-07 14:09:23 +00:00
|
|
|
disableForReadonlyView),
|
2022-12-06 13:57:29 +00:00
|
|
|
menuItemCmd(allCommands.insertFieldAfter, t("Insert column to the right"),
|
2022-02-07 14:09:23 +00:00
|
|
|
disableForReadonlyView),
|
|
|
|
|
|
|
|
|
|
|
|
menuDivider(),
|
|
|
|
|
|
|
|
// deletes
|
2022-10-17 09:47:16 +00:00
|
|
|
menuItemCmd(allCommands.deleteRecords, nameDeleteRows, dom.cls('disabled', disableDelete)),
|
2022-02-07 14:09:23 +00:00
|
|
|
|
|
|
|
menuItemCmd(allCommands.deleteFields, nameDeleteColumns, disableForReadonlyColumn),
|
|
|
|
|
|
|
|
// todo: add "hide N columns"
|
|
|
|
);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|