-
Notifications
You must be signed in to change notification settings - Fork 5
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
Conversation
Hello, I'm Franklin Bot and I will run some test suites that validate the page speed.
|
|
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.
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", |
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.
Do we need asset-library-stage
?
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 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.
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.
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') |
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.
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?
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 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.
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.
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.
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.
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.
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.
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.
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.
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'; |
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.
Likely this should change to one of the pre-existing asset link client IDs.
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.
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.
|
* @param {...any} theArgs Arguments to pass to the console log | ||
* statement. | ||
*/ | ||
function logMessage(...theArgs) { |
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.
Do we really need a wrapper function here?
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.
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]; |
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.
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'); |
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 prefer shorter messages
throw new Error('Did not receive response from request'); | |
throw new Error('No response from request'); |
maxRendition = rendition; | ||
} | ||
}); | ||
const renditions = getRel(asset, REL_RENDITIONS); |
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.
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') |
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.
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); |
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 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); |
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 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'); |
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 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]); |
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.
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> |
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.
<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); |
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.
Make the timeout value a constant, so we can reuse the same wait times for the UI/UX.
|
|
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:
hideTreeNav
andnoWrap
, which reduces the selector to the rail style, while not constraining us to drag/drop only.<img />
tag into the clipboard (BTW: this way has never worked for me - I get a 500 from theWEB_TOOLS
url request).Test URLs: