UNPKG

@adaptabletools/adaptable

Version:

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

388 lines (387 loc) 11.5 kB
import { MathOperation, } from '../AdaptableState/Common/Enums'; import { createUuid } from '../AdaptableState/Uuid'; import { buildCronExpression } from './Helpers/Scheduling/ScheduleHelper'; import { EMPTY_STRING } from './Constants/GeneralConstants'; import { ALERT_DEFAULT_MESSAGE_TYPE, ALERT_DEFAULT_SHOW_POPUP, PLUS_MINUS_DEFAULT_NUDGE_VALUE, } from './Constants/ObjectDefaultConstants'; import { Bounce, Flip, Slide, Zoom } from '../components/Toastify'; import { getSwatchColorVar } from '../View/UIHelper'; import { isPivotLayout } from '../Api/Implementation/LayoutHelpers'; export function CreateEmptyCustomSort() { return { Uuid: createUuid(), Name: EMPTY_STRING, ColumnId: EMPTY_STRING, SortedValues: [] }; } export function CreateAdaptableComment(text, api) { const comment = { Value: text, AdaptableId: api.optionsApi.getAdaptableId(), Author: { UserName: api.optionsApi.getUserName(), }, Timestamp: Date.now(), Uuid: createUuid(), }; return comment; } export function CreateEmptyCalculatedColumn(defaultSpecialColumnSettings) { return { Uuid: createUuid(), ColumnId: EMPTY_STRING, Query: { ScalarExpression: EMPTY_STRING, }, CalculatedColumnSettings: { ...defaultSpecialColumnSettings, DataType: undefined, }, }; } export function CreateEmptyNamedQuery(expression) { return { Uuid: createUuid(), Name: EMPTY_STRING, BooleanExpression: expression || EMPTY_STRING, }; } export function CreateEmptyPlusMinusNudge() { return { Uuid: createUuid(), Name: EMPTY_STRING, Scope: undefined, Rule: undefined, NudgeValue: PLUS_MINUS_DEFAULT_NUDGE_VALUE, }; } export function CreateGenericAlert(alertHeader, alertMessage, alertDefinition) { return { alertType: 'generic', Uuid: createUuid(), header: alertHeader, message: alertMessage, alertDefinition: alertDefinition, }; } export function CreateCellChangedAlert(alertHeader, alertMessage, alertDefinition, cellDataChangedInfo) { return { alertType: 'cellChanged', Uuid: createUuid(), header: alertHeader, message: alertMessage, alertDefinition, cellDataChangedInfo: cellDataChangedInfo, }; } export function CreateRowChangedAlert(alertHeader, alertMessage, alertDefinition, rowDataChangedInfo) { return { alertType: 'rowChanged', Uuid: createUuid(), header: alertHeader, message: alertMessage, alertDefinition, rowDataChangedInfo: rowDataChangedInfo, }; } export function CreateEmptyAlertDefinition() { return { Uuid: createUuid(), Name: EMPTY_STRING, Scope: { All: true }, Rule: { Predicates: [], }, MessageType: ALERT_DEFAULT_MESSAGE_TYPE, AlertProperties: {}, }; } export function CreateEmptyFlashingCellDefinition() { return { Uuid: createUuid(), Name: EMPTY_STRING, Scope: { ColumnIds: [] }, Rule: { Predicates: [ { PredicateId: 'AnyChange', }, ], }, }; } export function CreateInternalAlertDefinitionForMessages(messageType, alertProperties) { alertProperties = alertProperties ?? { DisplayNotification: ALERT_DEFAULT_SHOW_POPUP, }; return { Uuid: createUuid(), Name: EMPTY_STRING, Scope: undefined, Rule: { Predicates: [], }, MessageType: messageType, AlertProperties: alertProperties, }; } export function CreateEmptyReport() { return { Uuid: createUuid(), Name: EMPTY_STRING, Scope: undefined, ReportColumnScope: 'AllColumns', ReportRowScope: 'AllRows', Query: undefined, }; } export function CreateEmptyReportSchedule(reportFormat, reportName) { return { Uuid: createUuid(), Name: EMPTY_STRING, ReportName: reportName ?? EMPTY_STRING, Schedule: CreateDefaultSchedule(), ReportFormat: reportFormat ?? EMPTY_STRING, ExportDestination: 'Download', }; } export function CreateEmptyShortcut() { return { Uuid: createUuid(), Name: EMPTY_STRING, Scope: undefined, ShortcutKey: EMPTY_STRING, ShortcutValue: undefined, ShortcutOperation: MathOperation.Multiply, }; } export function CreateEmptyFormatColumn() { return { Uuid: createUuid(), Name: EMPTY_STRING, Scope: undefined, Style: CreateEmptyStyle(), DisplayFormat: undefined, RowScope: undefined, Target: 'cell', }; } export function CreateEmptyFreeTextColumn(defaultSpecialColumnSettings) { return { Uuid: createUuid(), ColumnId: EMPTY_STRING, DefaultValue: EMPTY_STRING, FreeTextStoredValues: [], TextEditor: 'Inline', FreeTextColumnSettings: { ...defaultSpecialColumnSettings, DataType: 'text', }, }; } export function CreateEmptyPivotLayout(pivotLayout) { const result = { ...pivotLayout, Uuid: createUuid(), ColumnSizing: pivotLayout.ColumnSizing || {}, ColumnHeaders: pivotLayout.ColumnHeaders || {}, ColumnPinning: pivotLayout.ColumnPinning || {}, ColumnSorts: pivotLayout.ColumnSorts || [], ColumnFilters: pivotLayout.ColumnFilters || [], PivotColumns: pivotLayout.PivotColumns || [], PivotAggregationColumns: pivotLayout.PivotAggregationColumns || [], PivotGroupedColumns: pivotLayout.PivotGroupedColumns || [], }; return result; } export function CreateEmptyTableLayout(tableLayout) { const result = { ...tableLayout, Uuid: createUuid(), ColumnSizing: tableLayout.ColumnSizing || {}, ColumnHeaders: tableLayout.ColumnHeaders || {}, ColumnPinning: tableLayout.ColumnPinning || {}, ColumnSorts: tableLayout.ColumnSorts || [], ColumnFilters: tableLayout.ColumnFilters || [], TableColumns: tableLayout.TableColumns || [], RowGroupedColumns: tableLayout.RowGroupedColumns || [], }; return result; } export function CreateEmptyLayout(layout) { if (isPivotLayout(layout)) { return CreateEmptyPivotLayout(layout); } else { return CreateEmptyTableLayout(layout); } } export function CreateEmptyStyle() { return { BackColor: undefined, ForeColor: undefined, BorderColor: undefined, FontWeight: undefined, FontStyle: undefined, FontSize: undefined, ClassName: undefined, Alignment: undefined, }; } export function CreateSystemStatusMessageInfo(message, type, furtherInfo) { return { Uuid: createUuid(), statusMessage: message, statusFurtherInformation: furtherInfo, statusType: type, timestamp: new Date(), }; } export function CreateEmptyCellSummmary() { return { Sum: undefined, Average: undefined, Median: undefined, Mode: undefined, Distinct: undefined, Max: undefined, Min: undefined, Count: undefined, Std_Deviation: undefined, Only: undefined, }; } export function CreateColumnFilter(ColumnId, PredicateId, Inputs) { return { ColumnId, Predicates: [ { PredicateId: PredicateId, Inputs, }, ], }; } export function CreateEmptyStyledColumn() { return { Uuid: createUuid(), Name: EMPTY_STRING, ColumnId: EMPTY_STRING, }; } export function CreateDefaultStyledColumnBadge() { return { Shape: 'Rounded', PillStyle: { BackColor: getSwatchColorVar(3), ForeColor: getSwatchColorVar(1), }, }; } export function CreateEmptyChartDefinition(chartDefinition) { return { Uuid: createUuid(), ...chartDefinition, }; } export function CreateCustomDisplayFormatterContext(value, node, abColumn, api) { return { adaptableColumn: abColumn, cellValue: value, rowNode: node, ...api.internalApi.buildBaseContext(), }; } export function CreateEmptyCommentThread(cellAddress) { return { ...cellAddress, Comments: [], }; } function getToastPosition(position) { switch (position) { case 'BottomLeft': return 'bottom-left'; case 'BottomCenter': return 'bottom-center'; case 'BottomRight': return 'bottom-right'; case 'TopLeft': return 'top-left'; case 'TopCenter': return 'top-center'; case 'TopRight': return 'top-right'; } } function getToastTransition(transition) { switch (transition) { case 'Bounce': return Bounce; case 'Slide': return Slide; case 'Zoom': return Zoom; case 'Flip': return Flip; default: return Bounce; } } export function CreateToastOptions(notificationsOptions, { onClose, containerId }, overides) { const adaptableToastPosition = notificationsOptions.position; const position = getToastPosition(adaptableToastPosition); const duration = overides.duration ?? notificationsOptions.duration; const showProgressBar = notificationsOptions.showProgressBar; const closeWhenClicked = notificationsOptions.closeWhenClicked; const pauseWhenHovering = notificationsOptions.pauseWhenHovering; const isDraggable = notificationsOptions.isDraggable; const transition = getToastTransition(notificationsOptions.transition); const toastProps = { containerId, position, autoClose: duration == 'always' ? false : duration, hideProgressBar: !showProgressBar, closeOnClick: closeWhenClicked, pauseOnHover: pauseWhenHovering, draggable: isDraggable, transition: transition, draggablePercent: 75, onClose, }; return toastProps; } export function CreateDefaultSchedule() { return { IsOneOff: false, CronExpression: buildCronExpression('weekdays', 9, 0), }; } export const ObjectFactory = { CreateEmptyCustomSort, CreateEmptyCalculatedColumn, CreateEmptyNamedQuery, CreateEmptyPlusMinusNudge, CreateGenericAlert, CreateCellChangedAlert, CreateRowChangedAlert, CreateEmptyAlertDefinition, CreateEmptyFlashingCellDefinition, CreateInternalAlertDefinitionForMessages, CreateEmptyReport, CreateEmptyReportSchedule, CreateEmptyShortcut, CreateEmptyFormatColumn, CreateEmptyFreeTextColumn, CreateEmptyLayout, CreateEmptyPivotLayout, CreateEmptyTableLayout, CreateColumnFilter, CreateEmptyStyle, CreateEmptyCellSummmary, CreateSystemStatusMessageInfo, CreateToastOptions, CreateCustomDisplayFormatterContext, CreateEmptyStyledColumn, CreateDefaultStyledColumnBadge, CreateEmptyChartDefinition, CreateEmptyCommentThread, CreateAdaptableComment, CreateDefaultSchedule, }; export default ObjectFactory;