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

Multiple popups open up at a time #793

Closed
wants to merge 10 commits into from

Conversation

RaviAnand111
Copy link
Contributor

fixes #750

This is the code I have done, all the improvement I had done till yesterday, I have deleted it this code just has the code I talked about in the issue chats, now we can discuss and find a way to solve this problem.
Thank You
@NARUDESIGNS @TildaDares

@gitpod-io
Copy link

gitpod-io bot commented Jan 15, 2022

@NARUDESIGNS
Copy link
Collaborator

@RaviAnand111 I fixed this but with more lines of code. I noticed that even bootstrap's example couldn't close when you click again on the button but only closes when you click outside it. So I couldn't find a resolution through bootstrap which made me write more lines of code.
I will create a PR now so you can see my approach and maybe we can get @TildaDares's input to know if it is okay to follow the pattern to resolve for other popovers.

@NARUDESIGNS
Copy link
Collaborator

Or would you prefer me to share with you the code snippet I added so that you can try it on your local environment and then push the changes?
@RaviAnand111

@RaviAnand111
Copy link
Contributor Author

Both are fine @NARUDESIGNS you can share or make a PR whichever sounds good to you, as soon as you push it can we try to find ways to solve this.
Thanks

@TildaDares
Copy link
Member

Hi @NARUDESIGNS, to make it easier for @RaviAnand111 to incorporate those changes you can make use of GitHub suggestions.

@NARUDESIGNS
Copy link
Collaborator

Thank you @TildaDares but his commits didn't include lines where I wanted to indicate the changes. I thought of making a PR cause I don't know if this can explain it enough but let me try this first.
@RaviAnand111 Please have a look at these snippets and then try to insert them. I've included some codes that were there before so that you can have an idea of where to include these snippets. The file is PublicLab.RichTextModule.Table.js

+ let popoverIsOpen = false;
  $('.wk-commands .woofmark-command-table').click(function() {
+    popoverIsOpen = !popoverIsOpen;
    $('.ple-table-size').click(function() {
        $('.woofmark-command-table').popover('toggle');
      });
    });

+    // close table popover when user click outside the page
+   $(':not(".woofmark-command-table")').click((e) => {
+      // check to see that the clicked element isn't fa-table icon, else when you click on the fa-table icon, the popover will close
+      if($('.woofmark-command-table').children()[0] != e.target){
+        const popoverContainer = document.querySelector('.popover');
+        const isChildElement = popoverContainer.contains(e.target);
+        if (popoverIsOpen && !e.target.classList.contains("woofmark-command-table") && !isChildElement) {
+          $('.woofmark-command-table').click();
+        }
+      }
+    });
  });
};

@NARUDESIGNS
Copy link
Collaborator

I hope this helps.

@RaviAnand111
Copy link
Contributor Author

Thanks @NARUDESIGNS , I will add them in the code and make a commit here.

@RaviAnand111
Copy link
Contributor Author

Hey @NARUDESIGNS, you have written a very beautifull code, if is working perfectly.

@NARUDESIGNS
Copy link
Collaborator

NARUDESIGNS commented Jan 18, 2022

Thank you @RaviAnand111 even though I feel like it's many lines of code for a simple task but you get the idea or pattern we can use for the other popovers right?

  1. we use a boolean popoverIsOpen variable to know whether or not the popover is open.
  2. next, we check if there's a click on the page and not the table tool button or its icon
  3. we then check to see if the element being clicked is contained in the popover because we wouldn't want to hide it if, for example, the user clicks on the - or + button
  4. if all checks out, then we just want to call the click event on the table button which is capable of hiding the popover.

@RaviAnand111
Copy link
Contributor Author

I got it, @NARUDESIGNS
Thanks for your help, I will try to learn as much as I can from you.
And now I will add this code in every button in .wk-commands and then commit it.
Thanks again
@NARUDESIGNS @TildaDares for this great opportunity where I am getting alot to learn.

@NARUDESIGNS
Copy link
Collaborator

Alright. At Public Lab, I learned that a PR should do just one thing (unless there are very minimal changes you want to group together). So I think we should make separate PRs for each tool button that has popovers. You can make changes for this table button and commit it then create another PR for any other tool button you'd like to work on next.

@RaviAnand111
Copy link
Contributor Author

ok great, then I will do it the way you said, and different PRs for different popovers.
Thanks
@NARUDESIGNS @TildaDares

