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

YDA-5234: fix for erroneous compulsary indication implemented for vault, research and deposit #225

Merged
merged 3 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 63 additions & 13 deletions deposit/metadata-form/src/AffiliationIdentifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class AffiliationIdentifier extends React.Component {
const titleAffiliationName = this.props.schema.properties.Affiliation_Name.title
const titleAffiliationIdentifier = this.props.schema.properties.Affiliation_Identifier.title

let label = <label className='form-label'>{titleAffiliationName}</label>
// let label = <label className='form-label'>{titleAffiliationName}</label>

const helpAffiliationName = this.props.uiSchema.Affiliation_Name['ui:help']
const helpAffiliationIdentifier = this.props.uiSchema.Affiliation_Identifier['ui:help']
Expand All @@ -71,10 +71,45 @@ class AffiliationIdentifier extends React.Component {
}
})
}
const required = this.props.required
const error = 'should be equal to one of the allowed values'
if ((this.props.rawErrors !== undefined && this.props.rawErrors.indexOf(error) >= 0) || (required && this.props.formData.Affiliation_Name == null)) {
label = <label className='text-danger form-label select-required'>{titleAffiliationName}*</label>

let parentContext = this.props.idSchema.$id
parentContext = parentContext.replace(this.props.idPrefix + '_', '')
parentContext = parentContext.replace('_Affiliation_', '')

const parts = parentContext.split('_')
parts.pop()
parentContext = parts.join('_')
console.log(parentContext)

let bothRequired = false
try {
bothRequired = this.props.registry.rootSchema.properties[parentContext].items.required.includes('Affiliation')
} catch (err) {
bothRequired = false
}

let reqName = ''
let classesName = 'select-box'
let reqIdf = ''
let classesIdf = 'form-control'

const namePresent = !(typeof Affiliation_Name === 'undefined' || Affiliation_Name.length === 0)
const idfPresent = !(typeof Affiliation_Identifier === 'undefined' || Affiliation_Identifier.length === 0)

// Specific class handling for both elements Name/Identifier
if (namePresent) {
if (!idfPresent) {
classesIdf += ' is-invalid'
}
} else if (idfPresent) { // als naam wel is ingeuvuld
classesName += ' is-invalid'
} else if (bothRequired) {
classesName += ' is-invalid'
classesIdf += ' is-invalid'
}

// set the customStyle for the select if invalid
if (classesName.search('is-invalid') > -1) {
customStyles = {
control: styles => ({
...styles,
Expand All @@ -85,20 +120,29 @@ class AffiliationIdentifier extends React.Component {
}
})
}
} else if (required) {
label = <label className='form-label select-required select-filled'>{titleAffiliationName}*</label>
}

// Handling of '*' in the label of both fields
if (bothRequired) {
reqName = '*'
reqIdf = '*'
} else {
label = <label className='form-label select-required select-filled'>{titleAffiliationName}</label>
if (!(typeof Affiliation_Name === 'undefined' || Affiliation_Name.length === 0)) {
reqIdf = '*'
}
if (!(typeof Affiliation_Identifier === 'undefined' || Affiliation_Identifier.length === 0)) {
reqName = '*'
}
}

return (
<div className='d-flex'>
<div className='col compound-field'>
{label}
<label className='form-label select-required select-filled'>{titleAffiliationName}{reqName}</label>
<CreatableSelect
className='select-box'
className='select-box is-invalid'
options={this.options}
required={required}
required={reqName === '*'}
isDisabled={this.props.readonly}
placeholder={Affiliation_Name}
onChange={this.handleChange}
Expand All @@ -113,8 +157,14 @@ class AffiliationIdentifier extends React.Component {

<div className='col compound-field'>
<div className='mb-0 form-group'>
<label className='form-label'>{titleAffiliationIdentifier}</label>
<input type='text' className='form-control' readOnly={this.props.readonly} onChange={this.handleChangeIdentifier} value={Affiliation_Identifier} />
<label className='form-label'>{titleAffiliationIdentifier}{reqIdf}</label>
<input
type='text'
className={classesIdf} // 'form-control is-invalid'
readOnly={this.props.readonly}
onChange={this.handleChangeIdentifier}
value={Affiliation_Identifier}
/>
{helpAffiliationIdentifier && (
<small className='text-muted form-text'>
<p className='help-block'>{helpAffiliationIdentifier}</p>
Expand Down
2 changes: 1 addition & 1 deletion deposit/static/deposit/js/metadata-form.js

Large diffs are not rendered by default.

76 changes: 63 additions & 13 deletions research/metadata-form/src/AffiliationIdentifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class AffiliationIdentifier extends React.Component {
const titleAffiliationName = this.props.schema.properties.Affiliation_Name.title
const titleAffiliationIdentifier = this.props.schema.properties.Affiliation_Identifier.title

let label = <label className='form-label'>{titleAffiliationName}</label>
// let label = <label className='form-label'>{titleAffiliationName}</label>

const helpAffiliationName = this.props.uiSchema.Affiliation_Name['ui:help']
const helpAffiliationIdentifier = this.props.uiSchema.Affiliation_Identifier['ui:help']
Expand All @@ -71,10 +71,45 @@ class AffiliationIdentifier extends React.Component {
}
})
}
const required = this.props.required
const error = 'should be equal to one of the allowed values'
if ((this.props.rawErrors !== undefined && this.props.rawErrors.indexOf(error) >= 0) || (required && this.props.formData.Affiliation_Name == null)) {
label = <label className='text-danger form-label select-required'>{titleAffiliationName}*</label>

let parentContext = this.props.idSchema.$id
parentContext = parentContext.replace(this.props.idPrefix + '_', '')
parentContext = parentContext.replace('_Affiliation_', '')

const parts = parentContext.split('_')
parts.pop()
parentContext = parts.join('_')
console.log(parentContext)

let bothRequired = false
try {
bothRequired = this.props.registry.rootSchema.properties[parentContext].items.required.includes('Affiliation')
} catch (err) {
bothRequired = false
}

let reqName = ''
let classesName = 'select-box'
let reqIdf = ''
let classesIdf = 'form-control'

const namePresent = !(typeof Affiliation_Name === 'undefined' || Affiliation_Name.length === 0)
const idfPresent = !(typeof Affiliation_Identifier === 'undefined' || Affiliation_Identifier.length === 0)

// Specific class handling for both elements Name/Identifier
if (namePresent) {
if (!idfPresent) {
classesIdf += ' is-invalid'
}
} else if (idfPresent) { // als naam wel is ingeuvuld
classesName += ' is-invalid'
} else if (bothRequired) {
classesName += ' is-invalid'
classesIdf += ' is-invalid'
}

// set the customStyle for the select if invalid
if (classesName.search('is-invalid') > -1) {
customStyles = {
control: styles => ({
...styles,
Expand All @@ -85,20 +120,29 @@ class AffiliationIdentifier extends React.Component {
}
})
}
} else if (required) {
label = <label className='form-label select-required select-filled'>{titleAffiliationName}*</label>
}

// Handling of '*' in the label of both fields
if (bothRequired) {
reqName = '*'
reqIdf = '*'
} else {
label = <label className='form-label select-required select-filled'>{titleAffiliationName}</label>
if (!(typeof Affiliation_Name === 'undefined' || Affiliation_Name.length === 0)) {
reqIdf = '*'
}
if (!(typeof Affiliation_Identifier === 'undefined' || Affiliation_Identifier.length === 0)) {
reqName = '*'
}
}

return (
<div className='d-flex'>
<div className='col compound-field'>
{label}
<label className='form-label select-required select-filled'>{titleAffiliationName}{reqName}</label>
<CreatableSelect
className='select-box'
className='select-box is-invalid'
options={this.options}
required={required}
required={reqName === '*'}
isDisabled={this.props.readonly}
placeholder={Affiliation_Name}
onChange={this.handleChange}
Expand All @@ -113,8 +157,14 @@ class AffiliationIdentifier extends React.Component {

<div className='col compound-field'>
<div className='mb-0 form-group'>
<label className='form-label'>{titleAffiliationIdentifier}</label>
<input type='text' className='form-control' readOnly={this.props.readonly} onChange={this.handleChangeIdentifier} value={Affiliation_Identifier} />
<label className='form-label'>{titleAffiliationIdentifier}{reqIdf}</label>
<input
type='text'
className={classesIdf} // 'form-control is-invalid'
readOnly={this.props.readonly}
onChange={this.handleChangeIdentifier}
value={Affiliation_Identifier}
/>
{helpAffiliationIdentifier && (
<small className='text-muted form-text'>
<p className='help-block'>{helpAffiliationIdentifier}</p>
Expand Down
6 changes: 3 additions & 3 deletions research/static/research/js/metadata-form.js

Large diffs are not rendered by default.

76 changes: 63 additions & 13 deletions vault/metadata-form/src/AffiliationIdentifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class AffiliationIdentifier extends React.Component {
const titleAffiliationName = this.props.schema.properties.Affiliation_Name.title
const titleAffiliationIdentifier = this.props.schema.properties.Affiliation_Identifier.title

let label = <label className='form-label'>{titleAffiliationName}</label>
// let label = <label className='form-label'>{titleAffiliationName}</label>

const helpAffiliationName = this.props.uiSchema.Affiliation_Name['ui:help']
const helpAffiliationIdentifier = this.props.uiSchema.Affiliation_Identifier['ui:help']
Expand All @@ -71,10 +71,45 @@ class AffiliationIdentifier extends React.Component {
}
})
}
const required = this.props.required
const error = 'should be equal to one of the allowed values'
if ((this.props.rawErrors !== undefined && this.props.rawErrors.indexOf(error) >= 0) || (required && this.props.formData.Affiliation_Name == null)) {
label = <label className='text-danger form-label select-required'>{titleAffiliationName}*</label>

let parentContext = this.props.idSchema.$id
parentContext = parentContext.replace(this.props.idPrefix + '_', '')
parentContext = parentContext.replace('_Affiliation_', '')

const parts = parentContext.split('_')
parts.pop()
parentContext = parts.join('_')
console.log(parentContext)

let bothRequired = false
try {
bothRequired = this.props.registry.rootSchema.properties[parentContext].items.required.includes('Affiliation')
} catch (err) {
bothRequired = false
}

let reqName = ''
let classesName = 'select-box'
let reqIdf = ''
let classesIdf = 'form-control'

const namePresent = !(typeof Affiliation_Name === 'undefined' || Affiliation_Name.length === 0)
const idfPresent = !(typeof Affiliation_Identifier === 'undefined' || Affiliation_Identifier.length === 0)

// Specific class handling for both elements Name/Identifier
if (namePresent) {
if (!idfPresent) {
classesIdf += ' is-invalid'
}
} else if (idfPresent) { // als naam wel is ingeuvuld
classesName += ' is-invalid'
} else if (bothRequired) {
classesName += ' is-invalid'
classesIdf += ' is-invalid'
}

// set the customStyle for the select if invalid
if (classesName.search('is-invalid') > -1) {
customStyles = {
control: styles => ({
...styles,
Expand All @@ -85,20 +120,29 @@ class AffiliationIdentifier extends React.Component {
}
})
}
} else if (required) {
label = <label className='form-label select-required select-filled'>{titleAffiliationName}*</label>
}

// Handling of '*' in the label of both fields
if (bothRequired) {
reqName = '*'
reqIdf = '*'
} else {
label = <label className='form-label select-required select-filled'>{titleAffiliationName}</label>
if (!(typeof Affiliation_Name === 'undefined' || Affiliation_Name.length === 0)) {
reqIdf = '*'
}
if (!(typeof Affiliation_Identifier === 'undefined' || Affiliation_Identifier.length === 0)) {
reqName = '*'
}
}

return (
<div className='d-flex'>
<div className='col compound-field'>
{label}
<label className='form-label select-required select-filled'>{titleAffiliationName}{reqName}</label>
<CreatableSelect
className='select-box'
className='select-box is-invalid'
options={this.options}
required={required}
required={reqName === '*'}
isDisabled={this.props.readonly}
placeholder={Affiliation_Name}
onChange={this.handleChange}
Expand All @@ -113,8 +157,14 @@ class AffiliationIdentifier extends React.Component {

<div className='col compound-field'>
<div className='mb-0 form-group'>
<label className='form-label'>{titleAffiliationIdentifier}</label>
<input type='text' className='form-control' readOnly={this.props.readonly} onChange={this.handleChangeIdentifier} value={Affiliation_Identifier} />
<label className='form-label'>{titleAffiliationIdentifier}{reqIdf}</label>
<input
type='text'
className={classesIdf} // 'form-control is-invalid'
readOnly={this.props.readonly}
onChange={this.handleChangeIdentifier}
value={Affiliation_Identifier}
/>
{helpAffiliationIdentifier && (
<small className='text-muted form-text'>
<p className='help-block'>{helpAffiliationIdentifier}</p>
Expand Down
2 changes: 1 addition & 1 deletion vault/static/vault/js/metadata-form.js

Large diffs are not rendered by default.

Loading