-
Notifications
You must be signed in to change notification settings - Fork 3
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
Allow setting builds as args rather than parameters #90
Conversation
// @ts-expect-error | ||
AddonVisualTestsBuild: constructResult({ storyBuild: pendingBuild }), |
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.
For some reason it errors if I set this arg on the Story
but not on the Meta
.
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.
Does it make more sense to make more sense for the arg to be the input to constructResult
if we want the user to be able to edit this in the controls panel?
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.
How would that work @shilman? constructResult
is specific to this query...
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.
Ah, yes, if you use typeof meta
, it only looks at the component type, and it can really do anything with the satisfies part.
You will have to do something as:
type StoryArgs = Parameters<typeof VisualTests>[0] & {
AddonVisualTestsBuild: ResultOf<typeof QueryBuild>;
}
const meta = { } satisfies Meta<StoryArgs>;
type Story = StoryObj<StoryArgs>
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.
@kasperpeulen but am I correct in saying that would mean we would lose any args that were defined in meta
(in terms of being required?)
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.
That is right, you have to set them optional yourself in StoryObj.
I have thought about this scenario, but I think there is no way, as the satisfies
constraint has no effect on the inferred return type of meta
.
Factories would solve this problem 🤓
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 figured you'd say that :)
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.
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.
Cool!!
Really nice to see that args can be used for together with |
Closing this in favour of a similar change in #124 Note in that PR I nested the args under addon-visual-tests/src/screens/VisualTests/VisualTests.stories.tsx Lines 281 to 298 in fcaf963
I also add a "mapping" concept: addon-visual-tests/src/screens/VisualTests/VisualTests.stories.tsx Lines 136 to 141 in fcaf963
addon-visual-tests/src/screens/VisualTests/VisualTests.stories.tsx Lines 101 to 125 in fcaf963
It works pretty well. @shilman I think nesting under export const StoryAddedNotInBuild = {
args: {
$graphql: {
AddonVisualTestsBuild: {
selectedBuild: withTests({ ...pendingBuild }, []),
},
},
},
}
// vs
export const StoryAddedNotInBuild = {
args: {
AddonVisualTestsBuild: {
selectedBuild: withTests({ ...pendingBuild }, []),
},
},
} On the one hand the extra level of nesting is just more work all the time, on the other hand it makes it much more clear what this arg that has nothing to do with the component's props is doing. |
Haven't thought this through, but I wonder if we could just hoist |
@shilman we could but I guess I was saying the If it was Maybe that's a good tradeoff though? I guess in any given project you are probably only going to have one or two arg "targets". If we did it that way, we could even just make the |
Sorry I meant the other way. Pull |
So a new annotation? |
I think it makes sense to have them under args:
|
Yeah a new class of annotation. Where we could have I don't love it, but I'm bringing it up because we always try to be careful about scoping things correctly and then we generate these deeply nested structures that are not that ergonomic, and then we end up hoisting them later. But maybe we should consider just hoisting from the beginning under the assumption that targeted args will be a big deal and people will be using them a lot. |
Trying this out - is this what you had in mind @yannbf? It seems like the types don't like it though @kasperpeulen (see the
@ts-expect-error
, not quite sure why. I can setargs.AddonVisualTestsBuild
in the meta but not in the story.It does work though.
📦 Published PR as canary version:
0.0.64--canary.90.6a458fa.0
✨ Test out this PR locally via: