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

Implement rail style for selector #47

Merged
merged 6 commits into from
Aug 22, 2023
Merged

Implement rail style for selector #47

merged 6 commits into from
Aug 22, 2023

Conversation

mfrisbey
Copy link
Collaborator

Changes the style of the selector so that it appears as a rail on the right of the sidekick. In summary, the changes include the following:

  • Changes the asset selector's options so that it's more compact - this includes setting hideTreeNav and noWrap, which reduces the selector to the rail style, while not constraining us to drag/drop only.
  • Adds a "Copy" button to the Franklin integration's header, which will change its state based on selection events from the asset selector.
  • Clicking "Copy" will either:
    • Use the existing method to load an <img /> tag into the clipboard (BTW: this way has never worked for me - I get a 500 from the WEB_TOOLS url request).
    • If "Use Rapi" is defined in the block's config, the method will use the repository API to request a presigned URL for the asset blob, which it loads into the clipboard. Note that this will require a modified CORS config on the target AEM instance in order to work.
  • Misc cleanup, such as javadoc, copyrights, method renames, basic error handling, etc.

Test URLs:

@mfrisbey mfrisbey self-assigned this Aug 21, 2023
@aem-code-sync
Copy link

aem-code-sync bot commented Aug 21, 2023

Hello, I'm Franklin Bot and I will run some test suites that validate the page speed.
In case there are problems, just click the checkbox below to rerun the respective action.

  • Re-run PSI Checks

@aem-code-sync
Copy link

aem-code-sync bot commented Aug 21, 2023

Page Scores Audits Google
/aem-asset-selector-stage PERFORMANCE A11Y SEO BEST PRACTICES SI FCP LCP TBT CLS PSI

Copy link
Collaborator

@sdmcraft sdmcraft left a comment

Choose a reason for hiding this comment

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

Thanks @mfrisbey . Added a few comments.

"paletteRect": "top: 50px; bottom: 10px; right: 10px; left: auto; width:400px; height: calc(100vh - 60px)"
},
{
"id": "asset-library-stage",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need asset-library-stage ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's not required. This was more just for convenience for us, since we've been using a stage environment so that we can verify everything end-to-end, including using one of asset link's client IDs. You can see the document that corresponds with this button here.

FWIW, the stage button will only show up for anyone working on the asset selector code itself - it wouldn't need to be there for customers. But I can remove if and we can add the button locally if we don't want to include it here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes probably its fine to have if it helps with testing. Customer are going to add their own sidekick configs and we'd document only the prod one.

return maxRendition;
}
renditions
.filter((rendition) => rendition.type === 'image/png')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is the rendition.type === 'image/png' check necessary? With it, we'd be omitting the better resolution renditions. I recollect having added it since clipboard api did not support other mime types. Do we still have that limitation?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The clipboard API only supports PNGs as blobs, so I added that for expedience. I'll add a TODO that we should revisit this and create a follow-up tickiet.

Copy link
Collaborator

Choose a reason for hiding this comment

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

ok, I think the best png rendition we have is 319px which may become quite blurry on rendering. I thought the signed url from RAPI does not require auth headers but apparently it does need. One thing worth trying could be local object urls.

Choose a reason for hiding this comment

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

Wouldn't Franklin convert the images anyway into webp (or other formats/sizes depending on the js)? SO having PNG at least should be fine to start with an MVP.

Copy link
Collaborator

@sdmcraft sdmcraft Aug 22, 2023

Choose a reason for hiding this comment

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

Wouldn't Franklin convert the images anyway into webp

Yes it would but what I am not sure is whether it'd improve the image in anyway if it input image is a 319px png rendition. I agree that we can park it and tackle in a separate issue but overall seems to be an important requirement for real customer use cases.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agreed that this needs to be improved. I put it in there as a "placeholder" without doing a great job communicating that it needs to be improved :)

I've created #48 as a follow-up to this.

const AS_MFE = 'https://experience.adobe.com/solutions/CQ-assets-selectors/static-assets/resources/assets-selectors.js';
const IMS_ENV_STAGE = 'stg1';
const IMS_ENV_PROD = 'prod';
const API_KEY = 'franklin';
const WEB_TOOLS = 'https://master-sacred-dove.ngrok-free.app';
const REL_DOWNLOAD = 'http://ns.adobe.com/adobecloud/rel/download';
const REL_RENDITIONS = 'http://ns.adobe.com/adobecloud/rel/rendition';
// TODO: change this to Asset Link IMS client ID
const IMS_CLIENT_ID = 'p66302-franklin';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Likely this should change to one of the pre-existing asset link client IDs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, we're planning on using one. I haven't changed it yet because we're waiting on a static host so that the client ID will work in production IMS.

