TagSpaces is an offline, open source, document manager with tagging support
chore: extracting perspective selection component
Ilian Sapundshiev5f14c8c5958a
diff --git a/app/components/EntryProperties.tsx b/app/components/EntryProperties.tsxindex f094bde64..344805e6f 100644--- a/app/components/EntryProperties.tsx+++ b/app/components/EntryProperties.tsx@@ -33,12 +33,8 @@ import Tooltip from '@material-ui/core/Tooltip';import LocationIcon from '@material-ui/icons/WorkOutline';import CloudLocationIcon from '@material-ui/icons/CloudQueue';import Select from '@material-ui/core/Select';-import Input from '@material-ui/core/Input';import MenuItem from '@material-ui/core/MenuItem';import ClearColorIcon from '@material-ui/icons/Backspace';-import ListItemIcon from '@material-ui/core/ListItemIcon';-import LayersClearIcon from '@material-ui/icons/LayersClear';-import ListItemText from '@material-ui/core/ListItemText';import {AttributionControl,Map,@@ -82,7 +78,7 @@ import { TS } from '-/tagspaces.namespace';import NoTileServer from '-/components/NoTileServer';import InfoIcon from '-/components/InfoIcon';import { ProTooltip } from '-/components/HelperComponents';-import { AvailablePerspectives } from '-/perspectives';+import PerspectiveSelector from '-/components/PerspectiveSelector';const ThumbnailChooserDialog =Pro && Pro.UI ? Pro.UI.ThumbnailChooserDialog : false;@@ -584,40 +580,6 @@ const EntryProperties = (props: Props) => {const showLinkForDownloading = isCloudLocation && currentEntry.isFile;- const perspectiveSelectorMenuItems = [];- perspectiveSelectorMenuItems.push(- <MenuItem style={{ display: 'flex' }} key="unspecified" value="unspecified">- <div style={{ display: 'flex' }}>- <ListItemIcon style={{ paddingLeft: 3, paddingTop: 3 }}>- <LayersClearIcon />- </ListItemIcon>- <ListItemText>{i18n.t('core:unspecified')}</ListItemText>- </div>- </MenuItem>- );-- AvailablePerspectives.forEach(perspective => {- let includePerspective = perspective.beta === false;- if (!Pro && perspective.pro === true) {- includePerspective = false;- }- if (Pro && perspective.beta === false) {- includePerspective = true;- }- if (includePerspective) {- perspectiveSelectorMenuItems.push(- <MenuItem key={perspective.key} value={perspective.id}>- <div style={{ display: 'flex' }}>- <ListItemIcon style={{ paddingLeft: 3, paddingTop: 3 }}>- {perspective.icon}- </ListItemIcon>- <ListItemText>{perspective.title}</ListItemText>- </div>- </MenuItem>- );- }- });-// @ts-ignorereturn (<div className={classes.entryProperties}>@@ -1217,15 +1179,11 @@ const EntryProperties = (props: Props) => {</div><ProTooltip tooltip={i18n.t('core:choosePerspective')}><FormControl fullWidth={true} className={classes.formControl}>- <Select- disabled={!Pro}- data-tid="changePerspectiveTID"- defaultValue={perspectiveDefault}+ <PerspectiveSelectoronChange={changePerspective}- input={<Input id="changePerspectiveId" />}- >- {perspectiveSelectorMenuItems}- </Select>+ defaultValue={perspectiveDefault}+ testId="changePerspectiveTID"+ /></FormControl></ProTooltip></Grid>diff --git a/app/components/PerspectiveSelector.tsx b/app/components/PerspectiveSelector.tsxnew file mode 100644index 000000000..2c0937b3f--- /dev/null+++ b/app/components/PerspectiveSelector.tsx@@ -0,0 +1,80 @@+/**+ * TagSpaces - universal file and folder organizer+ * Copyright (C) 2021-present TagSpaces UG (haftungsbeschraenkt)+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License (version 3) as+ * published by the Free Software Foundation.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ */++import React from 'react';+import Input from '@material-ui/core/Input';+import ListItemIcon from '@material-ui/core/ListItemIcon';+import LayersClearIcon from '@material-ui/icons/LayersClear';+import ListItemText from '@material-ui/core/ListItemText';+import Select from '@material-ui/core/Select';+import MenuItem from '@material-ui/core/MenuItem';+import { AvailablePerspectives } from '-/perspectives';+import i18n from '../services/i18n';+import { Pro } from '-/pro';++const PerspectiveSelector = props => {+ const { defaultValue, onChange, testId } = props;++ const perspectiveSelectorMenuItems = [];+ perspectiveSelectorMenuItems.push(+ <MenuItem style={{ display: 'flex' }} key="unspecified" value="unspecified">+ <div style={{ display: 'flex' }}>+ <ListItemIcon style={{ paddingLeft: 3, paddingTop: 3 }}>+ <LayersClearIcon />+ </ListItemIcon>+ <ListItemText>{i18n.t('core:unspecified')}</ListItemText>+ </div>+ </MenuItem>+ );++ AvailablePerspectives.forEach(perspective => {+ let includePerspective = perspective.beta === false;+ if (!Pro && perspective.pro === true) {+ includePerspective = false;+ }+ if (Pro && perspective.beta === false) {+ includePerspective = true;+ }+ if (includePerspective) {+ perspectiveSelectorMenuItems.push(+ <MenuItem key={perspective.key} value={perspective.id}>+ <div style={{ display: 'flex' }}>+ <ListItemIcon style={{ paddingLeft: 3, paddingTop: 3 }}>+ {perspective.icon}+ </ListItemIcon>+ <ListItemText>{perspective.title}</ListItemText>+ </div>+ </MenuItem>+ );+ }+ });++ return (+ <Select+ disabled={!Pro}+ data-tid={testId}+ defaultValue={defaultValue}+ onChange={onChange}+ input={<Input id="changePerspectiveId" />}+ >+ {perspectiveSelectorMenuItems}+ </Select>+ );+};++export default PerspectiveSelector;