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: Configurable question tags #4694

Open
wants to merge 39 commits into
base: main
Choose a base branch
from
Open

Conversation

dsamojlenko
Copy link
Member

@dsamojlenko dsamojlenko commented Nov 21, 2024

Summary | Résumé

#4378 "Machine readable tags or IDs":

  • Adds a tag property to the form schema (under properties)
  • Defaults this tag to a UUID when adding a new form element in the form-builder
  • Adds a configuration component in MoreDialog to configure the tag name
  • Modifies transformFormResponses to support tagged responses
  • Adds test coverage for tagged responses

About tagged responses

A tagged response has the following structure:

{
  tag: "...",
  answer: [string]
}

The answer string can sometimes be a serialized object - in the cases of FormattedDate and AddressComplete, they will be serialized JSON. Checkboxes also render as a serialized object/array of values.

When responses are downloaded as HTML or CSV they pass through the fetchSubmissions server action, where the response will be extracted and returned without the tag.

When responses are downloaded from the API, they will be returned following the object structure above.

If a form was created before this feature rolls out, but modified after- pre-existing inputs will not have tags, any newly added inputs will have tags. Tags can be added to pre-existing inputs by opening the MoreDialog, editing the tag, and saving.

If a form has a mix of tagged and untagged inputs, the responses to that form will have mixed tagged/untagged responses.

Copy link
Contributor

@dsamojlenko dsamojlenko marked this pull request as ready for review November 25, 2024 17:12
Copy link
Contributor

<div>
<InfoDetails summary={t("How tags can help")}>
<div className="mb-8 mt-4 border-l-3 border-gray-500 pl-8">
<p className="mb-4 text-sm">{t("text description")}</p>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need a proper description here

<section className="mb-4 mt-8">
<Label htmlFor="">{t("Question tag")}</Label>
<Hint>
{t("Adding a question tag allows the question to contain a permanent identifier.")}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need proper i18n here

@timarney
Copy link
Member

timarney commented Jan 7, 2025

Tested --- working well

Updated my API test app to use

const getAnswerByTag = (answersObj, tag) => {
  const answers = Object.entries(answersObj );
  const entry = answers.find(([_, value]) => value.tag === tag);
  return entry ? entry[1].answer : null;
};

const answers = JSON.parse(formSubmission.answers);
const email = getAnswerByTag(answers, "email");

Note

👉 Any existing partner integrations that aren't published would need to be update to pull from .answer prop on the response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants