Skip to content

Conversation

@khaliqgant
Copy link
Contributor

@khaliqgant khaliqgant commented May 3, 2019

Description

Tags at present moment cannot be renamed. This PR reuses the "RenameFolderModal" to allow a user to rename a tag that is selected.

video

This update also renames the "RenameFolderModal.styl" to "RenameModal.styl" since the RenameTagModal.js uses that style as well and I felt it was clearer to use a more generic name. This is my first PR to the project (be kind! 😬) so I wasn't sure if that is something the maintainers would agree with or not.

Issue fixed

Fixes #1706

Type of changes

  • ⚪ Bug fix (Change that fixed an issue)
  • ⚪ Breaking change (Change that can cause existing functionality to change)
  • ⚪ Improvement (Change that improves the code. Maybe performance or development improvement)
  • 🔘 Feature (Change that adds new functionality)
  • ⚪ Documentation change (Change that modifies documentation. Maybe typo fixes)

Checklist:

  • 🔘 My code follows the project code style
  • ⚪ I have written test for my code and it has been tested
  • 🔘 All existing tests have been passed
  • 🔘 I have attached a screenshot/video to visualize my change if possible

• repurpose RenameFolderModal.styl to RenameModal so it is more generic
@ZeroX-DG ZeroX-DG added the awaiting review ❇️ Pull request is awaiting a review. label May 4, 2019
}
}

handleConfirmButtonClick (e) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you call this.confirm directly instead of making a whole new method for it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking it over! Updated.

@ZeroX-DG ZeroX-DG added awaiting changes 🖊️ Pull request has been reviewed, but contributor needs to make changes. and removed awaiting review ❇️ Pull request is awaiting a review. labels May 4, 2019
<div styleName='header'>
<div styleName='title'>{i18n.__('Rename Tag')}</div>
</div>
<ModalEscButton handleEscButtonClick={(e) => this.handleCloseButtonClick(e)} />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit. I think handleCloseButtonClick method is not needed here.
You could destructure prop close with const { close } = this.props and do

Suggested change
<ModalEscButton handleEscButtonClick={(e) => this.handleCloseButtonClick(e)} />
<ModalEscButton handleEscButtonClick={close} />

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in e985f12

<div styleName='control'>
<input styleName='control-input'
placeholder={i18n.__('Tag Name')}
ref='name'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to use callback refs as it's likely that this will be deprecated in a future React version. Please use ref={ref => this.nameInput=ref} & add this.nameInput = null to the constructor & update the references from this.refs.name to the new property.

Docs about string refs leagcy api

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in b1d62c8

placeholder={i18n.__('Tag Name')}
ref='name'
value={this.state.name}
onChange={(e) => this.handleChange(e)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit. Please use .bind(this) for onChange, onKeyDown and onClick so you can write e.g. onChange={this.handleChange}.
But this requires this.handleChange = this.handleChange.bind(this) in the constructor - we could probably also use class properties but I think that's not used in the code base.
I'm also not sure if it's supported by the Babel setup - I haven't checked.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in ce5d4ac

@AWolf81
Copy link
Contributor

AWolf81 commented May 8, 2019

Looks great. Just some smaller inline comments & one point would be awesome if you could add.

If you're selecting a tag and then rename it - the location is wrong and no notes are displayed.

By adding the following code to your renameTag method before closing the modal you can redirect to the selected tag to correctly update:

import { hashHistory } from 'react-router' // add to imports

renameTag (tag, updatedTag) {
  Promise
    .all(notes.map(note => dataApi.updateNote(note.storage, note.key, note)))
    .then(() => { /* ... */ })
    .then(() => {
      if (window.location.hash.includes(tag)) {
        hashHistory.replace(`/tags/${updatedTag}`)
      }
      this.props.close()
    })
}

@khaliqgant
Copy link
Contributor Author

Thanks for the detailed feedback @AWolf81!

Great tip with your comment above as it exposed an issue with the topbar tag
image
not updating when the tag was renamed. I added in an event (not sure if is the optimal way, but the best I could come up with at the time) to keep that portion up to date. Result below:

updated-video

@khaliqgant
Copy link
Contributor Author

Branch has been brought up to date with the latest master

@khaliqgant
Copy link
Contributor Author

Just a friendly ping on this @ZeroX-DG 😀

@ZeroX-DG
Copy link
Member

Hi @khaliqgant , sorry for the late response.

Can you change the color of the modal so that it will match the theme? For example, here is how it look on monokai theme

image

Also a note can't have duplicated tags but if you do like this, the bug will appear:

  1. Add a tag called tag1 to a note
  2. Add a tag called tag2 to that same note
  3. Rename tag2 to tag1
  4. The note will now have duplicated tags.

@khaliqgant
Copy link
Contributor Author

khaliqgant commented Sep 15, 2019

Thanks for the feedback @ZeroX-DG.

Can you change the color of the modal so that it will match the theme?

Updated with 9a2dcbc

Also a note can't have duplicated tags but if you do like this, the bug will appear:

Updated with 4efbe08 and added in an error message to assist the user as seen in the video:

video

@Flexo013 Flexo013 requested a review from ZeroX-DG September 16, 2019 08:36
@Flexo013 Flexo013 added awaiting review ❇️ Pull request is awaiting a review. and removed awaiting changes 🖊️ Pull request has been reviewed, but contributor needs to make changes. labels Sep 16, 2019
@ZeroX-DG
Copy link
Member

@khaliqgant This is not quite what I wanted, I think it's better to merge tag into the existing tag if there's any. If the user want to rename tag computer to computers which already existed, the app should display a message showing the tag computers already existed, renaming this will make note with tag computer become computers and still allow user to rename it if it's what the user want.

@ZeroX-DG
Copy link
Member

@khaliqgant ping

@ZeroX-DG
Copy link
Member

@khaliqgant ping 2

@ZeroX-DG
Copy link
Member

Close due to inactivity

@ZeroX-DG ZeroX-DG closed this Mar 22, 2020
Rokt33r pushed a commit that referenced this pull request Apr 21, 2020
* allow a tag to be renamed and update all notes that use that tag

• repurpose RenameFolderModal.styl to RenameModal so it is more generic

* call handleConfirmButtonClick directly instead of sending through a confirm method

* better name for method to confirm the rename

* use close prop instead of a new method

* use callback ref instead of legacy string refs

* bind the handleChange in the constructor to allow for direct function assignment

* update the tag in the URL upon change

* use the eventEmitter to update the tags in the SnippetNoteDetail header via the TagSelect component

* respect themes when modal is opened

* show error message when trying to rename to an existing tag

* lint fix, const over let

* add missing letter

* fix routing and add merge warning dialog

* fix space-before-parens lint error

* change theming

* add check if tag changed

Co-authored-by: Khaliq Gant <khaliqgant@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review ❇️ Pull request is awaiting a review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Option to rename tags

4 participants