TagSpaces is an offline, open source, document manager with tagging support
TSN377-refactoring dialogs (#1083)
mladensapbf44fd76cb99
diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.ymlindex 71640e11f..b76eda48a 100644--- a/.github/workflows/pull_request.yml+++ b/.github/workflows/pull_request.yml@@ -14,8 +14,8 @@ jobs:- uses: actions/setup-node@v1with:node-version: '10.x'- - name: Running npm install and type check+ - name: Running yarn install, prettier and type checksrun: |- npm install- npm run prettier-check- npm run type-check+ yarn install+ yarn prettier-check+ yarn type-checkdiff --git a/app/components/EntryProperties.tsx b/app/components/EntryProperties.tsxindex 72b7061d4..ecb5c872a 100644--- a/app/components/EntryProperties.tsx+++ b/app/components/EntryProperties.tsx@@ -16,7 +16,7 @@**/-import React, { Component } from 'react';+import React, { Component, ChangeEvent } from 'react';import uuidv1 from 'uuid';import marked from 'marked';import classNames from 'classnames';@@ -492,13 +492,22 @@ class EntryProperties extends Component<Props, State> {handleCloseTagMenu = () => this.setState({ tagMenuOpened: false });- handleInputChange = (event: any) => {+ handleFileNameChange = (event: ChangeEvent<HTMLInputElement>) => {const { target } = event;- const value = target.type === 'checkbox' ? target.checked : target.value;- const { name } = target;+ const { value, name } = target;- // @ts-ignore- this.setState({ [name]: value });+ if (name === 'name') {+ this.setState({ name: value });+ }+ };++ handleDescriptionChange = (event: ChangeEvent<HTMLInputElement>) => {+ const { target } = event;+ const { value, name } = target;++ if (name === 'description') {+ this.setState({ description: value });+ }};handleChange = (name, value, action) => {@@ -644,7 +653,7 @@ class EntryProperties extends Component<Props, State> {this.renameEntry();}}}- onChange={e => this.handleInputChange(e)}+ onChange={this.handleFileNameChange}/></div></FormControl>@@ -724,7 +733,7 @@ class EntryProperties extends Component<Props, State> {className={styles.textField}value={description}fullWidth={true}- onChange={e => this.handleInputChange(e)}+ onChange={this.handleDescriptionChange}/>) : (<Typographydiff --git a/app/components/Search.tsx b/app/components/Search.tsxindex 670349bbe..b0fd6a09b 100644--- a/app/components/Search.tsx+++ b/app/components/Search.tsx@@ -141,6 +141,33 @@ class Search extends React.Component<Props, State> {);};+ // handleFileTypeChange = (event: React.ChangeEvent<HTMLInputElement>) => {+ // const { target } = event;+ // const { value, name } = target;++ // if (name === 'fileTypes') {+ // this.setState({ fileTypes: [value] }, this.executeSearch);+ // }+ // };++ handleFileSizeChange = (event: React.ChangeEvent<HTMLInputElement>) => {+ const { target } = event;+ const { value, name } = target;++ if (name === 'fileSize') {+ this.setState({ fileSize: value }, this.executeSearch);+ }+ };++ handleLastModifiedChange = (event: React.ChangeEvent<HTMLInputElement>) => {+ const { target } = event;+ const { value, name } = target;++ if (name === 'lastModified') {+ this.setState({ lastModified: value }, this.executeSearch);+ }+ };+handleTagFieldChange = (name, value) => {// @ts-ignorethis.setState({ [name]: value }, this.executeSearch);@@ -545,7 +572,7 @@ class Search extends React.Component<Props, State> {</InputLabel><Selectvalue={this.state.fileSize}- onChange={this.handleInputChange}+ onChange={this.handleFileSizeChange}input={<Input name="fileSize" id="file-size" />}displayEmpty>@@ -591,7 +618,7 @@ class Search extends React.Component<Props, State> {</InputLabel><Selectvalue={this.state.lastModified}- onChange={this.handleInputChange}+ onChange={this.handleLastModifiedChange}input={<Input name="lastModified" id="modification-date" />}displayEmpty>diff --git a/app/components/dialogs/CreateDialog.tsx b/app/components/dialogs/CreateDialog.tsxindex 27cdcb0a2..3bd7bc145 100644--- a/app/components/dialogs/CreateDialog.tsx+++ b/app/components/dialogs/CreateDialog.tsx@@ -81,7 +81,7 @@ interface Props {}const CreateDialog = (props: Props) => {- let fileInput: HTMLFormElement;+ let fileInput: HTMLInputElement;const fileName ='note' +AppConfig.beginTagContainer +@@ -289,7 +289,6 @@ const CreateDialog = (props: Props) => {<inputstyle={{ display: 'none' }}ref={input => {- // @ts-ignorefileInput = input;}}accept="*"diff --git a/app/components/dialogs/CreateFileDialog.tsx b/app/components/dialogs/CreateFileDialog.tsxindex eddcd3c8d..e8f68b135 100644--- a/app/components/dialogs/CreateFileDialog.tsx+++ b/app/components/dialogs/CreateFileDialog.tsx@@ -111,17 +111,31 @@ class CreateFileDialog extends React.Component<Props, State> {this.setState({ fileType: target.value });};- handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {+ handleFileNameChange = (event: React.ChangeEvent<HTMLInputElement>) => {const { target } = event;- const value = target.type === 'checkbox' ? target.checked : target.value;- const { name } = target;- this.setState(- // @ts-ignore- {- [name]: value- },- this.handleValidation- );+ const { value, name } = target;++ if (name === 'fileName') {+ this.setState({ fileName: value }, this.handleValidation);+ }+ };++ handleFileContentChange = (event: React.ChangeEvent<HTMLInputElement>) => {+ const { target } = event;+ const { value, name } = target;++ if (name === 'fileContent') {+ this.setState({ fileContent: value }, this.handleValidation);+ }+ };++ handleFilePathChange = (event: React.ChangeEvent<HTMLInputElement>) => {+ const { target } = event;+ const { value, name } = target;++ if (name === 'selectedDirectoryPath') {+ this.setState({ selectedDirectoryPath: value }, this.handleValidation);+ }};handleValidation() {@@ -212,7 +226,7 @@ class CreateFileDialog extends React.Component<Props, State> {inputRef={ref => {this.fileName = ref;}}- onChange={this.handleInputChange}+ onChange={this.handleFileNameChange}value={this.state.fileName}data-tid="createFileDialog_fileName"/>@@ -227,7 +241,7 @@ class CreateFileDialog extends React.Component<Props, State> {multilinename="fileContent"value={this.state.fileContent}- onChange={this.handleInputChange}+ onChange={this.handleFileContentChange}onKeyDown={this.handleKeyPress}margin="normal"fullWidth={true}@@ -267,12 +281,10 @@ class CreateFileDialog extends React.Component<Props, State> {requiredmargin="dense"name="selectedDirectoryPath"- // @ts-ignore- label={i18n.t('core:filePath')}fullWidth={true}data-tid="createFileDialog_filePath"value={this.state.selectedDirectoryPath}- onChange={this.handleInputChange}+ onChange={this.handleFilePathChange}endAdornment={PlatformIO.haveObjectStoreSupport() ? (undefineddiff --git a/app/components/dialogs/CreateLocationDialog.tsx b/app/components/dialogs/CreateLocationDialog.tsxindex 45ff66790..767855b1c 100644--- a/app/components/dialogs/CreateLocationDialog.tsx+++ b/app/components/dialogs/CreateLocationDialog.tsx@@ -383,8 +383,6 @@ class CreateLocationDialog extends React.Component<Props, State> {title={Pro ? '' : i18n.t('core:thisFunctionalityIsAvailableInPro')}- // @ts-ignore- component="label"aria-label={i18n.t('core:locationType')}name="type"value={this.state.type}diff --git a/app/components/dialogs/CreateTagGroupDialog.tsx b/app/components/dialogs/CreateTagGroupDialog.tsxindex 98fa8efc5..d71261f6e 100644--- a/app/components/dialogs/CreateTagGroupDialog.tsx+++ b/app/components/dialogs/CreateTagGroupDialog.tsx@@ -62,18 +62,13 @@ class CreateTagGroupDialog extends React.Component<Props, State> {uuid: ''};- handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {+ handleTagGroupTitleChange = (event: React.ChangeEvent<HTMLInputElement>) => {const { target } = event;- const value = target.type === 'checkbox' ? target.checked : target.value;- const { name } = target;+ const { value, name } = target;- this.setState(- // @ts-ignore- {- [name]: value- },- this.handleValidation- );+ if (name === 'title') {+ this.setState({ title: value }, this.handleValidation);+ }};handleValidation() {@@ -173,7 +168,7 @@ class CreateTagGroupDialog extends React.Component<Props, State> {name="title"label={i18n.t('core:createTagGroupName')}value={this.state.title}- onChange={this.handleInputChange}+ onChange={this.handleTagGroupTitleChange}data-tid="createTagGroupInput"/>{this.state.inputError && (diff --git a/app/components/dialogs/CreateTagsDialog.tsx b/app/components/dialogs/CreateTagsDialog.tsxindex cccf27746..c7142640a 100644--- a/app/components/dialogs/CreateTagsDialog.tsx+++ b/app/components/dialogs/CreateTagsDialog.tsx@@ -49,18 +49,13 @@ class CreateTagsDialog extends React.Component<Props, State> {tagTitle: ''};- handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {+ handleTagTitleChange = (event: React.ChangeEvent<HTMLInputElement>) => {const { target } = event;- const value = target.type === 'checkbox' ? target.checked : target.value;- const { name } = target;+ const { value, name } = target;- this.setState(- // @ts-ignore- {- [name]: value- },- this.handleValidation- );+ if (name === 'tagTitle') {+ this.setState({ tagTitle: value }, this.handleValidation);+ }};handleValidation() {@@ -102,7 +97,7 @@ class CreateTagsDialog extends React.Component<Props, State> {name="tagTitle"autoFocuslabel={i18n.t('core:addTagsToGroupTagsPlaceholder')}- onChange={this.handleInputChange}+ onChange={this.handleTagTitleChange}value={this.state.tagTitle}data-tid="addTagsInput"fullWidth={true}diff --git a/app/components/dialogs/EditLocationDialog.tsx b/app/components/dialogs/EditLocationDialog.tsxindex cf7549ba0..cef1171d5 100644--- a/app/components/dialogs/EditLocationDialog.tsx+++ b/app/components/dialogs/EditLocationDialog.tsx@@ -320,8 +320,6 @@ class EditLocationDialog extends React.Component<Props, State> {title={Pro ? '' : i18n.t('core:thisFunctionalityIsAvailableInPro')}- // @ts-ignore- component="label"aria-label={i18n.t('core:locationType')}name="type"value={this.state.type}diff --git a/app/components/dialogs/EditTagDialog.tsx b/app/components/dialogs/EditTagDialog.tsxindex 26bd4e422..39d6c0eae 100644--- a/app/components/dialogs/EditTagDialog.tsx+++ b/app/components/dialogs/EditTagDialog.tsx@@ -75,18 +75,13 @@ class EditTagDialog extends React.Component<Props, State> {}};- handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {+ handleTagTitleChange = (event: React.ChangeEvent<HTMLInputElement>) => {const { target } = event;- const value = target.type === 'checkbox' ? target.checked : target.value;- const { name } = target;+ const { value, name } = target;- this.setState(- // @ts-ignore- {- [name]: value- },- this.handleValidation- );+ if (name === 'title') {+ this.setState({ title: value }, this.handleValidation);+ }};handleValidation() {@@ -210,7 +205,7 @@ class EditTagDialog extends React.Component<Props, State> {name="title"autoFocuslabel={i18n.t('core:editTag')}- onChange={this.handleInputChange}+ onChange={this.handleTagTitleChange}value={this.state.title}data-tid="editTagInput"fullWidth={true}diff --git a/app/components/dialogs/EditTagGroupDialog.tsx b/app/components/dialogs/EditTagGroupDialog.tsxindex ab2bfb04e..619796d9d 100644--- a/app/components/dialogs/EditTagGroupDialog.tsx+++ b/app/components/dialogs/EditTagGroupDialog.tsx@@ -78,18 +78,13 @@ class EditTagGroupDialog extends React.Component<Props, State> {}};- handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {+ handleTagGroupTitleChange = (event: React.ChangeEvent<HTMLInputElement>) => {const { target } = event;- const value = target.type === 'checkbox' ? target.checked : target.value;- const { name } = target;+ const { value, name } = target;- this.setState(- // @ts-ignore- {- [name]: value- },- this.handleValidation- );+ if (name === 'title') {+ this.setState({ title: value }, this.handleValidation);+ }};handleValidation() {@@ -212,7 +207,7 @@ class EditTagGroupDialog extends React.Component<Props, State> {name="title"autoFocuslabel={i18n.t('core:editTagGroupNewName')}- onChange={this.handleInputChange}+ onChange={this.handleTagGroupTitleChange}value={this.state.title}data-tid="editTagGroupInput"fullWidth={true}diff --git a/app/components/dialogs/LocalForm.tsx b/app/components/dialogs/LocalForm.tsxindex 8c02dc1e5..9a63d955a 100644--- a/app/components/dialogs/LocalForm.tsx+++ b/app/components/dialogs/LocalForm.tsx@@ -90,8 +90,6 @@ class LocalForm extends React.Component<Props> {requiredmargin="dense"name="path"- // @ts-ignore- label={i18n.t('core:createLocationPath')}fullWidth={true}data-tid="locationPath"onChange={handleInputChange}diff --git a/app/components/dialogs/ObjectStoreForm.tsx b/app/components/dialogs/ObjectStoreForm.tsxindex 6e86195f2..f91660f0a 100644--- a/app/components/dialogs/ObjectStoreForm.tsx+++ b/app/components/dialogs/ObjectStoreForm.tsx@@ -249,8 +249,6 @@ class ObjectStoreForm extends React.Component<Props> {requiredmargin="dense"name="storeName"- // @ts-ignore- label={i18n.t('core:createLocationName')}fullWidth={true}data-tid="locationName"onChange={handleInputChange}@@ -269,8 +267,6 @@ class ObjectStoreForm extends React.Component<Props> {<Inputmargin="dense"name="storePath"- // @ts-ignore- label={i18n.t('core:createLocationPath')}fullWidth={true}data-tid="locationPath"onChange={handleInputChange}@@ -289,8 +285,6 @@ class ObjectStoreForm extends React.Component<Props> {<Inputmargin="dense"name="accessKeyId"- // @ts-ignore- label={i18n.t('core:accessKeyId')}fullWidth={true}data-tid="accessKeyId"onChange={handleInputChange}@@ -310,8 +304,6 @@ class ObjectStoreForm extends React.Component<Props> {margin="dense"name="secretAccessKey"type="password"- // @ts-ignore- label={i18n.t('core:secretAccessKey')}fullWidth={true}data-tid="secretAccessKey"onChange={handleInputChange}@@ -333,8 +325,6 @@ class ObjectStoreForm extends React.Component<Props> {requiredmargin="dense"name="bucketName"- // @ts-ignore- label={i18n.t('core:bucketName')}fullWidth={true}data-tid="bucketName"onChange={handleInputChange}diff --git a/app/components/dialogs/RenameFileDialog.tsx b/app/components/dialogs/RenameFileDialog.tsxindex d3b07dff4..26b47ee46 100644--- a/app/components/dialogs/RenameFileDialog.tsx+++ b/app/components/dialogs/RenameFileDialog.tsx@@ -89,18 +89,13 @@ class RenameFileDialog extends React.Component<Props, State> {fileName;- handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {+ handleRenameFile = (event: React.ChangeEvent<HTMLInputElement>) => {const { target } = event;- const value = target.type === 'checkbox' ? target.checked : target.value;- const { name } = target;-- this.setState(- // @ts-ignore- {- [name]: value- },- this.handleValidation- );+ const { value, name } = target;++ if (name === 'fileName') {+ this.setState({ fileName: value }, this.handleValidation);+ }};handleValidation() {@@ -146,7 +141,7 @@ class RenameFileDialog extends React.Component<Props, State> {this.fileName = ref;}}label={i18n.t('core:renameNewFileName')}- onChange={this.handleInputChange}+ onChange={this.handleRenameFile}value={this.state.fileName}data-tid="renameFileDialogInput"fullWidth={true}diff --git a/app/components/dialogs/SelectDirectoryDialog.tsx b/app/components/dialogs/SelectDirectoryDialog.tsxindex 5c88f3a33..6e0775248 100644--- a/app/components/dialogs/SelectDirectoryDialog.tsx+++ b/app/components/dialogs/SelectDirectoryDialog.tsx@@ -177,17 +177,24 @@ class SelectDirectoryDialog extends React.Component<Props, State> {this.loadListDirectory(selectedPath);};- handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {- const target = event.target;- const value = target.type === 'checkbox' ? target.checked : target.value;- const name = target.name;+ handleCurrentPath = (event: React.ChangeEvent<HTMLInputElement>) => {+ const { target } = event;+ const { value, name } = target;- // @ts-ignore- this.setState({- [name]: value,- currentPath: value- });- this.loadListDirectory(value as string);+ if (name === 'currentPath') {+ this.setState({ currentPath: value });+ this.loadListDirectory(value as string);+ }+ };++ handleChoosePath = (event: React.ChangeEvent<HTMLInputElement>) => {+ const { target } = event;+ const { value, name } = target;++ if (name === 'choosePath') {+ this.setState({ choosePath: value });+ this.loadListDirectory(value as string);+ }};onBackButton = () => {@@ -241,9 +248,7 @@ class SelectDirectoryDialog extends React.Component<Props, State> {requiredmargin="dense"name="path"- onChange={this.handleInputChange}- // @ts-ignore- label={i18n.t('core:selectDialogCurrentPath')}+ onChange={this.handleCurrentPath}data-tid="selectDirectoryDialogInput"value={this.state.currentPath}disabled={AppConfig.isWin}@@ -260,7 +265,7 @@ class SelectDirectoryDialog extends React.Component<Props, State> {autoWidthname="choosePath"value={this.state.choosePath}- onChange={this.handleInputChange}+ onChange={this.handleChoosePath}input={<Input id="choosePath" />}>{drives.map(drive => (diff --git a/app/components/dialogs/settings/SettingsGeneral.tsx b/app/components/dialogs/settings/SettingsGeneral.tsxindex 019f39355..945b87acd 100644--- a/app/components/dialogs/settings/SettingsGeneral.tsx+++ b/app/components/dialogs/settings/SettingsGeneral.tsx@@ -285,8 +285,6 @@ class SettingsGeneral extends React.Component<Props, State> {style={{ maxWidth: '100px' }}type="number"data-tid="settingsMaxSearchResult"- // @ts-ignore- label={i18n.t('core:maxSearchResult')}value={this.props.settings.maxSearchResult}onChange={this.handleMaxSearchResult}/>diff --git a/app/components/menus/DirectoryMenu.tsx b/app/components/menus/DirectoryMenu.tsxindex 0555cec91..6ec0b8e0d 100644--- a/app/components/menus/DirectoryMenu.tsx+++ b/app/components/menus/DirectoryMenu.tsx@@ -286,10 +286,7 @@ const DirectoryMenu = (props: Props) => {}return (- <div- // @ts-ignore- style={{ overflowY: 'hidden !important' }}- >+ <div style={{ overflowY: 'hidden' }}><RenameDirectoryDialogkey={uuidv1()}open={isRenameDirectoryDialogOpened}diff --git a/app/components/menus/EntryTagMenu.tsx b/app/components/menus/EntryTagMenu.tsxindex 83b3576de..4189e3b11 100644--- a/app/components/menus/EntryTagMenu.tsx+++ b/app/components/menus/EntryTagMenu.tsx@@ -85,10 +85,7 @@ const EntryTagMenu = (props: Props) => {}return (- <div- // @ts-ignore- style={{ overflowY: 'hidden !important' }}- >+ <div style={{ overflowY: 'hidden' }}><Menu anchorEl={props.anchorEl} open={props.open} onClose={props.onClose}><MenuItemdata-tid="showFilesWithThisTag"diff --git a/app/components/menus/FileMenu.tsx b/app/components/menus/FileMenu.tsxindex f193ea4ad..d122e237b 100644--- a/app/components/menus/FileMenu.tsx+++ b/app/components/menus/FileMenu.tsx@@ -90,10 +90,7 @@ const FileMenu = (props: Props) => {}return (- <div- // @ts-ignore- style={{ overflowY: 'hidden !important' }}- >+ <div style={{ overflowY: 'hidden' }}><Menu anchorEl={props.anchorEl} open={props.open} onClose={props.onClose}><MenuItem data-tid="fileMenuOpenFile" onClick={openFile}><ListItemIcon>diff --git a/app/components/menus/LocationManagerMenu.tsx b/app/components/menus/LocationManagerMenu.tsxindex 08f378f40..dba6a8243 100644--- a/app/components/menus/LocationManagerMenu.tsx+++ b/app/components/menus/LocationManagerMenu.tsx@@ -34,10 +34,7 @@ interface Props {}const LocationManagerMenu = (props: Props) => (- <div- // @ts-ignore- style={{ overflowY: 'hidden !important' }}- >+ <div style={{ overflowY: 'hidden' }}><Menu anchorEl={props.anchorEl} open={props.open} onClose={props.onClose}><MenuItemdata-tid="locationManagerMenu"diff --git a/app/components/menus/SearchMenu.tsx b/app/components/menus/SearchMenu.tsxindex c3f4700a1..2d91af408 100644--- a/app/components/menus/SearchMenu.tsx+++ b/app/components/menus/SearchMenu.tsx@@ -34,10 +34,7 @@ interface Props {}const SearchMenu = (props: Props) => (- <div- // @ts-ignore- style={{ overflowY: 'hidden !important' }}- >+ <div style={{ overflowY: 'hidden' }}><Menu anchorEl={props.anchorEl} open={props.open} onClose={props.onClose}><MenuItemdata-tid="searchMenuHelp"diff --git a/app/components/menus/TagGroupMenu.tsx b/app/components/menus/TagGroupMenu.tsxindex 299bcd20e..729012d85 100644--- a/app/components/menus/TagGroupMenu.tsx+++ b/app/components/menus/TagGroupMenu.tsx@@ -80,10 +80,7 @@ const TagLibraryMenu = (props: Props) => {}return (- <div- // @ts-ignore- style={{ overflowY: 'hidden !important' }}- >+ <div style={{ overflowY: 'hidden' }}><MenuanchorEl={props.anchorEl}open={props.open}diff --git a/app/components/menus/TagLibraryMenu.tsx b/app/components/menus/TagLibraryMenu.tsxindex 2e9c41018..8731d8a7e 100644--- a/app/components/menus/TagLibraryMenu.tsx+++ b/app/components/menus/TagLibraryMenu.tsx@@ -117,10 +117,7 @@ const TagLibraryMenu = (props: Props) => {}return (- <div- // @ts-ignore- style={{ overflowY: 'hidden !important' }}- >+ <div style={{ overflowY: 'hidden' }}><ImportExportTagGroupsDialogopen={isImportExportTagGroupDialogOpened}onClose={handleCloseDialogs}diff --git a/app/components/menus/TagMenu.tsx b/app/components/menus/TagMenu.tsxindex 178cf05a9..e8d81a8e6 100644--- a/app/components/menus/TagMenu.tsx+++ b/app/components/menus/TagMenu.tsx@@ -88,10 +88,7 @@ const TagLibraryMenu = (props: Props) => {}return (- <div- // @ts-ignore- style={{ overflowY: 'hidden !important' }}- >+ <div style={{ overflowY: 'hidden' }}><Menu anchorEl={props.anchorEl} open={props.open} onClose={props.onClose}><MenuItemdata-tid="showFilesWithThisTag"