Chore/cleanup filter attribute (#1500)

* refactor: 💡 Rename attributes called filter

* refactor: 💡 Remove adapter handling of old attribute errors

* refactor: 💡 Check for undefined in serializer instead of falsy
This commit is contained in:
Zhihe Li authored and GitHub committed 2022-12-02 13:44:11 -05:00
1 parent b1f14e5c62
commit f8429b15e9
11 files changed
+160 -53

No files matched your search

+20 -3
View File
@@ -3,7 +3,7 @@ import { copy } from 'ember-copy';
const fieldByType = {
aws: ['preferred_endpoints', 'filters', 'sync_interval_seconds'],
azure: ['preferred_endpoints', 'filter', 'sync_interval_seconds'],
azure: ['preferred_endpoints', 'filter_string', 'sync_interval_seconds'],
};
export default class HostSetSerializer extends ApplicationSerializer {
// =properties
@@ -69,6 +69,15 @@ export default class HostSetSerializer extends ApplicationSerializer {
delete json.attributes[key];
}
}
if (key === 'filter_string') {
const { filter_string } = json.attributes;
if (filter_string) {
json.attributes.filter = json.attributes.filter_string;
}
delete json.attributes.filter_string;
}
return value;
}
@@ -80,10 +89,18 @@ export default class HostSetSerializer extends ApplicationSerializer {
*/
normalize(typeClass, hash, ...rest) {
const normalizedHash = copy(hash, true);
if (typeof normalizedHash?.attributes?.filters === 'string') {
normalizedHash.attributes.filters = [normalizedHash.attributes.filters];
}
const normalized = super.normalize(typeClass, normalizedHash, ...rest);
return normalized;
// Change name from filter to filter_string
if (normalizedHash?.attributes?.filter) {
normalizedHash.attributes.filter_string =
normalizedHash.attributes.filter;
delete normalizedHash.attributes.filter;
}
return super.normalize(typeClass, normalizedHash, ...rest);
}
}
@@ -1,4 +1,5 @@
import ApplicationSerializer from './application';
import { copy } from 'ember-copy';
export default class ManagedGroupSerializer extends ApplicationSerializer {
// =properties
@@ -7,4 +8,27 @@ export default class ManagedGroupSerializer extends ApplicationSerializer {
* @type {boolean}
*/
serializeScopeID = false;
serialize() {
const serialized = super.serialize(...arguments);
if (serialized.attributes.filter_string !== undefined) {
serialized.attributes.filter = serialized.attributes.filter_string;
}
delete serialized.attributes.filter_string;
return serialized;
}
normalize(typeClass, hash, ...rest) {
const normalizedHash = copy(hash, true);
if (normalizedHash?.attributes?.filter) {
normalizedHash.attributes.filter_string =
normalizedHash.attributes.filter;
delete normalizedHash.attributes.filter;
}
return super.normalize(typeClass, normalizedHash, ...rest);
}
}