-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Feature/3683 url generator add copy button #11317
Conversation
Manage this branch in SquashTest this branch here: https://the-r3aper7feature3683-url-gen-dx4wa.squash.io |
There was a problem hiding this 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](https://private-user-images.githubusercontent.com/1396140/288909165-184980ea-30ba-472e-afe3-708c7296fbdd.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTkyNjY5MzgsIm5iZiI6MTcxOTI2NjYzOCwicGF0aCI6Ii8xMzk2MTQwLzI4ODkwOTE2NS0xODQ5ODBlYS0zMGJhLTQ3MmUtYWZlMy03MDhjNzI5NmZiZGQucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDYyNCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA2MjRUMjIwMzU4WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NzhmMDk3NzkwODI1YzUyNGI3NWRjYjEyZTVjNjZmYzVjYjUwMGM5ZjVlZGU3N2U3YjhmZDg5NTk0ZDhiYTBkYyZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.UGCBvjWVmnQ2pvaBGnpw1nG_VpAE6yDrrBXdY6YnOIQ)
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.
client/src/controllers/index.ts
Outdated
@@ -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' }, |
There was a problem hiding this comment.
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' },
client/src/controllers/index.ts
Outdated
@@ -21,6 +21,7 @@ import { TagController } from './TagController'; | |||
import { TeleportController } from './TeleportController'; | |||
import { TooltipController } from './TooltipController'; | |||
import { UpgradeController } from './UpgradeController'; | |||
import { ClipboardController } from './ClipboardController'; |
There was a problem hiding this comment.
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';
wagtail/images/templates/wagtailimages/images/url_generator.html
Outdated
Show resolved
Hide resolved
wagtail/images/templates/wagtailimages/images/url_generator.html
Outdated
Show resolved
Hide resolved
wagtail/images/templates/wagtailimages/images/url_generator.html
Outdated
Show resolved
Hide resolved
| HTMLSelectElement; | ||
|
||
copy() { | ||
this.dispatch('start'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
|
||
navigator.clipboard.writeText(value).then( | ||
() => this.showSuccess(), | ||
() => this.showError(), |
There was a problem hiding this comment.
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' } }); | ||
} |
There was a problem hiding this comment.
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' } }));
}
i have resolved the stacking issue. and updated the PR description |
There was a problem hiding this 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).
fadf150
to
9becb8b
Compare
@the-r3aper7 I have added you to the contributors list as 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. |
thank you for your appreciation. |
Fixes #3683 Part B
![image](https://private-user-images.githubusercontent.com/80447788/289153168-fde055c4-8314-4f6e-a8c8-c0907058576b.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTkyNjY5MzcsIm5iZiI6MTcxOTI2NjYzNywicGF0aCI6Ii84MDQ0Nzc4OC8yODkxNTMxNjgtZmRlMDU1YzQtODMxNC00ZjZlLWE4YzgtYzA5MDcwNTg1NzZiLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MjQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjI0VDIyMDM1N1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWQzNWFhMmQyYzRlNmIwNjE5YWQzM2JlY2Q4NDVjN2U2N2I1Mjg4MjFmNWQwOWMzZmY4MjRhZTg4ODZlMzI3YjAmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.wLOx-2vFytdaqHiC3IVYyKBZzkg10Iz3bcK8MT_KzbU)
After clicking Copy button
![Screenshot 2023-12-08 at 23-33-16 Editing image Lightnin' Hopkins - Wagtail](https://private-user-images.githubusercontent.com/80447788/289152756-4abe6442-4a27-4b9d-abe7-cd73fb9567a7.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTkyNjY5MzcsIm5iZiI6MTcxOTI2NjYzNywicGF0aCI6Ii84MDQ0Nzc4OC8yODkxNTI3NTYtNGFiZTY0NDItNGEyNy00YjlkLWFiZTctY2Q3M2ZiOTU2N2E3LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MjQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjI0VDIyMDM1N1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTFhNDk3NDliOTI3MGQwMWE2Y2I5YzAwOWFlMTBmZDM4NGZhNDg1NDAwZDQ4NGZkYzU2MzY2N2E4ZjViMDI2NWMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.uMi1FeE8ki1vooJjzlLq_jbgxiutMmLUOaEDDF8lb2Y)
When no clipboard is defined
![image](https://private-user-images.githubusercontent.com/80447788/289153578-b03eabca-1953-473e-a80f-2aea00753442.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTkyNjY5MzcsIm5iZiI6MTcxOTI2NjYzNywicGF0aCI6Ii84MDQ0Nzc4OC8yODkxNTM1NzgtYjAzZWFiY2EtMTk1My00NzNlLWE4MGYtMmFlYTAwNzUzNDQyLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MjQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjI0VDIyMDM1N1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWNjNTVmYTZmMTAwYzI4ZGJjOTkzNmMzYWIyMTVjZGZhOTJmN2E3OTAxMzNkNDdmMDE2YWM5ZDRhYjc1ZmZjNjYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.YV11rSnn-sTlJeF9fyeVqcWmsynVT7gMPR1e5tSRn_Y)
Please check the following:
make lint
from the Wagtail root.Please describe additional details for testing this change.
Footnotes
Development Testing ↩
Browser and device support ↩
Accessibility Target ↩