Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable single- and multiple-choice questions in the inquiry preview #2522

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ export default class CdInquiryDialogInquiryPartComponent extends Component {

return this.args.type === "answer"
? this.args.inquiry.childCase.document.info.edges
.filter((edge) => !isEmpty(edge.node.value))
.filter(
(edge) =>
!isEmpty(edge.node.value) ||
!isEmpty(edge.node.selectedOption) ||
!isEmpty(edge.node.selectedOptions),
)
.sort(
(a, b) =>
questions.indexOf(a.node.question.slug) -
Expand All @@ -68,6 +73,22 @@ export default class CdInquiryDialogInquiryPartComponent extends Component {
.map((edge) => ({
question: edge.node.question.label,
value: edge.node.value,
selectedOption: edge.node?.selectedOption,
selectedOptions: edge.node?.selectedOptions,
anehx marked this conversation as resolved.
Show resolved Hide resolved
}))
// For single choice the value is simply the selectedOption label
.map((answer) => ({
...answer,
value: answer.selectedOption
? answer.selectedOption.label
: answer.value,
}))
// For multiple choice the value is a list of selectedOption labels
.map((answer) => ({
...answer,
value: answer.selectedOptions
? answer.selectedOptions.edges.map((edge) => edge.node.label)
: answer.value,
anehx marked this conversation as resolved.
Show resolved Hide resolved
}))
: null;
}
Expand Down
24 changes: 16 additions & 8 deletions packages/distribution/addon/components/cd-truncated.hbs
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
<p class="cd-truncated" ...attributes>
{{~this.displayedText~}}
{{#if this.truncate}}
<a href="" {{on "click" this.toggleExpand}}>
{{~t (concat "caluma.distribution." (if this.expand "less" "more"))~}}
</a>
{{/if}}
</p>
{{#if (is-array @text)}}
<UkList @bullet={{true}} class="uk-margin-remove" as |list|>
anehx marked this conversation as resolved.
Show resolved Hide resolved
{{#each @text as |item|}}
<list.item>{{item}}</list.item>
{{/each}}
</UkList>
{{else}}
<p class="cd-truncated" ...attributes>
{{~this.displayedText~}}
{{#if this.truncate}}
<a href="" {{on "click" this.toggleExpand}}>
{{~t (concat "caluma.distribution." (if this.expand "less" "more"))~}}
</a>
{{/if}}
</p>
{{/if}}
12 changes: 12 additions & 0 deletions packages/distribution/addon/gql/fragments/inquiry-answer.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ fragment InquiryAnswer on Document {
}
... on StringAnswer {
value
selectedOption {
label
}
}
... on ListAnswer {
selectedOptions {
edges {
node {
label
}
}
}
}
}
}
Expand Down
13 changes: 8 additions & 5 deletions packages/testing/addon/mirage-graphql/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,14 @@ export default function createGraphqlHandler(server) {
SelectedOption: ({ value }) => {
const option = server.schema.options.findBy({ slug: value });

return {
slug: value,
label: option.label,
__typename: "SelectedOption",
};
if (option) {
return {
slug: value,
label: option.label,
__typename: "SelectedOption",
};
}
return null;
anehx marked this conversation as resolved.
Show resolved Hide resolved
},
},
preserveResolvers: false,
Expand Down