UNPKG

@adaptabletools/adaptable

Version:

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

61 lines (60 loc) 2.26 kB
import { ApiBase } from './ApiBase'; import { RowFormInternalApi } from '../Internal/RowFormInternalApi'; import { PopupShowForm } from '../../Redux/ActionsReducers/PopupRedux'; export class RowFormApiImpl extends ApiBase { internalApi; constructor(_adaptable) { super(_adaptable); this.internalApi = new RowFormInternalApi(_adaptable); } async displayEditRowForm(primaryKey) { const rowNode = this.getGridApi().getRowNodeForPrimaryKey(primaryKey); if (!rowNode) { this.logWarn(`Cannot edit row: rowNode not found for primaryKey ${primaryKey}`); return; } const editForm = await this.internalApi.buildRowEditForm(rowNode); this.dispatchAction(PopupShowForm({ Id: 'edit_row_form', Form: editForm, FormProps: { rowNode, }, })); } async displayCreateRowForm() { const createForm = await this.internalApi.buildRowCreateForm(); this.dispatchAction(PopupShowForm({ Id: 'create_row_form', Form: createForm, })); } async displayCloneRowForm(primaryKey) { const rowNode = this.getGridApi().getRowNodeForPrimaryKey(primaryKey); if (!rowNode) { this.logWarn(`Can NOT clone row: rowNode not found for primaryKey ${primaryKey}`); return; } const createForm = await this.internalApi.buildRowCreateForm(rowNode); this.dispatchAction(PopupShowForm({ Id: 'create_row_form', Form: createForm, FormProps: { clonedRowNode: rowNode, }, })); } displayDeleteRowForm(primaryKey) { const rowNode = this.getGridApi().getRowNodeForPrimaryKey(primaryKey); if (!rowNode) { this.logWarn(`Can NOT delete row: rowNode not found for primaryKey ${primaryKey}`); } const eventInfo = { type: 'rowDeleted', rowNode: rowNode, ...this.getAdaptableInternalApi().buildBaseContext(), }; this.getEventApi().internalApi.fireRowFormSubmittedEvent(eventInfo); this.getRowFormOptions().onRowFormSubmit?.(eventInfo); } }