Skip to content

Feat DF-662: Allows new component to be added with minimal effort#1223

Merged
jbarnsley10 merged 5 commits intomainfrom
feat/DF-662-new-component
Dec 5, 2025
Merged

Feat DF-662: Allows new component to be added with minimal effort#1223
jbarnsley10 merged 5 commits intomainfrom
feat/DF-662-new-component

Conversation

@jbarnsley10
Copy link
Copy Markdown
Contributor

@jbarnsley10 jbarnsley10 commented Dec 2, 2025

A new component can be added with minimal effort.
Originally, around 25 files needed to be change.
Now, only 6 files need to be changed.

There is also a small PR in forms-runner to handle components not yet setup in the preview DEFRA/forms-engine-plugin#274

Changes required in forms-designer to add a new component (this example uses 'UnicornField'):

model/src/components/enums.ts:

	UnicornField = ‘UnicornField’

model/src/components/types.ts:

	export interface UnicornFieldComponent extends FormFieldBase {
            type: ComponentType.UnicornField
            options: FormFieldBase['options'] & {
                condition?: string
            }
         }

       . . .

	export type InputFieldsComponentsDef =
  	| TextFieldComponent
  	. . .
  	| UnicornFieldComponent

model/src/components/component-types.ts:

	{
    		name: 'UnicornField',
    		title: 'Unicorn field',
    		type: ComponentType.UnicornField,
    		hint: '',
    		options: {},
    		schema: {}
  	}

client/src/i18n/translations/en.translation.json:

	fieldTypeToName: {
		. . .
		"UnicornField": "Unicorn field",
    		"UnicornField_info": "For internal processing"

model/src/form/form-editor/index.ts:

export const questionTypeSchema = Joi.string()
. . .
ComponentType.UnicornField
)
. . .

designer/server/src/models/forms/editor-v2/question-type.js:

const questionTypeRadioItems = /** @type {FormEditorCheckbox[]} */ ([
. . .
{
    text: 'Unicorn',
    hint: {
      text: 'Rainbows and stuff'
    },
    value: ComponentType.UnicornField
  },
. . .

…he component to be in preview or engine-plugin)
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Dec 2, 2025

🧪 Acceptance Test Results

❌ Some acceptance tests failed

View Details

Copy link
Copy Markdown
Contributor

@alexluckett alexluckett left a comment

Choose a reason for hiding this comment

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

What an improvement! Nice work.

Can you put an updated step-by-step guide together?

it('should update the List class when listeners are called', () => {
const preview = /** @type {ListSortableQuestion} */ (
SetupPreview.ListSortable()
SetupPreview('ListSortable')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

enum here?

SetupPreview(PreviewTypes.ListSortable)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is from Chris' original implementation (and the 'Question' too).
Will see if it's easy to enum them both

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah, it's because he was using ComponentType for most apart from these two. Obvs we don;t want to add these two to ComponentType. I'll create a PreviewComponentType

document.body.innerHTML =
questionDetailsLeftPanelHTML + questionDetailsPreviewHTML
const res = SetupPreview.Question()
const res = SetupPreview('Question')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

enum here?

SetupPreview(PreviewTypes.Question)

Added a step-by-step guide to README
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Dec 4, 2025

@jbarnsley10 jbarnsley10 merged commit 7c4b15d into main Dec 5, 2025
10 of 11 checks passed
@jbarnsley10 jbarnsley10 deleted the feat/DF-662-new-component branch December 5, 2025 08:25
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