UNPKG

@adaptabletools/adaptable

Version:

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

89 lines (88 loc) 2.55 kB
import { EMPTY_ARRAY } from '../../Utilities/Constants/GeneralConstants'; import AdaptableHelper from '../../Utilities/Helpers/AdaptableHelper'; /** * @ReduxAction A Report has been selected */ export const REPORT_SELECT = 'REPORT_SELECT'; /** * @ReduxAction A Report has been added */ export const REPORT_ADD = 'REPORT_ADD'; /** * @ReduxAction A Report has been edited */ export const REPORT_EDIT = 'REPORT_EDIT'; /** * @ReduxAction A Report has been deleted */ export const REPORT_DELETE = 'REPORT_DELETE'; /** * @ReduxAction Export Module is ready */ export const EXPORT_READY = 'EXPORT_READY'; /** * @ReduxAction A report Format has been selected */ export const FORMAT_SELECT = 'FORMAT_SELECT'; export const ReportSelect = (SelectedReport) => ({ type: REPORT_SELECT, SelectedReport, }); export const ReportAdd = (report) => ({ type: REPORT_ADD, report, }); export const ReportEdit = (report) => ({ type: REPORT_EDIT, report, }); export const ReportDelete = (report) => ({ type: REPORT_DELETE, report, }); export const ExportReady = (exportState) => ({ type: EXPORT_READY, exportState, }); export const FormatSelect = (SelectedFormat) => ({ type: FORMAT_SELECT, SelectedFormat, }); const initialState = { Reports: EMPTY_ARRAY, }; export const ExportReducer = (state = initialState, action) => { let reports; switch (action.type) { case REPORT_SELECT: return Object.assign({}, state, { CurrentReport: action.SelectedReport, }); case REPORT_ADD: { const actionReport = action.report; AdaptableHelper.addAdaptableObjectPrimitives(actionReport); reports = [].concat(state.Reports); reports.push(actionReport); return { ...state, Reports: reports }; } case REPORT_EDIT: const actionReport = action.report; return { ...state, Reports: state.Reports.map((abObject) => abObject.Uuid === actionReport.Uuid ? actionReport : abObject), }; case REPORT_DELETE: { const actionReport = action.report; return { ...state, Reports: state.Reports.filter((abObject) => abObject.Uuid !== actionReport.Uuid), }; } case FORMAT_SELECT: return Object.assign({}, state, { CurrentFormat: action.SelectedFormat, }); default: return state; } };