@RaviAnand111
Copy link
Contributor Author

I just pushed the new changes, you can check and tell me if there is something to change.
So now I have to make a new PR and solve popup problem of other buttons just like this,
So I will be doing that.
Thanks
@NARUDESIGNS

@RaviAnand111
Copy link
Contributor Author

I just had this doubt, @NARUDESIGNS as in the end all the code in modules become part of PublicLab.Editor.js so I cannot create same variables again again right, I would have to give different name to every variable in every module.
right ?

@NARUDESIGNS
Copy link
Collaborator

NARUDESIGNS commented Jan 18, 2022

The let and const declaration keywords scopes the variable to its enclosing function, therefore the variable isn't global but is only accessible within the function it was declared.
I don't think this will be a problem but when you make your next attempt we can find out.

@RaviAnand111
Copy link
Contributor Author

I tried both ways, with different variable names and with same variable names and I found out that both ways are working perfectly, there is not problem, so what do you recommend which way should I do it ?
Thanks

@NARUDESIGNS
Copy link
Collaborator

Well for sake of consistency, let's just use same one for all.

@RaviAnand111
Copy link
Contributor Author

I am adding the function in try catch as it is printing errors in console on clicking on the page as the contains function is being called on null.

@NARUDESIGNS
Copy link
Collaborator

Is this for a different tool button and popover?
If yes, I think we should make a PR for it, and then we can move the conversation about it there.

@RaviAnand111
Copy link
Contributor Author

See this is the error in the console,
image

