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

Feature/3683 url generator add copy button #11317

Merged

Conversation

the-r3aper7
Copy link
Contributor

@the-r3aper7 the-r3aper7 commented Dec 7, 2023

Fixes #3683 Part B
image

After clicking Copy button
Screenshot 2023-12-08 at 23-33-16 Editing image Lightnin' Hopkins - Wagtail

When no clipboard is defined
image

Please check the following:

  • Do the tests still pass?1
  • Does the code comply with the style guide?
    • Run make lint from the Wagtail root.
  • For Python changes: Have you added tests to cover the new/fixed behaviour?
  • For front-end changes: Did you test on all of Wagtail’s supported environments?2
    • Please list the exact browser and operating system versions you tested:
    • Please list which assistive technologies 3 you tested:
  • For new features: Has the documentation been updated accordingly?

Please describe additional details for testing this change.

Footnotes

  1. Development Testing

  2. Browser and device support

  3. Accessibility Target

Copy link

squash-labs bot commented Dec 7, 2023

Manage this branch in Squash

Test this branch here: https://the-r3aper7feature3683-url-gen-dx4wa.squash.io

@lb- lb- self-requested a review December 7, 2023 10:32
Copy link
Member

@lb- lb- left a comment

Choose a reason for hiding this comment

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

Wow @the-r3aper7 - this is awesome.

Thanks for understanding the brief and working through + getting feedback on Slack.

I have done a review locally and it looks like the message is being duplicated each copy but then gets removed after some time so some tweaks may be needed.

Screenshot 2023-12-08 at 8 28 57 am

I have also gone through the code and put a bunch of feedback, do not be overwhelmed, just work through comments one by one. Once you feel it's resolved and have pushed up changes just resolve the comment.

Finally, you may want to start working on a unit test suite for this new Clipboard controller.

I would suggest you look at client/src/controllers/ActionController.test.js as a bit of a reference for setting up a unit test.

When you feel it's ready for another round of feedback, please just add a message on the PR.

Thank you again for taking the time to contribute. I am super excited about seeing this land in core, it's not only a versatile feature (ability to copy text) but also makes this page much more useful for Wagtail editors.

@@ -33,6 +34,7 @@ export const coreControllerDefinitions: Definition[] = [
{ controllerConstructor: CloneController, identifier: 'w-clone' },
{ controllerConstructor: CloneController, identifier: 'w-messages' },
{ controllerConstructor: CountController, identifier: 'w-count' },
{ controllerConstructor: ClipboardController, identifier: 'w-clipboard' },
Copy link
Member

Choose a reason for hiding this comment

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

Let's move this to alpha order - so it's easier to navigate through this file.

Just under bulk I think.

  { controllerConstructor: BulkController, identifier: 'w-bulk' },
++  { controllerConstructor: ClipboardController, identifier: 'w-clipboard' },

@@ -21,6 +21,7 @@ import { TagController } from './TagController';
import { TeleportController } from './TeleportController';
import { TooltipController } from './TooltipController';
import { UpgradeController } from './UpgradeController';
import { ClipboardController } from './ClipboardController';
Copy link
Member

Choose a reason for hiding this comment

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

Can this import please be moved to alpha order.

import { BulkController } from './BulkController';
++import { ClipboardController } from './ClipboardController';
import { CloneController } from './CloneController';

| HTMLSelectElement;

copy() {
this.dispatch('start');
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
this.dispatch('start');
const event = this.dispatch('copy');
if (event.defaultPrevented) return;

Let's rename this as copy, it's probably a bit nicer than start.

Additionally with a one line defaultPrevented check we can enable a much more flexible usage of this in the future.

client/src/controllers/ClipboardController.ts Outdated Show resolved Hide resolved

navigator.clipboard.writeText(value).then(
() => this.showSuccess(),
() => this.showError(),
Copy link
Member

Choose a reason for hiding this comment

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

It's probably more common to put the rejection handler inside catch, unless I am missing something specific we need to do here.
e.g.

   navigator.clipboard.writeText(value).then(
      () => this.showSuccess(),
  ).catch(() => this.showError())


showSuccess() {
this.dispatch('copied', { detail: { type: 'success' } });
}
Copy link
Member

Choose a reason for hiding this comment

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

I would probably recommend a simpler approach, where we avoid the extra methods for success/error, bringing in the suggestions from above could look something like this.

Wrapping the initial check for navigator.clipboard in a promise means we can use a Promise resolve/reject all the way through.

The dispatching events will happen in one place, then/catch which means no need to abstract these out too early.

  copy() {
    const value = this.valueTarget.value;
    if (!value) return;

    const event = this.dispatch('copy');
    if (event.defaultPrevented) return;

    new Promise((resolve, reject) => {
      if (navigator.clipboard) {
        navigator.clipboard.writeText(value).then(resolve, reject);
      } else {
        reject();
      }
    })
      .then(() => this.dispatch('copied', { detail: { type: 'success' } }))
      .catch(() => this.dispatch('error', { detail: { type: 'error' } }));
  }

client/src/controllers/ClipboardController.ts Show resolved Hide resolved
@the-r3aper7
Copy link
Contributor Author

the-r3aper7 commented Dec 8, 2023

i have resolved the stacking issue. and updated the PR description

Copy link
Member

@lb- lb- left a comment

Choose a reason for hiding this comment

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

@the-r3aper7 just wanted to say thank you so much for your efforts here.

I have reviewed and this mostly works, I understand what you were trying to do with the clear delay and realised that the current clone controller does not support 'clearing after a time' but that value is more for how the classes work.

I have taken the liberty to add this to your PR as a feature and will merge in shortly.

I have also adjusted the classes a bit to use pure tailwind classes for the positioning of the note and fixed up the accessibility for this.

I hope this is OK, it was super close but just needed a bit more polish to get over the line.

I will push to your branch shortly and get this merged in (assuming the CI passes).


Screenshot of VoiceOver reading the label when it appears (when copied).

Screenshot 2023-12-15 at 8 06 18 am (2)

@lb- lb- force-pushed the feature/3683-url-generator-add-copy-button branch from fadf150 to 9becb8b Compare December 15, 2023 03:33
@lb- lb- merged commit bb33e7c into wagtail:main Dec 15, 2023
18 checks passed
lb- added a commit that referenced this pull request Dec 15, 2023
@lb-
Copy link
Member

lb- commented Dec 15, 2023

@the-r3aper7 I have added you to the contributors list as Sai Srikar Dumpeti. Let me know if you wanted a different name listed.

Well done on your first contribution - and for it being a really epic one. This is such a great functionality to have in core and a marked improvement for interacting with this page.

a57c63d

@the-r3aper7
Copy link
Contributor Author

@the-r3aper7 I have added you to the contributors list as Sai Srikar Dumpeti. Let me know if you wanted a different name listed.

Well done on your first contribution - and for it being a really epic one. This is such a great functionality to have in core and a marked improvement for interacting with this page.

a57c63d

thank you for your appreciation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Image URL generator is confusing for end users
2 participants