Files
threshold-ui/addons/api/mirage/factories/worker.js
T
Cameron Perera 40ebbf8b09 Icu 13889 update tags column to action that opens hds flyout and add link to tags tab if more than 10 tags (#2355)
* refactor: 💡 update worker factory to include api_tags

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13889

* feat: 🎸 add tags flyout for workers table

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13889

* refactor: 💡 move test selector to const

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13889

* refactor: 💡 only show 'view more tags' if more than 10 tags

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13889

* test: 💍 update test name

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13889

* refactor: 💡 update how worker tags are shown in flyout

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13889

* refactor: 💡 add one more api tag for worker in mirage

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13889

* refactor: 💡 fix tagDisplayName signature

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13889

* refactor: 💡 update tag shortener styling

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13889
2024-07-16 15:48:10 -05:00

74 lines
1.7 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import factory from '../generated/factories/worker';
import permissions from '../helpers/permissions';
import generateId from '../helpers/id';
import { faker } from '@faker-js/faker';
const types = ['pki', 'kms'];
export default factory.extend({
id: () => generateId('w_'),
authorized_actions: () =>
permissions.authorizedActionsFor('worker') || [
'no-op',
'read',
'update',
'delete',
],
type: (i) => types[i % types.length],
config_tags: (i) => {
if (i % 3 === 0) {
return {
os: ['ubuntu'],
env: ['dev', 'local'],
};
}
if (i % 2 === 0) {
return { os: ['ubuntu'] };
}
return undefined;
},
api_tags: (i) => {
if (i % 3 === 0) {
return {
type: [faker.word.words(1), faker.word.words(1)],
os: ['z-os'],
env: ['prod', 'qa'],
sample: [faker.word.words(1), faker.word.words(1)],
path: [faker.word.words(1)],
};
}
if (i % 2 === 0) {
return { os: ['z-os'] };
}
return undefined;
},
canonical_tags() {
const configTags = this.config_tags || {};
const apiTags = this.api_tags || {};
const canonicalTags = {};
Object.keys(configTags).forEach((key) => {
canonicalTags[key] = new Set(configTags[key]);
});
Object.keys(apiTags).forEach((key) => {
if (canonicalTags[key]) {
apiTags[key].forEach((tag) => canonicalTags[key].add(tag));
} else {
canonicalTags[key] = new Set(apiTags[key]);
}
});
Object.keys(canonicalTags).forEach((key) => {
canonicalTags[key] = Array.from(canonicalTags[key]);
});
return canonicalTags;
},
});