From 8df0232a78a3d2cd62268eca7e07dfb39bb23ea3 Mon Sep 17 00:00:00 2001 From: Angel Garbarino Date: Wed, 7 Sep 2022 14:04:41 -0700 Subject: [PATCH] Move SecretListHeader and SecretListHeaderTab to addon folder (#16981) * move two components to add on and create new helper for engines * change nmae of options-for-backend. will need conditional in template * move options for backend * pass through isEngine to secretListHeaderTab * secret list header remove comments * conditional options-for-backend * missing part for documentation * pr comments cleanup * cleanup * cleanup * cleanup --- ui/app/components/secret-list-header.js | 15 ---- .../components/secret-list-header-tab.hbs | 5 -- .../addon/components/key-value-header.hbs | 2 +- .../core/addon/components/key-value-header.js | 2 + .../components/secret-list-header-tab.hbs | 11 +++ .../components/secret-list-header-tab.js | 3 + .../addon}/components/secret-list-header.hbs | 69 +++++++++++-------- .../addon/components/secret-list-header.js | 29 ++++++++ .../addon}/helpers/options-for-backend.js | 16 ++++- .../app/components/secret-list-header-tab.js | 1 + .../core/app/components/secret-list-header.js | 1 + .../core/app/helpers/options-for-backend.js | 1 + ui/lib/pki/addon/templates/overview.hbs | 11 ++- 13 files changed, 114 insertions(+), 52 deletions(-) delete mode 100644 ui/app/components/secret-list-header.js delete mode 100644 ui/app/templates/components/secret-list-header-tab.hbs create mode 100644 ui/lib/core/addon/components/secret-list-header-tab.hbs rename ui/{app => lib/core/addon}/components/secret-list-header-tab.js (92%) rename ui/{app/templates => lib/core/addon}/components/secret-list-header.hbs (63%) create mode 100644 ui/lib/core/addon/components/secret-list-header.js rename ui/{app => lib/core/addon}/helpers/options-for-backend.js (93%) create mode 100644 ui/lib/core/app/components/secret-list-header-tab.js create mode 100644 ui/lib/core/app/components/secret-list-header.js create mode 100644 ui/lib/core/app/helpers/options-for-backend.js diff --git a/ui/app/components/secret-list-header.js b/ui/app/components/secret-list-header.js deleted file mode 100644 index 4bb884d46e..0000000000 --- a/ui/app/components/secret-list-header.js +++ /dev/null @@ -1,15 +0,0 @@ -import Component from '@glimmer/component'; - -export default class SecretListHeader extends Component { - // api - isCertTab = false; - isConfigure = false; - baseKey = null; - backendCrumb = null; - model = null; - options = null; - - get isKV() { - return ['kv', 'generic'].includes(this.args.model.engineType); - } -} diff --git a/ui/app/templates/components/secret-list-header-tab.hbs b/ui/app/templates/components/secret-list-header-tab.hbs deleted file mode 100644 index afae54be72..0000000000 --- a/ui/app/templates/components/secret-list-header-tab.hbs +++ /dev/null @@ -1,5 +0,0 @@ -{{#unless this.dontShowTab}} - - {{@label}} - -{{/unless}} \ No newline at end of file diff --git a/ui/lib/core/addon/components/key-value-header.hbs b/ui/lib/core/addon/components/key-value-header.hbs index 29da23c953..28e048ac96 100644 --- a/ui/lib/core/addon/components/key-value-header.hbs +++ b/ui/lib/core/addon/components/key-value-header.hbs @@ -4,7 +4,7 @@ {{#each this.secretPath as |path index|}}
  • / - {{#if this.linkToPaths}} + {{#if (and this.linkToPaths (not @isEngine))}} + {{@label}} + + {{else}} + + {{@label}} + + {{/if}} +{{/unless}} \ No newline at end of file diff --git a/ui/app/components/secret-list-header-tab.js b/ui/lib/core/addon/components/secret-list-header-tab.js similarity index 92% rename from ui/app/components/secret-list-header-tab.js rename to ui/lib/core/addon/components/secret-list-header-tab.js index a6cf273962..ef281b5d13 100644 --- a/ui/app/components/secret-list-header-tab.js +++ b/ui/lib/core/addon/components/secret-list-header-tab.js @@ -14,6 +14,8 @@ * @param {string} [path] - set on options-for-backend this tells us the specifics of the URL the query should hit. * @param {string} label - The name displayed on the tab. Set on the options-for-backend. * @param {string} [tab] - The name of the tab. Set on the options-for-backend. + * @param {boolean} [isEngine=false] - If used within an Ember engine, will need to modify how the links to routes are defined. + * @param {string} [link] - If within an engine provide the name of the link that is defined in the routes file fo the engine, example : 'overview'. * */ import Component from '@glimmer/component'; @@ -23,6 +25,7 @@ import { inject as service } from '@ember/service'; export default class SecretListHeaderTab extends Component { @service store; @tracked dontShowTab; + constructor() { super(...arguments); this.fetchCapabilities(); diff --git a/ui/app/templates/components/secret-list-header.hbs b/ui/lib/core/addon/components/secret-list-header.hbs similarity index 63% rename from ui/app/templates/components/secret-list-header.hbs rename to ui/lib/core/addon/components/secret-list-header.hbs index dbaeeaf43a..7399bd0b72 100644 --- a/ui/app/templates/components/secret-list-header.hbs +++ b/ui/lib/core/addon/components/secret-list-header.hbs @@ -1,14 +1,23 @@ -{{#let (options-for-backend @model.engineType) as |options|}} +{{#let (options-for-backend @model.engineType "" @isEngine) as |options|}} - +
  • / - - secrets - + {{#if @isEngine}} + {{link-to-external "secrets" "secrets"}} + {{else}} + + secrets + + {{/if}}
  • @@ -28,35 +37,39 @@ {{#if options.tabs}}
    {{else}} diff --git a/ui/lib/core/addon/components/secret-list-header.js b/ui/lib/core/addon/components/secret-list-header.js new file mode 100644 index 0000000000..c462452dd5 --- /dev/null +++ b/ui/lib/core/addon/components/secret-list-header.js @@ -0,0 +1,29 @@ +import Component from '@glimmer/component'; + +/** + * @module SecretListHeader + * SecretListHeader component is breadcrumb, title with icon and menu with tabs component. + * + * @example + * ```js + * + * ``` + * @param {object} model - Model used to pull information about icon and title and backend type for navigation. + * @param {string} [baseKey] - Provided for navigation on the breadcrumbs. + * @param {object} [backendCrumb] - Includes label, text, path and model ID. + * @param {boolean} [isEngine=false] - Changes link type if the component is being used inside an Ember engine. + */ + +export default class SecretListHeader extends Component { + get isKV() { + return ['kv', 'generic'].includes(this.args.model.engineType); + } +} diff --git a/ui/app/helpers/options-for-backend.js b/ui/lib/core/addon/helpers/options-for-backend.js similarity index 93% rename from ui/app/helpers/options-for-backend.js rename to ui/lib/core/addon/helpers/options-for-backend.js index bf52622288..dd7feccd2d 100644 --- a/ui/app/helpers/options-for-backend.js +++ b/ui/lib/core/addon/helpers/options-for-backend.js @@ -10,6 +10,18 @@ const DEFAULT_DISPLAY = { editComponent: 'secret-edit', listItemPartial: 'secret-list/item', }; +const ENGINE_SECRET_BACKENDS = { + pki: { + displayName: 'PKI', + navigateTree: false, + tabs: [ + { + label: 'Overview', + link: 'overview', + }, + ], + }, +}; const SECRET_BACKENDS = { aws: { displayName: 'AWS', @@ -166,8 +178,8 @@ const SECRET_BACKENDS = { }, }; -export function optionsForBackend([backend, tab]) { - const selected = SECRET_BACKENDS[backend]; +export function optionsForBackend([backend, tab, isEngine]) { + const selected = isEngine ? ENGINE_SECRET_BACKENDS[backend] : SECRET_BACKENDS[backend]; let backendOptions; if (selected && selected.tabs) { diff --git a/ui/lib/core/app/components/secret-list-header-tab.js b/ui/lib/core/app/components/secret-list-header-tab.js new file mode 100644 index 0000000000..fe2874d345 --- /dev/null +++ b/ui/lib/core/app/components/secret-list-header-tab.js @@ -0,0 +1 @@ +export { default } from 'core/components/secret-list-header-tab'; diff --git a/ui/lib/core/app/components/secret-list-header.js b/ui/lib/core/app/components/secret-list-header.js new file mode 100644 index 0000000000..ed151c7b9a --- /dev/null +++ b/ui/lib/core/app/components/secret-list-header.js @@ -0,0 +1 @@ +export { default } from 'core/components/secret-list-header'; diff --git a/ui/lib/core/app/helpers/options-for-backend.js b/ui/lib/core/app/helpers/options-for-backend.js new file mode 100644 index 0000000000..c31004620e --- /dev/null +++ b/ui/lib/core/app/helpers/options-for-backend.js @@ -0,0 +1 @@ +export { default } from 'core/helpers/options-for-backend'; diff --git a/ui/lib/pki/addon/templates/overview.hbs b/ui/lib/pki/addon/templates/overview.hbs index 560b7a964c..ed227a84ce 100644 --- a/ui/lib/pki/addon/templates/overview.hbs +++ b/ui/lib/pki/addon/templates/overview.hbs @@ -1 +1,10 @@ -Overview WIP \ No newline at end of file + \ No newline at end of file