-
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
Changes from all commits
480249f
8273748
b93e224
098f89a
68ae310
94c35ed
c69959a
c9fb222
5e257f8
4440845
ed82bc6
8865643
564644c
1cc8571
ed2956c
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
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. 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.