mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-01 19:17:58 +00:00
UI: OIDC config cleanup (#17105)
* cleanup infotableitemarray, add render name option to component * wait until items fetched before rendering child component * update test * finish tests for info table item array * remove unused capability checks * remove unnecessary path alias * fix info table row arg * fix wildcards getting info tooltip
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
import Component from '@glimmer/component';
|
||||
import { tracked } from '@glimmer/tracking';
|
||||
import { inject as service } from '@ember/service';
|
||||
import { task } from 'ember-concurrency';
|
||||
import { isWildcardString } from 'vault/helpers/is-wildcard-string';
|
||||
import { action } from '@ember/object';
|
||||
|
||||
/**
|
||||
* @module InfoTableItemArray
|
||||
@@ -30,15 +29,17 @@ import { isWildcardString } from 'vault/helpers/is-wildcard-string';
|
||||
* @param {boolean} [isLink] - Indicates if the item should contain a link-to component. Only setup for arrays, but this could be changed if needed.
|
||||
* @param {string || array} [rootRoute="vault.cluster.secrets.backend.list-root"] - Tells what route the link should go to when selecting "view all". If the route requires more than one dynamic param, insert an array.
|
||||
* @param {string || array} [itemRoute=vault.cluster.secrets.backend.show] - Tells what route the link should go to when selecting the individual item. If the route requires more than one dynamic param, insert an array.
|
||||
* @param {string} [modelType] - Tells which model you want data for the allOptions to be returned from. Used in conjunction with the the isLink.
|
||||
* @param {string} [modelType] - Tells which model you want to query and set allOptions. Used in conjunction with the the isLink.
|
||||
* @param {string} [wildcardLabel] - when you want the component to return a count on the model for options returned when using a wildcard you must provide a label of the count e.g. role. Should be singular.
|
||||
* @param {string} [backend] - To specify which backend to point the link to.
|
||||
* @param {boolean} [doNotTruncate=false] - Determines whether to show the View all "roles" link.
|
||||
* @param {boolean} [doNotTruncate=false] - Determines whether to show the View all "roles" link. Otherwise uses the ReadMore component's "See More" toggle
|
||||
* @param {boolean} [renderItemName=false] - If true renders the item name instead of its id
|
||||
*/
|
||||
export default class InfoTableItemArray extends Component {
|
||||
@tracked allOptions = null;
|
||||
@tracked wildcardInDisplayArray = false;
|
||||
@service store;
|
||||
@tracked allOptions = null;
|
||||
@tracked itemNameById; // object is only created if renderItemName=true
|
||||
@tracked fetchComplete = false;
|
||||
|
||||
get rootRoute() {
|
||||
return this.args.rootRoute || 'vault.cluster.secrets.backend.list-root';
|
||||
@@ -62,29 +63,26 @@ export default class InfoTableItemArray extends Component {
|
||||
return displayArray;
|
||||
}
|
||||
|
||||
async checkWildcardInArray() {
|
||||
if (!this.args.displayArray) {
|
||||
return;
|
||||
}
|
||||
let filteredArray = await this.args.displayArray.filter((item) => isWildcardString([item]));
|
||||
this.wildcardInDisplayArray = filteredArray.length > 0 ? true : false;
|
||||
}
|
||||
|
||||
@task *fetchOptions() {
|
||||
@action async fetchOptions() {
|
||||
if (this.args.isLink && this.args.modelType) {
|
||||
let queryOptions = {};
|
||||
let queryOptions = this.args.backend ? { backend: this.args.backend } : {};
|
||||
|
||||
if (this.args.backend) {
|
||||
queryOptions = { backend: this.args.backend };
|
||||
let modelRecords = await this.store.query(this.args.modelType, queryOptions).catch((err) => {
|
||||
if (err.httpStatus === 404) {
|
||||
return [];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
this.allOptions = modelRecords ? modelRecords.mapBy('id') : null;
|
||||
if (this.args.renderItemName && modelRecords) {
|
||||
modelRecords.forEach(({ id, name }) => {
|
||||
// create key/value pair { item-id: item-name } for each record
|
||||
this.itemNameById = { ...this.itemNameById, [id]: name };
|
||||
});
|
||||
}
|
||||
|
||||
let options = yield this.store.query(this.args.modelType, queryOptions);
|
||||
this.formatOptions(options);
|
||||
}
|
||||
this.checkWildcardInArray();
|
||||
}
|
||||
|
||||
formatOptions(options) {
|
||||
this.allOptions = options.mapBy('id');
|
||||
this.fetchComplete = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user