UNPKG

@adaptabletools/adaptable

Version:

Powerful AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements

75 lines (74 loc) 3.21 kB
import { ACCESS_LEVEL_READ_ONLY } from '../Utilities/Constants/GeneralConstants'; import * as ModuleConstants from '../Utilities/Constants/ModuleConstants'; import { AdaptableModuleBase } from './AdaptableModuleBase'; export class NoteModule extends AdaptableModuleBase { constructor(api) { super(ModuleConstants.NoteModuleId, ModuleConstants.NoteFriendlyName, 'note', 'NotePopup', 'Notes', api); } isModuleEnabled() { return !this.api.optionsApi.isAutogeneratePrimaryKey(); } getModuleAdaptableObjects() { return this.api.noteApi.getAllNotes(); } createContextMenuItems(menuContext) { if (!this.isModuleVisible()) { return; } if (!this.api.noteApi.internalApi.areNotesSupported()) { return; } if (menuContext.isRowGroupColumn || menuContext.isGroupedNode || !menuContext.isSingleSelectedCell) { return; } const isReadOnly = this.api.entitlementApi.getEntitlementAccessLevelForModule(this.moduleInfo.ModuleName) === ACCESS_LEVEL_READ_ONLY; if (isReadOnly) { return undefined; } const isCellNotable = typeof this.api.optionsApi?.getNoteOptions()?.isCellNotable === 'function' ? this.api.optionsApi.getNoteOptions().isCellNotable({ gridCell: menuContext.gridCell, ...this.api.internalApi.buildBaseContext(), }) : true; if (!isCellNotable) { return; } const note = this.api.noteApi.getNoteForCell({ PrimaryKeyValue: menuContext.primaryKeyValue, ColumnId: menuContext.adaptableColumn.columnId, }); if (note) { const showNoteAction = this.api.optionsApi?.getNoteOptions()?.showNoteAction ?? 'hover'; const inMenuMode = showNoteAction === 'menu'; const items = [ this.createMenuItemClickFunction('note-remove', 'Remove Note', inMenuMode ? 'visibility-off' : this.moduleInfo.Glyph, () => { this.api.noteApi.deleteNote(note); }), ]; if (inMenuMode) { items.unshift(this.createMenuItemClickFunction('note-show', 'Show Note', 'visibility-on', () => { this.api.internalApi.getAnnotationsService().showPopup({ PrimaryKeyValue: menuContext.primaryKeyValue, ColumnId: menuContext.adaptableColumn.columnId, }, true); })); } return items; } else { return [ this.createMenuItemClickFunction('note-add', 'Add Note', this.moduleInfo.Glyph, () => { this.api.noteApi.addNote('', menuContext.primaryKeyValue, menuContext.adaptableColumn.columnId); this.api.internalApi.getAnnotationsService().showPopup({ PrimaryKeyValue: menuContext.primaryKeyValue, ColumnId: menuContext.adaptableColumn.columnId, }, true); }), ]; } } }