Skip to content

Commit

Permalink
Merge pull request #33 from /issues/25-admin-cant-create-record
Browse files Browse the repository at this point in the history
Fix admin can't create record
  • Loading branch information
blcham authored Dec 11, 2023
2 parents 69acbb0 + 514bc80 commit 0f38ac0
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion js/components/record/Record.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Record extends React.Component {
{this._showInstitution() && this._renderInstitution()}
<RecordProvenance record={record}/>
</form>
{this._renderForm()}
{record.formTemplate && this._renderForm()}
{this._renderButtons()}
{showAlert && recordSaved.status === ACTION_STATUS.ERROR &&
<div>
Expand Down
12 changes: 7 additions & 5 deletions js/components/record/RecordForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ class RecordForm extends React.Component {
}

componentDidMount() {
this.props.loadFormgen(ACTION_STATUS.PENDING);
this.loadWizard();
if(this.props.record.formTemplate) {
this.props.loadFormgen(ACTION_STATUS.PENDING);
this.loadWizard();
}
}

componentDidUpdate(prevProps, prevState, snapshot) {
const {record} = this.props;

if (prevProps.record.question?.uri !== record.question?.uri) {
if(record.formTemplate && record.formTemplate != prevProps.record.formTemplate) {
this.props.loadFormgen(ACTION_STATUS.PENDING);
this.loadWizard();
}
}
Expand Down Expand Up @@ -119,7 +121,7 @@ class RecordForm extends React.Component {
return <AlertMessage
type={ALERT_TYPES.DANGER}
message={this.props.formatMessage('record.load-form-error', {error: this.props.formgen.error.message})}/>;
} else if (this.props.formgen.status === ACTION_STATUS.PENDING || !this.state.form) {
} else if (!!this.props.record.formTemplate && (this.props.formgen.status === ACTION_STATUS.PENDING || !this.state.form)) {
return <Loader/>;
}

Expand Down
1 change: 1 addition & 0 deletions js/components/record/RequiredAttributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class RequiredAttributes extends React.Component {
<div className='col-11 col-sm-6'>
<HorizontalInput
labelWidth={4} inputWidth={8}
isDisabled={!!record.formTemplate}
type='autocomplete' name='formTemplate' value={record.formTemplate || formTemplate}
label={this.i18n('records.form-template') + '*'} onChange={this.props.onChange}
possibleValuesEndpoint={possibleValuesEndpoint}
Expand Down
5 changes: 3 additions & 2 deletions js/components/record/TypeaheadAnswer.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const TypeaheadAnswer = (props) => {
isSearchable={true}
isLoading={isLoading}
isClearable={true}
isDisabled={isLoading}
isDisabled={isLoading || (props.isDisabled === true) }
value={options.filter((option) => option.id === props.value)}
placeholder={''}
getOptionLabel={(option) => option.name}
Expand All @@ -73,7 +73,8 @@ TypeaheadAnswer.propTypes = {
possibleValuesEndpoint: PropTypes.string.isRequired,
label: PropTypes.string.isRequired,
value: PropTypes.string,
onChange: PropTypes.func.isRequired
onChange: PropTypes.func.isRequired,
isDisabled: PropTypes.bool
};

export default TypeaheadAnswer;

0 comments on commit 0f38ac0

Please sign in to comment.