Skip to content

TagSpaces is an offline, open source, document manager with tagging support

Refactor Create/Edit location dialog (#1292)

Stanimirec06222b3bb8
diff --git a/.github/workflows/workflow_scheduled.yml b/.github/workflows/workflow_scheduled.yml
index 8e23a92dc..afb14765d 100644
--- a/.github/workflows/workflow_scheduled.yml
+++ b/.github/workflows/workflow_scheduled.yml
@@ -248,3 +248,128 @@ jobs:
with:
name: test-reports
path: tests/test-reports/
+
+ e2eTestsElectronUbuntu:
+ name: E2E Ubuntu Electron
+ runs-on: ubuntu-latest
+ steps:
+ - name: Checking out default branch
+ uses: actions/checkout@v2
+ with:
+ ref: develop
+ submodules: true
+ - name: Checkout TestData
+ uses: actions/checkout@v2
+ with:
+ repository: tagspaces/testdata
+ path: tests/testdata
+ - uses: actions/setup-node@v2-beta
+ with:
+ node-version: '10.x'
+ - name: Running yarn install, prettier and type checks
+ run: |
+ yarn install --check-files --cache-folder .ycache
+ yarn prettier-check
+ yarn type-check
+ - name: Run Unit tests
+ run: yarn test-unit
+ - name: Run Electron tests
+ run: |
+ yarn install-ext
+ yarn build-main
+ yarn build-e2e
+ yarn test-e2e-electron
+
+ e2eTestsMinioUbuntu:
+ name: E2E Ubuntu Minio
+ runs-on: ubuntu-latest
+ steps:
+ - name: Checking out default branch
+ uses: actions/checkout@v2
+ with:
+ ref: develop
+ submodules: true
+ - name: Checkout TagspacesPro
+ uses: actions/checkout@v2
+ with:
+ repository: tagspaces/tagspacespro
+ token: ${{ secrets.CHECKOUT_TSPRO }}
+ path: extensions/tagspacespro
+ - name: Checkout TestData
+ uses: actions/checkout@v2
+ with:
+ repository: tagspaces/testdata
+ path: tests/testdata
+ - uses: actions/setup-node@v2-beta
+ with:
+ node-version: '10.x'
+ - name: Running yarn install, prettier and type checks
+ run: |
+ yarn install --check-files --cache-folder .ycache
+ yarn prettier-check
+ yarn type-check
+ - name: Run Unit tests
+ run: yarn test-unit
+ - uses: suisei-cn/actions-download-file@v1
+ id: minio
+ name: Download the Minio
+ with:
+ url: 'https://dl.min.io/server/minio/release/linux-amd64/minio'
+ target: tests/bin/
+ - name: Make the Minio executable
+ run: chmod +x ./tests/bin/minio
+ - name: Run Electron tests
+ run: |
+ yarn install-ext
+ yarn build-main
+ yarn build-e2e
+ yarn test-e2e-electron-minio
+
+ e2eTestsWebUbuntu:
+ name: E2E Ubuntu Web
+ runs-on: ubuntu-latest
+ steps:
+ - name: Checking out default branch
+ uses: actions/checkout@v2
+ with:
+ ref: develop
+ submodules: true
+ - name: Checkout TagspacesPro
+ uses: actions/checkout@v2
+ with:
+ repository: tagspaces/tagspacespro
+ token: ${{ secrets.CHECKOUT_TSPRO }}
+ path: extensions/tagspacespro
+ - name: Checkout TestData
+ uses: actions/checkout@v2
+ with:
+ repository: tagspaces/testdata
+ path: tests/testdata
+ - uses: actions/setup-node@v2-beta
+ with:
+ node-version: '10.x'
+ - name: Running yarn install, prettier and type checks
+ run: |
+ yarn install --check-files --cache-folder .ycache
+ yarn prettier-check
+ yarn type-check
+ - name: Run Unit tests
+ run: yarn test-unit
+ - uses: suisei-cn/actions-download-file@v1
+ id: minio
+ name: Download the Minio.exe
+ with:
+ url: 'https://dl.min.io/server/minio/release/linux-amd64/minio'
+ target: tests/bin/
+ - name: Make the Minio executable
+ run: chmod +x ./tests/bin/minio
+ - name: Run Electron tests
+ run: |
+ yarn install-ext
+ yarn build-main
+ yarn build-e2e
+ yarn test-e2e-web
+ - uses: actions/upload-artifact@v2
+ with:
+ name: test-reports
+ path: tests/test-reports/
diff --git a/app/components/LocationManager.tsx b/app/components/LocationManager.tsx
index 2571fe2df..caf180b4a 100644
--- a/app/components/LocationManager.tsx
+++ b/app/components/LocationManager.tsx
@@ -18,7 +18,6 @@
import React, { useEffect, useState } from 'react';
import { bindActionCreators } from 'redux';
-import uuidv1 from 'uuid';
import { connect } from 'react-redux';
import { withStyles } from '@material-ui/core/styles';
import List from '@material-ui/core/List';
@@ -32,36 +31,23 @@ import CustomLogo from './CustomLogo';
import {
actions as LocationActions,
getLocations,
- locationType,
Location
} from '../reducers/locations';
import { actions as AppActions } from '../reducers/app';
import { getPerspectives } from '-/reducers/settings';
import i18n from '../services/i18n';
import AppConfig from '../config';
-import PlatformIO from '../services/platform-io';
import LoadingLazy from '-/components/LoadingLazy';
import LocationView from '-/components/LocationView';
-const CreateLocationDialog = React.lazy(() =>
+const CreateEditLocationDialog = React.lazy(() =>
import(
- /* webpackChunkName: "CreateLocationDialog" */ './dialogs/CreateLocationDialog'
+ /* webpackChunkName: "CreateEditLocationDialog" */ './dialogs/CreateEditLocationDialog'
)
);
-const CreateLocationDialogAsync = props => (
+const CreateEditLocationDialogAsync = props => (
<React.Suspense fallback={<LoadingLazy />}>
- <CreateLocationDialog {...props} />
- </React.Suspense>
-);
-
-const EditLocationDialog = React.lazy(() =>
- import(
- /* webpackChunkName: "CreateLocationDialog" */ './dialogs/EditLocationDialog'
- )
-);
-const EditLocationDialogAsync = props => (
- <React.Suspense fallback={<LoadingLazy />}>
- <EditLocationDialog {...props} />
+ <CreateEditLocationDialog {...props} />
</React.Suspense>
);
@@ -172,7 +158,7 @@ const LocationManager = (props: Props) => {
)}
<div>
{isCreateLocationDialogOpened && (
- <CreateLocationDialogAsync
+ <CreateEditLocationDialogAsync
open={isCreateLocationDialogOpened}
onClose={() => setCreateLocationDialogOpened(false)}
addLocation={props.addLocation}
@@ -180,13 +166,12 @@ const LocationManager = (props: Props) => {
/>
)}
{isEditLocationDialogOpened && (
- <EditLocationDialogAsync
+ <CreateEditLocationDialogAsync
open={isEditLocationDialogOpened}
onClose={() => setEditLocationDialogOpened(false)}
location={selectedLocation}
editLocation={props.editLocation}
showSelectDirectoryDialog={showSelectDirectoryDialog}
- selectedDirectoryPath={selectedDirectoryPath}
/>
)}
{isDeleteLocationDialogOpened && (
diff --git a/app/components/dialogs/CreateEditLocationDialog.tsx b/app/components/dialogs/CreateEditLocationDialog.tsx
new file mode 100644
index 000000000..69b341ae7
--- /dev/null
+++ b/app/components/dialogs/CreateEditLocationDialog.tsx
@@ -0,0 +1,491 @@
+/**
+ * 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/>.
+ *
+ */
+
+import React, { ChangeEvent, useEffect, useState } from 'react';
+import Button from '@material-ui/core/Button';
+import uuidv1 from 'uuid';
+import { withStyles } from '@material-ui/core/styles';
+import withMobileDialog from '@material-ui/core/withMobileDialog';
+import DialogActions from '@material-ui/core/DialogActions';
+import DialogContent from '@material-ui/core/DialogContent';
+import DialogTitle from '@material-ui/core/DialogTitle';
+import Switch from '@material-ui/core/Switch';
+import FormControl from '@material-ui/core/FormControl';
+import FormControlLabel from '@material-ui/core/FormControlLabel';
+import FormGroup from '@material-ui/core/FormGroup';
+import Grid from '@material-ui/core/Grid';
+import Radio from '@material-ui/core/Radio';
+import RadioGroup from '@material-ui/core/RadioGroup';
+import { Typography } from '@material-ui/core';
+import Dialog from '@material-ui/core/Dialog';
+import i18n from '-/services/i18n';
+import { Location, locationType } from '-/reducers/locations';
+import { Pro } from '-/pro';
+import ObjectStoreForm from './ObjectStoreForm';
+import LocalForm from './LocalForm';
+import useFirstRender from '-/utils/useFirstRender';
+
+const styles: any = theme => ({
+ root: {
+ display: 'flex'
+ },
+ formControl: {
+ margin: theme.spacing(3)
+ },
+ group: {
+ margin: theme.spacing(1, 0),
+ display: 'flex',
+ flexDirection: 'row'
+ }
+});
+
+interface Props {
+ location?: Location;
+ open: boolean;
+ onClose: () => void;
+ fullScreen: boolean;
+ addLocation?: (location: Location) => void;
+ editLocation?: (location: Location) => void;
+ showSelectDirectoryDialog: () => void;
+}
+
+const CreateEditLocationDialog = (props: Props) => {
+ const [showAdvancedMode, setShowAdvancedMode] = useState<boolean>(false);
+ const [showSecretAccessKey, setShowSecretAccessKey] = useState<boolean>(
+ false
+ );
+ const [errorTextPath, setErrorTextPath] = useState<boolean>(false);
+ const [errorTextName, setErrorTextName] = useState<boolean>(false);
+ // const [errorTextId, setErrorTextId] = useState<boolean>(false);
+ const [name, setName] = useState<string>(
+ props.location && props.location.type === locationType.TYPE_LOCAL
+ ? props.location.name
+ : ''
+ );
+ const [path, setPath] = useState<string>(
+ props.location && props.location.type === locationType.TYPE_LOCAL
+ ? props.location.path
+ : ''
+ );
+ const [endpointURL, setEndpointURL] = useState<string>(
+ props.location ? props.location.endpointURL : ''
+ );
+ const [isDefault, setIsDefault] = useState<boolean>(
+ props.location ? props.location.isDefault : false
+ );
+ const [isReadOnly, setIsReadOnly] = useState<boolean>(
+ props.location ? props.location.isReadOnly : false
+ );
+ const [watchForChanges, setWatchForChanges] = useState<boolean>(
+ props.location ? props.location.watchForChanges : false
+ );
+ const [persistIndex, setPersistIndex] = useState<boolean>(
+ props.location ? props.location.persistIndex : false
+ );
+ const [fullTextIndex, setFullTextIndex] = useState<boolean>(
+ props.location ? props.location.fullTextIndex : false
+ );
+ const [storeName, setStoreName] = useState<string>(
+ props.location && props.location.type === locationType.TYPE_CLOUD
+ ? props.location.name
+ : ''
+ );
+ const [cloudErrorTextName, setCloudErrorTextName] = useState<boolean>(false);
+ // const [cloudErrorTextPath, setCloudErrorTextPath] = useState<boolean>(false);
+ const [cloudErrorAccessKey, setCloudErrorAccessKey] = useState<boolean>(
+ false
+ );
+ const [cloudErrorSecretAccessKey, setCloudErrorSecretAccessKey] = useState<
+ boolean
+ >(false);
+ // const [cloudErrorBucketName, setCloudErrorBucketName] = useState<boolean>(false);
+ // const [cloudErrorRegion, setCloudErrorRegion] = useState<boolean>(false);
+ const [accessKeyId, setAccessKeyId] = useState<string>(
+ props.location ? props.location.accessKeyId : ''
+ );
+ const [secretAccessKey, setSecretAccessKey] = useState<string>(
+ props.location ? props.location.secretAccessKey : ''
+ );
+ const [bucketName, setBucketName] = useState<string>(
+ props.location ? props.location.bucketName : ''
+ );
+ const [region, setRegion] = useState<string>(
+ props.location ? props.location.region : ''
+ );
+ const [storePath, setStorePath] = useState<string>(
+ props.location && props.location.type === locationType.TYPE_CLOUD
+ ? props.location.path
+ : ''
+ );
+ const [type, setType] = useState<string>(
+ props.location ? props.location.type : locationType.TYPE_LOCAL
+ );
+ const [newuuid, setNewUuid] = useState<string>(
+ props.location ? props.location.uuid : uuidv1()
+ );
+
+ const firstRender = useFirstRender();
+
+ useEffect(() => {
+ if (!firstRender) {
+ validateObjectStore();
+ }
+ }, [storeName, accessKeyId, secretAccessKey]);
+
+ useEffect(() => {
+ if (!firstRender) {
+ validateLocal();
+ }
+ }, [name, path]);
+
+ /**
+ * @param checkOnly - switch to set errors or only to check validation
+ * return true - have errors; false - no errors
+ */
+ const validateObjectStore = (checkOnly: boolean = false): boolean => {
+ if (!storeName || storeName.length === 0) {
+ if (checkOnly) return true;
+ setCloudErrorTextName(true);
+ } else if (!checkOnly) {
+ setCloudErrorTextName(false);
+ }
+
+ if (!accessKeyId || accessKeyId.length === 0) {
+ if (checkOnly) return true;
+ setCloudErrorAccessKey(true);
+ } else if (!checkOnly) {
+ setCloudErrorAccessKey(false);
+ }
+
+ if (!secretAccessKey || secretAccessKey.length === 0) {
+ if (checkOnly) return true;
+ setCloudErrorSecretAccessKey(true);
+ } else if (!checkOnly) {
+ setCloudErrorSecretAccessKey(false);
+ }
+ return false;
+ };
+
+ /**
+ * @param checkOnly - switch to set errors or only to check validation
+ * return true - have errors; false - no errors
+ */
+ const validateLocal = (checkOnly: boolean = false): boolean => {
+ if (!name || name.length === 0) {
+ if (checkOnly) return true;
+ setErrorTextName(true);
+ } else if (!checkOnly) {
+ setErrorTextName(false);
+ }
+ if (!path || path.length === 0) {
+ if (checkOnly) return true;
+ setErrorTextPath(true);
+ } else if (!checkOnly) {
+ setErrorTextPath(false);
+ }
+ return false;
+ };
+
+ const disableConfirmButton = () => {
+ if (type === locationType.TYPE_LOCAL) {
+ return errorTextName || errorTextPath || validateLocal(true);
+ }
+ return (
+ cloudErrorTextName ||
+ cloudErrorAccessKey ||
+ cloudErrorSecretAccessKey ||
+ validateObjectStore(true)
+ );
+ };
+
+ const { fullScreen, open, onClose } = props;
+
+ const onConfirm = () => {
+ if (!disableConfirmButton()) {
+ let loc;
+ if (type === locationType.TYPE_LOCAL) {
+ loc = {
+ uuid: props.location ? props.location.uuid : newuuid,
+ type,
+ name,
+ path,
+ paths: [path],
+ isDefault,
+ isReadOnly,
+ persistIndex,
+ fullTextIndex,
+ watchForChanges
+ };
+ } else if (type === locationType.TYPE_CLOUD) {
+ loc = {
+ uuid: props.location ? props.location.uuid : newuuid,
+ type,
+ name: storeName,
+ path: storePath,
+ paths: [storePath],
+ endpointURL,
+ accessKeyId,
+ secretAccessKey,
+ bucketName,
+ region,
+ isDefault,
+ isReadOnly,
+ persistIndex,
+ fullTextIndex,
+ watchForChanges: false
+ };
+ }
+
+ if (props.addLocation) {
+ props.addLocation(loc);
+ } else if (props.editLocation) {
+ loc.newuuid = newuuid;
+ props.editLocation(loc);
+ } else {
+ console.error('No addLocation or editLocation props exist');
+ }
+ onClose();
+ // this.props.resetState('createLocationDialogKey');
+ }
+ };
+
+ let content;
+ if (type === locationType.TYPE_CLOUD) {
+ content = (
+ <ObjectStoreForm
+ cloudErrorTextName={cloudErrorTextName}
+ cloudErrorTextPath={false}
+ cloudErrorAccessKey={cloudErrorAccessKey}
+ cloudErrorSecretAccessKey={cloudErrorSecretAccessKey}
+ cloudErrorBucketName={false}
+ cloudErrorRegion={false}
+ errorTextId={false}
+ showAdvancedMode={showAdvancedMode}
+ showSecretAccessKey={showSecretAccessKey}
+ storeName={storeName}
+ storePath={storePath}
+ accessKeyId={accessKeyId}
+ secretAccessKey={secretAccessKey}
+ setShowSecretAccessKey={setShowSecretAccessKey}
+ bucketName={bucketName}
+ region={region}
+ endpointURL={endpointURL}
+ newuuid={newuuid}
+ setStoreName={setStoreName}
+ setStorePath={setStorePath}
+ setAccessKeyId={setAccessKeyId}
+ setSecretAccessKey={setSecretAccessKey}
+ setBucketName={setBucketName}
+ setEndpointURL={setEndpointURL}
+ setNewUuid={setNewUuid}
+ setRegion={setRegion}
+ />
+ );
+ } else {
+ content = (
+ <LocalForm
+ showSelectDirectoryDialog={props.showSelectDirectoryDialog}
+ showAdvancedMode={showAdvancedMode}
+ errorTextPath={errorTextPath}
+ errorTextName={errorTextName}
+ errorTextId={false}
+ setName={setName}
+ setPath={setPath}
+ setNewUuid={setNewUuid}
+ path={path}
+ name={name}
+ newuuid={newuuid}
+ />
+ );
+ }
+
+ return (
+ <Dialog
+ open={open}
+ onClose={onClose}
+ fullScreen={fullScreen}
+ keepMounted
+ scroll="paper"
+ onKeyDown={event => {
+ if (event.key === 'Enter' || event.keyCode === 13) {
+ event.preventDefault();
+ event.stopPropagation();
+ onConfirm();
+ } else if (event.key === 'Escape') {
+ onClose();
+ }
+ }}
+ >
+ <DialogTitle>
+ {props.location
+ ? i18n.t('core:editLocationTitle')
+ : i18n.t('core:createLocationTitle')}
+ </DialogTitle>
+ <DialogContent>
+ <Grid container spacing={2}>
+ <Grid item xs={2} style={{ marginTop: 13, textAlign: 'left' }}>
+ <Typography>{i18n.t('core:locationType')}</Typography>
+ </Grid>
+ <Grid item xs={10}>
+ <FormControl disabled={!Pro}>
+ <RadioGroup
+ title={
+ Pro ? '' : i18n.t('core:thisFunctionalityIsAvailableInPro')
+ }
+ aria-label={i18n.t('core:locationType')}
+ name="type"
+ value={type}
+ onChange={(event: ChangeEvent<HTMLInputElement>) =>
+ setType(event.target.value)
+ }
+ row
+ >
+ <FormControlLabel
+ data-tid="localLocation"
+ value={locationType.TYPE_LOCAL}
+ control={<Radio />}
+ label="Local"
+ />
+ <FormControlLabel
+ data-tid="objectStorageLocation"
+ value={locationType.TYPE_CLOUD}
+ control={<Radio />}
+ title={i18n.t('core:objectStorageTitle')}
+ label={i18n.t('core:objectStorage')}
+ />
+ </RadioGroup>
+ </FormControl>
+ </Grid>
+ </Grid>
+ {content}
+ <FormGroup>
+ <FormControlLabel
+ control={
+ <Switch
+ data-tid="locationIsDefault"
+ name="isDefault"
+ checked={isDefault}
+ onChange={(event: ChangeEvent<HTMLInputElement>) =>
+ setIsDefault(event.target.checked)
+ }
+ />
+ }
+ label={i18n.t('core:startupLocation')}
+ />
+ <FormControlLabel
+ control={
+ <Switch
+ disabled={!Pro}
+ data-tid="changeFullTextIndex"
+ name="fullTextIndex"
+ checked={fullTextIndex}
+ onChange={(event: ChangeEvent<HTMLInputElement>) =>
+ setFullTextIndex(event.target.checked)
+ }
+ />
+ }
+ label={
+ i18n.t('core:createFullTextIndex') +
+ (Pro ? '' : ' - ' + i18n.t('core:proFeature'))
+ }
+ />
+ <FormControlLabel
+ control={
+ <Switch
+ disabled={!Pro || type === locationType.TYPE_CLOUD}
+ data-tid="changeWatchForChanges"
+ name="watchForChanges"
+ checked={watchForChanges}
+ onChange={(event: ChangeEvent<HTMLInputElement>) =>
+ setWatchForChanges(event.target.checked)
+ }
+ />
+ }
+ label={
+ i18n.t('core:watchForChangesInLocation') +
+ (Pro ? '' : ' - ' + i18n.t('core:proFeature'))
+ }
+ />
+ {showAdvancedMode && (
+ <FormControlLabel
+ control={
+ <Switch
+ disabled={!Pro}
+ data-tid="changeReadOnlyMode"
+ name="isReadOnly"
+ checked={isReadOnly}
+ onChange={(event: ChangeEvent<HTMLInputElement>) =>
+ setIsReadOnly(event.target.checked)
+ }
+ />
+ }
+ label={
+ i18n.t('core:readonlyModeSwitch') +
+ (Pro ? '' : ' - ' + i18n.t('core:proFeature'))
+ }
+ />
+ )}
+ {showAdvancedMode && (
+ <FormControlLabel
+ control={
+ <Switch
+ disabled={!Pro}
+ data-tid="changePersistIndex"
+ name="persistIndex"
+ checked={persistIndex}
+ onChange={(event: ChangeEvent<HTMLInputElement>) =>
+ setPersistIndex(event.target.checked)
+ }
+ />
+ }
+ label={
+ i18n.t('core:persistIndexSwitch') +
+ (Pro ? '' : ' - ' + i18n.t('core:proFeature'))
+ }
+ />
+ )}
+ </FormGroup>
+ </DialogContent>
+ <DialogActions style={{ justifyContent: 'space-between' }}>
+ <Button
+ data-tid="switchAdvancedModeTID"
+ onClick={() => setShowAdvancedMode(!showAdvancedMode)}
+ >
+ {showAdvancedMode
+ ? i18n.t('core:switchSimpleMode')
+ : i18n.t('core:switchAdvancedMode')}
+ </Button>
+ <div>
+ <Button onClick={() => onClose()} color="primary">
+ {i18n.t('core:cancel')}
+ </Button>
+ <Button
+ disabled={disableConfirmButton()}
+ onClick={onConfirm}
+ data-tid="confirmLocationCreation"
+ color="primary"
+ >
+ {i18n.t('core:ok')}
+ </Button>
+ </div>
+ </DialogActions>
+ </Dialog>
+ );
+};
+
+export default withStyles(styles)(withMobileDialog()(CreateEditLocationDialog));
diff --git a/app/components/dialogs/CreateLocationDialog.tsx b/app/components/dialogs/CreateLocationDialog.tsx
deleted file mode 100644
index 9f72ec3f7..000000000
--- a/app/components/dialogs/CreateLocationDialog.tsx
+++ /dev/null
@@ -1,432 +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/>.
- *
- */
-
-import React from 'react';
-import Button from '@material-ui/core/Button';
-import uuidv1 from 'uuid';
-import { withStyles } from '@material-ui/core/styles';
-import withMobileDialog from '@material-ui/core/withMobileDialog';
-import DialogActions from '@material-ui/core/DialogActions';
-import DialogContent from '@material-ui/core/DialogContent';
-import DialogTitle from '@material-ui/core/DialogTitle';
-import Switch from '@material-ui/core/Switch';
-import FormControl from '@material-ui/core/FormControl';
-import FormControlLabel from '@material-ui/core/FormControlLabel';
-import FormGroup from '@material-ui/core/FormGroup';
-import Grid from '@material-ui/core/Grid';
-import Radio from '@material-ui/core/Radio';
-import RadioGroup from '@material-ui/core/RadioGroup';
-import { Typography } from '@material-ui/core';
-import Dialog from '@material-ui/core/Dialog';
-import i18n from '-/services/i18n';
-import { Location, locationType } from '-/reducers/locations';
-import { Pro } from '-/pro';
-import ObjectStoreForm from './ObjectStoreForm';
-import LocalForm from './LocalForm';
-
-const styles: any = theme => ({
- root: {
- display: 'flex'
- },
- formControl: {
- margin: theme.spacing(3)
- },
- group: {
- margin: theme.spacing(1, 0),
- display: 'flex',
- flexDirection: 'row'
- }
-});
-
-interface Props {
- open: boolean;
- onClose: () => void;
- fullScreen: boolean;
- addLocation: (location: Location) => void;
- showSelectDirectoryDialog: () => void;
-}
-
-interface State {
- showAdvancedMode: boolean;
- showSecretAccessKey: boolean;
- errorTextPath: boolean;
- errorTextName: boolean;
- disableConfirmButton: boolean;
- name: string;
- path: string;
- newuuid: string;
- endpointURL: string;
- perspective: string;
- isDefault: boolean;
- isReadOnly: boolean;
- watchForChanges: boolean;
- persistIndex: boolean;
- fullTextIndex: boolean;
- storeName: string;
- cloudErrorTextName: boolean;
- cloudErrorAccessKey: boolean;
- cloudErrorSecretAccessKey: boolean;
- cloudErrorBucketName: boolean;
- cloudErrorRegion: boolean;
- accessKeyId: string;
- secretAccessKey: string;
- bucketName: string;
- region?: any;
- storePath: string;
- type: string;
-}
-
-class CreateLocationDialog extends React.Component<Props, State> {
- state = {
- showAdvancedMode: false,
- showSecretAccessKey: false,
- errorTextPath: false,
- errorTextName: false,
- disableConfirmButton: true,
- newuuid: uuidv1(),
- name: '',
- path: '',
- endpointURL: '',
- perspective: '',
- isDefault: false,
- isReadOnly: false,
- watchForChanges: false,
- persistIndex: false,
- fullTextIndex: false,
- storeName: '',
- cloudErrorTextName: false,
- cloudErrorAccessKey: false,
- cloudErrorSecretAccessKey: false,
- cloudErrorBucketName: false,
- cloudErrorRegion: false,
- accessKeyId: '',
- secretAccessKey: '',
- bucketName: '',
- region: undefined,
- storePath: '',
- type: locationType.TYPE_LOCAL
- };
-
- handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {
- const { target } = event;
- const value = target.type === 'checkbox' ? target.checked : target.value;
- const { name } = target;
- if (target.type === 'radio') {
- // type is changed (skip validation)
- // @ts-ignore
- this.setState({
- [name]: value
- });
- } else {
- this.handleChange(name, value);
- }
- };
-
- handleChange = (name, value) => {
- this.setState(
- // @ts-ignore
- {
- [name]: value
- },
- this.handleValidation
- );
- };
-
- switchAdvancedMode = () => {
- this.setState(prevState => ({
- showAdvancedMode: !prevState.showAdvancedMode
- }));
- };
-
- switchSecretAccessKeyVisibility = () => {
- this.setState(prevState => ({
- showSecretAccessKey: !prevState.showSecretAccessKey
- }));
- };
-
- handleValidation() {
- // const pathRegex = this.state.path.match('^((\.\./|[a-zA-Z0-9_/\-\\])*\.[a-zA-Z0-9]+)$');
- // const nameRegex = this.state.name.match('^[A-Z][-a-zA-Z]+$');
- if (this.state.type === locationType.TYPE_CLOUD) {
- let cloudErrorTextName = false;
- let cloudErrorAccessKey = false;
- let cloudErrorSecretAccessKey = false;
- let disableConfirmButton = false;
- if (!this.state.storeName || this.state.storeName.length === 0) {
- cloudErrorTextName = true;
- disableConfirmButton = true;
- }
-
- if (!this.state.accessKeyId || this.state.accessKeyId.length === 0) {
- cloudErrorAccessKey = true;
- disableConfirmButton = true;
- }
-
- if (
- !this.state.secretAccessKey ||
- this.state.secretAccessKey.length === 0
- ) {
- cloudErrorSecretAccessKey = true;
- disableConfirmButton = true;
- }
-
- // @ts-ignore
- this.setState({
- cloudErrorTextName,
- cloudErrorAccessKey,
- cloudErrorSecretAccessKey,
- disableConfirmButton
- });
- } else {
- let errorTextName = false;
- let errorTextPath = false;
- let disableConfirmButton = false;
- if (!this.state.name || this.state.name.length === 0) {
- errorTextName = true;
- disableConfirmButton = true;
- }
- if (!this.state.path || this.state.path.length === 0) {
- errorTextPath = true;
- disableConfirmButton = true;
- }
- this.setState({ errorTextName, errorTextPath, disableConfirmButton });
- }
- }
-
- onConfirm = () => {
- if (!this.state.disableConfirmButton) {
- if (this.state.type === locationType.TYPE_LOCAL) {
- this.props.addLocation({
- uuid: this.state.newuuid,
- type: locationType.TYPE_LOCAL,
- name: this.state.name,
- path: this.state.path,
- isDefault: this.state.isDefault,
- isReadOnly: this.state.isReadOnly,
- persistIndex: this.state.persistIndex,
- fullTextIndex: this.state.fullTextIndex,
- watchForChanges: this.state.watchForChanges
- });
- } else if (this.state.type === locationType.TYPE_CLOUD) {
- this.props.addLocation({
- uuid: this.state.newuuid,
- type: locationType.TYPE_CLOUD,
- name: this.state.storeName,
- path: this.state.storePath,
- endpointURL: this.state.endpointURL,
- accessKeyId: this.state.accessKeyId,
- secretAccessKey: this.state.secretAccessKey,
- bucketName: this.state.bucketName,
- region: this.state.region,
- isDefault: this.state.isDefault,
- isReadOnly: this.state.isReadOnly,
- persistIndex: this.state.persistIndex,
- fullTextIndex: this.state.fullTextIndex,
- watchForChanges: false
- });
- }
- this.props.onClose();
- // this.props.resetState('createLocationDialogKey');
- }
- };
-
- onCancel = () => {
- this.props.onClose();
- // this.props.resetState('createLocationDialogKey');
- };
-
- render() {
- const { fullScreen, open, onClose } = this.props;
-
- // const { classes } = this.props;
- let content;
- if (this.state.type === locationType.TYPE_CLOUD) {
- content = (
- <ObjectStoreForm
- switchSecretAccessKeyVisibility={this.switchSecretAccessKeyVisibility}
- handleInputChange={this.handleInputChange}
- handleChange={this.handleChange}
- state={this.state}
- />
- );
- } else {
- content = (
- <LocalForm
- showSelectDirectoryDialog={this.props.showSelectDirectoryDialog}
- handleInputChange={this.handleInputChange}
- handleChange={this.handleChange}
- state={this.state}
- />
- );
- }
-
- return (
- <Dialog
- open={open}
- onClose={onClose}
- fullScreen={fullScreen}
- keepMounted
- scroll="paper"
- onKeyDown={event => {
- if (event.key === 'Enter' || event.keyCode === 13) {
- event.preventDefault();
- event.stopPropagation();
- this.onConfirm();
- } else if (event.key === 'Escape') {
- onClose();
- }
- }}
- >
- <DialogTitle>{i18n.t('core:createLocationTitle')}</DialogTitle>
- <DialogContent>
- <Grid container spacing={2}>
- <Grid item xs={2} style={{ marginTop: 13, textAlign: 'left' }}>
- <Typography>{i18n.t('core:locationType')}</Typography>
- </Grid>
- <Grid item xs={10}>
- <FormControl disabled={!Pro}>
- <RadioGroup
- title={
- Pro ? '' : i18n.t('core:thisFunctionalityIsAvailableInPro')
- }
- aria-label={i18n.t('core:locationType')}
- name="type"
- value={this.state.type}
- onChange={this.handleInputChange}
- row
- >
- <FormControlLabel
- data-tid="localLocation"
- value={locationType.TYPE_LOCAL}
- control={<Radio />}
- label="Local"
- />
- <FormControlLabel
- data-tid="objectStorageLocation"
- value={locationType.TYPE_CLOUD}
- control={<Radio />}
- title={i18n.t('core:objectStorageTitle')}
- label={i18n.t('core:objectStorage')}
- />
- </RadioGroup>
- </FormControl>
- </Grid>
- </Grid>
- {content}
- <FormGroup>
- <FormControlLabel
- control={
- <Switch
- data-tid="locationIsDefault"
- name="isDefault"
- checked={this.state.isDefault}
- onChange={this.handleInputChange}
- />
- }
- label={i18n.t('core:startupLocation')}
- />
- {this.state.showAdvancedMode && (
- <FormControlLabel
- control={
- <Switch
- disabled={!Pro}
- data-tid="changeReadOnlyMode"
- name="isReadOnly"
- checked={this.state.isReadOnly}
- onChange={this.handleInputChange}
- />
- }
- label={
- i18n.t('core:readonlyModeSwitch') +
- (Pro ? '' : ' - ' + i18n.t('core:proFeature'))
- }
- />
- )}
- <FormControlLabel
- control={
- <Switch
- disabled={!Pro}
- data-tid="changeFullTextIndex"
- name="fullTextIndex"
- checked={this.state.fullTextIndex}
- onChange={this.handleInputChange}
- />
- }
- label={
- i18n.t('core:createFullTextIndex') +
- (Pro ? '' : ' - ' + i18n.t('core:proFeature'))
- }
- />
- {this.state.showAdvancedMode && (
- <FormControlLabel
- control={
- <Switch
- disabled={!Pro}
- data-tid="changePersistIndex"
- name="persistIndex"
- checked={this.state.persistIndex}
- onChange={this.handleInputChange}
- />
- }
- label={
- i18n.t('core:persistIndexSwitch') +
- (Pro ? '' : ' - ' + i18n.t('core:proFeature'))
- }
- />
- )}
- <FormControlLabel
- control={
- <Switch
- disabled={!Pro || this.state.type === locationType.TYPE_CLOUD}
- data-tid="changeWatchForChanges"
- name="watchForChanges"
- checked={this.state.watchForChanges}
- onChange={this.handleInputChange}
- />
- }
- label={
- i18n.t('core:watchForChangesInLocation') +
- (Pro ? '' : ' - ' + i18n.t('core:proFeature'))
- }
- />
- </FormGroup>
- </DialogContent>
- <DialogActions>
- <Button onClick={this.switchAdvancedMode}>
- {this.state.showAdvancedMode
- ? i18n.t('core:switchSimpleMode')
- : i18n.t('core:switchAdvancedMode')}
- </Button>
- <Button onClick={this.onCancel} color="primary">
- {i18n.t('core:cancel')}
- </Button>
- <Button
- disabled={this.state.disableConfirmButton}
- onClick={this.onConfirm}
- data-tid="confirmLocationCreation"
- color="primary"
- >
- {i18n.t('core:ok')}
- </Button>
- </DialogActions>
- </Dialog>
- );
- }
-}
-
-export default withStyles(styles)(withMobileDialog()(CreateLocationDialog));
diff --git a/app/components/dialogs/EditLocationDialog.tsx b/app/components/dialogs/EditLocationDialog.tsx
deleted file mode 100644
index ae869128e..000000000
--- a/app/components/dialogs/EditLocationDialog.tsx
+++ /dev/null
@@ -1,526 +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/>.
- *
- */
-
-import React from 'react';
-import withMobileDialog from '@material-ui/core/withMobileDialog';
-import Button from '@material-ui/core/Button';
-import DialogActions from '@material-ui/core/DialogActions';
-import DialogContent from '@material-ui/core/DialogContent';
-import DialogTitle from '@material-ui/core/DialogTitle';
-import Switch from '@material-ui/core/Switch';
-import FormControl from '@material-ui/core/FormControl';
-import FormControlLabel from '@material-ui/core/FormControlLabel';
-import FormGroup from '@material-ui/core/FormGroup';
-import Grid from '@material-ui/core/Grid';
-import Radio from '@material-ui/core/Radio';
-import RadioGroup from '@material-ui/core/RadioGroup';
-import { Typography } from '@material-ui/core';
-import Dialog from '@material-ui/core/Dialog';
-import i18n from '-/services/i18n';
-import { extractDirectoryName, getLocationPath } from '-/utils/paths';
-import { Location, locationType } from '-/reducers/locations';
-import ObjectStoreForm from './ObjectStoreForm';
-import LocalForm from './LocalForm';
-import { Pro } from '-/pro';
-import PlatformIO from '-/services/platform-io';
-
-interface Props {
- open: boolean;
- fullScreen?: boolean;
- onClose: () => void;
- location: Location | null;
- editLocation: (location: Location) => void;
- showSelectDirectoryDialog: () => void;
- selectedDirectoryPath: string | null;
- onCancel?: () => void;
-}
-
-interface State {
- showAdvancedMode: boolean;
- showSecretAccessKey: boolean;
- errorTextPath: boolean;
- errorTextName: boolean;
- errorTextId: boolean;
- disableConfirmButton: boolean;
- cloudErrorTextName: boolean;
- cloudErrorId: boolean;
- cloudErrorBucketName: boolean;
- cloudErrorRegion: boolean;
- cloudErrorAccessKey: boolean;
- cloudErrorSecretAccessKey: boolean;
- uuid: string;
- newuuid: string;
- name: string;
- path: string;
- endpointURL: string;
- isDefault: boolean;
- isReadOnly: boolean;
- watchForChanges: boolean;
- fullTextIndex: boolean;
- persistIndex: boolean;
- storeName: string;
- accessKeyId: string;
- secretAccessKey: string;
- bucketName: string;
- region?: any;
- storePath: string;
- type: string;
-}
-
-class EditLocationDialog extends React.Component<Props, State> {
- constructor(props) {
- super(props);
-
- if (props.open === true && props.location) {
- const dir = props.selectedDirectoryPath;
- let properties;
- if (props.location.type === locationType.TYPE_CLOUD) {
- properties = {
- storeName: dir
- ? extractDirectoryName(dir, PlatformIO.getDirSeparator())
- : props.location.name,
- storePath: dir || getLocationPath(props.location)
- };
- } else {
- properties = {
- // TODO maybe its better to separate name/path keys for different locationTypes ??
- name: dir
- ? extractDirectoryName(dir, PlatformIO.getDirSeparator())
- : props.location.name,
- path: dir || getLocationPath(props.location)
- };
- }
- this.state = {
- ...properties,
- showAdvancedMode: false,
- showSecretAccessKey: false,
- uuid: props.location.uuid,
- newuuid: props.location.uuid,
- isDefault: props.location.isDefault,
- isReadOnly: props.location.isReadOnly,
- watchForChanges: props.location.watchForChanges,
- persistIndex: props.location.persistIndex,
- fullTextIndex: props.location.fullTextIndex,
- type: props.location.type || locationType.TYPE_LOCAL,
- accessKeyId: props.location.accessKeyId,
- secretAccessKey: props.location.secretAccessKey,
- bucketName: props.location.bucketName,
- endpointURL: props.location.endpointURL,
- region: props.location.region
- };
- } else {
- this.state = {
- showAdvancedMode: false,
- showSecretAccessKey: false,
- errorTextPath: false,
- errorTextName: false,
- errorTextId: false,
- disableConfirmButton: true,
- cloudErrorTextName: false,
- cloudErrorBucketName: false,
- cloudErrorRegion: false,
- cloudErrorAccessKey: false,
- cloudErrorSecretAccessKey: false,
- cloudErrorId: false,
- uuid: '',
- newuuid: '',
- name: '',
- path: '',
- endpointURL: '',
- isDefault: false,
- isReadOnly: false,
- watchForChanges: false,
- persistIndex: false,
- fullTextIndex: false,
- storeName: '',
- accessKeyId: '',
- secretAccessKey: '',
- bucketName: '',
- region: undefined,
- storePath: '',
- type: locationType.TYPE_LOCAL
- };
- }
- }
-
- switchAdvancedMode = () => {
- this.setState(prevState => ({
- showAdvancedMode: !prevState.showAdvancedMode
- }));
- };
-
- switchSecretAccessKeyVisibility = () => {
- this.setState(prevState => ({
- showSecretAccessKey: !prevState.showSecretAccessKey
- }));
- };
-
- handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {
- const { target } = event;
- const value = target.type === 'checkbox' ? target.checked : target.value;
- const { name } = target;
- if (target.type === 'radio') {
- // type is changed (skip validation)
- // @ts-ignore
- this.setState({
- [name]: value
- });
- } else {
- this.handleChange(name, value);
- }
- };
-
- handleChange = (name, value) => {
- this.setState(
- // @ts-ignore
- {
- [name]: value
- },
- this.handleValidation
- );
- };
-
- handleValidation() {
- // const pathRegex = this.state.path.match('^((\.\./|[a-zA-Z0-9_/\-\\])*\.[a-zA-Z0-9]+)$');
- // const nameRegex = this.state.name.match('^[A-Z][-a-zA-Z]+$');
- if (this.state.type === locationType.TYPE_CLOUD) {
- let cloudErrorTextName = false;
- let cloudErrorAccessKey = false;
- let cloudErrorSecretAccessKey = false;
- let cloudErrorId = false;
- let disableConfirmButton = false;
- if (!this.state.storeName || this.state.storeName.length === 0) {
- cloudErrorTextName = true;
- disableConfirmButton = true;
- }
-
- if (!this.state.accessKeyId || this.state.accessKeyId.length === 0) {
- cloudErrorAccessKey = true;
- disableConfirmButton = true;
- }
-
- if (!this.state.uuid || this.state.uuid.length === 0) {
- cloudErrorId = true;
- disableConfirmButton = true;
- }
-
- if (
- !this.state.secretAccessKey ||
- this.state.secretAccessKey.length === 0
- ) {
- cloudErrorSecretAccessKey = true;
- disableConfirmButton = true;
- }
-
- // @ts-ignore
- this.setState({
- cloudErrorTextName,
- cloudErrorAccessKey,
- cloudErrorSecretAccessKey,
- cloudErrorId,
- disableConfirmButton
- });
- } else {
- let errorTextName = false;
- let errorTextPath = false;
- let errorTextId = false;
- let disableConfirmButton = false;
- if (!this.state.name || this.state.name.length === 0) {
- errorTextName = true;
- disableConfirmButton = true;
- }
- if (!this.state.path || this.state.path.length === 0) {
- errorTextPath = true; // make in optional in cloud mode
- disableConfirmButton = true;
- }
- if (!this.state.newuuid || this.state.newuuid.length === 0) {
- errorTextId = true;
- disableConfirmButton = true;
- }
- this.setState({
- errorTextName,
- errorTextPath,
- errorTextId,
- disableConfirmButton
- });
- }
- }
-
- /* openDirectory = () => {
- if (AppConfig.isElectron) {
- this.setState({ openDirectoryButtonDisabled: true });
- PlatformIO.selectDirectoryDialog().then((selectedPaths) => {
- const newName = (this.state.name.length < 1) ? extractDirectoryName(selectedPaths[0]) : this.state.name;
- this.setState({
- openDirectoryButtonDisabled: false,
- name: newName,
- path: selectedPaths[0]
- });
- this.handleValidation();
- return true;
- }).catch((err) => {
- this.setState({ openDirectoryButtonDisabled: false });
- console.log('selectDirectoryDialog failed with: ' + err);
- });
- } else {
- this.props.showSelectDirectoryDialog();
- }
- } */
-
- onConfirm = () => {
- if (!this.state.disableConfirmButton) {
- if (this.state.type === locationType.TYPE_LOCAL) {
- this.props.editLocation({
- uuid: this.state.uuid,
- newuuid: this.state.newuuid,
- type: locationType.TYPE_LOCAL,
- name: this.state.name,
- path: this.state.path,
- paths: [this.state.path], // deprecated, kept for compatibility with older versions
- isDefault: this.state.isDefault,
- isReadOnly: this.state.isReadOnly,
- persistIndex: this.state.persistIndex,
- fullTextIndex: this.state.fullTextIndex,
- watchForChanges: this.state.watchForChanges
- });
- } else if (this.state.type === locationType.TYPE_CLOUD) {
- this.props.editLocation({
- uuid: this.state.uuid,
- newuuid: this.state.newuuid,
- type: locationType.TYPE_CLOUD,
- name: this.state.storeName,
- path: this.state.storePath,
- paths: [this.state.storePath], // deprecated, kept for compatibility with older versions
- endpointURL: this.state.endpointURL,
- accessKeyId: this.state.accessKeyId,
- secretAccessKey: this.state.secretAccessKey,
- bucketName: this.state.bucketName,
- region: this.state.region,
- isDefault: this.state.isDefault,
- isReadOnly: this.state.isReadOnly,
- persistIndex: this.state.persistIndex,
- fullTextIndex: this.state.fullTextIndex,
- watchForChanges: false
- });
- }
- this.props.onClose();
- // this.props.resetState('editLocationDialogKey');
- }
- };
-
- onCancel = () => {
- this.props.onClose();
- // this.props.resetState('editLocationDialogKey');
- };
-
- renderTitle = () => (
- <DialogTitle>{i18n.t('core:editLocationTitle')}</DialogTitle>
- );
-
- renderContent = () => {
- let content;
- if (this.state.type === locationType.TYPE_CLOUD) {
- content = (
- <ObjectStoreForm
- switchSecretAccessKeyVisibility={this.switchSecretAccessKeyVisibility}
- handleInputChange={this.handleInputChange}
- handleChange={this.handleChange}
- state={this.state}
- />
- );
- } else {
- content = (
- <LocalForm
- showSelectDirectoryDialog={this.props.showSelectDirectoryDialog}
- handleInputChange={this.handleInputChange}
- handleChange={this.handleChange}
- state={this.state}
- />
- );
- }
- return (
- <DialogContent>
- <Grid container spacing={2}>
- <Grid item xs={2} style={{ marginTop: 13, textAlign: 'left' }}>
- <Typography>{i18n.t('core:locationType')}</Typography>
- </Grid>
- <Grid item xs={10}>
- <FormControl disabled={!Pro}>
- <RadioGroup
- title={
- Pro ? '' : i18n.t('core:thisFunctionalityIsAvailableInPro')
- }
- aria-label={i18n.t('core:locationType')}
- name="type"
- value={this.state.type}
- onChange={this.handleInputChange}
- row
- >
- <FormControlLabel
- value={locationType.TYPE_LOCAL}
- control={<Radio />}
- label="Local"
- />
- <FormControlLabel
- value={locationType.TYPE_CLOUD}
- control={<Radio />}
- title={i18n.t('core:objectStorageTitle')}
- label={i18n.t('core:objectStorage')}
- />
- </RadioGroup>
- </FormControl>
- </Grid>
- </Grid>
- {content}
- <FormControl>
- <FormGroup>
- <FormControlLabel
- control={
- <Switch
- data-tid="editStartupLocation"
- name="isDefault"
- checked={this.state.isDefault}
- onChange={this.handleInputChange}
- />
- }
- label={i18n.t('core:startupLocation')}
- />
- {this.state.showAdvancedMode && (
- <FormControlLabel
- control={
- <Switch
- disabled={!Pro}
- data-tid="changeReadOnlyMode"
- name="isReadOnly"
- checked={this.state.isReadOnly}
- onChange={this.handleInputChange}
- />
- }
- label={
- i18n.t('core:readonlyModeSwitch') +
- (Pro ? '' : ' - ' + i18n.t('core:proFeature'))
- }
- />
- )}
- <FormControlLabel
- control={
- <Switch
- disabled={!Pro}
- data-tid="changeFullTextIndex"
- name="fullTextIndex"
- checked={this.state.fullTextIndex}
- onChange={this.handleInputChange}
- />
- }
- label={
- i18n.t('core:createFullTextIndex') +
- (Pro ? '' : ' - ' + i18n.t('core:proFeature'))
- }
- />
- {this.state.showAdvancedMode && (
- <FormControlLabel
- control={
- <Switch
- disabled={!Pro}
- data-tid="changePersistIndex"
- name="persistIndex"
- checked={this.state.persistIndex}
- onChange={this.handleInputChange}
- />
- }
- label={
- i18n.t('core:persistIndexSwitch') +
- (Pro ? '' : ' - ' + i18n.t('core:proFeature'))
- }
- />
- )}
- <FormControlLabel
- control={
- <Switch
- disabled={!Pro || this.state.type === locationType.TYPE_CLOUD}
- data-tid="changeWatchForChanges"
- name="watchForChanges"
- checked={this.state.watchForChanges}
- onChange={this.handleInputChange}
- />
- }
- label={
- i18n.t('core:watchForChangesInLocation') +
- (Pro ? '' : ' - ' + i18n.t('core:proFeature'))
- }
- />
- </FormGroup>
- </FormControl>
- </DialogContent>
- );
- };
-
- renderActions = () => (
- <DialogActions>
- <Button onClick={this.switchAdvancedMode}>
- {this.state.showAdvancedMode
- ? i18n.t('core:switchSimpleMode')
- : i18n.t('core:switchAdvancedMode')}
- </Button>
- <Button
- data-tid="closeEditLocationDialog"
- color="primary"
- onClick={() => {
- this.props.onClose();
- // this.props.resetState('editLocationDialogKey');
- }}
- >
- {i18n.t('core:cancel')}
- </Button>
- <Button
- disabled={this.state.disableConfirmButton}
- onClick={this.onConfirm}
- data-tid="confirmEditLocationDialog"
- color="primary"
- >
- {i18n.t('core:ok')}
- </Button>
- </DialogActions>
- );
-
- render() {
- const { open, onClose, fullScreen, onCancel } = this.props;
- return (
- <Dialog
- open={open}
- onClose={onCancel}
- fullScreen={fullScreen}
- onKeyDown={event => {
- if (event.key === 'Enter' || event.keyCode === 13) {
- event.preventDefault();
- event.stopPropagation();
- this.onConfirm();
- } else if (event.key === 'Escape') {
- onClose();
- }
- }}
- >
- {this.renderTitle()}
- {this.renderContent()}
- {this.renderActions()}
- </Dialog>
- );
- }
-}
-
-export default withMobileDialog()(EditLocationDialog);
diff --git a/app/components/dialogs/LocalForm.tsx b/app/components/dialogs/LocalForm.tsx
index 834d86bdb..3f8d6237b 100644
--- a/app/components/dialogs/LocalForm.tsx
+++ b/app/components/dialogs/LocalForm.tsx
@@ -32,28 +32,46 @@ import { extractDirectoryName } from '-/utils/paths';
import PlatformIO from '-/services/platform-io';
interface Props {
- state: any;
- handleChange: (param1: string, param2: string) => void;
- handleInputChange: (event: any) => void;
showSelectDirectoryDialog: () => void;
+ showAdvancedMode: boolean;
+ errorTextPath: boolean;
+ errorTextName: boolean;
+ errorTextId: boolean;
+ setName: (string) => void;
+ setPath: (string) => void;
+ setNewUuid: (string) => void;
+ path: string;
+ name: string;
+ newuuid: string;
}
const LocalForm = (props: Props) => {
- function openDirectory() {
+ const {
+ errorTextPath,
+ errorTextName,
+ errorTextId,
+ setName,
+ setPath,
+ setNewUuid,
+ path,
+ name,
+ newuuid,
+ showAdvancedMode,
+ showSelectDirectoryDialog
+ } = props;
+
+ const openDirectory = () => {
if (AppConfig.isElectron) {
PlatformIO.selectDirectoryDialog()
.then(selectedPaths => {
const selectedPath = selectedPaths[0];
- props.handleChange('path', selectedPath);
- if (props.state.name.length < 1 && selectedPath.length > 0) {
+ setPath(selectedPath);
+ if (name.length < 1 && selectedPath.length > 0) {
const dirName = extractDirectoryName(
selectedPath,
PlatformIO.getDirSeparator()
);
- props.handleChange(
- 'name',
- dirName.charAt(0).toUpperCase() + dirName.slice(1)
- );
+ setName(dirName.charAt(0).toUpperCase() + dirName.slice(1));
}
return true;
})
@@ -61,15 +79,14 @@ const LocalForm = (props: Props) => {
console.log('selectDirectoryDialog failed with: ' + err);
});
} else {
- props.showSelectDirectoryDialog();
+ showSelectDirectoryDialog();
}
- }
+ };
- const { handleInputChange, state } = props;
return (
<Grid container spacing={2}>
<Grid item xs={12}>
- <FormControl fullWidth={true} error={state.errorTextPath}>
+ <FormControl fullWidth={true} error={errorTextPath}>
<InputLabel htmlFor="path">
{i18n.t('core:createLocationPath')}
</InputLabel>
@@ -80,8 +97,8 @@ const LocalForm = (props: Props) => {
name="path"
fullWidth={true}
data-tid="locationPath"
- onChange={handleInputChange}
- value={state.path}
+ onChange={event => setPath(event.target.value)}
+ value={path}
placeholder="Enter a folder path or select it with the button on the right"
endAdornment={
<InputAdornment position="end" style={{ height: 32 }}>
@@ -97,7 +114,7 @@ const LocalForm = (props: Props) => {
</FormControl>
</Grid>
<Grid item xs={12}>
- <FormControl fullWidth={true} error={state.errorTextName}>
+ <FormControl fullWidth={true} error={errorTextName}>
<InputLabel htmlFor="path">
{i18n.t('core:createLocationName')}
</InputLabel>
@@ -105,8 +122,8 @@ const LocalForm = (props: Props) => {
required
margin="dense"
name="name"
- onChange={handleInputChange}
- value={state.name}
+ onChange={event => setName(event.target.value)}
+ value={name}
data-tid="locationName"
fullWidth={true}
/>
@@ -115,9 +132,9 @@ const LocalForm = (props: Props) => {
)} */}
</FormControl>
</Grid>
- {state.showAdvancedMode && (
+ {showAdvancedMode && (
<Grid item xs={12}>
- <FormControl fullWidth={true} error={state.errorTextId}>
+ <FormControl fullWidth={true} error={errorTextId}>
<InputLabel htmlFor="newuuid">
{i18n.t('core:locationId')}
</InputLabel>
@@ -128,8 +145,8 @@ const LocalForm = (props: Props) => {
fullWidth={true}
data-tid="newuuid"
placeholder="Unique location identifier"
- onChange={handleInputChange}
- value={state.newuuid}
+ onChange={event => setNewUuid(event.target.value)}
+ value={newuuid}
/>
{/* {state.errorTextId && (
<FormHelperText>{i18n.t('core:invalidId')}</FormHelperText>
diff --git a/app/components/dialogs/ObjectStoreForm.tsx b/app/components/dialogs/ObjectStoreForm.tsx
index ec021042a..6e092d020 100644
--- a/app/components/dialogs/ObjectStoreForm.tsx
+++ b/app/components/dialogs/ObjectStoreForm.tsx
@@ -22,7 +22,6 @@ import Autocomplete from '@material-ui/lab/Autocomplete';
import TextField from '@material-ui/core/TextField';
import Grid from '@material-ui/core/Grid';
import FormControl from '@material-ui/core/FormControl';
-import FormHelperText from '@material-ui/core/FormHelperText';
import IconButton from '@material-ui/core/IconButton';
import Input from '@material-ui/core/Input';
import InputLabel from '@material-ui/core/InputLabel';
@@ -122,31 +121,80 @@ const styles: any = (theme: any) => ({
});
interface Props {
- state: any;
- handleChange: (name: string, value: any, action?: string) => void;
- handleInputChange: (event: any) => void;
- switchSecretAccessKeyVisibility: () => void;
classes: any;
theme: any;
+ cloudErrorTextName: boolean;
+ cloudErrorTextPath: boolean;
+ cloudErrorAccessKey: boolean;
+ cloudErrorSecretAccessKey: boolean;
+ cloudErrorBucketName: boolean;
+ cloudErrorRegion: boolean;
+ errorTextId: boolean;
+ showAdvancedMode: boolean;
+ showSecretAccessKey: boolean;
+ storeName: string;
+ storePath: string;
+ accessKeyId: string;
+ secretAccessKey: string;
+ bucketName: string;
+ region: string;
+ endpointURL: string;
+ newuuid: string;
+ setStoreName: (string) => void;
+ setStorePath: (string) => void;
+ setAccessKeyId: (string) => void;
+ setSecretAccessKey: (string) => void;
+ setShowSecretAccessKey: (boolean) => void;
+ setBucketName: (string) => void;
+ setRegion: (string) => void;
+ setEndpointURL: (string) => void;
+ setNewUuid: (string) => void;
}
const ObjectStoreForm = (props: Props) => {
- function handleRegionChange(inputValue: any, region: string, reason: string) {
+ const {
+ setShowSecretAccessKey,
+ cloudErrorTextName,
+ cloudErrorTextPath,
+ cloudErrorAccessKey,
+ cloudErrorSecretAccessKey,
+ cloudErrorBucketName,
+ cloudErrorRegion,
+ errorTextId,
+ showAdvancedMode,
+ showSecretAccessKey,
+ storeName,
+ storePath,
+ accessKeyId,
+ secretAccessKey,
+ bucketName,
+ region,
+ endpointURL,
+ newuuid,
+ setStoreName,
+ setStorePath,
+ setAccessKeyId,
+ setSecretAccessKey,
+ setBucketName,
+ setEndpointURL,
+ setNewUuid,
+ setRegion
+ } = props;
+
+ function handleRegionChange(inputValue: any, value: string, reason: string) {
if (reason === 'input') {
- props.handleChange('region', region, reason);
+ setRegion(value);
} else if (reason === 'select-option') {
- props.handleChange('region', region, reason);
+ setRegion(value);
}
if (reason === 'clear') {
- props.handleChange('region', '', reason);
+ setRegion('');
}
}
- const { handleInputChange, switchSecretAccessKeyVisibility, state } = props;
-
return (
<Grid container spacing={2}>
<Grid item xs={12}>
- <FormControl fullWidth={true} error={state.cloudErrorTextName}>
+ <FormControl fullWidth={true} error={cloudErrorTextName}>
<InputLabel htmlFor="storeName">
{i18n.t('core:createLocationName')}
</InputLabel>
@@ -157,8 +205,8 @@ const ObjectStoreForm = (props: Props) => {
name="storeName"
fullWidth={true}
data-tid="locationName"
- onChange={handleInputChange}
- value={state.storeName}
+ onChange={event => setStoreName(event.target.value)}
+ value={storeName}
/>
{/* {state.cloudErrorTextName && (
<FormHelperText>{i18n.t('core:invalidName')}</FormHelperText>
@@ -166,7 +214,7 @@ const ObjectStoreForm = (props: Props) => {
</FormControl>
</Grid>
<Grid item xs={12}>
- <FormControl fullWidth={true} error={state.cloudErrorTextPath}>
+ <FormControl fullWidth={true} error={cloudErrorTextPath}>
<InputLabel htmlFor="path">
{i18n.t('core:createLocationPath')}
</InputLabel>
@@ -175,8 +223,8 @@ const ObjectStoreForm = (props: Props) => {
name="storePath"
fullWidth={true}
data-tid="locationPath"
- onChange={handleInputChange}
- value={state.storePath}
+ onChange={event => setStorePath(event.target.value)}
+ value={storePath}
/>
{/* {state.cloudErrorTextPath && (
<FormHelperText>{i18n.t('core:invalidPath')}</FormHelperText>
@@ -184,7 +232,7 @@ const ObjectStoreForm = (props: Props) => {
</FormControl>
</Grid>
<Grid item xs={12}>
- <FormControl fullWidth={true} error={state.cloudErrorAccessKey}>
+ <FormControl fullWidth={true} error={cloudErrorAccessKey}>
<InputLabel htmlFor="accessKeyId">
{i18n.t('core:accessKeyId')}
</InputLabel>
@@ -193,8 +241,8 @@ const ObjectStoreForm = (props: Props) => {
name="accessKeyId"
fullWidth={true}
data-tid="accessKeyId"
- onChange={handleInputChange}
- value={state.accessKeyId}
+ onChange={event => setAccessKeyId(event.target.value)}
+ value={accessKeyId}
/>
{/* {state.cloudErrorAccessKey && (
<FormHelperText>{i18n.t('core:invalidAccessKey')}</FormHelperText>
@@ -202,29 +250,25 @@ const ObjectStoreForm = (props: Props) => {
</FormControl>
</Grid>
<Grid item xs={12}>
- <FormControl fullWidth={true} error={state.cloudErrorSecretAccessKey}>
+ <FormControl fullWidth={true} error={cloudErrorSecretAccessKey}>
<InputLabel htmlFor="secretAccessKey">
{i18n.t('core:secretAccessKey')}
</InputLabel>
<Input
margin="dense"
name="secretAccessKey"
- type={state.showSecretAccessKey ? 'text' : 'password'}
+ type={showSecretAccessKey ? 'text' : 'password'}
fullWidth={true}
data-tid="secretAccessKey"
- onChange={handleInputChange}
- value={state.secretAccessKey}
+ onChange={event => setSecretAccessKey(event.target.value)}
+ value={secretAccessKey}
endAdornment={
<InputAdornment position="end">
<IconButton
aria-label="toggle password visibility"
- onClick={switchSecretAccessKeyVisibility}
+ onClick={() => setShowSecretAccessKey(!showSecretAccessKey)}
>
- {state.showSecretAccessKey ? (
- <Visibility />
- ) : (
- <VisibilityOff />
- )}
+ {showSecretAccessKey ? <Visibility /> : <VisibilityOff />}
</IconButton>
</InputAdornment>
}
@@ -237,7 +281,7 @@ const ObjectStoreForm = (props: Props) => {
</FormControl>
</Grid>
<Grid item xs={12}>
- <FormControl fullWidth={true} error={state.cloudErrorBucketName}>
+ <FormControl fullWidth={true} error={cloudErrorBucketName}>
<InputLabel htmlFor="bucketName">
{i18n.t('core:bucketName')}
</InputLabel>
@@ -246,8 +290,8 @@ const ObjectStoreForm = (props: Props) => {
name="bucketName"
fullWidth={true}
data-tid="bucketName"
- onChange={handleInputChange}
- value={state.bucketName}
+ onChange={event => setBucketName(event.target.value)}
+ value={bucketName}
/>
{/* {state.cloudErrorBucketName && (
<FormHelperText>
@@ -257,10 +301,10 @@ const ObjectStoreForm = (props: Props) => {
</FormControl>
</Grid>
<Grid item xs={12}>
- <FormControl fullWidth={true} error={state.cloudErrorRegion}>
+ <FormControl fullWidth={true} error={cloudErrorRegion}>
<Autocomplete
options={regions}
- value={state.region}
+ value={region}
freeSolo
onChange={handleRegionChange}
onInputChange={handleRegionChange}
@@ -278,7 +322,7 @@ const ObjectStoreForm = (props: Props) => {
)} */}
</FormControl>
</Grid>
- {state.showAdvancedMode && (
+ {showAdvancedMode && (
<Grid item xs={12}>
<FormControl fullWidth={true}>
<InputLabel htmlFor="endpointURL">
@@ -290,8 +334,8 @@ const ObjectStoreForm = (props: Props) => {
fullWidth={true}
data-tid="endpointURL"
placeholder="Advanced setting, could be left empty"
- onChange={handleInputChange}
- value={state.endpointURL}
+ onChange={event => setEndpointURL(event.target.value)}
+ value={endpointURL}
/>
{/* {state.cloudErrorId && (
<FormHelperText>{i18n.t('core:missingId')}</FormHelperText>
@@ -299,9 +343,9 @@ const ObjectStoreForm = (props: Props) => {
</FormControl>
</Grid>
)}
- {state.showAdvancedMode && (
+ {showAdvancedMode && (
<Grid item xs={12}>
- <FormControl fullWidth={true}>
+ <FormControl fullWidth={true} error={errorTextId}>
<InputLabel htmlFor="newuuid">
{i18n.t('core:locationId')}
</InputLabel>
@@ -311,8 +355,8 @@ const ObjectStoreForm = (props: Props) => {
fullWidth={true}
data-tid="newuuid"
placeholder="Advanced setting"
- onChange={handleInputChange}
- value={state.newuuid}
+ onChange={event => setNewUuid(event.target.value)}
+ value={newuuid}
/>
</FormControl>
</Grid>
diff --git a/app/locales/en/core.json b/app/locales/en/core.json
index c04a784d7..48e83b592 100644
--- a/app/locales/en/core.json
+++ b/app/locales/en/core.json
@@ -492,5 +492,11 @@
"openLink": "Open Link",
"invalidLink": "Invalid Link",
"link": "Link",
+ "desktopFolder": "Desktop",
+ "documentsFolder": "Documents",
+ "downloadsFolder": "Downloads",
+ "musicFolder": "Music",
+ "picturesFolder": "Pictures",
+ "videosFolder": "Videos",
"-": "-"
}
diff --git a/app/reducers/locations.ts b/app/reducers/locations.ts
index 767e54c12..03a52f827 100644
--- a/app/reducers/locations.ts
+++ b/app/reducers/locations.ts
@@ -18,7 +18,8 @@
import uuidv1 from 'uuid';
import { immutablySwapItems } from '-/utils/misc';
-import { actions as AppActions } from '../reducers/app';
+import { actions as AppActions } from '-/reducers/app';
+import i18n from '-/services/i18n';
import PlatformIO from '-/services/platform-io';
import AppConfig from '-/config';
@@ -159,7 +160,7 @@ export const actions = {
{
uuid: uuidv1(),
type: locationType.TYPE_LOCAL,
- name: key, // TODO use i18n
+ name: i18n.t(key),
path: devicePaths[key],
isDefault: AppConfig.isWeb && devicePaths[key] === '/files/', // Used for the web ts demo
isReadOnly: false,
@@ -195,7 +196,16 @@ export const actions = {
// disableObjectStoreSupport to revoke objectStoreAPI cached object
PlatformIO.disableObjectStoreSupport();
}
- dispatch(AppActions.openLocation(location));
+ /**
+ * check if location uuid is changed
+ */
+ if (location.newuuid !== location.uuid) {
+ dispatch(
+ AppActions.openLocation({ ...location, uuid: location.newuuid })
+ );
+ } else {
+ dispatch(AppActions.openLocation(location));
+ }
dispatch(AppActions.setReadOnlyMode(location.isReadOnly || false));
},
changeLocation: (location: Location) => ({
diff --git a/app/services/electron-io.ts b/app/services/electron-io.ts
index ddca9c0fa..e33031b10 100644
--- a/app/services/electron-io.ts
+++ b/app/services/electron-io.ts
@@ -160,12 +160,12 @@ export default class ElectronIO {
getDevicePaths = (): Object => {
const paths = {
- Desktop: this.app.getPath('desktop'),
- Documents: this.app.getPath('documents'),
- Downloads: this.app.getPath('downloads'),
- Music: this.app.getPath('music'),
- Pictures: this.app.getPath('pictures'),
- Videos: this.app.getPath('videos')
+ desktopFolder: this.app.getPath('desktop'),
+ documentsFolder: this.app.getPath('documents'),
+ downloadsFolder: this.app.getPath('downloads'),
+ musicFolder: this.app.getPath('music'),
+ picturesFolder: this.app.getPath('pictures'),
+ videosFolder: this.app.getPath('videos')
};
return paths;
};
diff --git a/app/utils/useFirstRender.ts b/app/utils/useFirstRender.ts
new file mode 100644
index 000000000..40daff593
--- /dev/null
+++ b/app/utils/useFirstRender.ts
@@ -0,0 +1,11 @@
+import { useRef, useEffect } from 'react';
+
+export default function useFirstRender() {
+ const firstRender = useRef(true);
+
+ useEffect(() => {
+ firstRender.current = false;
+ }, []);
+
+ return firstRender.current;
+}
diff --git a/tests/e2e/location.e2e.js b/tests/e2e/location.e2e.js
index 0c577fdf2..fc7765f9e 100644
--- a/tests/e2e/location.e2e.js
+++ b/tests/e2e/location.e2e.js
@@ -95,7 +95,7 @@ describe('TST03 - Testing locations:', () => {
await openLocationMenu(testLocationName);
await clickOn('[data-tid=editLocation]');
await setInputKeys('locationName', newLocationName);
- await clickOn('[data-tid=confirmEditLocationDialog]');
+ await clickOn('[data-tid=confirmLocationCreation]');
/*await delay(500);
await global.client.$('[data-tid=locationList]');
const allLocationsList = await global.client.getText(
diff --git a/tests/e2e/location.helpers.js b/tests/e2e/location.helpers.js
index 18f800425..cbb442bfc 100644
--- a/tests/e2e/location.helpers.js
+++ b/tests/e2e/location.helpers.js
@@ -60,13 +60,9 @@ export async function createMinioLocation(
const lastLocationTID = await getLocationTid(-1);
// Check if location not exist (from extconfig.js)
if (locationName !== lastLocationTID) {
- const elem = await global.client.$('[data-tid=createNewLocation]');
- await elem.click();
-
- const objectStorageLocation = await global.client.$(
- '[data-tid=objectStorageLocation]'
- );
- await objectStorageLocation.click();
+ await clickOn('[data-tid=createNewLocation]');
+ await clickOn('[data-tid=objectStorageLocation]');
+ await clickOn('[data-tid=switchAdvancedModeTID]');
// SET LOCATION NAME
await setInputKeys(
@@ -79,7 +75,6 @@ export async function createMinioLocation(
await setInputKeys('bucketName', locationName);
await setInputKeys('endpointURL', minioEndpointURL);
- // await delay(1500);
if (isDefault) {
await clickOn('[data-tid=locationIsDefault]');
}
@@ -230,8 +225,8 @@ export async function aboutDialogExt(title, ext) {
export async function startupLocation() {
await clickOn('[data-tid=editLocation]');
// await global.client.pause(500);
- await clickOn('[data-tid=editStartupLocation]');
- await clickOn('[data-tid=confirmEditLocationDialog]');
+ await clickOn('[data-tid=locationIsDefault]');
+ await clickOn('[data-tid=confirmLocationCreation]');
}
/**