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

feat(lib): provide more properties to selected asset #395

Merged
merged 6 commits into from
Sep 18, 2024

Conversation

eunjae-lee
Copy link
Contributor

@eunjae-lee eunjae-lee commented Sep 16, 2024

What?

This PR should be released only after https://github.com/storyblok/storyfront/pull/6357 is released.

Why?

JIRA: SHAPE-7043
fixes: #392

How to test? (optional)

I've confirmed working (local storyfront + locally built field plugin pointing to local storyfront as postMessage origin)
Screenshot 2024-09-16 at 15 25 55@2x

Copy link

vercel bot commented Sep 16, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
plugin-sandbox ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 18, 2024 8:54am

@eunjae-lee eunjae-lee marked this pull request as ready for review September 16, 2024 13:30
@eunjae-lee eunjae-lee changed the title feat(SHAPE-7043): provide more properties to selected asset feat(lib): provide more properties to selected asset Sep 16, 2024
focus: '',
alt: '',
source: '',
is_private: false,
Copy link
Contributor

Choose a reason for hiding this comment

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

Hey @eunjae-lee 👋

I don't know how feasible it would be but would be possible to also have the is_external_url property added? 🤔
May it not be possible or not make sense but just commenting once I saw this property exists in the image shared on the issue's description.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm 🤔 I actually don't know about external asset. Do you know @Dawntraoz maybe? I want to test a situation where is_external_url is true.

Copy link
Contributor

@Dawntraoz Dawntraoz Sep 17, 2024

Choose a reason for hiding this comment

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

Indeed @eunjae-lee, you need to go to the image field definition in the Block and check the Allow External URL, then when creating the story, instead of selecting an asset from the Assets Library, you should click on the externalURL icon and add a link to an image (for example for this one: https://letsenhance.io/static/8f5e523ee6b2479e26ecc91b9c25261e/1015f/MainAfter.jpg). Then you will be able to see the is_external_url to true!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you @Dawntraoz! I've followed your instruction, and I was able to upload an external asset.

Screenshot 2024-09-17 at 14 07 35

But, in asset selector, I don't see that. I feel like this should be normal, right? (It's just attached to the story as an external URL, but not really uploaded to my space).

So, if I understand this correctly, the selected asset can never be external. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

You have a point since the message sent only involves Asset Manager iteration in the field plugin. It will always be false 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess that's why is_external_url even doesn't exist on storyfront right before it's passed down to field plugin.

Copy link
Contributor

@demetriusfeijoo demetriusfeijoo left a comment

Choose a reason for hiding this comment

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

Nice improvement, @eunjae-lee 👏
Left a question but overall, great work 🚀

@@ -231,9 +231,29 @@ describe('createPluginActions', () => {
field: 'dummy',
callbackId: TEST_CALLBACK_ID,
filename,
fieldtype: 'asset',
name: '',
meta_data: {},
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a question: Since metadata has already title, source, and such, why do we need the properties twice?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not 100% sure, but I think it can contain more than that.

Screenshot 2024-09-17 at 14 12 47

https://www.storyblok.com/docs/api/management/core-resources/assets/the-asset-object

BibiSebi

This comment was marked as duplicate.

Copy link
Contributor

@BibiSebi BibiSebi left a comment

Choose a reason for hiding this comment

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

so quick, love this! i think once its done we can even share this on discord and reply to the specific threads/feature requests where people requested this (if we find them)

I would wait for the changes that were applied on storyfront and then approve so that we do not accidentally approve before :)

🚀

@@ -1,22 +1,37 @@
import { hasKey } from '../../../utils'
import { AssetSelectedMessage } from './AssetSelectedMessage'

export type AssetWrapper = {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Previous Asset has been renamed to AssetWrapper, and AssetWrapper['asset'] is now called Asset that is a full object for the asset.

Storyfront sends AssetWrapper to field plugins, and field plugin unwrapped it and return its Asset to field plugin users.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -231,9 +231,33 @@ describe('createPluginActions', () => {
field: 'dummy',
callbackId: TEST_CALLBACK_ID,
filename,
asset: {
Copy link
Contributor

Choose a reason for hiding this comment

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

I know these are just tests, but maybe it's useful to create an asset variable to share among them to avoid duplicating the fields everywhere.

export const emptyAsset: {
  id: 0,
  fieldtype: 'asset',
  name: '',
  filename: '',
  meta_data: {},
  title: '',
  copyright: '',
  focus: '',
  alt: '',
  source: '',
  is_private: false,
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

applied :D

@@ -35,24 +56,8 @@ describe('Asset', function () {
assetFromAssetSelectedMessage(assetSelectedMessage),
).toHaveProperty('filename')
})
it('keeps unknown properties', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was intended to allow properties that might be added on the storyfront side, but now that we're wrapping all the "potential" additions under "asset" property, we no longer need this.

filename: 'https://somthing.com/myimage.jpg',
}),
).toEqual(true)
const { field: _field, ...withoutField } = stub
Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixing flaky test

@eunjae-lee eunjae-lee dismissed BibiSebi’s stale review September 18, 2024 09:02

The corresponding PR on storyfront has been just merged :)

Copy link
Contributor

@Dawntraoz Dawntraoz left a comment

Choose a reason for hiding this comment

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

LGTM!

@eunjae-lee eunjae-lee merged commit 5aa3c20 into main Sep 18, 2024
4 checks passed
@eunjae-lee eunjae-lee deleted the SHAPE-7043-sdk-update-typedef branch September 18, 2024 12:18
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.

"actions.selectAsset()" only returns the filename but not things like Alt Text or Asset ID
4 participants