TagSpaces is an offline, open source, document manager with tagging support
TSN305 - return the original EditTagGroupDialog.js
Mladen Sapundshievd6a6260c8d08
diff --git a/app/components/dialogs/EditTagGroupDialog.js b/app/components/dialogs/EditTagGroupDialog.jsindex 1af1009f5..d5d2a67ce 100644--- a/app/components/dialogs/EditTagGroupDialog.js+++ b/app/components/dialogs/EditTagGroupDialog.js@@ -17,7 +17,7 @@* @flow*/-import React, { useState } from 'react';+import React from 'react';import Button from '@material-ui/core/Button';import moment from 'moment';import TextField from '@material-ui/core/TextField';@@ -34,14 +34,13 @@ import i18n from '../../services/i18n';import TransparentBackground from '../TransparentBackground';type Props = {- // classes: Object,open?: boolean,editTagGroup: (tagGroup: TagGroup) => void,selectedTagGroupEntry?: TagGroup,onClose: () => void};-/*type State = {+type State = {inputError?: boolean,displayColorPicker?: boolean,displayTextColorPicker?: boolean,@@ -51,9 +50,9 @@ type Props = {color?: string,textcolor?: string,modifiedDate?: string-};*/+};-/*class EditTagGroupDialog extends React.Component<Props, State> {+class EditTagGroupDialog extends React.Component<Props, State> {state = {displayColorPicker: false,displayTextColorPicker: false,@@ -64,18 +63,7 @@ type Props = {color: '',textcolor: '',modifiedDate: ''- };*/--const EditTagGroupDialog = (props: Props) => {- const [displayColorPicker, setDisplayColorPicker] = useState(false);- const [displayTextColorPicker, setDisplayTextColorPicker] = useState(false);- cosnt [inputError, setInputError] = useState(false);- const [disableConfirmButton, setDisableConfirmButton] = useState(true);- const [applyChanges, setApplyChanges] = useState(false);- const [title, setTitle] = useState('');- const [color, setColor] = useState('');- const [textcolor, setTextcolor] = useState('');- const [modifiedDate, setModifiedData] = useState('');+ };componentWillReceiveProps = ({ open, selectedTagGroupEntry }) => {if (open === true) {@@ -88,20 +76,7 @@ const EditTagGroupDialog = (props: Props) => {modifiedDate: selectedTagGroupEntry.modified_date});}- }--- /* function componentWillReceiveProps({ open, selectedTagGroupEntry }) {- if (open === true) {- setDisplayTextColorPicker(!selectedTagGroupEntry.title);- setApplyChanges(false);- setTitle(selectedTagGroupEntry.title);- setColor(selectedTagGroupEntry.color);- setTestcolor(selectedTagGroupEntry.textcolor);- setModifiedData(selectedTagGroupEntry.modified_date);- }- } */-+ };handleInputChange = (event: Object) => {const target = event.target;@@ -111,27 +86,17 @@ const EditTagGroupDialog = (props: Props) => {this.setState({[name]: value}, this.handleValidation);- }+ };- /* handleValidation() {+ handleValidation() {if (this.state.title && this.state.title.length > 0) {this.setState({ inputError: false, disableConfirmButton: false });} else {this.setState({ inputError: true, disableConfirmButton: true });}- } */-- function handleValidation() {- if (title && title.length > 0) {- setInputError(false);- setDisableConfirmButton(false);- } else {- setInputError(true);- setDisableConfirmButton(true);- }}- /* onConfirm = () => {+ onConfirm = () => {const { disableConfirmButton, applyChanges } = this.state;const { selectedTagGroupEntry } = this.props;if (disableConfirmButton) {@@ -154,114 +119,33 @@ const EditTagGroupDialog = (props: Props) => {this.setState({ inputError: false, disableConfirmButton: true });this.props.onClose();}- }; */-- function onConfirm() {- const { disableConfirmButton, applyChanges } = state;- const { selectedTagGroupEntry } = props;- if (disableConfirmButton) {- return;- }+ };- if (selectedTagGroupEntry && selectedTagGroupEntry.children) {- props.editTagGroup({- ...selectedTagGroupEntry,- title: title,- color: color,- textcolor: textcolor,- children: selectedTagGroupEntry.children.map((tag) => ({- ...tag,- color: applyChanges ? color : tag.color,- textcolor: applyChanges ? textcolor : tag.textcolor,- style: tag.style- }))- });- setInputError(false);- setDisableConfirmButton(true);- props.onClose();- }- }-- /* toggleDefaultTagBackgroundColorPicker = () => {+ toggleDefaultTagBackgroundColorPicker = () => {this.setState({ displayColorPicker: !this.state.displayColorPicker });- }; */-- function toggleDefaultTagBackgroundColorPicker() {- setDisplayColorPicker(!displayColorPicker);- }+ };- /* toggleDefaultTagTextColorPicker = () => {+ toggleDefaultTagTextColorPicker = () => {this.setState({ displayTextColorPicker: !this.state.displayTextColorPicker });- }; */+ };- function toggleDefaultTagTextColorPicker() {- setDisplayTextColorPicker(!displayTextColorPicker );- }-- /* handleChangeColor = (color: string) => {+ handleChangeColor = (color: string) => {this.setState({ color });- }; */-- function handleChangeColor(color) {- setColor(color);- }-- /* handleChangeTextColor = (color: string) => {- this.setState({ textcolor: color });- }; */-- function handleChangeTextColor(color) {- setTextcolor(color);- }+ };- /* setApplyChanges = (applyColorChanges: boolean) => {- this.setState({ applyChanges: applyColorChanges });- }; */+ handleChangeTextColor = (color: string) => {+ this.setState({ textcolor: color });+ };- function setApplyChanges() {- setApplyChanges(applyColorChanges);- }-- /* renderTitle = () => (- <DialogTitle style={{ overflow: 'visible' }}>{i18n.t('core:editTagGroupTitle')}{` '${this.state.title}'`}</DialogTitle>- ); */-- function renderTitle() {- return (- <DialogTitle style={{ overflow: 'visible' }}>{i18n.t('core:editTagGroupTitle')}{`'${title}'`}</DialogTitle>- );- }+ setApplyChanges = (applyColorChanges: boolean) => {+ this.setState({ applyChanges: applyColorChanges });+ };- /* renderContent = () => {- const { color, textcolor, modifiedDate } = this.state;- const styles = {- color: {- width: '100%',- height: 30,- borderRadius: 2,- borderWidth: 1,- borderStyle: 'solid',- borderColor: 'gray',- padding: '5px',- background: color- },- textcolor: {- width: '100%',- height: 30,- borderRadius: 2,- borderWidth: 1,- borderStyle: 'solid',- borderColor: 'gray',- padding: '5px',- background: textcolor- },- helpText: {- marginBottom: '5px',- fontSize: '1rem'- },- }; */+ renderTitle = () => (+ <DialogTitle style={{ overflow: 'visible' }}>{i18n.t('core:editTagGroupTitle')}{` '${this.state.title}'`}</DialogTitle>+ );- function renderContent() {+ renderContent = () => {const { color, textcolor, modifiedDate } = this.state;const styles = {color: {@@ -289,85 +173,84 @@ const EditTagGroupDialog = (props: Props) => {fontSize: '1rem'},};- }- return (- <DialogContent style={{ overflow: 'visible' }}>- <FormControl- fullWidth={true}- error={this.state.inputError}- style={{ overflow: 'visible' }}- >- {modifiedDate !== '' && (- <div className="tag-date" style={{ fontSize: 12, position: 'relative', bottom: 20, color: '#808080' }}>- <span className="text" style={{ fontWeight: 600 }}>{`${i18n.t('core:modifiedDate')}: `}</span>- <time>{moment(modifiedDate).format('MMM. DD, YYYY')}</time>- </div>- )}- <TextField+ return (+ <DialogContent style={{ overflow: 'visible' }}>+ <FormControl+ fullWidth={true}error={this.state.inputError}- margin="dense"- name="title"- label={i18n.t('core:editTagGroupNewName')}- onChange={this.handleInputChange}- value={this.state.title}- data-tid="editTagGroupInput"+ style={{ overflow: 'visible' }}+ >+ {modifiedDate !== '' && (+ <div className="tag-date" style={{ fontSize: 12, position: 'relative', bottom: 20, color: '#808080' }}>+ <span className="text" style={{ fontWeight: 600 }}>{`${i18n.t('core:modifiedDate')}: `}</span>+ <time>{moment(modifiedDate).format('MMM. DD, YYYY')}</time>+ </div>+ )}+ <TextField+ error={this.state.inputError}+ margin="dense"+ name="title"+ label={i18n.t('core:editTagGroupNewName')}+ onChange={this.handleInputChange}+ value={this.state.title}+ data-tid="editTagGroupInput"+ fullWidth={true}+ />+ {this.state.inputError && <FormHelperText>{i18n.t('core:taggroupTitleHelper')}</FormHelperText>}+ </FormControl>+ <FormControlfullWidth={true}- />- {this.state.inputError && <FormHelperText>{i18n.t('core:taggroupTitleHelper')}</FormHelperText>}- </FormControl>- <FormControl- fullWidth={true}- >- <FormHelperText style={styles.helpText}>{i18n.t('core:tagBackgroundColor')}</FormHelperText>- <TransparentBackground>- <Button- onClick={this.toggleDefaultTagBackgroundColorPicker}- data-tid="editTagGroupBackgroundColor"- style={styles.color}- > - </Button>- </TransparentBackground>- <ColorPickerDialog- open={this.state.displayColorPicker}- setColor={this.handleChangeColor}- onClose={this.toggleDefaultTagBackgroundColorPicker}- color={this.state.color}- />- </FormControl>- <FormControl- fullWidth={true}- >- <FormHelperText style={styles.helpText}>{i18n.t('core:tagForegroundColor')}</FormHelperText>- <TransparentBackground>- <Button- onClick={this.toggleDefaultTagTextColorPicker}- data-tid="editTagGroupForegroundColor"- style={styles.textcolor}- role="presentation"- > - </Button>- </TransparentBackground>- <ColorPickerDialog- open={this.state.displayTextColorPicker}- setColor={this.handleChangeTextColor}- onClose={this.toggleDefaultTagTextColorPicker}- color={this.state.textcolor}- />- </FormControl>- <FormControl>- <FormHelperText style={styles.helpText}>{i18n.t('core:colorChangesToAllTags')}</FormHelperText>- <Switch- data-tid="editTagGroupSwitch"- onClick={() => this.setApplyChanges(!this.state.applyChanges)}- checked={this.state.applyChanges}- />- </FormControl>- </DialogContent>- );-+ >+ <FormHelperText style={styles.helpText}>{i18n.t('core:tagBackgroundColor')}</FormHelperText>+ <TransparentBackground>+ <Button+ onClick={this.toggleDefaultTagBackgroundColorPicker}+ data-tid="editTagGroupBackgroundColor"+ style={styles.color}+ > + </Button>+ </TransparentBackground>+ <ColorPickerDialog+ open={this.state.displayColorPicker}+ setColor={this.handleChangeColor}+ onClose={this.toggleDefaultTagBackgroundColorPicker}+ color={this.state.color}+ />+ </FormControl>+ <FormControl+ fullWidth={true}+ >+ <FormHelperText style={styles.helpText}>{i18n.t('core:tagForegroundColor')}</FormHelperText>+ <TransparentBackground>+ <Button+ onClick={this.toggleDefaultTagTextColorPicker}+ data-tid="editTagGroupForegroundColor"+ style={styles.textcolor}+ role="presentation"+ > + </Button>+ </TransparentBackground>+ <ColorPickerDialog+ open={this.state.displayTextColorPicker}+ setColor={this.handleChangeTextColor}+ onClose={this.toggleDefaultTagTextColorPicker}+ color={this.state.textcolor}+ />+ </FormControl>+ <FormControl>+ <FormHelperText style={styles.helpText}>{i18n.t('core:colorChangesToAllTags')}</FormHelperText>+ <Switch+ data-tid="editTagGroupSwitch"+ onClick={() => this.setApplyChanges(!this.state.applyChanges)}+ checked={this.state.applyChanges}+ />+ </FormControl>+ </DialogContent>+ );+ };- /*renderActions = () => (+ renderActions = () => (<DialogActions><ButtononClick={this.props.onClose}@@ -384,38 +267,17 @@ const EditTagGroupDialog = (props: Props) => {{i18n.t('core:ok')}</Button></DialogActions>- );*/-- function renderActions() {- return (- <DialogActions>- <Button- onClick={props.onClose}- color="primary"- >- {i18n.t('core:cancel')}- </Button>- <Button- disabled={disableConfirmButton}- onClick={onConfirm}- data-tid="editTagGroupConfirmButton"- color="primary"- >- {i18n.t('core:ok')}- </Button>- </DialogActions>- );- }+ );- function render() {+ render() {return (<GenericDialog- open={props.open}- onClose={props.onClose}- onEnterKey={(event) => onEnterKeyHandler(event, onConfirm)}- renderTitle={renderTitle}- renderContent={renderContent}- renderActions={renderActions}+ open={this.props.open}+ onClose={this.props.onClose}+ onEnterKey={(event) => onEnterKeyHandler(event, this.onConfirm)}+ renderTitle={this.renderTitle}+ renderContent={this.renderContent}+ renderActions={this.renderActions}/>);}