UNPKG

@adaptabletools/adaptable

Version:

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

78 lines (77 loc) 3.16 kB
import * as ModuleConstants from '../Utilities/Constants/ModuleConstants'; import { AdaptableModuleBase } from './AdaptableModuleBase'; export class CommentModule extends AdaptableModuleBase { constructor(api) { super(ModuleConstants.CommentModuleId, ModuleConstants.CommentFriendlyName, 'comments', 'CommentsPopup', 'comments', api); } onAdaptableReady() { this.loadComments(); } isModuleAvailable() { const options = this.api.optionsApi.getCommentOptions(); if (!options || !options.persistCommentThreads || !options.loadCommentThreads) { return false; } if (this.api.optionsApi.isAutogeneratePrimaryKey()) { return false; } return super.isModuleAvailable(); } async loadComments() { const commentThreads = await this.api.optionsApi .getCommentOptions() ?.loadCommentThreads?.(this.api.internalApi.buildBaseContext()); this.api.commentApi.setComments(commentThreads); } createContextMenuItems(menuContext) { if (!this.isModuleAvailable()) { return; } if (!this.api.commentApi.internalApi.areCommentsSupportedInLayout()) { return; } if (menuContext.isRowGroupColumn || menuContext.isGroupedNode) { return; } const items = []; const isCellCommentable = typeof this.api.optionsApi?.getCommentOptions()?.isCellCommentable === 'function' ? this.api.optionsApi?.getCommentOptions()?.isCellCommentable({ gridCell: menuContext.gridCell, ...this.api.internalApi.buildBaseContext(), }) : true; if (!isCellCommentable) { return; } const cellAddress = { PrimaryKeyValue: menuContext.primaryKeyValue, ColumnId: menuContext.adaptableColumn.columnId, }; const cellComments = this.api.commentApi.getCommentThreadForCell(cellAddress)?.Comments; if (cellComments) { return [ this.createMenuItemClickFunction('comment-remove', 'Remove Comment', this.moduleInfo.Glyph, () => { this.api.commentApi.deleteCommentThread(cellAddress); }), ]; } else { return [ this.createMenuItemClickFunction('comment-add', 'Add Comment', this.moduleInfo.Glyph, () => { // add an empty one this.api.commentApi.addCommentThread({ ...cellAddress, Comments: [], }); requestAnimationFrame(() => { this.api.internalApi.getAnnotationsService().showPopup({ PrimaryKeyValue: menuContext.primaryKeyValue, ColumnId: menuContext.adaptableColumn.columnId, }, true); this.api.internalApi.getAnnotationsService().editFocusedEntity('Comment'); }); }), ]; } } }