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

Support customizable content types #44

Merged
merged 5 commits into from
Feb 13, 2024
Merged

Support customizable content types #44

merged 5 commits into from
Feb 13, 2024

Conversation

danielnaab
Copy link
Contributor

@danielnaab danielnaab commented Feb 9, 2024

As part of #21, this defines a structure of adding additional form content types to a form definition.

This branch adds a FormConfig type to define injectable form field definitions. In the design package, there's a FormUIContext, and both would be good to iterate on as part of #43 or #25.

The general structure of working with a form now looks like this:

/*
 * On the content generation-side, we create a form and then save it for later usage.
 */

// Create a form system configuration, which defines the content types used by the form system.
const config: FormConfig = { /* ... */ };

// Create a form definition. This is what the content producer creates via the form builder interface.
const form: FormDefinition = { /* ... */ };
// Or, use a utility function as a helper factory
//const form = createSequentialForm( /* ... */ );

// We can now save this form with the form service, where we can interact with it in the future.
const formService: FormService = createFormService();
formService.saveForm(form);

/*
 *  On the public-facing side, we can fill this form out.
 */

const form = formService.getForm(id);

// Create a session. This tracks the current state of an end-user's journey through the form.
const session = createFormSession(form);

// Create a prompt. Prompts define what the user interface should display, and what operations are legal given the current state of the session.
const prompt = createPrompt(config, session);

// Submit collected data to a backend, where something can be done with it.
const collectedFormData: Record<string, string> = {}; // a mapping of form field IDs to values - what the user entered via the UI
const formService = createFormService();
formService.submitForm(form.id, collectedFormData);

…is is an overly large commit, but includes most of the refactoring necessary for this purpose. In the design package, we could use a better type and/or constructor for configuring the UI side of the form field configuration.
Copy link

github-actions bot commented Feb 9, 2024

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines Unknown% 0 / 0
🔵 Statements Unknown% 0 / 0
🔵 Functions Unknown% 0 / 0
🔵 Branches Unknown% 0 / 0
File CoverageNo changed files found.
Generated in workflow #87

@danielnaab danielnaab merged commit aa43d61 into main Feb 13, 2024
2 checks passed
@danielnaab danielnaab deleted the form-config branch February 13, 2024 15:46
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.

1 participant