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

COR-680: Tenant Switcher #522

Merged
merged 82 commits into from
Oct 4, 2017
Merged

COR-680: Tenant Switcher #522

merged 82 commits into from
Oct 4, 2017

Conversation

MKwenhua
Copy link
Contributor

@MKwenhua MKwenhua commented Sep 1, 2017

Purpose:

Have a tenant switcher so that users can easily change the Cortex Tenant like CircleCI

JIRA:

https://cb-content-enablement.atlassian.net/browse/COR-680

Steps to Take On Prod

  1. run migrations on the database

Changes:

  • Changes to setup

    • run bundle exec rake db:migrate
  • Architectural changes
    *

  • Migrations

    • yes I added a new attribute on User active_tenant
  • Library changes

    • yes I made changes to cortex-plugins
  • Side effects
    *

Screenshots

  • Before
    cortex administration dashboard 2017-09-05 17-29-08

  • After
    cortex administration dashboard 2017-09-05 17-29-33

QA Links:

http://web.cortex-3.development.c66.me/

How to Verify These Changes

  • Specific pages to visit
    *

  • Steps to take

  1. go to http://web.cortex-3.development.c66.me/
  2. try and switch tenants
  3. make sure the UI responds as it's supposed to.
  4. refresh the page and make sure the Tenant change has persisted.
  • Responsive considerations
    *

Relevant PRs/Dependencies:

cortex-cms/cortex-plugins-core#60

Additional Information

A few things to note: classes like .sidebar--tentant-display are temporary and should be removed once both the side bar and the content area are rendered within React.

} from 'dashboard/elements/loaders'

const TenantItem = ({name, subdomain}, tenantClicked) => (
<li key={subdomain} className="mdl-list__item" onClick={tenantClicked}>
Copy link
Member

Choose a reason for hiding this comment

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

I think you'd need to add the button role (among other things, such as tabindex) to make this accessible: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_button_role

More important for Employer than Cortex, but accessability issues are something we want to avoid regardless

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok I will add

Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch here! Could the contents of the li be a button or a tag instead? Then you wouldn't need the button role. Before adding ARIA roles consider if there is a way to make the HTML more semantic

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@arelia I just used the mdl https://getmdl.io/components/index.html#lists-section examples for list items and if I were to add a button inside of the list item I would have to add extra styling to override the default browser stylings and well as account for potential overriding of any default behaviors. I just tried wrapping the list items and it would require a lot of extra styling:

  • button

cortex administration dashboard 2017-09-06 13-30-26

  • a-tag
    cortex administration dashboard 2017-09-06 13-29-52

…tainer to remove sidebar--tenant-display class from #layout_wrapper on successful tenant switch
… method to index and create a lookup object for tenants by organization
@toastercup
Copy link
Member

@MKwenhua The main issue I'm seeing so far is that there's no way to select a top-level tenant/org - if you click it, it expands to display sub-tenants, but does not allow you to select the top-level tenant itself. Most of our users will be interacting with top-level tenants, so this we'll need to sort out how this works prior to merge. Let's whiteboard this and discuss.

@MKwenhua
Copy link
Contributor Author

MKwenhua commented Sep 6, 2017

The main issue I'm seeing so far is that there's no way to select a top-level tenant/org - if you click it, it expands to display sub-tenants, but does not allow you to select the top-level tenant itself. Most of our users will be interacting with top-level tenants, so this we'll need to sort out how this works prior to merge. Let's whiteboard this and discuss.

@toastercup Oh yeah! How did I miss that, when you get the time let's discuss the implementation details

Copy link
Contributor

@arelia arelia left a comment

Choose a reason for hiding this comment

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

I don't think I need to re-review for any of my comments, since all of this is temporary. The only thing I'm really concerned about is making sure there are lis nested in the ul tags and not spans

});
// $(document).ready(function(){
// $('#sidebar__toggle-button').on('click', function() {
// $('body').toggleClass('sidebar--collapsed');
Copy link
Contributor

Choose a reason for hiding this comment

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

Either way is fine with me, but since you've commented this out, if you're planning to bring this back later should the class name go back to being .layout__container so that it works if you un-comment this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh actually I was planning on removing that code completely, but yeah I have changed it to having a parent conatianer over .layout__container called #layout_wrapper which is used for the three Dashboard layout states 'no class', .sidebar--collapsed, and .sidebar--tentant-display

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

height: 11em;
border-radius: 50%;
background: $color-teal;
background: -moz-linear-gradient(left, $color-teal 10%, rgba(0,255,255, 0) 42%);
Copy link
Contributor

