Skip to content

[top nav] Enhancements to make nav item state more dynamic#7630

Merged
ycombinator merged 12 commits intoelastic:masterfrom
ycombinator:kbn-top-nav/enhancements
Jul 6, 2016
Merged

[top nav] Enhancements to make nav item state more dynamic#7630
ycombinator merged 12 commits intoelastic:masterfrom
ycombinator:kbn-top-nav/enhancements

Conversation

@ycombinator
Copy link
Copy Markdown
Contributor

@ycombinator ycombinator commented Jul 5, 2016

Currently the state of a top nav item (specifically whether is should be hidden or not, via the hideButton property) can be set only once, when that item is registered. This PR introduces the following enhancements for top nav items:

  • Allows the hideButton property to be a function that returns a boolean value, instead of a scalar boolean value. If a scalar boolean value is passed in, it will be converted to a function that returns that boolean value; this preserves backwards-compatibility as well.
  • Introduces a disableButton property, similar in syntax to the hideButton property. When this property evaluates to true, the top nav button is disabled (grayed out and unclickable); else the top nav button appears and functions normally.
  • Introduces a tooltip property, similar in syntax to the hideButton property. This allows a tooltip to be shown on the top nav item.

@ycombinator
Copy link
Copy Markdown
Contributor Author

ycombinator commented Jul 5, 2016

Build (on old/current Jenkins) is passing after the latest commit (ed0c48a): http://build-eu-00.elastic.co/job/kibana_core_pr/4488/

This can be done because of better defaulting of non-function values, implemented in 0b0280c and ed0c48a.
border-radius: 0;
}

button.is-kbn-top-nav-button-disabled {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is it possible to simplify this to just the class .is-kbn-top-nav-button-disabled?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I tried that first but it didn't apply the style. I had to add button to make the selector more specific.

@cjcenizal
Copy link
Copy Markdown
Contributor

1 question, then 👍

@cjcenizal cjcenizal closed this Jul 5, 2016
@cjcenizal cjcenizal reopened this Jul 5, 2016
run: (item) => !item.disableButton() && this.toggle(item.key)
});

defaultedOpt.hideButton = isFunction(opt.hideButton) ? opt.hideButton : () => (opt.hideButton || false);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You can use _.result for all of these.

For example: defaultedOpt.hideButton = result(opt, 'hideButton', false);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah, thanks for finding that function. I looked through the lodash docs but result didn't sound like the thing I was looking for :)

@w33ble
Copy link
Copy Markdown
Contributor

w33ble commented Jul 6, 2016

This is a funny side effect of the function handling and the digest loop 🍔

jul-06-2016 12-57-32

Not a problem, just thought it was fun and wanted to share.

Aside from that change to using _.result, this LGTM!

@w33ble w33ble assigned ycombinator and unassigned w33ble Jul 6, 2016
@ycombinator ycombinator assigned w33ble and unassigned ycombinator Jul 6, 2016
@ycombinator
Copy link
Copy Markdown
Contributor Author

jenkins, test it

@ycombinator ycombinator force-pushed the kbn-top-nav/enhancements branch from e5e2ca2 to 46c37c0 Compare July 6, 2016 22:30
@ycombinator ycombinator force-pushed the kbn-top-nav/enhancements branch from 46c37c0 to cf99029 Compare July 6, 2016 22:40
// apply the defaults to individual options
_applyOptDefault(opt = {}) {
return defaults({}, opt, {
const defaultedOpt = defaults({}, opt, {
Copy link
Copy Markdown
Contributor

@cjcenizal cjcenizal Jul 6, 2016

Choose a reason for hiding this comment

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

I think this can be rewritten without defaults:

      const defaultedOpt = Object.assign({
        label: capitalize(opt.key),
        hasFunction: !!opt.run,
        description: opt.run ? opt.key : `Toggle ${opt.key} view`,
        run: (item) => !item.disableButton && this.toggle(item.key)
      }, opt);

@cjcenizal
Copy link
Copy Markdown
Contributor

Looks great, just had 1 suggestion and 1 question.

@cjcenizal
Copy link
Copy Markdown
Contributor

LGTM!

@w33ble
Copy link
Copy Markdown
Contributor

w33ble commented Jul 6, 2016

Changing to result actually stops the value from being evaluated with each digest loop, but just on route load instead.

jul-06-2016 16-16-50

Nice!

LGTM!!!

@ycombinator ycombinator merged commit c2e99e3 into elastic:master Jul 6, 2016
@ycombinator ycombinator deleted the kbn-top-nav/enhancements branch July 6, 2016 23:25
airow pushed a commit to airow/kibana that referenced this pull request Feb 16, 2017
…ents

[top nav] Enhancements to make nav item state more dynamic

Former-commit-id: c2e99e3
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.

4 participants