Since we'll be defining a single block that everyone uses, we could potentially still require the client ID in the block config. That would at least keep the client ID out of a public github repository. It'll still end up in the rendered javascript, but at least it wouldn't be github that way.

@aem-code-sync
Copy link

aem-code-sync bot commented Aug 22, 2023

Page Scores Audits Google
/aem-asset-selector-stage PERFORMANCE A11Y SEO BEST PRACTICES SI FCP LCP TBT CLS PSI

* @param {...any} theArgs Arguments to pass to the console log
* statement.
*/
function logMessage(...theArgs) {

Choose a reason for hiding this comment

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

Do we really need a wrapper function here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not necessarily, I just added it so that we don't have to add an eslint ignore rule every time we write to the console.

*/
function getRel(repositoryMetadata, rel) {
// eslint-disable-next-line no-underscore-dangle
return repositoryMetadata._links[rel];
Copy link

@tmathern tmathern Aug 22, 2023

Choose a reason for hiding this comment

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

Do we need to check for null/undefined to be more defensive?

const json = await response.json();
return json['asset-url'];
if (!response) {
throw new Error('Did not receive response from request');

Choose a reason for hiding this comment

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

I prefer shorter messages

Suggested change
throw new Error('Did not receive response from request');
throw new Error('No response from request');

maxRendition = rendition;
}
});
const renditions = getRel(asset, REL_RENDITIONS);
Copy link

@tmathern tmathern Aug 22, 2023

Choose a reason for hiding this comment

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

Either here or in getRel, we need to make sure asset is not null/undefined ("empty").

return maxRendition;
}
renditions
.filter((rendition) => rendition.type === 'image/png')

Choose a reason for hiding this comment

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

Wouldn't Franklin convert the images anyway into webp (or other formats/sizes depending on the js)? SO having PNG at least should be fine to start with an MVP.

* @returns {Promise} Resolves when the item has been written to the clipboard.
*/
async function copyToClipboardWithBinary(assetPublicUrl, mimeType) {
const binary = await fetch(assetPublicUrl);

Choose a reason for hiding this comment

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

Can we trust the URL to be properly formatted? Or should we verify it (so we can add nice error handling).

return false;
}
const downloadJson = await res.json();
await copyToClipboardWithBinary(downloadJson.href, downloadJson.type);

Choose a reason for hiding this comment

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

I would proactively check that downloadJson is not null/undefined ("empty"), instead of possbly having it throw at the next line.

* @returns {HTMLElement} The asset selector.
*/
function getAssetSelector() {
return document.getElementById('asset-selector');

Choose a reason for hiding this comment

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

I would make 'asset-selector' a constant on top an export it. I have a feeling this will be reused.

function handleAssetSelection(selection, cfg) {
if (cfg) {
if (selection.length && cfg.onAssetSelected) {
cfg.onAssetSelected(selection[0]);

Choose a reason for hiding this comment

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

If length > 1, can we log that we use only the first one? Or at least explain it in the readme.

<div id="login">
<p>Welcome to the Asset Selector! After signing in you'll have the option to select which assets to use.</p>
<p>Welcome to the Asset Selector! Please sign in to view your assets.</p>

Choose a reason for hiding this comment

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

Suggested change
<p>Welcome to the Asset Selector! Please sign in to view your assets.</p>
<p>Welcome to the Asset Selector. Please sign in to view your assets.</p>

block.querySelector('#loading').style.display = 'none';
block.querySelector('#login').style.display = 'flex';
}
}, 2000);

Choose a reason for hiding this comment

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

Make the timeout value a constant, so we can reuse the same wait times for the UI/UX.

@tmathern tmathern mentioned this pull request Aug 22, 2023
@aem-code-sync
Copy link

aem-code-sync bot commented Aug 22, 2023

Page Scores Audits Google
/aem-asset-selector-stage PERFORMANCE A11Y SEO BEST PRACTICES SI FCP LCP TBT CLS PSI

@aem-code-sync
Copy link

aem-code-sync bot commented Aug 22, 2023

Page Scores Audits Google
/aem-asset-selector-stage PERFORMANCE A11Y SEO BEST PRACTICES SI FCP LCP TBT CLS PSI

@mfrisbey mfrisbey merged commit e291d79 into main Aug 22, 2023
2 checks passed
@mfrisbey mfrisbey deleted the rail-selector branch August 22, 2023 20:11
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.

3 participants