starter icon indicating copy to clipboard operation
starter copied to clipboard

How to easily update component authoring behaviour?

Open wildone opened this issue 2 years ago • 9 comments

Is your feature request related to a problem? Please describe. Some components need to have new buttons added to the edit toolbar and have ability to refresh page or component when interacting within edit ui.

image

Need to be able to add new items specifying icon, text and URL to open.

How to do this easily?

Describe the solution you'd like Would be great to specify this at component level in a dedicated file same as dialog config component/edit/content.json. Similar functionality exist in AEM eg cq:listeners and cq:actionConfigs. You can see possible dialog configs here https://experienceleague.adobe.com/docs/experience-manager-65/developing/components/components-basics.html?lang=en#cq-actionconfigs-classic-ui-only

Implementing these will allow more separation of concern so that we don't have to override everything.

Describe alternatives you've considered Overriding existing JS but its source but that is yuck and just going to be messy long term.

wildone avatar Jan 29 '23 03:01 wildone

We are working on the documentation related to extending the page editor. It should be ready in a few days.

paweljozwicki avatar Jan 30 '23 10:01 paweljozwicki

@paweljozwicki will you cover how to extend Dialog fields as well? I am trying to add isDisabled to Text and other form components.

wildone avatar Feb 03 '23 05:02 wildone

@paweljozwicki I am trying to add a simple Link component to dialog, but it does not seem to work.

I have created Link.js:

function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

import { Link as Button } from "/apps/websight-atlaskit-esm/web-resources/@atlaskit/button.js";
import React from "/apps/websight-atlaskit-esm/web-resources/react.js";
export default class Link extends React.Component {
  render() {
    // eslint-disable-next-line react/jsx-props-no-spreading
    return /*#__PURE__*/React.createElement(Button, _extends({
      autocomplete: "off"
    }, this.props));
  }

}

and link.json.html

{
    "type": "/apps/typerefinery/components/dialog/link/Link.js",
    "props": {
        "name": "${properties.name}",
        "label": "${properties.label}",
        "description": "${properties.description}",
        "removeIfEmpty": "${properties.removeIfEmpty || false}",
        "appearance": "${properties.appearance || 'link'}",
        <sly data-sly-test="${properties.disblaed}">"isDisabled": ${properties.disabled || false},</sly>
        <sly data-sly-test="${properties.spacing}">"spacing": ${properties.spacing || ''},</sly>
        <sly data-sly-test="${properties.href}">"href": ${properties.href || ''},</sly>
        <sly data-sly-test="${properties.target}">"target": ${properties.target || ''},</sly>
        <sly data-sly-test="${properties.type}">"type": ${properties.type || ''},</sly>
        "defaultValue": ""
    }
}

and then added it to my dialog

      "editflow2": {
        "sling:resourceType": "typerefinery/components/dialog/link",
        "name": "flowapi_editurll",
        "label": "Edit"
      }

wildone avatar Feb 04 '23 01:02 wildone

@paweljozwicki I am trying to add a simple Link component to dialog, but it does not seem to work.

....

Anyways I've figured out how to do this :D

image

wildone avatar Feb 04 '23 12:02 wildone

@paweljozwicki Have you overwritten window.open in React? I am trying to do window.open with target "_blank" and it opens in same tab 😢

wildone avatar Feb 04 '23 12:02 wildone

We didn't overwrite window.open. On what browser do you have a problem? For verifying an issue I added a button to our assetreference field with

        this.openLink = () => {
            const { value } = this.props;
            window.open(value, '_blank');
        }; 

and it works fine on Chrome (Version 109.0.5414.119), Firefox (Version 109.0.1), and Safari (Version 15.6.1)

paweljozwicki avatar Feb 06 '23 09:02 paweljozwicki

We didn't overwrite window.open. On what browser do you have a problem? For verifying an issue I added a button to our assetreference field with

        this.openLink = () => {
            const { value } = this.props;
            window.open(value, '_blank');
        }; 

and it works fine on Chrome (Version 109.0.5414.119), Firefox (Version 109.0.1), and Safari (Version 15.6.1)

I was on brave. I've changed the button to appearance=link and it work fine. :D

image

wildone avatar Feb 07 '23 02:02 wildone

@paweljozwicki I am still keen to see how to add a button to the edit controls of a component. :D

wildone avatar Feb 07 '23 02:02 wildone

We remember that, but still working on documentation. If it's urgent then you can use a WebAction (here is an example) but we would like to introduce new solution and not sure if WebActions will be supported in the future.

paweljozwicki avatar Feb 07 '23 11:02 paweljozwicki