2021-06-28 18:02:45 +00:00
|
|
|
import { allCommands } from 'app/client/components/commands';
|
2022-10-28 16:11:08 +00:00
|
|
|
import { makeT } from 'app/client/lib/localization';
|
2021-06-28 18:02:45 +00:00
|
|
|
import { menuDivider, menuItemCmd } from 'app/client/ui2018/menus';
|
|
|
|
import { dom } from 'grainjs';
|
|
|
|
|
2022-10-28 16:11:08 +00:00
|
|
|
const t = makeT('RowContextMenu');
|
|
|
|
|
2022-04-19 13:01:08 +00:00
|
|
|
export interface IRowContextMenu {
|
2021-06-28 18:02:45 +00:00
|
|
|
disableInsert: boolean;
|
|
|
|
disableDelete: boolean;
|
|
|
|
isViewSorted: boolean;
|
2022-04-19 13:01:08 +00:00
|
|
|
numRows: number;
|
2021-06-28 18:02:45 +00:00
|
|
|
}
|
|
|
|
|
2022-04-19 13:01:08 +00:00
|
|
|
export function RowContextMenu({ disableInsert, disableDelete, isViewSorted, numRows }: IRowContextMenu) {
|
2021-06-28 18:02:45 +00:00
|
|
|
const result: Element[] = [];
|
|
|
|
if (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.
|
|
|
|
result.push(
|
2022-10-28 16:11:08 +00:00
|
|
|
menuItemCmd(allCommands.insertRecordAfter, t('InsertRow'),
|
2021-06-28 18:02:45 +00:00
|
|
|
dom.cls('disabled', disableInsert)),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
result.push(
|
2022-10-28 16:11:08 +00:00
|
|
|
menuItemCmd(allCommands.insertRecordBefore, t('InsertRowAbove'),
|
2021-06-28 18:02:45 +00:00
|
|
|
dom.cls('disabled', disableInsert)),
|
2022-10-28 16:11:08 +00:00
|
|
|
menuItemCmd(allCommands.insertRecordAfter, t('InsertRowBelow'),
|
2021-06-28 18:02:45 +00:00
|
|
|
dom.cls('disabled', disableInsert)),
|
|
|
|
);
|
|
|
|
}
|
2022-04-19 13:01:08 +00:00
|
|
|
result.push(
|
2022-10-28 16:11:08 +00:00
|
|
|
menuItemCmd(allCommands.duplicateRows, t('DuplicateRows', { count: numRows }),
|
2022-04-19 13:01:08 +00:00
|
|
|
dom.cls('disabled', disableInsert || numRows === 0)),
|
|
|
|
);
|
2021-06-28 18:02:45 +00:00
|
|
|
result.push(
|
|
|
|
menuDivider(),
|
2022-02-07 14:09:23 +00:00
|
|
|
// TODO: should show `Delete ${num} rows` when multiple are selected
|
2022-10-28 16:11:08 +00:00
|
|
|
menuItemCmd(allCommands.deleteRecords, t('Delete'),
|
2021-06-28 18:02:45 +00:00
|
|
|
dom.cls('disabled', disableDelete)),
|
|
|
|
);
|
|
|
|
result.push(
|
|
|
|
menuDivider(),
|
2022-10-28 16:11:08 +00:00
|
|
|
menuItemCmd(allCommands.copyLink, t('CopyAnchorLink')));
|
2021-06-28 18:02:45 +00:00
|
|
|
return result;
|
|
|
|
}
|