Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete selected mocks and groups with keyboard #222

Merged

Conversation

dmitrika
Copy link
Contributor

Hello!

This pr is connected with #216.

It's my first contribution with code-changes, so feel free to point where I should correct it.
And I couldn't get how to cover it with test, any thoughts?

Copy link
Owner

@morsdyce morsdyce left a comment

Choose a reason for hiding this comment

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

Hi!

Thanks so much for this PR, i've written some notes on things that should be changed.

Also there is another challenge with this issue is that we need to take care of.
The current issue is if I press delete or backspace anywhere on the screen except when in focus on the editor, the selected items will be deleted.

I think for now we might want to check if the user mouse is hovering over the MockSidebar component or any of it's children and only then process the delete operation.

@ilyagelman I'd love your thoughts about this on how we can do this without causing the user to accidentally delete mocks.

Regarding tests:
Currently we do not have UI tests but just API and integration tests that check the core functionality of this library (being able to mock requests).
We'd love to bring in jest and start testing UI components, I'll create an issue for it so we can handle it in it's own context.

}

componentWillUnmount() {
API.off(EVENTS.UPDATE_MOCK, this.reRender);
API.off(EVENTS.UPDATE_GROUP, this.reRender);

document.removeEndEventListener("keydown", this.onKeyDown);
Copy link
Owner

Choose a reason for hiding this comment

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

should be removeEventListener instead of removeEndEventListener

}

onKeyDown = (event) => {
if (event.keyCode === KEYCODES.BACKSPACE || event.keyCode === KEYCODES.DELETE) {
const selectedGroupsIds = this.props.selectedGroups.map(group => group.id);
Copy link
Owner

Choose a reason for hiding this comment

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

There is no need to do this logic yourself, we have State classes to handle these mutations so we can have them all in one place.

You can import MocksState which is the state for anything related directly to mocks (and groups) and use the deleteSelected method.

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess we have to document all the states we have

@ilyagelman
Copy link
Contributor

@morsdyce Good question about focus... Obviously we would need undo for this.

What about adding a sidebarInFocus flag to the mocks state? It could be set to true when clicking inside the sidebar or on one of its items and unset with clickOutside or something.

@morsdyce
Copy link
Owner

Good idea, I like it much better than assuming that if the mouse is in the sidebar area then you probably meant to delete.

I think this is the proper solution for now, undo will be important for this feature so we might want to release them together.

@dmitrika dmitrika force-pushed the Delete-selected-mocks-and-groups-with-keyboard branch from b449cfa to 7a89654 Compare March 20, 2017 06:10
@dmitrika dmitrika force-pushed the Delete-selected-mocks-and-groups-with-keyboard branch from 7a89654 to 4875afd Compare March 20, 2017 06:11
@dmitrika
Copy link
Contributor Author

Done with typo and MocksState.

I got idea with focus, all right.

And how particularly you see undo logic here? Is this a button or cmd + z hotkey? Or gmail like popover?

@morsdyce
Copy link
Owner

We have a button which is hidden right now because the functionality isn't ready which might also be bound to a hotkey

@ilyagelman
Copy link
Contributor

@dmitrika I'd tackle the undo as a different issue, doesn't have to be done now

@dmitrika
Copy link
Contributor Author

dmitrika commented Apr 1, 2017

I'm still want to finish the task, but waiting when I would be able to get DOM-node from styled-components and add 'click' event-listener to it.

Now it's kinda broken styled-components/styled-components#629

@dmitrika
Copy link
Contributor Author

dmitrika commented Apr 4, 2017

I added sidebarInFocus flag and toggle function to the MocksState.

Unfortunately, I couldn't get DOM-element from styled-components, despite bugfix, so I added cb to DnD component to get node from it.

@morsdyce
Copy link
Owner

morsdyce commented Apr 5, 2017 via email

@dmitrika
Copy link
Contributor Author

dmitrika commented May 8, 2017

@morsdyce Just want to ping you in case if you missed pr :)

@morsdyce
Copy link
Owner

morsdyce commented May 8, 2017

@dmitrika Don't worry, I didn't forget about you, I just came back from a month long vaction and have to deal with some work catch up stuff as well as preparing a few things to present mimic in oscon. I will check this as soon as I can which should be in the next few days.

Thanks for your help!

@morsdyce morsdyce changed the base branch from master to next May 15, 2017 22:32
@morsdyce
Copy link
Owner

@dmitrika I just checked it and it works beautifully!
Thanks so much for the help :)

@morsdyce morsdyce merged commit e967043 into morsdyce:next May 15, 2017
@dmitrika dmitrika deleted the Delete-selected-mocks-and-groups-with-keyboard branch May 16, 2017 07:09
@dmitrika
Copy link
Contributor Author

Great, thanks!

morsdyce added a commit that referenced this pull request Aug 11, 2017
* next:
  Feat (editor): Add codemirror plugins for closing and matching brackets (#249)
  Fix (mocks): Allow duplicating a mock in the same group (#248)
  chore(UI): Upgrade React PropTypes to the new prop-types package
  chore(Build): Upgrade dependencies
  refactor(API): exported Group, Mock and Request models in the API levle
  Chore (npm scripts): Remove postinstall script as I think it's a bit too much installing a dependency and showing this on every install
  Added call to donate after npm install
  Added backers and sponsors on the README
  Support loading mimic inside <head> tag
  Release v2.0.2
  Add a small paragraph to clarify what this tool does;
  Feat (Mocks Sidebar) Allow to delete selected mocks and groups with keyboard shortcuts (#222)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants