-
Notifications
You must be signed in to change notification settings - Fork 3
feat(davinci-client): support form agreements with AgreementCollector #579
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
Open
ancheetah
wants to merge
1
commit into
main
Choose a base branch
from
SDKS-4691-agreements
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+274
−5
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@forgerock/davinci-client': minor | ||
| --- | ||
|
|
||
| Support form agreements with AgreementCollector |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /* | ||
| * Copyright (c) 2026 Ping Identity Corporation. All rights reserved. | ||
| * | ||
| * This software may be modified and distributed under the terms | ||
| * of the MIT license. See the LICENSE file for details. | ||
| */ | ||
| import type { AgreementCollector } from '@forgerock/davinci-client/types'; | ||
|
|
||
| export default function (formEl: HTMLFormElement, collector: AgreementCollector) { | ||
| const output = collector.output; | ||
| const componentEnabled = output.enabled; | ||
|
|
||
| if (!componentEnabled) { | ||
| return; | ||
| } | ||
|
|
||
| const content = output.label; | ||
| const titleEnabled = output.titleEnabled; | ||
| const title = output.title; | ||
|
|
||
| if (titleEnabled) { | ||
| const titleEl = document.createElement('h3'); | ||
| titleEl.innerText = title; | ||
| formEl?.appendChild(titleEl); | ||
| } | ||
|
|
||
| const agreement = document.createElement('p'); | ||
| agreement.innerText = content; | ||
| formEl?.appendChild(agreement); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,6 +46,7 @@ import type { | |
| SingleSelectField, | ||
| StandardField, | ||
| ValidatedField, | ||
| AgreementField, | ||
| } from './davinci.types.js'; | ||
|
|
||
| /** | ||
|
|
@@ -717,7 +718,7 @@ export function returnObjectValueCollector( | |
| * @returns {NoValueCollector} The constructed NoValueCollector object. | ||
| */ | ||
| export function returnNoValueCollector< | ||
| Field extends ReadOnlyField | QrCodeField, | ||
| Field extends ReadOnlyField | QrCodeField | AgreementField, | ||
| CollectorType extends NoValueCollectorTypes = 'NoValueCollector', | ||
| >(field: Field, idx: number, collectorType: CollectorType) { | ||
| let error = ''; | ||
|
|
@@ -728,6 +729,20 @@ export function returnNoValueCollector< | |
| error = `${error}Type is not found in the field object. `; | ||
| } | ||
|
|
||
| let output = {}; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of reassigning the output property we should just create it inline like we do elsewhere in the file. Looks cleaner. |
||
|
|
||
| if (collectorType === 'AgreementCollector' && field.type === 'AGREEMENT') { | ||
| output = { | ||
| titleEnabled: field.titleEnabled, | ||
| title: field.title, | ||
| agreement: { | ||
| id: field.agreement?.id ?? '', | ||
| useDynamicAgreement: field.agreement?.useDynamicAgreement ?? false, | ||
| }, | ||
| enabled: field.enabled ?? false, | ||
| }; | ||
| } | ||
|
|
||
| return { | ||
| category: 'NoValueCollector', | ||
| error: error || null, | ||
|
|
@@ -738,6 +753,7 @@ export function returnNoValueCollector< | |
| key: `${field.key || field.type}-${idx}`, | ||
| label: field.content, | ||
| type: field.type, | ||
| ...output, | ||
| }, | ||
| } as InferNoValueCollectorType<CollectorType>; | ||
| } | ||
|
|
@@ -771,6 +787,16 @@ export function returnQrCodeCollector(field: QrCodeField, idx: number): QrCodeCo | |
| }; | ||
| } | ||
|
|
||
| /** | ||
| * @function returnAgreementCollector - Creates an AgreementCollector object based on the provided field and index. | ||
| * @param {AgreementField} field - The field object containing key, label, type, and agreement details. | ||
| * @param {number} idx - The index to be used in the id of the AgreementCollector. | ||
| * @returns {AgreementCollector} The constructed AgreementCollector object. | ||
| */ | ||
| export function returnAgreementCollector(field: AgreementField, idx: number) { | ||
| return returnNoValueCollector(field, idx, 'AgreementCollector'); | ||
| } | ||
|
|
||
| /** | ||
| * @function returnValidator - Creates a validator function based on the provided collector | ||
| * @param {ValidatedTextCollector | ObjectValueCollectors | MultiValueCollectors | AutoCollectors} collector - The collector to which the value will be validated | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we update this
extendsto be on theReadOnlyFieldstype