-
Notifications
You must be signed in to change notification settings - Fork 2
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
Group components in a single view #2
Comments
Love it.
This can already be done. Most of the time automatically, but we also have
Very good question. I'm sure there's a simple answer somewhere that we didn't find yet. Here's an idea for the mix: When you click on a component you see all the fixtures one after another, sorted alphabetically. But you could have a magic |
Here is some progress to display all fixtures of a component in a single view: react-cosmos/react-cosmos#371. Components can be clicked in the menu. The route used as a component page has a component part and no fixture part "?component=Counter". I'm making a plan for rendering several instances on one page. Currently I think we could transport more than one fixture and introduce a new component that translates them into a list of loaders with single fixtures. On component click, we send all fixtures to Layouter and he will render them one by one. In a next step, we could have all components view, which would require introducing a default fixture. My biggest worry is that we may need more complex routing system at some point. |
@maciej-ka so cool you started working on this! I wish I were more transparent on this, but I'm actually working hard on react-cosmos/react-cosmos#364 and ended up refactoring both Playground and Loader. Component Playground has very old code so it was always something to avoid, especially since the tests are convoluted and use the Mocha/Karma setup. Besides what I already pushed on Playground ⇆ Loader communicationThe Cosmos UI is built out of two frames (both conceptually but also literally–components are loaded inside an From Playground to Loader:
From Loader to Playground:
Order of events at init:
Order of events on selecting fixture:
A coupe of thoughts for this issue:
I hate to have to say this, but you should probably pause your work on this until we finish react-cosmos/react-cosmos#364. Would you be interested in helping with reviewing it when it's ready? |
Sure, I will code review, probably just to dive into the related code. I will remove WIP PR for now. Thanks for the extended info about Playground - Loader protocol! |
Hi @skidding, I've seen activity on a branch that you linked. Is it possible to pass many fixtures now and work on this (group components) task? |
Hi @maciej-ka, Unfortunately (actually fortunately since it's going to be great :D), I went down the rabbit whole and ended up rewriting a lot of the old code to make it more robust, easier to understand and extend by contributors. See the highlights in this comment. While the branch is not ready to be merged, you should be able to start the groundwork for this as it requires some amount of planning and high level design. Just keep in mind that the CP is 100% rewritten on my branch, so best to take a look over it before coming up with any code. To answer your question, when I finish work on my branch we'll still not have a way to load more fixtures at once, so we'll need to come up with a solution for that here. It's relevant to note that the communication has changed and the Loader has the fixture contents now, while the Playground is merely a remote control that has acess to component and fixture names. The Loader actually wires the serializable fixture contents to the Playground in order for it to be displayed in the fixture editor. This said, here are the rough steps I see included in this feature:
This should be enough to start the conversation while I'm still working on finishing the other branch. @maciej-ka what do you think? See any flaws in the plan above? Any additional ideas or mentions? PS. I wouldn't worry about the router because the current router simply maps the querystring params to props, which is ugly but straightforward. Or did you have a specific concern related to routing? |
@maciej-ka react-cosmos/react-cosmos#364 is merged. You're no longer blocked! |
Oh I'd love this... I currently have an Icon component that renders an svg based on
Having all the possible icons on one screen would be fantastic. However, could this proposal include the extra ability to define multiple fixtures in a single file?
|
This would be a sweet! It's related to this, but can be implemented separately, after we have the functionality to render all fixtures of a component in a single page. An elegant way would be to allow fixture files to export a list of objects, treating each of those objects as a separate fixture and rendering them in the new page being developed in this PR. |
My 2 cents: you could have a convention to name a fixture the same thing as the file that contains your React Component. That would mean it exports multiple fixtures. In order to still support multiple fixture names I would export an ES6 Map out of the fixture to easily determine at runtime if the fixture is a "new" fixture or not in order to keep backwards compatibility and not have to export weird domain specific objects or Arrays of fixtures. |
Hmm, why not just export a bare Eg. // Single fixture
export default {
props: {
foo: 'bar'
}
}
// Multi fixture
export default [
{
props: {
foo: 'bar'
}
},
{
props: {
baz: 'qux'
}
}
] |
Because you've just lost the ability to give your fixtures friendly names. With a Map the key used could represent the name.
Later on...
|
Why not add a |
Interesting. I didn't imagine each fixture from a multi fixture file to have a name. 🤔 It sounds cool, but we need to see it as a whole. What @maciej-ka is working now is to put all existing single fixtures in a page. So if you had
You'll have a page like this
This means we render fixture names from file names. @ovidiubute you're proposing a way to name more fixtures in the same file. My only worry is how these two types of naming fit together. |
This is also interesting. It means you could have friendlier names for single fixture files that show up in the component page (where all fixtures are listed). And you have a unified way of naming fixtures... |
Big fan of @NiGhTTraX's idea of |
I think at this point you've gone so far off the initial idea of a fixture that this proposed format is basically a Cosmos specific DSL. Props are already split into their own property name, which may or may not be popular with users, but metadata like title/description is taking it a bit too far, in my opinion. Once you've added sufficient Cosmos data into a fixture what is the point at which you need to maintain the fixture itself? Can you still reliably use it in a unit-test? |
You could say so. You have
Hard to judge but I see your point. The question I think is if the benefits outweigh the cost.
As long as it's deterministic, I say yes. But truth be told Cosmos evolved into more of an integration tool. Depends on what you see as a unit. Is But we've strayed from the initial topic and we should open different threads to explore these avenues. |
Not sure if i followed everything in here correctly, but i am a huge fan of grouping fixtures on one page. This would be useful for:
By the way, with version 3 this should be already possible with an ugly workaround. What you need is a component that is basically a layout wrapper (css flex or grid) which gets loaded in the fixture. Then you define an arbitrary complex component structure as Example: import React from 'react';
import Flex from 'my/grid/Flex';
import Icon from 'my/icon/Icon';
export default {
component: Flex,
children: [
<Icon key="1" name="search" />,
<Icon key="2" name="comment" />,
],
}; Since you write your own markup, you can layout everything as you want. But again, this is an ugly hack. |
What's up?
Non-technical people have trouble navigating CP if your project has a lot of components and fixtures. Ideally they'd like to be able to see similar components grouped together on one page, or have all of the fixtures in a single page for one component.
Mkay, tell me more...
I'm thinking we have a tree structure in the left nav menu, where if you click on the directory name you'll get a page with all of the components within it rendered under a specific fixture (this could be configurable, let's say that all of your components have a
base.js
, this would be configured incosmos.config.js
).In addition to that, if you click on the name of a component, you should see a view of your component rendered in all states (or a subset of them). This would also be configurable, maybe we say render 3 fixtures per component, or maybe, wait for it: specify which fixtures are the most interesting to render (effectively showcasing your component in the most interesting states).
Obviously the pain points here are going to be:
There are more questions here but I'd love to hear your opinion on this, @skidding. I think it's a worthwhile investment to have this feature and it's something I've seen in other playgrounds as well, the difference being that they all require the users to write JSX, which is very difficult to maintain in the long term.
The text was updated successfully, but these errors were encountered: