open-nomad/ui/app/utils/qp-serialize.js
Michael Lange e8593ec1bb
ui: Update namespaces design (#10444)
This rethinks namespaces as a filter on list pages rather than a global setting.

The biggest net-new feature here is being able to select All (*) to list all jobs
or CSI volumes across namespaces.
2021-04-29 15:00:59 -05:00

24 lines
589 B
JavaScript

import { computed } from '@ember/object';
// An unattractive but robust way to encode query params
export const serialize = val => {
if (typeof val === 'string' || typeof val === 'number') return val;
return val.length ? JSON.stringify(val) : '';
};
export const deserialize = str => {
try {
return JSON.parse(str)
.compact()
.without('');
} catch (e) {
return [];
}
};
// A computed property macro for deserializing a query param
export const deserializedQueryParam = qpKey =>
computed(qpKey, function() {
return deserialize(this.get(qpKey));
});