Skip to content

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

refactoring location dialogs, adding endpoint dialog

Ilian Sapundshiev5f31ff652c45
diff --git a/app/components/dialogs/CreateLocationDialog.tsx b/app/components/dialogs/CreateLocationDialog.tsx
index 767855b1c..37299209e 100644
--- a/app/components/dialogs/CreateLocationDialog.tsx
+++ b/app/components/dialogs/CreateLocationDialog.tsx
@@ -68,6 +68,7 @@ interface State {
disableConfirmButton: boolean;
name: string;
path: string;
+ endpointURL: string;
perspective: string;
isDefault: boolean;
isReadOnly: boolean;
@@ -75,11 +76,11 @@ interface State {
persistIndex: boolean;
fullTextIndex: boolean;
storeName: string;
- cloudErrorTextName: string;
- cloudErrorAccessKey: string;
- cloudErrorSecretAccessKey: string;
- cloudErrorBucketName: string;
- cloudErrorRegion: string;
+ cloudErrorTextName: boolean;
+ cloudErrorAccessKey: boolean;
+ cloudErrorSecretAccessKey: boolean;
+ cloudErrorBucketName: boolean;
+ cloudErrorRegion: boolean;
accessKeyId: string;
secretAccessKey: string;
bucketName: string;
@@ -95,6 +96,7 @@ class CreateLocationDialog extends React.Component<Props, State> {
disableConfirmButton: true,
name: '',
path: '',
+ endpointURL: '',
perspective: '',
isDefault: false,
isReadOnly: false,
@@ -102,11 +104,11 @@ class CreateLocationDialog extends React.Component<Props, State> {
persistIndex: false,
fullTextIndex: false,
storeName: '',
- cloudErrorTextName: '',
- cloudErrorAccessKey: '',
- cloudErrorSecretAccessKey: '',
- cloudErrorBucketName: '',
- cloudErrorRegion: '',
+ cloudErrorTextName: false,
+ cloudErrorAccessKey: false,
+ cloudErrorSecretAccessKey: false,
+ cloudErrorBucketName: false,
+ cloudErrorRegion: false,
accessKeyId: '',
secretAccessKey: '',
bucketName: '',
@@ -278,7 +280,9 @@ class CreateLocationDialog extends React.Component<Props, State> {
disableConfirmButton,
cloudErrorRegion
},
- resolve(!disableConfirmButton)
+ () => {
+ resolve(!disableConfirmButton);
+ }
)
);
}
@@ -311,10 +315,11 @@ class CreateLocationDialog extends React.Component<Props, State> {
type: locationType.TYPE_CLOUD,
name: this.state.storeName,
paths: [this.state.storePath],
+ endpointURL: this.state.endpointURL,
accessKeyId: this.state.accessKeyId,
secretAccessKey: this.state.secretAccessKey,
bucketName: this.state.bucketName,
- region: this.state.region.value,
+ region: this.state.region,
perspective: this.state.perspective,
isDefault: this.state.isDefault,
isReadOnly: this.state.isReadOnly,
diff --git a/app/components/dialogs/EditLocationDialog.tsx b/app/components/dialogs/EditLocationDialog.tsx
index cef1171d5..c215d304d 100644
--- a/app/components/dialogs/EditLocationDialog.tsx
+++ b/app/components/dialogs/EditLocationDialog.tsx
@@ -34,7 +34,7 @@ import Dialog from '@material-ui/core/Dialog';
import i18n from '-/services/i18n';
import { extractDirectoryName } from '-/utils/paths';
import { Location, locationType } from '-/reducers/locations';
-import ObjectStoreForm, { suggestions } from './ObjectStoreForm';
+import ObjectStoreForm from './ObjectStoreForm';
import LocalForm from './LocalForm';
import { Pro } from '-/pro';
@@ -54,12 +54,15 @@ interface State {
errorTextPath: boolean;
errorTextName: boolean;
disableConfirmButton: boolean;
- cloudErrorTextName: string;
- cloudErrorBucketName: string;
- cloudErrorRegion: string;
+ cloudErrorTextName: boolean;
+ cloudErrorBucketName: boolean;
+ cloudErrorRegion: boolean;
+ cloudErrorAccessKey: boolean;
+ cloudErrorSecretAccessKey: boolean;
uuid: string;
name: string;
path: string;
+ endpointURL: string;
isDefault: boolean;
isReadOnly: boolean;
watchForChanges: boolean;
@@ -79,12 +82,15 @@ class EditLocationDialog extends React.Component<Props, State> {
errorTextPath: false,
errorTextName: false,
disableConfirmButton: true,
- cloudErrorTextName: '',
- cloudErrorBucketName: '',
- cloudErrorRegion: '',
+ cloudErrorTextName: false,
+ cloudErrorBucketName: false,
+ cloudErrorRegion: false,
+ cloudErrorAccessKey: false,
+ cloudErrorSecretAccessKey: false,
uuid: '',
name: '',
path: '',
+ endpointURL: '',
isDefault: false,
isReadOnly: false,
watchForChanges: false,
@@ -118,7 +124,6 @@ class EditLocationDialog extends React.Component<Props, State> {
this.setState({
...properties,
uuid: nextProps.location.uuid,
- perspective: nextProps.location.perspective,
isDefault: nextProps.location.isDefault,
isReadOnly: nextProps.location.isReadOnly,
watchForChanges: nextProps.location.watchForChanges,
@@ -128,7 +133,8 @@ class EditLocationDialog extends React.Component<Props, State> {
accessKeyId: nextProps.location.accessKeyId,
secretAccessKey: nextProps.location.secretAccessKey,
bucketName: nextProps.location.bucketName,
- region: suggestions.find(obj => obj.value === nextProps.location.region)
+ endpointURL: nextProps.location.endpointURL,
+ region: nextProps.location.region
});
}
};
@@ -163,11 +169,10 @@ class EditLocationDialog extends React.Component<Props, State> {
// const nameRegex = this.state.name.match('^[A-Z][-a-zA-Z]+$');
if (this.state.type === locationType.TYPE_CLOUD) {
let cloudErrorTextName = false;
- // let cloudErrorTextPath = false;
- const cloudErrorAccessKey = false;
- const cloudErrorSecretAccessKey = false;
+ let cloudErrorAccessKey = false;
+ let cloudErrorSecretAccessKey = false;
let cloudErrorBucketName = false;
- let cloudErrorRegion = false;
+ const cloudErrorRegion = false;
let disableConfirmButton = false;
if (!this.state.storeName || this.state.storeName.length === 0) {
cloudErrorTextName = true;
@@ -179,30 +184,35 @@ class EditLocationDialog extends React.Component<Props, State> {
disableConfirmButton = true;
} */
- // if (!this.state.accessKeyId || this.state.accessKeyId.length === 0) {
- // cloudErrorAccessKey = 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;
- // }
+ if (
+ !this.state.secretAccessKey ||
+ this.state.secretAccessKey.length === 0
+ ) {
+ cloudErrorSecretAccessKey = true;
+ disableConfirmButton = true;
+ }
if (!this.state.bucketName || this.state.bucketName.length === 0) {
cloudErrorBucketName = true;
disableConfirmButton = true;
}
- if (!this.state.region) {
- cloudErrorRegion = true;
- disableConfirmButton = true;
- }
+ // if (!this.state.region) {
+ // cloudErrorRegion = true;
+ // disableConfirmButton = true;
+ // }
// @ts-ignore
this.setState({
cloudErrorTextName,
cloudErrorBucketName,
+ cloudErrorAccessKey,
+ cloudErrorSecretAccessKey,
disableConfirmButton,
cloudErrorRegion
});
@@ -263,10 +273,11 @@ class EditLocationDialog extends React.Component<Props, State> {
type: locationType.TYPE_CLOUD,
name: this.state.storeName,
paths: [this.state.storePath],
+ endpointURL: this.state.endpointURL,
accessKeyId: this.state.accessKeyId,
secretAccessKey: this.state.secretAccessKey,
bucketName: this.state.bucketName,
- region: this.state.region.value,
+ region: this.state.region,
isDefault: this.state.isDefault,
isReadOnly: this.state.isReadOnly,
persistIndex: this.state.persistIndex,
diff --git a/app/components/dialogs/ObjectStoreForm.tsx b/app/components/dialogs/ObjectStoreForm.tsx
index f91660f0a..6c5e764e7 100644
--- a/app/components/dialogs/ObjectStoreForm.tsx
+++ b/app/components/dialogs/ObjectStoreForm.tsx
@@ -17,42 +17,35 @@
*/
import React from 'react';
-import CreatableSelect from 'react-select/creatable';
import { withStyles } from '@material-ui/core/styles';
-import Typography from '@material-ui/core/Typography';
-import NoSsr from '@material-ui/core/NoSsr';
+import Autocomplete from '@material-ui/lab/Autocomplete';
import TextField from '@material-ui/core/TextField';
-import Paper from '@material-ui/core/Paper';
import Grid from '@material-ui/core/Grid';
-import MenuItem from '@material-ui/core/MenuItem';
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 i18n from '-/services/i18n';
-export const suggestions = [
- { label: 'us-east-2 (US East Ohio)', value: 'us-east-2' },
- { label: 'us-east-1 (US East N. Virginia)', value: 'us-east-1' },
- { label: 'us-west-1 (US West N. California)', value: 'us-west-1' },
- { label: 'us-west-2 (US West Oregon)', value: 'us-west-2' },
- { label: 'ap-south-1 (Asia Pacific Mumbai)', value: 'ap-south-1' },
- {
- label: 'ap-northeast-3 (Asia Pacific Osaka-Local)',
- value: 'ap-northeast-3'
- },
- { label: 'ap-northeast-2 (Asia Pacific Seoul)', value: 'ap-northeast-2' },
- { label: 'ap-southeast-1 (Asia Pacific Singapore)', value: 'ap-southeast-1' },
- { label: 'ap-southeast-2 (Asia Pacific Sydney)', value: 'ap-southeast-2' },
- { label: 'ap-northeast-1 (Asia Pacific Tokyo)', value: 'ap-northeast-1' },
- { label: 'ca-central-1 (Canada Central)', value: 'ca-central-1' },
- { label: 'cn-north-1 (China Beijing)', value: 'cn-north-1' },
- { label: 'cn-northwest-1 (China Ningxia)', value: 'cn-northwest-1' },
- { label: 'eu-central-1 (EU Frankfurt)', value: 'eu-central-1' },
- { label: 'eu-west-1 (EU Ireland)', value: 'eu-west-1' },
- { 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' }
+export const regions = [
+ 'us-east-2',
+ 'us-east-1',
+ 'us-west-1',
+ 'us-west-2',
+ 'ap-south-1',
+ 'ap-northeast-3',
+ 'ap-northeast-2',
+ 'ap-southeast-1',
+ 'ap-southeast-2',
+ 'ap-northeast-1',
+ 'ca-central-1',
+ 'cn-north-1',
+ 'cn-northwest-1',
+ 'eu-central-1',
+ 'eu-west-1',
+ 'eu-west-2',
+ 'eu-west-3',
+ 'sa-east-1'
];
const styles: any = (theme: any) => ({
@@ -96,147 +89,28 @@ const styles: any = (theme: any) => ({
}
});
-function NoOptionsMessage(props) {
- return (
- <Typography
- color="textSecondary"
- className={props.selectProps.classes.noOptionsMessage}
- {...props.innerProps}
- >
- {props.children}
- </Typography>
- );
-}
-
-function inputComponent({ inputRef, ...props }) {
- return <div ref={inputRef} {...props} />;
-}
-
-function Control(props) {
- return (
- <TextField
- fullWidth
- InputProps={{
- inputComponent,
- inputProps: {
- className: props.selectProps.classes.input,
- inputRef: props.innerRef,
- children: props.children,
- ...props.innerProps
- }
- }}
- {...props.selectProps.textFieldProps}
- />
- );
-}
-
-function Option(props) {
- return (
- <MenuItem
- ref={props.innerRef}
- selected={props.isFocused}
- component="div"
- style={{
- fontWeight: props.isSelected ? 500 : 400
- }}
- {...props.innerProps}
- >
- {props.children}
- </MenuItem>
- );
-}
-
-function Placeholder(props) {
- return (
- <Typography
- color="textSecondary"
- className={props.selectProps.classes.placeholder}
- {...props.innerProps}
- >
- {props.children}
- </Typography>
- );
-}
-
-function SingleValue(props) {
- return (
- <Typography
- className={props.selectProps.classes.singleValue}
- {...props.innerProps}
- >
- {props.children}
- </Typography>
- );
-}
-
-function ValueContainer(props) {
- return (
- <div className={props.selectProps.classes.valueContainer}>
- {props.children}
- </div>
- );
-}
-
-function Menu(props) {
- return (
- <Paper
- elevation={2}
- square
- className={props.selectProps.classes.paper}
- {...props.innerProps}
- >
- {props.children}
- </Paper>
- );
-}
-
-const components = {
- Control,
- Menu,
- MultiValue: undefined,
- NoOptionsMessage,
- Option,
- Placeholder,
- SingleValue,
- ValueContainer
-};
-
interface Props {
state: any;
- handleChange: (name: string, value: any) => void;
+ handleChange: (name: string, value: any, action: string) => void;
handleInputChange: (event: any) => void;
classes: any;
theme: any;
}
class ObjectStoreForm extends React.Component<Props> {
- handleChange = name => value => {
- this.props.handleChange(name, value);
- };
-
- handleInputSelectChange = (inputValue: any, actionMeta: any) => {
- if (actionMeta.action === 'set-value') {
- suggestions.push({
- label: this.props.state.region,
- value: this.props.state.region
- });
- } else if (actionMeta.action === 'input-change') {
- this.props.handleChange('region', inputValue);
+ handleRegionChange = (inputValue: any, region: string, reason: string) => {
+ if (reason === 'input') {
+ this.props.handleChange('region', region, reason);
+ } else if (reason === 'select-option') {
+ this.props.handleChange('region', region, reason);
+ }
+ if (reason === 'clear') {
+ this.props.handleChange('region', '', reason);
}
};
render() {
- const { classes, theme, handleInputChange, state } = this.props;
-
- const selectStyles = {
- input: base => ({
- ...base,
- color: theme.palette.text.primary,
- '& input': {
- font: 'inherit'
- }
- })
- };
+ const { handleInputChange, state } = this.props;
return (
<Grid container spacing={2}>
@@ -316,8 +190,8 @@ class ObjectStoreForm extends React.Component<Props> {
)}
</FormControl>
</Grid>
- <Grid item xs={5}>
- <FormControl error={state.cloudErrorBucketName}>
+ <Grid item xs={12}>
+ <FormControl fullWidth={true} error={state.cloudErrorBucketName}>
<InputLabel htmlFor="bucketName">
{i18n.t('core:bucketName')}
</InputLabel>
@@ -337,27 +211,49 @@ class ObjectStoreForm extends React.Component<Props> {
)}
</FormControl>
</Grid>
- <Grid item xs={7}>
+ <Grid item xs={12}>
<FormControl fullWidth={true} error={state.cloudErrorRegion}>
- <NoSsr>
- <CreatableSelect
- isClearable
- classes={classes}
- options={suggestions}
- styles={selectStyles}
- fullWidth={true}
- components={components}
- value={state.region}
- onChange={this.handleChange('region')}
- onInputChange={this.handleInputSelectChange}
- placeholder={i18n.t('core:regionSearch')}
- />
- </NoSsr>
+ <Autocomplete
+ options={regions}
+ value={state.region}
+ freeSolo
+ onChange={this.handleRegionChange}
+ onInputChange={this.handleRegionChange}
+ placeholder={i18n.t('core:regionSearch')}
+ renderInput={params => (
+ <TextField
+ {...params}
+ label={i18n.t('core:regionSearch')}
+ margin="normal"
+ />
+ )}
+ />
{state.cloudErrorRegion && (
<FormHelperText>{i18n.t('core:invalidRegion')}</FormHelperText>
)}
</FormControl>
</Grid>
+ <Grid item xs={12}>
+ <FormControl fullWidth={true} error={state.cloudErrorSecretAccessKey}>
+ <InputLabel htmlFor="endpointURL">
+ {i18n.t('core:endpointURL')}
+ </InputLabel>
+ <Input
+ margin="dense"
+ name="endpointURL"
+ fullWidth={true}
+ data-tid="endpointURL"
+ placeholder="Advanced setting, could be left empty"
+ onChange={handleInputChange}
+ value={state.endpointURL}
+ />
+ {state.cloudErrorSecretAccessKey && (
+ <FormHelperText>
+ {i18n.t('core:invalidEndpointUrl')}
+ </FormHelperText>
+ )}
+ </FormControl>
+ </Grid>
</Grid>
);
}
diff --git a/app/perspectives/grid-perspective/components/CellContent.tsx b/app/perspectives/grid-perspective/components/CellContent.tsx
index 9968ebb70..9b74bb0d1 100644
--- a/app/perspectives/grid-perspective/components/CellContent.tsx
+++ b/app/perspectives/grid-perspective/components/CellContent.tsx
@@ -198,12 +198,10 @@ const CellContent = (props: Props) => {
</Typography>
</div>
) : (
- <div className={classes.gridDetails}>
+ <div className={classes.gridDetails} title={fsEntry.path}>
<FolderIcon
className={classes.gridFolder}
style={{ backgroundColor: fsEntryColor }}
- // @ts-ignore
- title={fsEntry.path}
/>
</div>
)}
diff --git a/app/reducers/location-index.ts b/app/reducers/location-index.ts
index 9b78ce517..10c0d8c24 100644
--- a/app/reducers/location-index.ts
+++ b/app/reducers/location-index.ts
@@ -265,7 +265,8 @@ export const actions = {
});
const result = locationPaths.reduce(
(accumulatorPromise, nextPath) =>
- accumulatorPromise.then(() => createDirectoryIndex(nextPath, extractText)
+ accumulatorPromise.then(() =>
+ createDirectoryIndex(nextPath, extractText)
.then(directoryIndex => {
if (Pro && Pro.Indexer) {
Pro.Indexer.persistIndex(
@@ -280,7 +281,8 @@ export const actions = {
})
.catch(err => {
dispatch(actions.indexDirectoryFailure(err));
- })),
+ })
+ ),
Promise.resolve()
);
@@ -385,8 +387,12 @@ export const actions = {
accumulatorPromise.then(() =>
createDirectoryIndex(nextPath, true)
.then(directoryIndex => {
- AppActions.showNotification(i18n.t('Searching:' + nextPath), 'default', true)
- console.log('Searching in:' + nextPath)
+ AppActions.showNotification(
+ i18n.t('Searching:' + nextPath),
+ 'default',
+ true
+ );
+ console.log('Searching in:' + nextPath);
Search.searchLocationIndex(directoryIndex, searchQuery)
.then(searchResults => {
dispatch(AppActions.appendSearchResults(searchResults));
diff --git a/app/reducers/locations.ts b/app/reducers/locations.ts
index 677ca4ff9..29b17192e 100644
--- a/app/reducers/locations.ts
+++ b/app/reducers/locations.ts
@@ -43,6 +43,7 @@ export type Location = {
region?: string;
paths: Array<string>;
path?: string;
+ endpointURL?: string;
children?: Array<any>;
perspective?: string; // id of the perspective
creationDate?: string;