2020-10-02 15:10:00 +00:00
|
|
|
import {allCommands} from 'app/client/components/commands';
|
2022-02-07 14:02:26 +00:00
|
|
|
import {ViewSectionRec} from 'app/client/models/DocModel';
|
2020-10-02 15:10:00 +00:00
|
|
|
import {testId} from 'app/client/ui2018/cssVars';
|
2021-05-27 11:06:26 +00:00
|
|
|
import {menuDivider, menuItemCmd, menuItemLink} from 'app/client/ui2018/menus';
|
2020-10-02 15:10:00 +00:00
|
|
|
import {dom} from 'grainjs';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a list of menu items for a view section.
|
|
|
|
*/
|
2022-02-07 14:02:26 +00:00
|
|
|
export function makeViewLayoutMenu(viewSection: ViewSectionRec, isReadonly: boolean) {
|
2021-06-28 18:02:45 +00:00
|
|
|
const viewInstance = viewSection.viewInstance.peek()!;
|
|
|
|
const gristDoc = viewInstance.gristDoc;
|
|
|
|
|
|
|
|
// get current row index from cursor
|
|
|
|
const cursorRow = viewInstance.cursor.rowIndex.peek();
|
|
|
|
// get row id from current data
|
|
|
|
// rowId can be string - it is wrongly typed in cursor and in viewData
|
|
|
|
const rowId = (cursorRow !== null ? viewInstance.viewData.getRowId(cursorRow) : null) as string|null|number;
|
|
|
|
const isAddRow = rowId === 'new';
|
|
|
|
|
|
|
|
const contextMenu = [
|
|
|
|
menuItemCmd(allCommands.deleteRecords,
|
|
|
|
'Delete record',
|
|
|
|
testId('section-delete-card'),
|
|
|
|
dom.cls('disabled', isReadonly || isAddRow)),
|
|
|
|
menuItemCmd(allCommands.copyLink,
|
|
|
|
'Copy anchor link',
|
|
|
|
testId('section-card-link'),
|
|
|
|
),
|
|
|
|
menuDivider(),
|
|
|
|
];
|
|
|
|
|
2022-02-07 14:02:26 +00:00
|
|
|
const viewRec = viewSection.view();
|
2020-10-02 15:10:00 +00:00
|
|
|
return [
|
2021-06-28 18:02:45 +00:00
|
|
|
dom.maybe((use) => ['single'].includes(use(viewSection.parentKey)), () => contextMenu),
|
2020-10-09 21:39:13 +00:00
|
|
|
menuItemCmd(allCommands.printSection, 'Print widget', testId('print-section')),
|
2021-05-27 11:06:26 +00:00
|
|
|
menuItemLink({ href: gristDoc.getCsvLink(), target: '_blank', download: ''},
|
|
|
|
'Download as CSV', testId('download-section')),
|
2020-10-02 15:10:00 +00:00
|
|
|
dom.maybe((use) => ['detail', 'single'].includes(use(viewSection.parentKey)), () =>
|
|
|
|
menuItemCmd(allCommands.editLayout, 'Edit Card Layout',
|
|
|
|
dom.cls('disabled', isReadonly))),
|
|
|
|
|
|
|
|
menuDivider(),
|
|
|
|
menuItemCmd(allCommands.viewTabOpen, 'Widget options', testId('widget-options')),
|
|
|
|
menuItemCmd(allCommands.sortFilterTabOpen, 'Advanced Sort & Filter'),
|
2020-10-09 21:39:13 +00:00
|
|
|
menuItemCmd(allCommands.dataSelectionTabOpen, 'Data selection'),
|
|
|
|
|
|
|
|
menuDivider(),
|
2022-01-12 13:30:51 +00:00
|
|
|
dom.maybe((use) => use(viewSection.parentKey) === 'custom' && use(viewSection.hasCustomOptions), () =>
|
|
|
|
menuItemCmd(allCommands.openWidgetConfiguration, 'Open configuration',
|
|
|
|
testId('section-open-configuration')),
|
|
|
|
),
|
2020-10-09 21:39:13 +00:00
|
|
|
menuItemCmd(allCommands.deleteSection, 'Delete widget',
|
2022-02-07 14:02:26 +00:00
|
|
|
dom.cls('disabled', !viewRec.getRowId() || viewRec.viewSections().peekLength <= 1 || isReadonly),
|
2020-10-09 21:39:13 +00:00
|
|
|
testId('section-delete')),
|
2020-10-02 15:10:00 +00:00
|
|
|
];
|
|
|
|
}
|