// Copyright (c) 2022 Uber Technologies, Inc. // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. import React, {Component} from 'react'; import {EXPORT_DATA_TYPE_OPTIONS} from 'constants/default-settings'; import {FileType} from 'components/common/icons'; import { StyledExportSection, StyledFilteredOption, StyledModalContent, StyledType, CheckMark } from 'components/common/styled-components'; import {injectIntl, IntlShape} from 'react-intl'; import {FormattedMessage} from 'localization'; import {Datasets} from 'reducers'; const getDataRowCount = ( datasets: Datasets, selectedDataset: string | undefined, filtered: boolean, intl: IntlShape ) => { if (selectedDataset === undefined) { return undefined; } const selectedData = datasets[selectedDataset]; if (!selectedData) { return intl.formatMessage( {id: 'modal.exportData.fileCount'}, {fileCount: Object.keys(datasets).length} ); } const {dataContainer, filteredIdxCPU} = selectedData; if (filtered && !filteredIdxCPU) { return '-'; } const rowCount = filtered ? filteredIdxCPU?.length : dataContainer.numRows(); return intl.formatMessage( {id: 'modal.exportData.rowCount'}, {rowCount: rowCount?.toLocaleString()} ); }; export interface ExportDataModalProps { datasets: Datasets; selectedDataset?: string; dataType: string; filtered: boolean; // callbacks applyCPUFilter: (filter: string | string[]) => void; onChangeExportSelectedDataset: (dataset: string) => void; onChangeExportDataType: (type: string) => void; onChangeExportFiltered: (isFiltered: boolean) => void; intl: IntlShape; supportedDataTypes: { id: string; label: string; available: boolean; }[]; } const ExportDataModalFactory = () => { class ExportDataModal extends Component { componentDidMount() { const toCPUFilter = this.props.selectedDataset || Object.keys(this.props.datasets); this.props.applyCPUFilter(toCPUFilter); } _onSelectDataset: React.ChangeEventHandler = ({target: {value}}) => { this.props.applyCPUFilter(value); this.props.onChangeExportSelectedDataset(value); }; render() { const { supportedDataTypes = EXPORT_DATA_TYPE_OPTIONS, datasets, selectedDataset, dataType, filtered, onChangeExportDataType, onChangeExportFiltered, intl } = this.props; return (
{supportedDataTypes.map(op => ( op.available && onChangeExportDataType(op.id)} > {dataType === op.id && } ))}
onChangeExportFiltered(false)} >
{getDataRowCount(datasets, selectedDataset, false, intl)}
{!filtered && }
onChangeExportFiltered(true)} >
{getDataRowCount(datasets, selectedDataset, true, intl)}
{filtered && }
); } } return injectIntl(ExportDataModal); }; export default ExportDataModalFactory;