UNPKG

@adaptabletools/adaptable

Version:

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

60 lines (59 loc) 3.31 kB
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime"; import { AlertType, getAlertTypeText } from '../Utilities/getAlertType'; import { Tag } from '../../../components/Tag'; import { Flex } from '../../../components/Flex'; import { useOnePageAdaptableWizardContext } from '../../Wizard/OnePageAdaptableWizard'; import { SummaryText } from '../../Wizard/OnePageAdaptableWizard'; import { getWizardTypeSelectionGridColumns, WizardNameFieldSection, WizardTypeSelectionCard, WizardTypeSelectionSection, } from '../../Wizard/WizardTypeSelection'; export const isSettingsValid = (data, api) => { if (!data.Name?.trim()) { return 'Name is required'; } const allAlerts = api.alertApi.getAlertDefinitions(); const isDuplicateName = allAlerts.some((a) => a.Name === data.Name && a.Uuid !== data.Uuid); if (isDuplicateName) { return 'An Alert already exists with that name'; } return true; }; export const renderAlertTypeSummary = (alertType, data) => { const text = getAlertTypeText(alertType); return (_jsxs(_Fragment, { children: [_jsxs(SummaryText, { children: ["Name ", _jsx(Tag, { children: data.Name || 'Not specified' })] }), _jsxs(SummaryText, { children: ["Type ", _jsx(Tag, { children: text })] })] })); }; const ALERT_TYPE_OPTIONS = [ { type: AlertType.DataChange, description: "A data change has been made to the Grid's data source", }, { type: AlertType.RowChange, description: 'A Row has been added or removed from the data source', }, { type: AlertType.Aggregation, description: 'A change has been made to aggregated data (i.e. from multiple Rows)', }, { type: AlertType.Observable, description: 'A specified change (or lack of change) over time has been observed in the Grid', }, { type: AlertType.Validation, description: "A change made to the Grid's data has broken a validation rule", }, { type: AlertType.Scheduled, description: 'A reminder is triggered to display at a specfied date and time', }, ]; const ALERT_TYPE_COUNT = ALERT_TYPE_OPTIONS.length; export const AlertTypeWizardSection = (props) => { const { data } = useOnePageAdaptableWizardContext(); const handleNameChange = (event) => { props.onChange({ ...data, Name: event.target.value, }); }; return (_jsxs(Flex, { flexDirection: "column", className: "twa:h-full twa:min-h-0 twa:p-2 twa:gap-2", children: [_jsx(WizardNameFieldSection, { value: data.Name ?? '', onChange: handleNameChange, inputDataName: "alert-name" }), _jsx(WizardTypeSelectionSection, { headingId: "alert-type-heading", title: "Alert Type", dataName: "alert-type", columns: getWizardTypeSelectionGridColumns(ALERT_TYPE_COUNT), intro: _jsxs(_Fragment, { children: ["Click a card to choose one of ", ALERT_TYPE_COUNT, " alert types for when the Alert should fire"] }), children: ALERT_TYPE_OPTIONS.map((option) => (_jsx(WizardTypeSelectionCard, { label: getAlertTypeText(option.type), description: option.description, selected: props.alertType === option.type, dataName: `alert-type-${option.type}`, onSelect: () => props.onAlertTypeChange(option.type) }, option.type))) })] })); };