UNPKG

@adaptabletools/adaptable

Version:

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

60 lines (59 loc) 5.33 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { useDispatch, useSelector } from 'react-redux'; import join from '../../components/utils/join'; import * as ExportRedux from '../../Redux/ActionsReducers/ExportRedux'; import * as PopupRedux from '../../Redux/ActionsReducers/PopupRedux'; import * as GeneralConstants from '../../Utilities/Constants/GeneralConstants'; import * as ModuleConstants from '../../Utilities/Constants/ModuleConstants'; import AdaptableHelper from '../../Utilities/Helpers/AdaptableHelper'; import ObjectFactory from '../../Utilities/ObjectFactory'; import { ButtonDelete } from '../Components/Buttons/ButtonDelete'; import { ButtonEdit } from '../Components/Buttons/ButtonEdit'; import { ButtonNew } from '../Components/Buttons/ButtonNew'; import { ButtonSchedule } from '../Components/Buttons/ButtonSchedule'; import { ReportNameSelector } from './ReportNameSelector'; import { ReportFormatSelector } from './ReportFormatSelector'; import { ExportDestinationPicker } from './ExportDestinationPicker'; import { Flex } from '../../components/Flex'; import { cn } from '../../lib/utils'; export const ExportViewPanel = (props) => { const dispatch = useDispatch(); const exportApi = props.api.exportApi; const userReports = useSelector((state) => state.Export.Reports); const currentReportName = useSelector((state) => state.Export.CurrentReport); const currentFormat = useSelector((state) => state.Export.CurrentFormat); const currentReport = exportApi.getReportByName(currentReportName); const accessLevel = AdaptableHelper.getAccessLevelForObject(currentReport, props.accessLevel); const scheduleCount = currentReport ? exportApi.getScheduledReports().filter((d) => d.ReportName === currentReport.Name).length : 0; const deleteMessage = currentReport ? scheduleCount > 0 ? `Are you sure you want to delete '${currentReport.Name}'? This will also delete ${scheduleCount} scheduled export(s).` : `Are you sure you want to delete '${currentReport.Name}'?` : 'Are you sure you want to delete this report?'; const isToolbar = props.viewType === 'Toolbar'; const elementType = isToolbar ? 'DashboardToolbar' : 'ToolPanel'; return (_jsxs(Flex, { flexDirection: "row", className: cn(`ab-${elementType}__CellSummary__wrap twa:gap-1 twa:flex-row`, { 'twa:min-w-[486px] twa:flex-nowrap': isToolbar, 'twa:flex-1 twa:flex-wrap': !isToolbar, }), children: [_jsx(ReportNameSelector, { viewType: props.viewType, reportName: currentReportName, userReports: userReports, onReportNameSelected: (reportName) => exportApi.selectReport(reportName) }), _jsx(ReportFormatSelector, { viewType: props.viewType, reportName: currentReportName, reportFormat: currentFormat, onReportFormatSelected: (reportFormat) => exportApi.selectFormat(reportFormat) }), _jsxs(Flex, { className: join(accessLevel == GeneralConstants.ACCESS_LEVEL_READ_ONLY ? GeneralConstants.READ_ONLY_STYLE : '', `ab-${elementType}__Export__controls twa:w-full`), children: [_jsx(Flex, { className: "twa:min-w-[44px]", children: _jsx(ExportDestinationPicker, { viewType: props.viewType, reportName: currentReportName, reportFormat: currentFormat }) }), _jsxs(Flex, { children: [_jsx(ButtonEdit, { onClick: () => dispatch(PopupRedux.PopupShowScreen(ModuleConstants.ExportModuleId, props.moduleInfo.Popup, { action: 'Edit', source: 'Toolbar', })), tooltip: "Edit Report", className: `ab-${elementType}__Export__edit`, disabled: currentReport == null, accessLevel: accessLevel }), _jsx(ButtonNew, { variant: "text", className: `ab-${elementType}__Export__new`, tone: "neutral", children: null, onClick: () => dispatch(PopupRedux.PopupShowScreen(ModuleConstants.ExportModuleId, props.moduleInfo.Popup, { action: 'New', source: 'Toolbar', })), tooltip: "Create New Report", accessLevel: props.accessLevel }), _jsx(ButtonDelete, { tooltip: "Delete Report", className: `ab-${elementType}__Export__delete`, disabled: currentReport == null, ConfirmAction: ExportRedux.ReportDelete(currentReport), ConfirmationMsg: deleteMessage, ConfirmationTitle: 'Delete Report', accessLevel: accessLevel }), _jsx(ButtonSchedule, { className: `ab-${elementType}__Export__schedule`, onClick: () => { const reportSchedule = ObjectFactory.CreateEmptyReportSchedule(currentFormat, currentReportName); dispatch(PopupRedux.PopupShowScreen(ModuleConstants.ExportModuleId, 'ExportPopup', { action: 'NewSchedule', source: 'Toolbar', value: { reportName: currentReportName, reportSchedule, }, })); }, tooltip: "Schedule", disabled: currentReport == null, accessLevel: props.accessLevel })] })] })] })); };