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

Allows selected injected default vars to be merged instead of overwritten #25318

Merged
merged 5 commits into from
Nov 16, 2018

Conversation

legrego
Copy link
Member

@legrego legrego commented Nov 7, 2018

Summary

Currently, injected variables (via injectDefaultVars) allows a variable from one plugin to overwrite a variable of the same name that another plugin provided.

This PR updates the collection of default variables to "flat merge" select variables together, so that properties from one plugin don't clobber variables from another plugin.

This is required to implement the uiCapabilities collection that we discussed.

Example (current functionality):

// Plugin 1
injectDefaultVars() {
	return {
      a: 'plugin 1',
      b: {
         c: 'plugin 1'
      }
	}
}
// Plugin 2
injectDefaultVars() {
	return {
      b: {
         d: 'plugin 2'
      }
	}
}

Results in:

{
  a: 'plugin 1',
  b: {
     d: 'plugin 2'
  }
}

Example (after this PR):

// Plugin 1
injectDefaultVars() {
	return {
      a: 'plugin 1',
      b: {
         c: 'plugin 1'
      }
	}
}
// Plugin 2
injectDefaultVars() {
	return {
      b: {
         d: 'plugin 2'
      }
	}
}

Results in:

{
  a: 'plugin 1',
  b: {
	 c: 'plugin 1',
     d: 'plugin 2'
  }
}

@legrego legrego added WIP Work in progress v7.0.0 v6.6.0 labels Nov 7, 2018
@legrego legrego requested review from spalger and kobelb November 7, 2018 18:21
kobelb
kobelb previously approved these changes Nov 7, 2018
Copy link
Contributor

@kobelb kobelb left a comment

Choose a reason for hiding this comment

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

LGTM - I did a quick audit of our existing default vars, and I'm not seeing any overlap currently that would be relying on the old behavior, and if they wanted to use the old behavior, they can do so using replaceInjectedVars.

@spalger
Copy link
Contributor

spalger commented Nov 7, 2018

I assume we will also want to use defaultDeep() when merging the injectedVars for an app and from the other defaults:

// kibana.js
uiExports: {
  app: {
    // ...
    injectedVars() {
      return {
        uiCapabilities: {
          x: true,
        }
      }
    }
  }
}

// nav_control.js
uiExports: {
  navControl: [ /* ... */ ],
  defaultInjectedVars() {
    return {
      uiCapabilities: {
        y: true,
      }
    }
  }
}

@spalger
Copy link
Contributor

spalger commented Nov 7, 2018

Actually, I take that back, I think we should limit the deep merging to just the uiCapabilities key. We can special case it in ui_render_mixin.js and support deep merging there, in the right order (and maybe even get rid of lodash in this module as a bonus?!). I think there is a decent amount of risk deep merging the injectedVars, and if we just special cased this key we could avoid all that risk.

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@kobelb
Copy link
Contributor

kobelb commented Nov 7, 2018

Actually, I take that back, I think we should limit the deep merging to just the uiCapabilities key. We can special case it in ui_render_mixin.js and support deep merging there, in the right order (and maybe even get rid of lodash in this module as a bonus?!). I think there is a decent amount of risk deep merging the injectedVars, and if we just special cased this key we could avoid all that risk.

If we're going to handle the uiCapabilities in a special case, should we just do a "flat merge" there as well? So it becomes a barely deep only for uiCapabilities merge?

@spalger
Copy link
Contributor

spalger commented Nov 7, 2018

If we're going to handle the uiCapabilities in a special case, should we just do a "flat merge" there as well?

I'm good with that if it accomplishes what we need

@legrego legrego changed the title Allows injected default vars to be merged instead of overwritten Allows selected injected default vars to be merged instead of overwritten Nov 8, 2018
src/ui/ui_render/lib/merge_variables.ts Outdated Show resolved Hide resolved
@elasticmachine

This comment has been minimized.

@elasticmachine

This comment has been minimized.

@legrego legrego force-pushed the default-vars-defaults-deep branch from 28747ab to 0021f89 Compare November 8, 2018 18:29
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@legrego legrego removed the WIP Work in progress label Nov 9, 2018
Copy link
Contributor

@spalger spalger left a comment

Choose a reason for hiding this comment

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

LGTM

@legrego legrego force-pushed the default-vars-defaults-deep branch from 0021f89 to 70bb471 Compare November 13, 2018 16:36
@elasticmachine
Copy link
Contributor

💔 Build Failed

@legrego legrego force-pushed the default-vars-defaults-deep branch from 70bb471 to b29db21 Compare November 13, 2018 19:37
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Contributor

💔 Build Failed

@legrego
Copy link
Member Author

legrego commented Nov 15, 2018

retest

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@legrego legrego merged commit 33f61a8 into elastic:master Nov 16, 2018
legrego added a commit to legrego/kibana that referenced this pull request Nov 16, 2018
…tten (elastic#25318)

## Summary

Currently, injected variables (via `injectDefaultVars`) allows a variable from one plugin to overwrite a variable of the same name that another plugin provided.

This PR updates the collection of default variables to "flat merge" select variables together, so that properties from one plugin don't clobber variables from another plugin.

This is required to implement the `uiCapabilities` collection that we discussed.

### Example (current functionality):
```javascript
// Plugin 1
injectDefaultVars() {
	return {
      a: 'plugin 1',
      b: {
         c: 'plugin 1'
      }
	}
}
```

```javascript
// Plugin 2
injectDefaultVars() {
	return {
      b: {
         d: 'plugin 2'
      }
	}
}
```

Results in:
```javascript
{
  a: 'plugin 1',
  b: {
     d: 'plugin 2'
  }
}
```


### Example (after this PR):
```javascript
// Plugin 1
injectDefaultVars() {
	return {
      a: 'plugin 1',
      b: {
         c: 'plugin 1'
      }
	}
}
```

```javascript
// Plugin 2
injectDefaultVars() {
	return {
      b: {
         d: 'plugin 2'
      }
	}
}
```

Results in:
```javascript
{
  a: 'plugin 1',
  b: {
	 c: 'plugin 1',
     d: 'plugin 2'
  }
}
```
@legrego legrego deleted the default-vars-defaults-deep branch November 16, 2018 12:39
@legrego legrego added the non-issue Indicates to automation that a pull request should not appear in the release notes label Nov 16, 2018
legrego added a commit that referenced this pull request Nov 16, 2018
…verwritten (#25318) (#25798)

Backports the following commits to 6.x:
 - Allows selected injected default vars to be merged instead of overwritten  (#25318)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
non-issue Indicates to automation that a pull request should not appear in the release notes v6.6.0 v7.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants