From 98933e12a0917330cf68a18f90ba55fcf99acf14 Mon Sep 17 00:00:00 2001 From: Michael Lange Date: Tue, 19 May 2020 17:28:23 -0700 Subject: [PATCH] Expose existing qp serialization util as a helper --- ui/app/helpers/qp-deserialize.js | 16 ++++++++++++++++ ui/app/helpers/qp-serialize.js | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 ui/app/helpers/qp-deserialize.js create mode 100644 ui/app/helpers/qp-serialize.js diff --git a/ui/app/helpers/qp-deserialize.js b/ui/app/helpers/qp-deserialize.js new file mode 100644 index 000000000..89f045e53 --- /dev/null +++ b/ui/app/helpers/qp-deserialize.js @@ -0,0 +1,16 @@ +import { helper } from '@ember/component/helper'; +import { deserialize } from 'nomad-ui/utils/qp-serialize'; + +/** + * Query Param Serialize + * + * Usage: {{qp-deserialize string}} + * + * Turns a serialized query param value string back into + * an array of values. + */ +export function qpDeserialize([str]) { + return deserialize(str); +} + +export default helper(qpDeserialize); diff --git a/ui/app/helpers/qp-serialize.js b/ui/app/helpers/qp-serialize.js new file mode 100644 index 000000000..f3231ff20 --- /dev/null +++ b/ui/app/helpers/qp-serialize.js @@ -0,0 +1,16 @@ +import { helper } from '@ember/component/helper'; +import { serialize } from 'nomad-ui/utils/qp-serialize'; + +/** + * Query Param Serialize + * + * Usage: {{qp-serialize array}} + * + * Turns an array of values into a safe url encoded query param + * value. This serialization is used throughout the app for facets. + */ +export function qpSerialize([values]) { + return serialize(values); +} + +export default helper(qpSerialize);