Choose a reason for hiding this comment

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

this doesn't reallly matter since all of this will eventually be redone, but Cortex only supports newer browsers and newer browsers don't need the prefixed version of linear-gradient, so you only need line 22

same for animation transform and @keyframes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't write this I just copied and pasted the css code I found here: https://projects.lukehaas.me/css-loaders/ pretty much all of the styles I have added are just temporary placeholders.

But with that said I will go back and remove the vendor prefixes.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

if (environment === 'production') return null
const flagClass = `mdl-navigation__link nav__item environment environment--${environment}`
return (
<div className={flagClass}>
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of rendering both divs, could you wrap them in an if/else?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Technically yes, but already in the CSS . environment__full is hidden and . environment__abbreviated is displayed when it has a parent with .sidebar--collapsed.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍 ok that's fine, it was just a thought since you're adding React

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh yeah, but I realized the logic was already accounted for so I just rendered out the HTML. Glad that the logic was already there so that I wouldn't have to account for it when creating the components

} from 'dashboard/elements/loaders'

const TenantItem = ({name, subdomain}, tenantClicked) => (
<li key={subdomain} className="mdl-list__item" onClick={tenantClicked}>
Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch here! Could the contents of the li be a button or a tag instead? Then you wouldn't need the button role. Before adding ARIA roles consider if there is a way to make the HTML more semantic

let {org_tenant, sub_tenants } = OrganizationLookup[org_id]
return (
<span key={org_tenant.subdomain + '_org'}>
<li role="button" className={ "mdl-list__item organization--label" + (organization_displayed === org_tenant.id ? ' active' : '' ) } tabIndex={index} onClick={organizationClicked(org_id)}><strong>{org_tenant.name}</strong></li>
Copy link
Contributor

Choose a reason for hiding this comment

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

like the comment I added above, if you can make the content of the li be a button that's better than adding role="button". Take a look at the Featured Items on the HiringDot homepage, which are styled to not look like buttons at all

image

return OrganizationLookup.organizations.map((org_id, index) => {
let {org_tenant, sub_tenants } = OrganizationLookup[org_id]
return (
<span key={org_tenant.subdomain + '_org'}>
Copy link
Contributor

Choose a reason for hiding this comment

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

Since these are going to get rendered into a ul, which can only take lis as children, can you move the key attribute to the li tag?

Add the subtenent ul before the closing li tag (because it's a list nested inside a list, right?), or move it into it's own component if you have to (if it's not meant to be nested), and that way you'll still have everything wrapped inside of one tag

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@arelia Ok good catch! I changed it to UL instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

@MKwenhua I don't think the span needs to be a ul, just move the </li> so that is is after the </ul> and remove the spans, like this

return (
  <li key={org_tenant.subdomain + '_org'} role="button" className={ "mdl-list__item organization--label" + (organization_displayed === org_tenant.id ? ' active' : '' ) } tabIndex={index} onClick={organizationClicked(org_id)}>
    <strong>{org_tenant.name}</strong>
    <ul className={ organization_displayed === org_tenant.id ? "demo-list-icon mdl-list" : "hidden"}>
      { sub_tenants.map((tenant) => TenantItem(tenant, () => selectTenant(tenant)) )}
    </ul>
  </li>
)

The subtenant list is a sub-list of the org tenant list, and so you can wrap that ul completely in the li

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@arelia yeah, using li was my first approach but there is some default hover state and styling set to list items so I ended up creating a class to offset it called .organization-tenants-list but then I decided that a UL would be easier, in fact I should probably remove the wrapping <ul className="demo-list-icon mdl-list"> and have the resulting HTML output like <ul>org 1 list</ul><ul>org 2 list</ul><ul>org 3 list</ul>

Copy link
Contributor

Choose a reason for hiding this comment

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

I think semantically it makes sense to have it all wrapped in <ul className="demo-list-icon mdl-list"> but again, since we'll re-do all of this do whatever works and is easiest, that's fine with me! So if you don't make any more changes, I'm okay with that

toastercup and others added 28 commits September 28, 2017 15:52
…l legacy concerns (API, Localizations, Doorkeeper, Abilities, etc)
…ant FK to correct table, start to integrate with Tenant Switcher component
… to base record class, simplify and correct various associations
…ble ContentItems per-tenant, implement basic Org logic, simplify active_tenant behavior, refresh upon tenant switch, prepare seeds
@toastercup toastercup merged commit 33548c8 into develop Oct 4, 2017
@toastercup toastercup deleted the COR-680/Tenant-Switcher branch October 4, 2017 22:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants