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

Admin UI branding hook #2474

Merged
merged 4 commits into from
Apr 16, 2020
Merged

Conversation

Vultraz
Copy link
Contributor

@Vultraz Vultraz commented Mar 3, 2020

This adds a new Branding Admin UI hook. This should be a React component and will appear on the Sign In page. In order to get this working, I needed to enable access to the Admin UI hooks prior to login. Should be ok since we allow access to the admin meta at that point already.

Does this seem like a good design?

@gautamsi (Since you've been working on the hooks stuff)

Example usage:

const Branding = memo(BrandingComponent);

export default {
  branding: {
    logo: ({ defaultLogo }) => (<Branding />)
  }
};

Resolves #2175

@changeset-bot
Copy link

changeset-bot bot commented Mar 3, 2020

🦋 Changeset is good to go

Latest commit: 8918d0d

We got this.

This PR includes changesets to release 1 package
Name Type
@keystonejs/app-admin-ui Minor

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

@@ -124,7 +127,7 @@ const SignInPage = () => {
</Alerts>
<PageTitle>{siteName}</PageTitle>
<Form method="post" onSubmit={onSubmit}>
<KeystoneLogo />
{Branding ? <Branding /> : <KeystoneLogo />}
Copy link
Member

@gautamsi gautamsi Mar 3, 2020

Choose a reason for hiding this comment

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

with recently added one hook by @MadeByMike and I added other hooks in #2469 the paradigm is that we pass on the existing component and you can decide if you want to render additional components or replace it. like this :
const brandingHook = ({Logo, ...props}) => (<div><MyLogo/></Logo/></div>) and you pass on existing components like {Branding? brandingHookName({ Logo, ...otherProps}) : <Logo/>

In this scenario it will mostly be replaced, I am with the design you are proposing.

I also feel that we should have more hooks for branding, not just Branding as logo replacement. There are other places the Logo size may be small and we may need multiple hooks for each logo placement and guideline for size etc.

eventually:

{
   branding: {
       logo: LogoComponent,
      footer: FooterCompnent,
      primaryColor: ColorCSSObject,
// etc
   }
}

Copy link
Contributor

@MadeByMike MadeByMike Mar 4, 2020

Choose a reason for hiding this comment

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

Remember our discussion where we decided that we should not be passing props through hooks?

Once we made our Admin UI components completely stateless and rely on context variables we no longer even need to pass the existing components through the hooks. Instead we just export them from @keystonejs/app-admin-ui/components

We're also not going to nest hooks in favour of a flat structure:

{
  logo: LogoComponent,
  footer: FooterCompnent,
  header: HeaderComponent,
}

For the Header component add a style tag, or alternatively we export Helmet from the list of components and you use this in other hooks? I need to give some more thought to styling overrides so I'd suggest leaving it off any initial PRs.

@gautamsi
Copy link
Member

gautamsi commented Mar 3, 2020

It should not be a problem to have hooks before auth, as some environment may not even use auth.

moreover it is developer who can make use of non-auth components here.

@Vultraz Vultraz force-pushed the admin-ui-branding branch from 44099f3 to ed51f81 Compare March 4, 2020 07:01
@Vultraz
Copy link
Contributor Author

Vultraz commented Mar 4, 2020

@gautamsi Thanks! Incorporated your suggestions 😃

@Vultraz Vultraz marked this pull request as ready for review March 4, 2020 07:02
@Vultraz Vultraz changed the title [RFC] Admin UI branding hook Admin UI branding hook Mar 4, 2020
@@ -23,6 +23,6 @@ module.exports = {
new GraphQLApp(),
new StaticApp({ path: '/', src: 'public' }),
// Setup the optional Admin UI
new AdminUIApp({ enableDefaultRoute: true }),
new AdminUIApp({ enableDefaultRoute: true, hooks: require.resolve('./admin/') }),
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't actually need this as it will look for an admin folder by default

Copy link
Contributor

Choose a reason for hiding this comment

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

That said maybe an explicit example is better?

@@ -124,7 +127,7 @@ const SignInPage = () => {
</Alerts>
<PageTitle>{siteName}</PageTitle>
<Form method="post" onSubmit={onSubmit}>
<KeystoneLogo />
{Branding ? <Branding /> : <KeystoneLogo />}
Copy link
Contributor

@MadeByMike MadeByMike Mar 4, 2020

Choose a reason for hiding this comment

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

Remember our discussion where we decided that we should not be passing props through hooks?

Once we made our Admin UI components completely stateless and rely on context variables we no longer even need to pass the existing components through the hooks. Instead we just export them from @keystonejs/app-admin-ui/components

We're also not going to nest hooks in favour of a flat structure:

{
  logo: LogoComponent,
  footer: FooterCompnent,
  header: HeaderComponent,
}

For the Header component add a style tag, or alternatively we export Helmet from the list of components and you use this in other hooks? I need to give some more thought to styling overrides so I'd suggest leaving it off any initial PRs.

Copy link
Contributor

@MadeByMike MadeByMike left a comment

Choose a reason for hiding this comment

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

Can we please split this up into one PR per hook implementing my suggestions above.

@Vultraz
Copy link
Contributor Author

Vultraz commented Mar 5, 2020

@MadeByMike switched to logo (no more nesting), stopped passing the default logo to the hook, and exported KeystoneLogo.

@abhijithvijayan
Copy link

Any updates on this PR?

@Vultraz
Copy link
Contributor Author

Vultraz commented Mar 22, 2020

It's ready, just waiting final approval by @MadeByMike

@timleslie timleslie merged commit 57e6ce2 into keystonejs:master Apr 16, 2020
@github-actions github-actions bot mentioned this pull request Apr 16, 2020
@Vultraz Vultraz deleted the admin-ui-branding branch April 16, 2020 22:59
Wkasel pushed a commit to gosignal/keystone that referenced this pull request Apr 30, 2020
@rafaneri
Copy link

rafaneri commented Nov 8, 2020

@Vultraz , how to use this feature?

@VinayaSathyanarayana
Copy link
Contributor

Is this still Work in Progress or merged?

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.

How to change admin UI logo
7 participants