TagSpaces is an offline, open source, document manager with tagging support
add dialog resetState && LocalForm component
Stanimir Marinovfb6bbbaf2e85
diff --git a/app/components/LocationManager.js b/app/components/LocationManager.jsindex 8c9a88eea..000b4a643 100644--- a/app/components/LocationManager.js+++ b/app/components/LocationManager.js@@ -19,6 +19,7 @@import React from 'react';import { bindActionCreators } from 'redux';+import uuidv1 from 'uuid';import { connect } from 'react-redux';import { withStyles } from '@material-ui/core/styles';import classNames from 'classnames';@@ -100,7 +101,8 @@ type State = {isEditLocationDialogOpened?: boolean,isDeleteLocationDialogOpened?: boolean,isSelectDirectoryDialogOpened?: boolean,- isCreateDirectoryDialogOpened?: boolean+ isCreateDirectoryDialogOpened?: boolean,+ createLocationDialogKey: string};class LocationManager extends React.Component<Props, State> {@@ -117,7 +119,8 @@ class LocationManager extends React.Component<Props, State> {isEditLocationDialogOpened: false,isDeleteLocationDialogOpened: false,isCreateDirectoryDialogOpened: false,- isSelectDirectoryDialogOpened: false+ isSelectDirectoryDialogOpened: false,+ createLocationDialogKey: uuidv1()};handleCloseDialogs = () => {@@ -269,6 +272,12 @@ class LocationManager extends React.Component<Props, State> {}};+ resetState = (dialogKey) => {+ this.setState({+ [dialogKey]: uuidv1()+ });+ };+// <Tooltip id="tooltip-icon" title={i18n.t('core:moreOperations')} placement="bottom"></Tooltip>renderLocation = (location: Location) => (<ListItem@@ -327,6 +336,8 @@ class LocationManager extends React.Component<Props, State> {</Button><div><CreateLocationDialog+ key={this.state.createLocationDialogKey}+ resetState={this.resetState}open={this.state.isCreateLocationDialogOpened}onClose={this.handleCloseDialogs}addLocation={this.props.addLocation}diff --git a/app/components/dialogs/CreateLocationDialog.js b/app/components/dialogs/CreateLocationDialog.jsindex 133547013..f85e0b597 100644--- a/app/components/dialogs/CreateLocationDialog.js+++ b/app/components/dialogs/CreateLocationDialog.js@@ -19,34 +19,24 @@import React from 'react';import Button from '@material-ui/core/Button';-import TextField from '@material-ui/core/TextField';import uuidv1 from 'uuid';import { withStyles } from '@material-ui/core/styles';import DialogActions from '@material-ui/core/DialogActions';import DialogContent from '@material-ui/core/DialogContent';import DialogTitle from '@material-ui/core/DialogTitle';-import IconButton from '@material-ui/core/IconButton';-import FolderIcon from '@material-ui/icons/Folder';import Switch from '@material-ui/core/Switch';-import FormControl from '@material-ui/core/FormControl';import FormControlLabel from '@material-ui/core/FormControlLabel';-import FormHelperText from '@material-ui/core/FormHelperText';import FormGroup from '@material-ui/core/FormGroup';-import Input from '@material-ui/core/Input';-import InputLabel from '@material-ui/core/InputLabel';-import InputAdornment from '@material-ui/core/InputAdornment';import Grid from '@material-ui/core/Grid';import Radio from '@material-ui/core/Radio';import RadioGroup from '@material-ui/core/RadioGroup';-import FormLabel from '@material-ui/core/FormLabel';import GenericDialog, { onEnterKeyHandler } from './GenericDialog';import i18n from '../../services/i18n';-import PlatformIO from '../../services/platform-io';import { extractDirectoryName } from '../../utils/paths';import { type Location, locationType } from '../../reducers/locations';-import AppConfig from '../../config';import { Pro } from '../../pro';import ObjectStoreForm from './ObjectStoreForm';+import LocalForm from './LocalForm';const styles = theme => ({root: {@@ -69,6 +59,7 @@ type Props = {addLocation: (location: Location) => void,perspectives: Array<Object>,showSelectDirectoryDialog: () => void,+ resetState: () => void,selectedDirectoryPath?: string | null};@@ -76,7 +67,7 @@ type State = {errorTextPath?: boolean,errorTextName?: boolean,disableConfirmButton?: boolean,- open?: boolean,+ // open?: boolean,name?: string,path?: string,perspective?: string,@@ -92,18 +83,18 @@ class CreateLocationDialog extends React.Component<Props, State> {errorTextPath: false,errorTextName: false,disableConfirmButton: true,- open: false,+ // open: false,name: '',path: '',perspective: '',isDefault: false,isReadOnly: false,- watchForChanges: false,+ watchForChanges: !!Pro,persistIndex: false,type: locationType.TYPE_LOCAL};- componentWillReceiveProps = (nextProps: any) => {+ /* componentWillReceiveProps = (nextProps: any) => {if (nextProps.open === true) {const dir = nextProps.selectedDirectoryPath;this.setState({@@ -116,6 +107,10 @@ class CreateLocationDialog extends React.Component<Props, State> {persistIndex: false});}+ }; */++ componentWillUnmount = () => {+ console.log('CreateLocationDialog componentWillUnmount');};handleInputChange = (event: Object) => {@@ -185,24 +180,6 @@ class CreateLocationDialog extends React.Component<Props, State> {}}- openDirectory = () => {- if (AppConfig.isElectron) {- PlatformIO.selectDirectoryDialog().then((selectedPaths) => {- const newName = (this.state.name.length < 1) ? extractDirectoryName(selectedPaths[0]) : this.state.name;- this.setState({- name: newName,- path: selectedPaths[0]- });- this.handleValidation();- return true;- }).catch((err) => {- console.log('selectDirectoryDialog failed with: ' + err);- });- } else {- this.props.showSelectDirectoryDialog();- }- };-onConfirm = () => {if (!this.state.disableConfirmButton) {if (this.state.type === locationType.TYPE_LOCAL) {@@ -217,12 +194,12 @@ class CreateLocationDialog extends React.Component<Props, State> {persistIndex: this.state.persistIndex,watchForChanges: this.state.watchForChanges});- this.setState({- open: false,+ /* this.setState({+ // open: false,errorTextPath: false,errorTextName: false,disableConfirmButton: true- });+ }); */} else if (this.state.type === locationType.TYPE_CLOUD) {this.props.addLocation({uuid: uuidv1(),@@ -249,9 +226,9 @@ class CreateLocationDialog extends React.Component<Props, State> {cloudErrorSecretAccessKey: false,disableConfirmButton: true}); */- this.setState({});}this.props.onClose();+ this.props.resetState('createLocationDialogKey');}};@@ -260,58 +237,12 @@ class CreateLocationDialog extends React.Component<Props, State> {);renderContent = () => {- const { classes } = this.props;+ // const { classes } = this.props;let content;if (this.state.type === locationType.TYPE_CLOUD) {content = (<ObjectStoreForm handleInputChange={this.handleInputChange} handleChange={this.handleChange} state={this.state} />);} else {- content = (- <div>- <FormControl- fullWidth={true}- error={this.state.errorTextName}- >- <TextField- error={this.state.errorTextName}- required- margin="dense"- name="name"- label={i18n.t('core:createLocationName')}- onChange={this.handleInputChange}- value={this.state.name}- data-tid="locationName"- fullWidth={true}- />- {this.state.errorTextName && <FormHelperText>{i18n.t('core:invalidName')}</FormHelperText>}- </FormControl>- <FormControl- fullWidth={true}- error={this.state.errorTextPath}- >- <InputLabel htmlFor="path">{i18n.t('core:createLocationPath')}</InputLabel>- <Input- required- margin="dense"- name="path"- label={i18n.t('core:createLocationPath')}- fullWidth={true}- data-tid="locationPath"- onChange={this.handleInputChange}- value={this.state.path}- endAdornment={- <InputAdornment position="end" style={{ height: 32 }}>- <IconButton- onClick={this.openDirectory}- >- <FolderIcon />- </IconButton>- </InputAdornment>- }- />- {this.state.errorTextPath && <FormHelperText>{i18n.t('core:invalidPath')}</FormHelperText>}- </FormControl>- </div>- );+ content = (<LocalForm showSelectDirectoryDialog={this.props.showSelectDirectoryDialog} handleInputChange={this.handleInputChange} handleChange={this.handleChange} state={this.state} />);}return (<DialogContent>diff --git a/app/components/dialogs/LocalForm.js b/app/components/dialogs/LocalForm.jsnew file mode 100644index 000000000..89a963968--- /dev/null+++ b/app/components/dialogs/LocalForm.js@@ -0,0 +1,95 @@+/* eslint-disable react/prop-types, react/jsx-handler-names */++import React from 'react';++import InputAdornment from '@material-ui/core/InputAdornment';+import TextField from '@material-ui/core/TextField';+import FormControl from '@material-ui/core/FormControl';+import FormHelperText from '@material-ui/core/FormHelperText';+import Input from '@material-ui/core/Input';+import InputLabel from '@material-ui/core/InputLabel';+import IconButton from '@material-ui/core/IconButton';+import FolderIcon from '@material-ui/icons/Folder';+import i18n from '../../services/i18n';+import AppConfig from '../../config';+import { extractDirectoryName } from '../../utils/paths';+import PlatformIO from '../../services/platform-io';++type Props = {+ state: Object,+ handleChange: () => void,+ handleInputChange: () => void,+ showSelectDirectoryDialog: () => void+};++class LocalForm extends React.Component<Props> {+ openDirectory = () => {+ if (AppConfig.isElectron) {+ PlatformIO.selectDirectoryDialog().then((selectedPaths) => {+ this.props.handleChange('path', selectedPaths[0]);+ if (this.props.state.name.length < 1) {+ this.props.handleChange('name', extractDirectoryName(selectedPaths[0]));+ }+ return true;+ }).catch((err) => {+ console.log('selectDirectoryDialog failed with: ' + err);+ });+ } else {+ this.props.showSelectDirectoryDialog();+ }+ };++ render() {+ const { handleInputChange, state } = this.props;++ return (+ <div>+ <FormControl+ fullWidth={true}+ error={state.errorTextName}+ >+ <TextField+ error={state.errorTextName}+ required+ margin="dense"+ name="name"+ label={i18n.t('core:createLocationName')}+ onChange={handleInputChange}+ value={state.name}+ data-tid="locationName"+ fullWidth={true}+ />+ {state.errorTextName && <FormHelperText>{i18n.t('core:invalidName')}</FormHelperText>}+ </FormControl>+ <FormControl+ fullWidth={true}+ error={state.errorTextPath}+ >+ <InputLabel htmlFor="path">{i18n.t('core:createLocationPath')}</InputLabel>+ <Input+ required+ margin="dense"+ name="path"+ label={i18n.t('core:createLocationPath')}+ fullWidth={true}+ data-tid="locationPath"+ onChange={handleInputChange}+ value={state.path}+ endAdornment={+ <InputAdornment position="end" style={{ height: 32 }}>+ <IconButton+ onClick={this.openDirectory}+ >+ <FolderIcon />+ </IconButton>+ </InputAdornment>+ }+ />+ {state.errorTextPath && <FormHelperText>{i18n.t('core:invalidPath')}</FormHelperText>}+ </FormControl>+ </div>+ );+ }+}++export default LocalForm;diff --git a/app/components/dialogs/ObjectStoreForm-old.js b/app/components/dialogs/ObjectStoreForm-old.jsdeleted file mode 100644index 1b60874a7..000000000--- a/app/components/dialogs/ObjectStoreForm-old.js+++ /dev/null@@ -1,359 +0,0 @@-/**- * TagSpaces - universal file and folder organizer- * Copyright (C) 2017-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/>.- *- * @flow- */--import React from 'react';-import Select from 'react-select';-import FormControl from '@material-ui/core/FormControl';-import FormControlLabel from '@material-ui/core/FormControlLabel';-import FormHelperText from '@material-ui/core/FormHelperText';-import FormGroup from '@material-ui/core/FormGroup';-import Paper from '@material-ui/core/Paper';-import Grid from '@material-ui/core/Grid';-import Input from '@material-ui/core/Input';-import InputLabel from '@material-ui/core/InputLabel';-import TextField from '@material-ui/core/TextField';-import Typography from '@material-ui/core/Typography';-import MenuItem from '@material-ui/core/MenuItem';-import NoSsr from '@material-ui/core/NoSsr';-import { emphasize } from '@material-ui/core/styles/colorManipulator';-import { bindActionCreators } from 'redux';-import { connect } from 'react-redux';-import { withStyles } from '@material-ui/core/styles';-// import styles from './SidePanels.css';-import i18n from '../../services/i18n';-import { Pro } from '../../pro';--type Props = {- state: Object,- handleChange: () => void,- handleInputChange: () => void-};--type State = {-};--const styles = {- root: {- flexGrow: 1,- height: 250,- },- input: {- display: 'flex',- padding: 0,- marginTop: 10- },- valueContainer: {- display: 'flex',- flexWrap: 'wrap',- flex: 1,- alignItems: 'center',- overflow: 'hidden',- },- chip: {- // margin: `${theme.spacing.unit / 2}px ${theme.spacing.unit / 4}px`,- },- chipFocused: {- /* backgroundColor: emphasize(- // theme.palette.type === 'light' ? theme.palette.grey[300] : theme.palette.grey[700],- 0.08,- ), */- },- noOptionsMessage: {- // padding: `${theme.spacing.unit}px ${theme.spacing.unit * 2}px`,- },- singleValue: {- fontSize: 16,- },- placeholder: {- position: 'absolute',- left: 2,- fontSize: 16,- },- paper: {- // position: 'absolute',- zIndex: 1,- // marginTop: theme.spacing.unit,- left: 0,- right: 0,- }-};--class ObjectStoreFormOld extends React.Component<Props, State> {- suggestions = [- { label: 'US East (Ohio)', value: 'us-east-2' },- { label: 'US East (N. Virginia)', value: 'us-east-1' },- { label: 'US West (N. California)', value: 'us-west-1' },- { label: 'US West (Oregon)', value: 'us-west-2' },- { label: 'Asia Pacific (Mumbai)', value: 'ap-south-1' },- { label: 'Asia Pacific (Osaka-Local)', value: 'ap-northeast-3' },- { label: 'Asia Pacific (Seoul)', value: 'ap-northeast-2' },- { label: 'Asia Pacific (Singapore)', value: 'ap-southeast-1' },- { label: 'Asia Pacific (Sydney)', value: 'ap-southeast-2' },- { label: 'Asia Pacific (Tokyo)', value: 'ap-northeast-1' },- { label: 'Canada (Central)', value: 'ca-central-1' },- { label: 'China (Beijing)', value: 'cn-north-1' },- { label: 'China (Ningxia)', value: 'cn-northwest-1' },- { label: 'EU (Frankfurt)', value: 'eu-central-1' },- { label: 'EU (Ireland)', value: 'eu-west-1' },- { label: 'EU (London)', value: 'eu-west-2' },- { label: 'EU (Paris)', value: 'eu-west-3' },- { label: 'South America (São Paulo)', value: 'sa-east-1' },- ].map(suggestion => ({- value: suggestion.value,- label: suggestion.label,- }));-- NoOptionsMessage = (props) => (- <Typography- color="textSecondary"- // className={props.selectProps.classes.noOptionsMessage}- {...props.innerProps}- >- {props.children}- </Typography>- );-- inputComponent = ({ inputRef, ...props }) => <div ref={inputRef} {...props} />-- Control = (props) => (- <TextField- fullWidth- InputProps={{- inputComponent: this.inputComponent,- inputProps: {- style: styles.input,- inputRef: props.innerRef,- children: props.children,- ...props.innerProps,- },- }}- {...props.selectProps.textFieldProps}- />- )-- Option = (props) => (- <MenuItem- buttonRef={props.innerRef}- selected={props.isFocused}- component="div"- style={{- fontWeight: props.isSelected ? 500 : 400,- }}- {...props.innerProps}- >- {props.children}- </MenuItem>- );-- Placeholder = (props) => (- <Typography- color="textSecondary"- style={styles.placeholder}- {...props.innerProps}- >- {props.children}- </Typography>- );-- SingleValue = (props) => (- <Typography style={styles.singleValue} {...props.innerProps}>- {props.children}- </Typography>- );-- ValueContainer = (props) => <div style={styles.valueContainer}>{props.children}</div>-- /* MultiValue = (props) => (- <Chip- tabIndex={-1}- label={props.children}- className={classNames(props.selectProps.classes.chip, {- [props.selectProps.classes.chipFocused]: props.isFocused,- })}- onDelete={props.removeProps.onClick}- deleteIcon={<CancelIcon {...props.removeProps} />}- />- ) */-- Menu = (props) => (- <Paper square style={styles.paper} {...props.innerProps}>- {props.children}- </Paper>- );-- components = {- Control: this.Control,- Menu: this.Menu,- // MultiValue: this.MultiValue,- NoOptionsMessage: this.NoOptionsMessage,- Option: this.Option,- Placeholder: this.Placeholder,- SingleValue: this.SingleValue,- ValueContainer: this.ValueContainer,- };-- handleChange = name => value => {- this.props.handleChange(name, value.value);- };-- render() {- const { handleInputChange, state } = this.props;- const selectStyles = {- input: base => ({- ...base,- // color: theme.palette.text.primary,- flex: 1,- '& input': {- font: 'inherit',- },- }),- };-- return (- <Grid container spacing={24}>- <Grid item xs={12}>- <FormControl- fullWidth={true}- error={state.errorTextPath}- >- <InputLabel htmlFor="storeName">{i18n.t('core:createLocationName')}</InputLabel>- <Input- required- margin="dense"- name="storeName"- label={i18n.t('core:createLocationName')}- fullWidth={true}- data-tid="locationName"- onChange={handleInputChange}- value={state.storeName}- />- {state.errorTextPath && <FormHelperText>{i18n.t('core:invalidPath')}</FormHelperText>}- </FormControl>- </Grid>- <Grid item xs={12}>- <FormControl- fullWidth={true}- error={state.errorTextPath}- >- <InputLabel htmlFor="path">{i18n.t('core:createLocationPath')}</InputLabel>- <Input- required- margin="dense"- name="storePath"- label={i18n.t('core:createLocationPath')}- fullWidth={true}- data-tid="locationPath"- onChange={handleInputChange}- value={state.storePath}- />- {state.errorTextPath && <FormHelperText>{i18n.t('core:invalidPath')}</FormHelperText>}- </FormControl>- </Grid>- <Grid item xs={12}>- <FormControl- fullWidth={true}- error={state.errorTextPath}- >- <InputLabel htmlFor="accessKey">{i18n.t('core:accessKeyId')}</InputLabel>- <Input- required- margin="dense"- name="accessKey"- label={i18n.t('core:accessKeyId')}- fullWidth={true}- data-tid="accessKeyId"- onChange={handleInputChange}- value={state.accessKey}- />- {state.errorTextPath && <FormHelperText>{i18n.t('core:invalidPath')}</FormHelperText>}- </FormControl>- </Grid>- <Grid item xs={12}>- <FormControl- fullWidth={true}- error={state.errorTextPath}- >- <InputLabel htmlFor="secretAccessKey">{i18n.t('core:secretAccessKey')}</InputLabel>- <Input- required- margin="dense"- name="secretAccessKey"- label={i18n.t('core:secretAccessKey')}- fullWidth={true}- data-tid="secretAccessKey"- onChange={handleInputChange}- value={state.secretAccessKey}- />- {state.errorTextPath && <FormHelperText>{i18n.t('core:invalidPath')}</FormHelperText>}- </FormControl>- </Grid>- <Grid item xs={6}>- <FormControl- error={state.errorTextPath}- >- <InputLabel htmlFor="bucketName">{i18n.t('core:bucketName')}</InputLabel>- <Input- required- margin="dense"- name="bucketName"- label={i18n.t('core:bucketName')}- fullWidth={true}- data-tid="bucketName"- onChange={handleInputChange}- value={state.bucketName}- />- {state.errorTextPath && <FormHelperText>{i18n.t('core:invalidPath')}</FormHelperText>}- </FormControl>- </Grid>- <Grid item xs={6}>- <NoSsr>- <Select- options={this.suggestions}- styles={selectStyles}- fullWidth={true}- components={this.components}- value={state.region}- onChange={this.handleChange('region')}- // placeholder="Search a region"- />- {state.errorTextPath && <FormHelperText>{i18n.t('core:invalidPath')}</FormHelperText>}- </NoSsr>- </Grid>- </Grid>- );- }-}--/* function mapStateToProps(state) {- return {- };-} */--/* function mapDispatchToProps(dispatch) {- return bindActionCreators({- searchLocationIndex: AppActions.searchLocationIndex,- loadDirectoryContent: AppActions.loadDirectoryContent- }, dispatch);-} */--export default ObjectStoreFormOld;-/* export default withStyles(styles)(- S3Form- // connect(mapStateToProps, mapDispatchToProps)(Search)-); */diff --git a/app/components/dialogs/ObjectStoreForm.js b/app/components/dialogs/ObjectStoreForm.jsindex 621a2d6e6..db8b7903e 100644--- a/app/components/dialogs/ObjectStoreForm.js+++ b/app/components/dialogs/ObjectStoreForm.js@@ -40,10 +40,7 @@ const suggestions = [{ label: 'eu-west-2 (EU London)', value: 'eu-west-2' },{ label: 'eu-west-3 (EU Paris)', value: 'eu-west-3' },{ label: 'sa-east-1 (South America São Paulo)', value: 'sa-east-1' },-].map(suggestion => ({- value: suggestion.value,- label: suggestion.label,-}));+];const styles = theme => ({root: {@@ -209,7 +206,7 @@ type Props = {theme: Object};-class IntegrationReactSelect extends React.Component<Props> {+class ObjectStoreForm extends React.Component<Props> {handleChange = name => value => {this.props.handleChange(name, value);};@@ -386,4 +383,4 @@ class IntegrationReactSelect extends React.Component<Props> {}}-export default withStyles(styles, { withTheme: true })(IntegrationReactSelect);+export default withStyles(styles, { withTheme: true })(ObjectStoreForm);