Skip to content

Commit

Permalink
fix fir date range piping (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
martyncolmer authored Jul 23, 2021
1 parent dc8d66c commit c4c6112
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
.env
coverage
coverage
.vscode/launch.json
14 changes: 10 additions & 4 deletions src/utils/convertPipes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,13 @@ const FILTER_MAP = {

const PIPE_TYPES = {
answers: {
retrieve: ({ id }, ctx) => getAnswer(ctx, id.toString()),
retrieve: ({ id, type }, ctx) => {
let tempId = id.toString()
if (type === "DateRange") {
tempId = id.endsWith("from") ? id.slice(0, -4) : id.slice(0, -2)
}
return getAnswer(ctx, tempId)
},
render: ({ id }) => `answer${id}`,
getType: ({ type }) => type,
},
Expand Down Expand Up @@ -128,7 +134,7 @@ const getPipedData = (store) => (element, ctx) => {
return "";
}

const output = pipeConfig.render(entity);
const output = elementData.type === "DateRange" ? pipeConfig.render(elementData) : pipeConfig.render(entity);
const pipedType = pipeConfig.getType(entity);

const transformed = FILTER_MAP[pipedType];
Expand All @@ -154,7 +160,7 @@ const getPipedData = (store) => (element, ctx) => {
transform: format,
arguments: options(
piped,
entity.key || `answer${entity.id}`,
entity.key || output,
dateFormat,
unitType
),
Expand All @@ -166,7 +172,7 @@ const getPipedData = (store) => (element, ctx) => {
placeholder: removeDash(placeHolderText),
value: {
source: piped,
identifier: entity.key || `answer${entity.id}`,
identifier: entity.key || output,
},
};
}
Expand Down

0 comments on commit c4c6112

Please sign in to comment.