-
Notifications
You must be signed in to change notification settings - Fork 1k
[WIP] Fixes #25756 - Adds extend-ability to react components #6366
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
Conversation
|
Issues: #25756 |
ohadlevy
left a comment
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.
Looks like a good start! I've added a few comments inline, plus there is an empty reducer file.
|
|
||
| const components = {}; | ||
|
|
||
| export const registerComponent = (SlotId, key, component, weight) => { |
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.
would register/unregister (or add/remove etc) are enough? I think the component should already part of the context, e.g. when you are using it:
import { add, remove } from './ExtendableRegistery';| } | ||
| }; | ||
|
|
||
| export const getComponent = id => |
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.
maybe worth comparing with the ruby implementation for menus e.g. at https://github.com/theforeman/foreman/blob/develop/app/registries/menu/manager.rb
| class Fill extends React.Component { | ||
| componentDidMount() { | ||
| const { children, registerFillComponent, id, weight, fillId } = this.props; | ||
| debugger; |
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.
oops
| removeRegisteredComponent(id, fillId); | ||
| } | ||
| render() { | ||
| return <div />; |
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.
TODO?
|
This is amazing! Would be great to have an option to give props to |
|
Great idea @glekner ! Props way// plugin
<Fill id='slot-id' fillId='some-id' overrideProps={{ text: 'this text given by a prop' }} /> // foreman core
const Wrapper = ({ text }) => <div>{text}</div>;
<Slot id='slot-id'>
<Wrapper text='some default text' />
</Slot>JSX way// plugin
<Fill id='slot-id' fillId='some-id'>
<div> some text </ div>
</ Fill>// foreman core
<Slot id='slot-id'>
default children // can be empty
</Slot> |
|
|
||
| export const remove = (SlotId, key) => { | ||
| if (components[SlotId]) { | ||
| components[SlotId].forEach((item, index) => { |
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.
nit: have you considered using filter?
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.
filter creates a new array, while using splice the removing process is in place.
we can use filter and splice, having something like:
obj.splice(0, obj.length, ...obj.filter(item => item.key !== key))
sharvit
left a comment
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.
Awesome work @amirfefer 🥇
| componentWillUnmount() { | ||
| const { id, removeRegisteredComponent, fillId } = this.props; | ||
|
|
||
| removeRegisteredComponent(id, fillId); |
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.
nitpick: unregisterFillComponent?
| if (isValidElement(object)) { | ||
| return cloneElement(object, props); | ||
| } | ||
| return cloneElement(children, object); |
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.
shouldn't you keep the old props? return cloneElement(children, { ...props, ...object });
| export const reducers = { extends: reducer }; | ||
|
|
||
| // export connected component | ||
| export default connect( |
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.
should be added into component registry, same for Slot
| @@ -0,0 +1,7 @@ | |||
| module ExtendableComponentsHelper | |||
| def slot(slot_id, multi=false) | |||
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.
Layout/SpaceAroundEqualsInParameterDefault: Surrounding space missing in default value assignment.
| @@ -0,0 +1,24 @@ | |||
| import { REGISTER_FILL, REMOVE_FILLED_COMPONENT } from './FillConstants'; | |||
| import { add, remove } from './ExtendableRegistery'; | |||
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.
Google knows only the version without 'e', could you rename please?
|
|
||
| case REMOVE_FILLED_COMPONENT: | ||
| return state.setIn( | ||
| ['RegisteredComponent', payload.slotId, payload.fillId], |
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.
Same as comment on the other end.
| </div> | ||
| </div> | ||
|
|
||
| <%= slot('about-footer-slot', true) %> |
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.
|
@amirfefer can you rebase this so I can test it out please? |
|
I'm closing this PR because I opened another one |


Work In Progress
This PR is written according to this design

In this demonstration I've added
<Fill>component in katello subscription details page, and a<Slot>in the upper left bar: