-
Notifications
You must be signed in to change notification settings - Fork 46
BAH-4952:Add Hyperlink Property Panel for Label Controls #131
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
base: master
Are you sure you want to change the base?
Changes from all commits
26b259d
879e5b5
095e7a0
9e9c15d
8b8ad0f
4af28a5
13f4a28
1e960f5
6e6d965
068d557
81a3ac5
429cda2
e054c92
af0c5b4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |
|
|
||
| import React, { Component } from 'react'; | ||
| import PropTypes from 'prop-types'; | ||
| import { formBuilderConstants } from 'form-builder/constants'; | ||
|
|
||
| export class Property extends Component { | ||
|
|
||
|
|
@@ -43,10 +44,9 @@ export class Property extends Component { | |
| </select>); | ||
| case 'text': | ||
| return (<input | ||
| className="fr" | ||
| defaultValue={this.props.value} | ||
| key={`${this.props.name}:${this.props.id}`} | ||
| {...(this.props.name === 'url' | ||
| {...(this.props.name === 'url' || this.props.name === formBuilderConstants.hyperlinkUrlProperty | ||
| ? { onBlur: e => this.updateProperty(e, elementType) } | ||
| : { onChange: e => this.updateProperty(e, elementType) })} | ||
| type="text" | ||
|
|
@@ -73,7 +73,7 @@ export class Property extends Component { | |
| render() { | ||
| const { name, elementType } = this.props; | ||
| return ( | ||
| <div> | ||
| <div className={elementType === 'text' ? 'property-text-row' : undefined}> | ||
|
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. suggestion: This applies Consider scoping the class (e.g. key off 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. This is intentional. The |
||
| <label>{name}</label> | ||
| {this.getElement(elementType)} | ||
| </div> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import { validateHyperlink } from 'bahmni-form-controls'; | ||
|
vvkpd marked this conversation as resolved.
|
||
| import { httpInterceptor } from 'common/utils/httpInterceptor'; | ||
| import { formBuilderConstants } from 'form-builder/constants'; | ||
|
|
||
| function collectHyperlinkUrls(controls, acc, visited = new Set()) { | ||
| if (!controls) return acc; | ||
| controls.forEach((control) => { | ||
| if (visited.has(control)) return; | ||
| visited.add(control); | ||
| if (control.type === 'label' && control.properties && control.properties.hyperlinkUrl) { | ||
| acc.push(control.properties.hyperlinkUrl); | ||
| } | ||
| if (control.label) collectHyperlinkUrls([control.label], acc, visited); | ||
| if (control.controls) collectHyperlinkUrls(control.controls, acc, visited); | ||
| }); | ||
| return acc; | ||
| } | ||
|
|
||
| export function validateFormHyperlinks(formJson, allowedDomains) { | ||
| const urls = collectHyperlinkUrls(formJson.controls || [], []); | ||
| return urls | ||
| .map((url) => validateHyperlink(url, allowedDomains)) | ||
| .filter((result) => !result.valid) | ||
| .map((result) => `Invalid hyperlink: ${result.error}`); | ||
| } | ||
|
|
||
| export function fetchAllowedDomains() { | ||
| return httpInterceptor | ||
| .get(formBuilderConstants.allowedDomainsGPUrl, 'text') | ||
| .then((data) => (data || '').split(',').map((d) => d.trim()).filter(Boolean)) | ||
| .catch(() => []); | ||
|
vvkpd marked this conversation as resolved.
|
||
| } | ||
|
vvkpd marked this conversation as resolved.
|
||
Uh oh!
There was an error while loading. Please reload this page.