// 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 from 'react'; import styled from 'styled-components'; import CloudTile from './cloud-tile'; import ImageModalContainer, {ImageModalContainerProps} from './image-modal-container'; import ProviderModalContainer, {ProviderModalContainerProps} from './provider-modal-container'; import StatusPanel, {UploadAnimation} from './status-panel'; import {MAP_THUMBNAIL_DIMENSION, MAP_INFO_CHARACTER} from 'constants/default-settings'; import { StyledModalContent, InputLight, TextAreaLight, StyledExportSection, StyledModalSection, StyledModalInputFootnote } from 'components/common/styled-components'; import ImagePreview from 'components/common/image-preview'; import {FormattedMessage} from 'localization'; import {ExportImage, MapInfo} from 'reducers'; import {Provider} from 'cloud-providers'; import {setMapInfo, cleanupExportImage} from 'actions'; /** @typedef {import('./save-map-modal').SaveMapModalProps} SaveMapModalProps */ const StyledSaveMapModal = styled.div.attrs({ className: 'save-map-modal' })` .save-map-modal-content { min-height: 400px; flex-direction: column; } .description { width: 300px; } .image-preview-panel { width: 300px; .image-preview { padding: 0; } } .map-info-panel { flex-direction: column; } .save-map-modal-description { .modal-section-subtitle { margin-left: 6px; } } `; const nop = _ => {}; type CharacterLimits = { title?: number; description?: number; }; type SaveMapModalProps = { mapInfo: MapInfo; exportImage: ExportImage; cloudProviders: Provider[]; isProviderLoading: boolean; currentProvider?: string; providerError?: any; characterLimits?: CharacterLimits; // callbacks onSetCloudProvider: ProviderModalContainerProps['onSetCloudProvider']; onUpdateImageSetting: ImageModalContainerProps['onUpdateImageSetting']; cleanupExportImage: typeof cleanupExportImage; onSetMapInfo: typeof setMapInfo; }; type MapInfoPanelProps = Pick & { onChangeInput: ( type: string, event: React.ChangeEvent ) => void; }; export const MapInfoPanel: React.FC = ({ mapInfo = {description: '', title: ''}, characterLimits, onChangeInput }) => (
Name*
onChangeInput('title', e)} placeholder="Type map title" />
Description
(optional)
onChangeInput('description', e)} placeholder="Type map description" />
Number(characterLimits?.description) } > {mapInfo.description.length}/ {characterLimits?.description || MAP_INFO_CHARACTER.description} characters
); function SaveMapModalFactory() { /** * @type {React.FunctionComponent} */ const SaveMapModal: React.FC = ({ mapInfo, exportImage, characterLimits = {}, cloudProviders, isProviderLoading, currentProvider, providerError, onSetCloudProvider, onUpdateImageSetting, cleanupExportImage, onSetMapInfo }) => { const onChangeInput = ( key: string, {target: {value}}: React.ChangeEvent ) => { onSetMapInfo({[key]: value}); }; const provider = currentProvider ? cloudProviders.find(p => p.name === currentProvider) : null; return (
{cloudProviders.map(cloudProvider => ( onSetCloudProvider(cloudProvider.name)} onSetCloudProvider={onSetCloudProvider} cloudProvider={cloudProvider} isSelected={cloudProvider.name === currentProvider} isConnected={Boolean( cloudProvider.getAccessToken && cloudProvider.getAccessToken() )} /> ))}
{provider && provider.getManagementUrl && (
)}
{isProviderLoading ? (
) : ( )}
{providerError ? ( ) : null} ); }; SaveMapModal.defaultProps = { characterLimits: MAP_INFO_CHARACTER, cloudProviders: [], providerError: null, isProviderLoading: false, onSetCloudProvider: nop, onUpdateImageSetting: nop }; return SaveMapModal; } export default SaveMapModalFactory;