@adaptabletools/adaptable
Version:
Powerful AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements
80 lines (79 loc) • 4.44 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import * as React from 'react';
import { useDispatch } from 'react-redux';
import * as ExportRedux from '../../../Redux/ActionsReducers/ExportRedux';
import ObjectFactory from '../../../Utilities/ObjectFactory';
import { OnePageAdaptableWizard, OnePageWizardSummary, useOnePageAdaptableWizardContext, } from '../../Wizard/OnePageAdaptableWizard';
import { isScheduleValid, ScheduleBuilderWizard, } from '../../Schedule/Wizard/ScheduleScheduleWizard';
import { ScheduleScheduleSummary } from '../../Schedule/Wizard/ScheduleScheduleSummary';
import { ObjectTagsWizardSection, renderObjectTagsSummary, } from '../../Wizard/ObjectTagsWizardSection';
import { ScheduledReportSettings } from './ScheduledReportSettings';
import { ScheduledReportSettingsSummary } from './ScheduledReportSettingsSummary';
import { isReportScheduleSettingsValid } from './isReportScheduledSettingsValid';
import { Box } from '../../../components/Flex';
export const ScheduledReportWizard = (props) => {
const popupValue = props.popupParams?.value;
const reportName = popupValue?.reportName;
const initialReportSchedule = popupValue?.reportSchedule ?? props.data;
const isNew = props.popupParams?.action
? props.popupParams.action === 'NewSchedule'
: !initialReportSchedule?.Name;
const [reportSchedule, setReportSchedule] = React.useState(() => {
return initialReportSchedule ?? ObjectFactory.CreateEmptyReportSchedule(reportName);
});
const dispatch = useDispatch();
const handleFinish = () => {
const resolvedReportName = reportName ?? reportSchedule.ReportName;
if (!resolvedReportName?.trim()) {
return;
}
const scheduleToSave = { ...reportSchedule, ReportName: resolvedReportName };
const action = isNew
? ExportRedux.ScheduledReportAdd(scheduleToSave)
: ExportRedux.ScheduledReportEdit(scheduleToSave);
dispatch(action);
props.onFinishWizard(scheduleToSave);
};
const handleScheduleChange = (scheduleData) => {
setReportSchedule({
...reportSchedule,
Schedule: scheduleData.Schedule,
});
};
return (_jsx(OnePageAdaptableWizard, { defaultCurrentSectionName: props.defaultCurrentSectionName, moduleInfo: props.moduleInfo, moduleName: "Report Schedule", data: reportSchedule, onHide: props.onCloseWizard, onFinish: handleFinish, sections: [
{
title: 'Settings',
isValid: (data, api) => isReportScheduleSettingsValid(data, api),
renderSummary: () => _jsx(ScheduledReportSettingsSummary, {}),
render: () => (_jsx(ScheduledReportSettingsSection, { onChange: setReportSchedule, reportName: reportName })),
},
{
title: 'Schedule',
isValid: (data) => isScheduleValid({ Schedule: data.Schedule }),
renderSummary: () => _jsx(ScheduleScheduleSummary, {}),
render: () => (_jsx(Box, { className: "twa:p-3", children: _jsx(ScheduleBuilderWizard, { onChange: handleScheduleChange }) })),
},
{
details: 'Select Schedule Tags',
title: 'Tags',
isVisible: (_, api) => api.internalApi.shouldDisplayTagSections(),
render: () => (_jsx(Box, { className: "twa:p-2", children: _jsx(ObjectTagsWizardSection, { onChange: setReportSchedule }) })),
renderSummary: renderObjectTagsSummary,
},
'-',
{
render: () => (_jsx(Box, { className: "twa:p-2", children: _jsx(OnePageWizardSummary, {}) })),
title: 'Summary',
},
] }));
};
const ScheduledReportSettingsSection = (props) => {
const { data, api } = useOnePageAdaptableWizardContext();
const allFormats = api.exportApi.getAvailableSystemFormats();
const allDestinations = api.exportApi.getAllExportDestinations();
const fixedReportName = props.reportName;
const allReportNames = fixedReportName
? undefined
: api.exportApi.internalApi.getAllAvailableReportNames();
return (_jsx(ScheduledReportSettings, { reportSchedule: data, onChange: props.onChange, allFormats: allFormats ?? [], allDestinations: allDestinations ?? [], allReportNames: allReportNames, fixedReportName: fixedReportName }));
};