chore: 🤖 alias target route (#2228)
This commit is contained in:
1 parent
c550faddb4
commit
bd65c91ff9
21 files changed
+745
-17
No files matched your search
@@ -120,4 +120,17 @@ export default class TargetSerializer extends ApplicationSerializer {
|
||||
storage_bucket_id: snapshot?.attr('storage_bucket_id'),
|
||||
};
|
||||
}
|
||||
|
||||
normalize(typeClass, hash, ...rest) {
|
||||
const normalizedHash = structuredClone(hash);
|
||||
const normalized = super.normalize(typeClass, normalizedHash, ...rest);
|
||||
// Ember data retains the previous entry in the array attr when the updated attr becomes undefined/empty.
|
||||
// So, we explicitly set the attr to an empty array if the updated attribute is undefined from the API
|
||||
|
||||
if (!normalized.data.attributes.aliases) {
|
||||
normalized.data.attributes.aliases = [];
|
||||
}
|
||||
|
||||
return normalized;
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ export default ApplicationSerializer.extend({
|
||||
this,
|
||||
arguments,
|
||||
);
|
||||
const { hostSets } = this.schema;
|
||||
const { hostSets, aliases } = this.schema;
|
||||
if (model.hostSetIds?.length) {
|
||||
json.host_sources = model.hostSetIds.map((host_set_id) => {
|
||||
const hostSet = hostSets.find(host_set_id);
|
||||
@@ -28,6 +28,23 @@ export default ApplicationSerializer.extend({
|
||||
return { id: host_set_id, host_catalog_id };
|
||||
});
|
||||
}
|
||||
|
||||
// After we clear an associated alias, we try to mimic the BE logic
|
||||
// by manually filter out the alias id from the target model
|
||||
|
||||
const associatedAliases = aliases
|
||||
.all()
|
||||
.models.reduce((arr, { destinationId, id }) => {
|
||||
// We iterate through the aliases list and
|
||||
// find the cleared alias by looking for camelCase destinationId since there is no other way to find the impacted alias
|
||||
if (destinationId !== null) arr.push(id);
|
||||
return arr;
|
||||
}, []);
|
||||
|
||||
json.aliases = model.aliases?.filter((alias) =>
|
||||
associatedAliases.includes(alias.id),
|
||||
);
|
||||
|
||||
return json;
|
||||
},
|
||||
});
|
||||
@@ -285,6 +285,7 @@ module('Unit | Serializer | application', function (hooks) {
|
||||
type: 'target',
|
||||
attributes: {
|
||||
authorized_actions: [],
|
||||
aliases: [],
|
||||
name: 'Target 1',
|
||||
scope: { id: 'o_123', scope_id: 'o_123' },
|
||||
host_sources: [],
|
||||
|
||||
@@ -364,6 +364,7 @@ module('Unit | Serializer | target', function (hooks) {
|
||||
id: '1',
|
||||
type: 'target',
|
||||
attributes: {
|
||||
aliases: [],
|
||||
authorized_actions: [],
|
||||
name: 'Target 1',
|
||||
host_sources: [
|
||||
@@ -400,6 +401,7 @@ module('Unit | Serializer | target', function (hooks) {
|
||||
id: '1',
|
||||
type: 'target',
|
||||
attributes: {
|
||||
aliases: [],
|
||||
brokered_credential_source_ids: [],
|
||||
injected_application_credential_source_ids: [],
|
||||
authorized_actions: [],
|
||||
@@ -432,6 +434,7 @@ module('Unit | Serializer | target', function (hooks) {
|
||||
id: '1',
|
||||
type: 'target',
|
||||
attributes: {
|
||||
aliases: [],
|
||||
authorized_actions: [],
|
||||
name: 'Target 1',
|
||||
scope: { id: 'o_123', scope_id: 'o_123' },
|
||||
@@ -464,6 +467,7 @@ module('Unit | Serializer | target', function (hooks) {
|
||||
id: '1',
|
||||
type: 'target',
|
||||
attributes: {
|
||||
aliases: [],
|
||||
authorized_actions: [],
|
||||
name: 'Target 1',
|
||||
host_sources: [],
|
||||
@@ -496,6 +500,7 @@ module('Unit | Serializer | target', function (hooks) {
|
||||
id: '1',
|
||||
type: 'target',
|
||||
attributes: {
|
||||
aliases: [],
|
||||
authorized_actions: [],
|
||||
name: 'Target 1',
|
||||
host_sources: [],
|
||||
@@ -528,6 +533,7 @@ module('Unit | Serializer | target', function (hooks) {
|
||||
id: '1',
|
||||
type: 'target',
|
||||
attributes: {
|
||||
aliases: [],
|
||||
authorized_actions: [],
|
||||
name: 'Target 1',
|
||||
host_sources: [],
|
||||
@@ -561,6 +567,7 @@ module('Unit | Serializer | target', function (hooks) {
|
||||
id: '1',
|
||||
type: 'target',
|
||||
attributes: {
|
||||
aliases: [],
|
||||
authorized_actions: [],
|
||||
name: 'Target 1',
|
||||
host_sources: [],
|
||||
|
||||
Reference in new issue
Block a user