Skip to content

feat(GlDuoChatMessage): added copy-code button

Denys Mishunov requested to merge dmishunov/duo-chat-copy-code into main

What does this MR do?

The MR adds a dedicated handling for the <copy-code> element, automatically returned by BE when generating markup for the messages, which contain code snippets.

The MR adds the new custom element for that copy-code element and sets the click event, copying the correct code snippet. The button is shown only when hovering over a code snippet in a message.

Screenshots or screen recordings

Screenshot_2023-11-14_at_22.58.33

The button has been tested in all the actual environments for the Duo Chat. Hence the integration MR into GitLab VSCode Extension

Before After
Web UI copy-code-webui-before copy-code-webui-after
VSCode desktop copy-code-vscode-before copy-code-vscode-after
Web IDE copy-code-webide-before copy-code-webide-after

IMPORTANT: The button in Web UI is not the one introduced by this MR both before and after. That's intentional. The reason for that is the way the custom element (<copy-code>) is implemented in this MR. By checking whether <copy-code> is already defined, we ensure that the button from this MR won't re-register the same element again, and all instances of <copy-code> will remain on the previous definition of this custom element. This allows for the non-breaking introduction of this feature to the simpler environments (VSCode, Web IDE), where such an element is still not defined while not breaking the environments with the element already defined (Web UI).

How to test

  • Either start the project locally (yarn start), or
  • Go to the Review App (the link is down below, right under the pipeline status)

No matter what environment you pick, you can test the copy-code button in a couple of components:

Integration merge requests

Does this MR meet the acceptance criteria?

This checklist encourages the authors, reviewers, and maintainers of merge requests (MRs) to confirm changes were analyzed for conformity with the project's guidelines, security and accessibility.

Toggle the acceptance checklist

Conformity

  • Code review guidelines.
  • GitLab UI's contributing guidelines.
  • If it changes a Pajamas-compliant component's look & feel, the MR has been reviewed by a UX designer.
  • If it changes GitLab UI's documentation guidelines, the MR has been reviewed by a Technical Writer.
  • If the MR changes a component's API, integration MR(s) have been opened (see integration merge requests above).
  • Added the ~"component:*" label(s) if applicable.

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • Security reports checked/validated by a reviewer from the AppSec team

Accessibility

If this MR adds or modifies a component, take a few moments to review the following:

  • All actions and functionality can be done with a keyboard.
  • Links, buttons, and controls have a visible focus state.
  • All content is presented in text or with a text equivalent. For example, alt text for SVG, or aria-label for icons that have meaning or perform actions.
  • Changes in a component’s state are announced by a screen reader. For example, changing aria-expanded="false" to aria-expanded="true" when an accordion is expanded.
  • Color combinations have sufficient contrast.

Closes gitlab#421394 (closed)

Edited by Denys Mishunov

Merge request reports

Loading