what I have understood is,

    $(':not(".woofmark-command-table")').click((e) => {
     // check to see that the clicked element isn't fa-table icon, else when you click on the fa-table icon, the popover will close
     if($('.woofmark-command-table').children()[0] != e.target){
       const popoverContainer = document.querySelector('.popover');
       const isChildElement = popoverContainer.contains(e.target);
       if (popoverIsOpen && !e.target.classList.contains("woofmark-command-table") && !isChildElement) {
         $('.woofmark-command-table').click();
       }
     }
    });```

as we are calling .contains so it is giving error on being called on null

@NARUDESIGNS
Copy link
Collaborator

NARUDESIGNS commented Jan 18, 2022

Yea I noticed. I dropped a suggestion for you. Please check.
Please try adding the changes and see if it eliminates the error. I was able to reproduce the error and that fixed it for me.
@RaviAnand111

RaviAnand111 added a commit to RaviAnand111/PublicLab.Editor that referenced this pull request Jan 18, 2022
@RaviAnand111
Copy link
Contributor Author

hey @NARUDESIGNS , sorry to ask, where can I see the suggestion, I can't find any.
Thanks

@NARUDESIGNS
Copy link
Collaborator

Yea there are too many comments already so I'd just paste it here:

if (popoverIsOPen && $('.woofmark-command-table').children()[0] != e.target) {

@RaviAnand111
Copy link
Contributor Author

I am adding the same video from the other PR, if any more demo video is required, then I will make another video

multiple-popover-bug.mp4

You can check the demo video
@NARUDESIGNS @TildaDares @jywarren
Thanks

Copy link
Collaborator

@NARUDESIGNS NARUDESIGNS left a comment

Choose a reason for hiding this comment

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

Awesome!

src/modules/PublicLab.RichTextModule.Table.js Outdated Show resolved Hide resolved
@NARUDESIGNS
Copy link
Collaborator

Hi, @RaviAnand111 there are 10 commits in this PR and some of the commits are from another PR. This usually happens when you checkout a new branch X from another branch Y, the commits from branch Y are automatically added in new branch X.

Did you checkout this branch from main branch?

Screenshot 2022-01-19 at 11 09 22 AM

@RaviAnand111
Copy link
Contributor Author

I think I have made a mistake here, and checkout a new branch from a branch,
What can I do to solve this ? 😨

@NARUDESIGNS
Copy link
Collaborator

Not to worry, I made same mistake some time when I joined as well. Tilda shared a very helpful resource, have a look at it here - https://luisdalmolin.dev/blog/branched-off-the-wrong-branch-in-git/

@RaviAnand111
Copy link
Contributor Author

hey @NARUDESIGNS I think I have done a massive mistake here.
git-image

Can you tell me how to solve, I am confused right now

@NARUDESIGNS
Copy link
Collaborator

I'm sorry, I don't really get your diagram but all the commits here are still in place. Maybe what you can do is git reset --hard <commit> where <commit> is the latest commit in your RaviAnand111:multiple-popups branch before you took these actions. This will reset all commits and update your local environment to point to the reverted commit. I think the <commit> should be this last one: c483f01

Screenshot 2022-01-19 at 5 15 00 PM

@TildaDares can you please help to check in that we are on track to resolve the issue @RaviAnand111 is having, thank you.

@RaviAnand111
Copy link
Contributor Author

My mistakes:

  1. I made a PR from main branch Padding added to table popover button for editor fixes#752 #768 Padding added to table popover button for editor fixes#752 #769
  2. then I created a branch multiple-popupsfrom main, there made a PR too Multiple popups open up at a time  #793
  3. then created another branch from multiple-popups branch with name customInsert-Popover-problem and made a PR from there too. Custom insert popover problem Solved  #794

It seems messed up, what should I do ?

@TildaDares
Copy link
Member

Not to worry, I made same mistake some time when I joined as well. Tilda shared a very helpful resource, have a look at it here - https://luisdalmolin.dev/blog/branched-off-the-wrong-branch-in-git/

@RaviAnand111 Have you tried this?

@RaviAnand111
Copy link
Contributor Author

Yeah, I tried this, it is giving merge conflict and something, I think the main mistake I did was, made a change and PR from main branch @TildaDares

@RaviAnand111
Copy link
Contributor Author

I think I should create a new branch, before I created a PR from main and git rebase that PR to that branch, what do you guys think ? is there any way to do that safely ?
@NARUDESIGNS @TildaDares

@TildaDares
Copy link
Member

@RaviAnand111 It’s best to leave the main branch untouched and use branches for your work.

I’m looking for resources to help with your issue.

@RaviAnand111
Copy link
Contributor Author

Yes I learned my lesson from this mistake, thankyou for helping me,

@TildaDares
Copy link
Member

@RaviAnand111 I found this article about how to rebase. You could pick and drop the commute you want in this PR. https://www.google.com/amp/s/www.digitalocean.com/community/tutorials/how-to-rebase-and-update-a-pull-request.amp

@RaviAnand111
Copy link
Contributor Author

Hey guys, I tried to solve this so I will write down what steps I took :

  1. I created a branch feature at the commit before the commit in which I made a PR from main.
  2. Then I did git rebase from the main commit in which I did a PR and transported all of commits after it in the feature branch.
  3. Then I did git reset to the commit point in which I created feature branch.
  4. Then I did a force push git push -f to my remote repo.
  5. Then I did git fetch upstream and git pull upstream main

I think I should make a video with sketch and drawing to make you guys understand, if you guys ask for it then I will make one.

so now we are here, now head is at the commit in which I have not pushed a PR yet, but the PR's I have done already are showing those previous files.

So I am thinking of closing those PR's and creating new one's
It was alot confusing but I tried to solve it so you guys don't have to waste time on it but I don't know if it was right or wrong
Its 2:30 AM here, now I am going to sleep,
If I did any mistake then please share and thankyou for helping

@NARUDESIGNS
Copy link
Collaborator

NARUDESIGNS commented Jan 20, 2022

Hello @RaviAnand111
Though your RaviAnand111:main branch is now in sync with publiclab:main, this PR still contains 10 commits, with the first 2 commits about #768

Maybe we need to just start the whole process all over since your main branch is now properly synced with that of publiclab.
So I advise that you

  • check out to main (i.e git checkout main)
  • create and branch off to a new branch (e.g git checkout -b "fix-multiple-popover-table-popover")
  • make changes and push new branch/changes to remote repo
  • create new PR

How about that?
cc @TildaDares

@RaviAnand111
Copy link
Contributor Author

That sounds good @NARUDESIGNS ,
once @TildaDares confirms that, I will start doing it.

@RaviAnand111
Copy link
Contributor Author

And one more thing,
should I delete the PR's I have created already ?

@TildaDares
Copy link
Member

Hi @RaviAnand111, you can follow those steps @NARUDESIGNS outlined. You can also close these PRs when you’ve opened the new ones. Thanks!

@RaviAnand111
Copy link
Contributor Author

Thanks @NARUDESIGNS @TildaDares

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.

Multiple pop-ups at once when tool buttons are clicked.
3 participants