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

Make org tabs draggable in sidebar #617

Closed
wants to merge 3 commits into from

Conversation

kanishk98
Copy link
Collaborator

@kanishk98 kanishk98 commented Dec 23, 2018


What's this PR do?
Updates domains.json on dragging server tabs and (intends to) reorder server tooltips along with that.

Any background context you want to provide?
Please refer to the discussion in #548.

You have tested this PR on:

  • Windows
  • Linux/Ubuntu
  • macOS

Current behaviour on Windows 10 (CSS animations by sortablejs not recorded by Windows Game Bar)
zulip1001201902_01_27am

Problems in current version
On my computer, the server tab freezes for a bit before I can switch tabs again.

Other possible solutions that I considered

  1. We could just change the server names if we're able to also map the hoverable area of a server tab properly.
  2. We could swap the tooltips' nodes in the DOM (they're just sibling nodes, we should be able to replaceChild() as long as we maintain clones of the old tooltip node.

@kanishk98 kanishk98 force-pushed the org-tab-drag branch 2 times, most recently from 4b970aa to f23cd95 Compare December 23, 2018 17:53
@abhigyank
Copy link
Collaborator

Don't know if its because its in WIP but the webviews (incll sidebar) hang for me if I try to drag and change the order,

@kanishk98
Copy link
Collaborator Author

Don't know if its because its in WIP but the webviews (incll sidebar) hang for me if I try to drag and change the order,

I don't know why that's happening. Can you explain any specific steps you took so that I can reproduce this?
I've updated the main PR description with a GIF showing sidebar behaviour on my end.

@kanishk98
Copy link
Collaborator Author

I've found another problem that you may see if you clear app data, add a couple (or more) organisations and then drag them around:

image

This is caused because of line number 178 in app/renderer/js/main.js, as follows:
domains.push(DomainUtil.getDomain(oldIndex));

I'll need to get the actual old index from the domains.json file instead of just taking it from the DOM. Will get to that in some time.

@abhigyank
Copy link
Collaborator

@kanishk98 attached a gif. You can also see the console error for onHover which probably is causing this. If you wamt I'd provide the full traceback or debug it for you.
peek 2018-12-24 22-03

@kanishk98
Copy link
Collaborator Author

@abhigyank thanks for the gif. Looks like this.state has not been properly defined. I'll get to it.

@kanishk98
Copy link
Collaborator Author

As for the problem I mentioned above (related to clearing app data, dragging new domains, and getting a crash), that's because the data-tab-id attribute only increments from the index of the previously added organisation. Can I get some ideas on where to start with this bug?

@abhigyank
Copy link
Collaborator

Yes, that is the main issue here. From what I recall, Akash had previously suggested storing the index of the servers in domain.json itself. Then we'd be work all functions according to that index.

@zulipbot zulipbot added size: M and removed size: XL labels Jan 8, 2019
@kanishk98 kanishk98 force-pushed the org-tab-drag branch 4 times, most recently from b58c34e to b9e600b Compare January 8, 2019 09:47
@kanishk98
Copy link
Collaborator Author

kanishk98 commented Jan 8, 2019

Yes, that is the main issue here. From what I recall, Akash had previously suggested storing the index of the servers in domain.json itself. Then we'd be work all functions according to that index.

I've used another solution, as follows:

tabElements.forEach((el, index) => {
	const oldIndex = +Number(el.getAttribute('data-tab-id')) % tabElements.length;

This should work fine for the reset and drag crash.

@kanishk98
Copy link
Collaborator Author

I'm unable to understand why the webviews freeze after dragging the server tabs. I've logged that they load and the index of the registered clicks is correct (and corresponds to the correct server). I'd really like some pointers on why this might happen.

@kanishk98
Copy link
Collaborator Author

To keep maintainers updated on the status of this PR, I've attached a gif below.

ezgif-5-52261d499369

I think this achieves the required functionality. Just working on a couple of things to make sure minimum code changes are needed. :)

@akashnimare
Copy link
Member

Looks great 👍

@kanishk98 kanishk98 changed the title [WIP] Make org tabs draggable in sidebar Make org tabs draggable in sidebar Feb 3, 2019
@kanishk98
Copy link
Collaborator Author

kanishk98 commented Feb 18, 2019

Hello, just checking in to ask if any other changes are required here. :)

Edit: I realized a little too late that running git rebase was the wrong idea here. The commit history is a little messed up on my end (duplicated commits) so if the maintainers give me the go ahead here, I'll clean up git history on my local machine and send in another PR.
Sorry, this work is from quite a while ago. :)

