Skip to content

Commit

Permalink
Merge pull request #60 from kbss-cvut/not-visible-workflow-buttons
Browse files Browse the repository at this point in the history
[#58] Fix not visible workflow buttons
  • Loading branch information
blcham authored Dec 20, 2023
2 parents 7bebb8f + eb5ecd3 commit 3695ec3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
13 changes: 6 additions & 7 deletions js/components/record/Record.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,17 @@ class Record extends React.Component {
const {record, recordSaved, formgen} = this.props;

return <div className="mt-3 text-center">
{record.phase === RECORD_PHASE.COMPLETED
|| EXTENSIONS === EXTENSION_CONSTANTS.OPERATOR
{EXTENSIONS === EXTENSION_CONSTANTS.SUPPLIER
&& (!record.isNew) && (record.phase === RECORD_PHASE.OPEN || this._isAdmin())
&& <Button className="mx-1" variant='danger' size='sm'
disabled={formgen.status === ACTION_STATUS.PENDING || recordSaved.status === ACTION_STATUS.PENDING
|| !this.state.isFormValid || !record.state.isComplete() || record.phase === RECORD_PHASE.REJECTED}
onClick={this.props.handlers.onReject}>
{this.i18n('reject')}{recordSaved.status === ACTION_STATUS.PENDING && <LoaderSmall/>}
</Button>}

{record.phase === RECORD_PHASE.COMPLETED
|| record.phase === RECORD_PHASE.PUBLISHED
{(EXTENSIONS === EXTENSION_CONSTANTS.SUPPLIER || EXTENSIONS === EXTENSION_CONSTANTS.OPERATOR)
&& (!record.isNew) && (record.phase === RECORD_PHASE.OPEN || this._isAdmin())
&& <Button className="mx-1" variant='success' size='sm'
disabled={formgen.status === ACTION_STATUS.PENDING || recordSaved.status === ACTION_STATUS.PENDING
|| !this.state.isFormValid || !record.state.isComplete() || record.phase === RECORD_PHASE.COMPLETED}
Expand All @@ -127,13 +127,12 @@ class Record extends React.Component {
<Button className="mx-1" variant='success' size='sm'
disabled={formgen.status === ACTION_STATUS.PENDING || recordSaved.status === ACTION_STATUS.PENDING
|| !this.state.isFormValid || !record.state.isComplete()}
hidden={(record.phase === RECORD_PHASE.COMPLETED && !this._isAdmin()) ||
record.phase === RECORD_PHASE.PUBLISHED}
hidden={!this._isAdmin()
&& ([RECORD_PHASE.COMPLETED, RECORD_PHASE.REJECTED, RECORD_PHASE.PUBLISHED].includes(record.phase))}
onClick={this.props.handlers.onSave}>
{this.i18n('save')}{recordSaved.status === ACTION_STATUS.PENDING && <LoaderSmall/>}
</Button>
<Button className="mx-1" variant='link' size='sm'
hidden={record.phase === RECORD_PHASE.COMPLETED || record.phase === RECORD_PHASE.PUBLISHED}
onClick={this.props.handlers.onCancel}>{this.i18n('cancel')}</Button>
</div>
}
Expand Down
22 changes: 12 additions & 10 deletions js/components/record/RecordController.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,18 @@ class RecordController extends React.Component {
// if (handlers) {
// transitionTo(handlers.onCancel);
// } else {
this._transitionToRecords();
// }
};

_transitionToRecords() {
const opts = {};
const formTemplate = this.state.record?.formTemplate
if (formTemplate) {
opts.query = new Map([["formTemplate", formTemplate]]);
}
this.props.transitionToWithOpts(Routes.records, opts);
// }
};
}

_onChange = (change) => {
const update = {...this.state.record, ...change};
Expand All @@ -128,23 +132,21 @@ class RecordController extends React.Component {

_onComplete = () => {
this._handlePhaseChange(RECORD_PHASE.COMPLETED);
this._transitionToRecords();
};

_onReject = () => {
this._handlePhaseChange(RECORD_PHASE.REJECTED);
this._transitionToRecords();
};

_handlePhaseChange = (newPhase) => {
const currentUser = this.props.currentUser;
const update = {...this.state.record, phase: newPhase};

this.setState({ record: update });

this.setState((prevState) => {
const update = {...prevState.record};
update.phase = newPhase;
return {record: update};
}, () => {
const updatedRecord = this.state.record;
this.props.updateRecord(updatedRecord, currentUser);
});
this.props.updateRecord(update, currentUser);
};

_getLocalName() {
Expand Down

0 comments on commit 3695ec3

Please sign in to comment.