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

Add more custom actions #2469

Closed
wants to merge 4 commits into from

Conversation

gautamsi
Copy link
Member

@gautamsi gautamsi commented Mar 3, 2020

adding more hooks like itemHeaderActions in #2279

  • listHeaderActions - this adds button in place of Create item button on list page.
    image
  • listManageActions - this adds button in place of multi select update on list page (Update Many and Delete Many).
    image
  • listItemActions - this adds dropdown buttons for each item in list. caveat: you have to recreate the DropDown component, can be copied from the source.
    image

All of the above is composable from the existing components on page. the react component should accept the components as props and render them if they want to keep the original component.

@changeset-bot
Copy link

changeset-bot bot commented Mar 3, 2020

🦋 Changeset is good to go

Latest commit: 030ab0c

We got this.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

onDelete={handleDelete}
/>
{listItemActions ? (
listItemActions({ list, item, link, onDelete, ...props, items })
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm sorry, I've done a poor job of communicating how AdminUI hooks are intended to work and this has evolved as we have discussed and evaluated the pattern.

Rather than passing a list of items to hooks like this:

We have decided that we want to make the components a part of the API, this makes it easier for people to add, remove, replace, and reorder parts as they need.

I know the current example in the codebase is a bad example as it is implemented in the same way as this:

...
{itemHeaderActions ? (
  itemHeaderActions({ ItemId, AddNewItem })
  ) : (
    <div>
      <ItemId />
      <AddNewItem />
    </div>
)}

This should be refactored to just:

{itemHeaderActions ? (
  itemHeaderActions(ctx)
  ) : (
    <div>
      <ItemId />
      <AddNewItem />
    </div>
)}

Your example is also exporting event callbacks which I assume is so that the consumer can manually re-apply these props to the items? This in particular is something we want to avoid.

In my example ctx is the as yet undetermined context variables such as the route and any other contextual information sortOrder etc... that may not be available through context. I began work creating a spec for each of these and what I think the context variables should be. I'll chase that down and share it here.

For this approach to work it's important that the items rendered inside a hook are simple stand-alone components without props: <ItemId /> and <AddNewItem /> have been refactored so that all the essential information is available from context providers.

For this to work, AddNewItem and ItemId both need to be exported from packages/app-admin-ui/components/index.js. This means consumers could write a hook like this:

// These imports are the API
import { AddNewItem, ItemID } from "@keystonejs/app-admin-ui/components";

export default {
  itemHeaderActions: (ctx) => (
    <>
     <ItemId />
     <p>Hello Admin Hooks</p>
     <AddNewItem />
    </>
  )
}

So... I know this is a bit of a pain but for this PR to be accepted I need it to conform with the intended direction. This means refactoring the components in listItemActions to be standalone and exported from packages/app-admin-ui/components/index.js. No props passed to listItemActions for now.

I'd also like to see one hook per PR for now as I want to be sure we are getting the API right before we add a bunch in one hook.

Copy link
Member Author

Choose a reason for hiding this comment

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

In my example ctx is the as yet undetermined context variables such as the route and any other contextual information sortOrder etc..

I think we can just use blank/no ctx for now and decide when the need come.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have create 4 new PR for this #2478 #2479 #2482 and #2483

currently no context is passed in custom action but added a provider for passing around specific details needed for making components stateless. more state/context info may be added as needed

@gautamsi
Copy link
Member Author

@MadeByMike seems like it is still not finalized 😞

@MadeByMike
Copy link
Contributor

@gautamsi what's the state of this PR? I feel like the other pull requests related to this are in better shape and maybe cover some of what is here. I'm not going to focus on this one today because I think that will be a distraction.

Is it worth factoring out the good bit from here and closing this?

@gautamsi
Copy link
Member Author

this was split into #2478, #2479 which are merged already.

remaining 2 PR can be reviewed separately #2482 and #2483, I will fix their conflict now.

@gautamsi gautamsi closed this May 27, 2020
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.

3 participants