app/package.json Outdated Show resolved Hide resolved
@kanishk98 kanishk98 force-pushed the org-tab-drag branch 3 times, most recently from 6386a39 to 98f6fc3 Compare June 23, 2019 19:27
@kanishk98
Copy link
Collaborator Author

Updated PR to TypeScript.

@akashnimare
Copy link
Member

@kanishk98 please update the PR. @priyank-p can you help him with the implementation/logic here?

@kanishk98
Copy link
Collaborator Author

please update the PR.

Fixed merge conflicts - I think the functionality was mostly alright. Would love a review anytime. :)

Copy link
Member

@priyank-p priyank-p left a comment

Choose a reason for hiding this comment

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

Left some comments! Looks like you forgot to add sortablejs as a dependency?

@@ -156,12 +156,12 @@ class ServerManagerView {
const domains = [];
const tabElements = document.querySelectorAll('#tabs-container .tab');
tabElements.forEach((el, index) => {
const oldIndex = +el.getAttribute('data-tab-id');
const oldIndex = +Number(el.getAttribute('data-tab-id'));
Copy link
Member

Choose a reason for hiding this comment

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

The use of Number is useless here, that's what the + does here.

@@ -15,7 +15,7 @@
</div>
<div id="sidebar" class="toggle-sidebar">
<div id="view-controls-container">
<div id="tabs-container"></div>
<div id="tabs-container" class="simple-list"></div>
Copy link
Member

Choose a reason for hiding this comment

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

We might want to pick a better name for this class here like organizations-list or sortable-organizations-list here.

@@ -231,14 +233,37 @@ class ServerManagerView {
}
}

onEnd(): void {
const newServers: any[] | ServerOrFunctionalTab[] = [];
const tabMap: any = {};
Copy link
Member

Choose a reason for hiding this comment

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

You should create a interface here for this, it's just:

Suggested change
const tabMap: any = {};
interface TabMap {
[key: number]: number;
}
const tabMap: TabMap = {};

Copy link
Member

Choose a reason for hiding this comment

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

Also we should probably add a detailed comment here what tabMap stores and how it works. I used know the logic back almost a year ago and now looking at this I have no idea what this is which is the perfect reason to add a comment here.

@@ -123,6 +126,7 @@ class ServerManagerView {
this.$dndTooltip = $actionsContainer.querySelector('#dnd-tooltip');

this.$sidebar = document.querySelector('#sidebar');
this.$drag = document.querySelector('#simple-list');
Copy link
Member

Choose a reason for hiding this comment

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

I think we could be more verbose here i.e. this.$sortableDrag

@@ -94,7 +94,7 @@ class ServerManagerView {
$fullscreenEscapeKey: string;
loading: AnyObject;
activeTabIndex: number;
servers: ServerOrFunctionalTab[];
servers: any[];
Copy link
Member

Choose a reason for hiding this comment

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

why is this switched back to any?

@@ -366,7 +366,9 @@ app.on('ready', () => {

app.on('before-quit', () => {
mainWindow.webContents.send('save-domains');
isQuitting = true;
setTimeout(() => {
isQuitting = true;
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, how did you come to this conclusion here? This seems a workaround than a correct fix.

@kanishk98
Copy link
Collaborator Author

@priyank-p thanks a lot for the review! I think a couple of those mistakes you listed above are because I accidentally force pushed a faulty commit at the time of review, but I'll have a look again and finalize this PR by tonight. :)

@kanishk98
Copy link
Collaborator Author

I've updated this PR and used a batch-write function for replacing the old order of domains with the new order. This works well for me, I'd love for everyone to try it out on their end and check for missing servers/duplication (this is why we're reading the order of servers from memory for the most part).

@akashnimare
Copy link
Member

@kanishk98 can you fix the merge conflict? Also, I have noticed that we are not loading the server which is being dragged and I think we want to load that server instead of the new org on that index. Also, the order is not right -

https://cl.ly/8d7c41fba8dc

@zulipbot
Copy link
Member

Heads up @kanishk98, we just merged some commits that conflict with the changes your made in this pull request! You can review this repository's recent commits to see where the conflicts occur. Please rebase your feature branch against the upstream/master branch and resolve your pull request's merge conflicts accordingly.

@manavmehta
Copy link
Collaborator

manavmehta commented Mar 24, 2020

@akashnimare I can't reproduce this

Also, the order is not right

The order is working well for me
@abhigyank can you have a look please ?

@akashnimare
Copy link
Member

I would suggest we should first look into the DB migration and then work on this feature.

abhigyank added a commit to abhigyank/zulip-desktop that referenced this pull request Jan 6, 2021
@abhigyank
Copy link
Collaborator

abhigyank commented Jan 6, 2021

Due to no recent activity, closing in favour of #1059 .

@abhigyank abhigyank closed this Jan 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants