@adaptabletools/adaptable
Version:
Powerful AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements
46 lines (45 loc) • 1.62 kB
JavaScript
import { createUuid } from '../../../AdaptableState/Uuid';
export function reportScheduleToSchedule(reportSchedule) {
const { ReportName: reportName, ScheduleType: _scheduleType, ...schedule } = reportSchedule;
return {
...schedule,
ReportName: reportSchedule.ReportName ?? reportName ?? '',
};
}
export function withReportName(schedule, reportName) {
return { ...schedule, ReportName: reportName };
}
export function normalizeScheduledReportSchedule(schedule) {
return schedule;
}
export function getScheduledReports(exportState) {
return exportState.ReportSchedules ?? [];
}
function ensureScheduleUuid(schedule) {
return schedule.Uuid ? schedule : { ...schedule, Uuid: createUuid() };
}
export function exportStateNeedsScheduleUuids(exportState) {
return (exportState.ReportSchedules ?? []).some((schedule) => !schedule.Uuid);
}
export function ensureExportStateSchedulesUuids(exportState) {
if (!exportStateNeedsScheduleUuids(exportState)) {
return exportState;
}
return {
...exportState,
ReportSchedules: (exportState.ReportSchedules ?? []).map(ensureScheduleUuid),
};
}
export function replaceScheduledReportScheduleInList(schedules, schedule) {
const index = schedules.findIndex((s) => s.Uuid === schedule.Uuid);
if (index < 0) {
return schedules;
}
const next = [...schedules];
next[index] = schedule;
return next;
}
export function countSchedulesForReport(exportState, reportName) {
return getScheduledReports(exportState).filter((s) => s.ReportName === reportName)
.length;
}