ui: Add unique slug key id to proxy (#8479)

This commit is contained in:
Kenia 2020-08-11 12:53:45 -04:00 committed by GitHub
parent efcda70b85
commit 85a878549b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 6 deletions

View File

@ -2,10 +2,10 @@ import Model from 'ember-data/model';
import attr from 'ember-data/attr';
export const PRIMARY_KEY = 'uid';
export const SLUG_KEY = 'ID';
export const SLUG_KEY = 'Node,ServiceID';
export default Model.extend({
[PRIMARY_KEY]: attr('string'),
[SLUG_KEY]: attr('string'),
ID: attr('string'),
ServiceName: attr('string'),
ServiceID: attr('string'),
Node: attr('string'),

View File

@ -4,16 +4,20 @@ export default function(foreignKey, nspaceKey, hash = JSON.stringify) {
throw new Error('Unable to create fingerprint, missing foreignKey value');
}
return function(item) {
if (item[slugKey] == null || item[slugKey].length < 1) {
throw new Error('Unable to create fingerprint, missing slug');
}
const slugKeys = slugKey.split(',');
const slugValues = slugKeys.map(function(slugKey) {
if (item[slugKey] == null || item[slugKey].length < 1) {
throw new Error('Unable to create fingerprint, missing slug');
}
return item[slugKey];
});
const nspaceValue = item[nspaceKey] || 'default';
return {
...item,
...{
[nspaceKey]: nspaceValue,
[foreignKey]: foreignKeyValue,
[primaryKey]: hash([nspaceValue, foreignKeyValue, item[slugKey]]),
[primaryKey]: hash([nspaceValue, foreignKeyValue].concat(slugValues)),
},
};
};