2022-10-28 16:11:08 +00:00
|
|
|
import {makeT} from 'app/client/lib/localization';
|
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';
|
2022-08-02 13:01:07 +00:00
|
|
|
import {urlState} from 'app/client/models/gristUrlState';
|
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';
|
|
|
|
|
2022-10-28 16:11:08 +00:00
|
|
|
const t = makeT('ViewLayoutMenu');
|
|
|
|
|
2020-10-02 15:10:00 +00:00
|
|
|
/**
|
|
|
|
* 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,
|
2022-12-06 13:57:29 +00:00
|
|
|
t("Delete record"),
|
2021-06-28 18:02:45 +00:00
|
|
|
testId('section-delete-card'),
|
|
|
|
dom.cls('disabled', isReadonly || isAddRow)),
|
|
|
|
menuItemCmd(allCommands.copyLink,
|
2022-12-06 13:57:29 +00:00
|
|
|
t("Copy anchor link"),
|
2021-06-28 18:02:45 +00:00
|
|
|
testId('section-card-link'),
|
|
|
|
),
|
|
|
|
menuDivider(),
|
|
|
|
];
|
|
|
|
|
2022-02-07 14:02:26 +00:00
|
|
|
const viewRec = viewSection.view();
|
2022-08-02 13:01:07 +00:00
|
|
|
const isLight = urlState().state.get().params?.style === 'light';
|
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),
|
2022-08-02 13:01:07 +00:00
|
|
|
dom.maybe((use) => !use(viewSection.isRaw) && !isLight,
|
2022-12-06 13:57:29 +00:00
|
|
|
() => menuItemCmd(allCommands.showRawData, t("Show raw data"), testId('show-raw-data')),
|
2022-08-02 13:01:07 +00:00
|
|
|
),
|
2022-12-06 13:57:29 +00:00
|
|
|
menuItemCmd(allCommands.printSection, t("Print widget"), testId('print-section')),
|
2021-05-27 11:06:26 +00:00
|
|
|
menuItemLink({ href: gristDoc.getCsvLink(), target: '_blank', download: ''},
|
2022-12-06 13:57:29 +00:00
|
|
|
t("Download as CSV"), testId('download-section')),
|
2022-09-14 18:55:44 +00:00
|
|
|
menuItemLink({ href: gristDoc.getXlsxActiveViewLink(), target: '_blank', download: ''},
|
2022-12-06 13:57:29 +00:00
|
|
|
t("Download as XLSX"), testId('download-section')),
|
2020-10-02 15:10:00 +00:00
|
|
|
dom.maybe((use) => ['detail', 'single'].includes(use(viewSection.parentKey)), () =>
|
2022-12-06 13:57:29 +00:00
|
|
|
menuItemCmd(allCommands.editLayout, t("Edit Card Layout"),
|
2020-10-02 15:10:00 +00:00
|
|
|
dom.cls('disabled', isReadonly))),
|
|
|
|
|
2022-08-02 13:01:07 +00:00
|
|
|
dom.maybe(!isLight, () => [
|
|
|
|
menuDivider(),
|
2022-12-06 13:57:29 +00:00
|
|
|
menuItemCmd(allCommands.viewTabOpen, t("Widget options"), testId('widget-options')),
|
|
|
|
menuItemCmd(allCommands.sortFilterTabOpen, t("Advanced Sort & Filter")),
|
|
|
|
menuItemCmd(allCommands.dataSelectionTabOpen, t("Data selection")),
|
2022-08-02 13:01:07 +00:00
|
|
|
]),
|
2020-10-09 21:39:13 +00:00
|
|
|
|
|
|
|
menuDivider(),
|
2022-01-12 13:30:51 +00:00
|
|
|
dom.maybe((use) => use(viewSection.parentKey) === 'custom' && use(viewSection.hasCustomOptions), () =>
|
2022-12-06 13:57:29 +00:00
|
|
|
menuItemCmd(allCommands.openWidgetConfiguration, t("Open configuration"),
|
2022-01-12 13:30:51 +00:00
|
|
|
testId('section-open-configuration')),
|
|
|
|
),
|
2022-12-06 13:57:29 +00:00
|
|
|
menuItemCmd(allCommands.deleteSection, t("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
|
|
|
];
|
|
|
|
}
|