open-vault/ui/app/helpers/split-object.js
Angel Garbarino c013e4a741
UI add custom metadata to KV2 (#12169)
* initial setup

* form field editType kv is very helpful

* setting up things

* setup two routes for metadata

* routing

* clean up routing

* meh router changes not my favorite but its working

* show metadata

* add controller for backendCrumb mixin

* setting up edit metadata and trimming SecretEditMetadata component

* add edit metadata save functionality

* create new version work

* setup model and formfieldgroups for added config data.

* add config network request to secret-engine

* fix validations on config

* add config rows

* breaking up secret edit

* add validation for metadata on create

* stuff, but broken now on metadata tab

* fix metadata route error

* permissions

* saving small text changes

* permissions

* cleanup

* some test fixes and convert secret create or update to glimmer

* all these changes fix secret create kv test

* remove alert banners per design request

* fix error for array instead of object in jsonEditor

* add changelog

* styling

* turn into glimmer component

* cleanup

* test failure fix

* add delete or

* clean up

* remove all hardcoded for api integration

* add helper and fix create mode on create new version

* address chelseas pr comments

* add jsdocs to helper

* fix test
2021-08-31 09:41:41 -06:00

33 lines
1.1 KiB
JavaScript

/**
* @module SplitObject
* SplitObject helper takes in a class of data as the first param and an array of keys that you want to split into another object as the second param.
* You will end up with an array of two objects. One no longer with the array of params, and the second with just the array of params.
*
* @example
* ```js
* splitObject(data, ['max_versions', 'delete_version_after', 'cas_required'])
* ```
* @param {object} - The object you want to split into two. This object will have all the keys from the second param (the array param).
* @param {array} - An array of params that you want to split off the object and turn into its own object.
*/
import { helper as buildHelper } from '@ember/component/helper';
export function splitObject(originalObject, array) {
let object1 = {};
let object2 = {};
// convert object to key's array
let keys = Object.keys(originalObject);
keys.forEach(key => {
if (array.includes(key)) {
object1[key] = originalObject[key];
} else {
object2[key] = originalObject[key];
}
});
return [object1, object2];
}
export default buildHelper(splitObject);