@adaptabletools/adaptable-cjs
Version:
Powerful data-agnostic HTML5 AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements
65 lines (64 loc) • 4.99 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AlertTypeWizardSection = exports.renderAlertTypeSummary = exports.isSettingsValid = void 0;
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const Tabs_1 = require("../../../components/Tabs");
const getAlertType_1 = require("../Utilities/getAlertType");
const TypeRadio_1 = require("../../Wizard/TypeRadio");
const Tag_1 = require("../../../components/Tag");
const Flex_1 = require("../../../components/Flex");
const OnePageAdaptableWizard_1 = require("../../Wizard/OnePageAdaptableWizard");
const FormLayout_1 = tslib_1.__importStar(require("../../../components/FormLayout"));
const Input_1 = tslib_1.__importDefault(require("../../../components/Input"));
const OnePageAdaptableWizard_2 = require("../../Wizard/OnePageAdaptableWizard");
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;
};
exports.isSettingsValid = isSettingsValid;
const renderAlertTypeSummary = (alertType) => {
const { data } = (0, OnePageAdaptableWizard_1.useOnePageAdaptableWizardContext)();
const text = (0, getAlertType_1.getAlertTypeText)(alertType);
return (React.createElement(React.Fragment, null,
React.createElement(OnePageAdaptableWizard_2.SummaryText, null,
"Name ",
React.createElement(Tag_1.Tag, null, data.Name || 'Not specified')),
React.createElement(OnePageAdaptableWizard_2.SummaryText, null,
"Type ",
React.createElement(Tag_1.Tag, null, text))));
};
exports.renderAlertTypeSummary = renderAlertTypeSummary;
const AlertTypeWizardSection = (props) => {
const { data } = (0, OnePageAdaptableWizard_1.useOnePageAdaptableWizardContext)();
const handleNameChange = (event) => {
props.onChange({
...data,
Name: event.target.value,
});
};
return (React.createElement(Flex_1.Flex, { flexDirection: "column" },
React.createElement(Tabs_1.Tabs, null,
React.createElement(Tabs_1.Tabs.Tab, null, "Settings"),
React.createElement(Tabs_1.Tabs.Content, null,
React.createElement(FormLayout_1.default, null,
React.createElement(FormLayout_1.FormRow, { label: "Name" },
React.createElement(Input_1.default, { "data-name": "alert-name", className: "twa:flex-1 twa:max-w-[200px] twa:mr-3", onChange: handleNameChange, placeholder: "Enter Name", value: data.Name ?? '' }))))),
React.createElement(Tabs_1.Tabs, { className: "twa:mt-2" },
React.createElement(Tabs_1.Tabs.Tab, null, "Alert Type"),
React.createElement(Tabs_1.Tabs.Content, null,
React.createElement(Flex_1.Flex, { flexDirection: "column" },
React.createElement(TypeRadio_1.TypeRadio, { text: (0, getAlertType_1.getAlertTypeText)(getAlertType_1.AlertType.DataChange), description: "A change has been made to the Grid's underlying data", checked: props.alertType === getAlertType_1.AlertType.DataChange, onClick: () => props.onAlertTypeChange(getAlertType_1.AlertType.DataChange) }),
React.createElement(TypeRadio_1.TypeRadio, { text: (0, getAlertType_1.getAlertTypeText)(getAlertType_1.AlertType.RowChange), description: "A Row was added or removed from the data source", checked: props.alertType === getAlertType_1.AlertType.RowChange, onClick: () => props.onAlertTypeChange(getAlertType_1.AlertType.RowChange) }),
React.createElement(TypeRadio_1.TypeRadio, { text: (0, getAlertType_1.getAlertTypeText)(getAlertType_1.AlertType.Aggregation), description: "A change has been made to aggregated data (i.e. from multiple Rows)", onClick: () => props.onAlertTypeChange(getAlertType_1.AlertType.Aggregation), checked: props.alertType === getAlertType_1.AlertType.Aggregation }),
React.createElement(TypeRadio_1.TypeRadio, { text: (0, getAlertType_1.getAlertTypeText)(getAlertType_1.AlertType.Observable), description: "A specified change (or lack of change) over time has been observed in the Grid", onClick: () => props.onAlertTypeChange(getAlertType_1.AlertType.Observable), checked: props.alertType === getAlertType_1.AlertType.Observable }),
React.createElement(TypeRadio_1.TypeRadio, { text: (0, getAlertType_1.getAlertTypeText)(getAlertType_1.AlertType.Validation), description: "A change has broken a data validation rule", checked: props.alertType === getAlertType_1.AlertType.Validation, onClick: () => props.onAlertTypeChange(getAlertType_1.AlertType.Validation) }))))));
};
exports.AlertTypeWizardSection = AlertTypeWizardSection;