-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
24f76d1
commit ad43609
Showing
18 changed files
with
1,644 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
@import "@folio/stripes-components/lib/variables.css"; | ||
|
||
.referred-record__entity-type { | ||
font-size: 1.1em; | ||
font-weight: bold; | ||
color: var(--color-text); | ||
} | ||
|
||
.assignments-list__item { | ||
color: var(--primary); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import React, { Component, Fragment } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { FormattedMessage } from 'react-intl'; | ||
|
||
import { | ||
KeyValue, | ||
List, | ||
} from '@folio/stripes-components'; | ||
|
||
import styles from './AssignmentsList.css'; | ||
|
||
import { | ||
referredEntityDataShape, | ||
linkedEntitiesTypesShape, | ||
} from '../NoteForm/noteShapes'; | ||
|
||
export default class AssignmentsList extends Component { | ||
static propTypes = { | ||
entityTypePluralizedTranslationKeyMap: PropTypes.objectOf(PropTypes.string), | ||
entityTypeTranslationKeyMap: PropTypes.objectOf(PropTypes.string), | ||
linkedEntitiesTypes: linkedEntitiesTypesShape, | ||
referredEntityData: referredEntityDataShape.isRequired, | ||
}; | ||
|
||
static defaultProps = { | ||
linkedEntitiesTypes: [], | ||
}; | ||
|
||
renderReferredRecord = () => { | ||
const { | ||
referredEntityData: { | ||
name, | ||
type, | ||
}, | ||
entityTypeTranslationKeyMap, | ||
} = this.props; | ||
|
||
const entityType = ( | ||
<span className={styles['referred-record__entity-type']}> | ||
<FormattedMessage id={entityTypeTranslationKeyMap[type]} /> | ||
</span> | ||
); | ||
|
||
return ( | ||
<KeyValue label={entityType}> | ||
{name} | ||
</KeyValue> | ||
); | ||
} | ||
|
||
renderEntityTypesAssignmentsList = () => { | ||
return ( | ||
<List | ||
items={this.getListItems()} | ||
listStyle="bullets" | ||
/> | ||
); | ||
} | ||
|
||
getListItems() { | ||
const { | ||
linkedEntitiesTypes, | ||
entityTypePluralizedTranslationKeyMap, | ||
} = this.props; | ||
|
||
return linkedEntitiesTypes.map(({ count, type }) => ( | ||
<span className={styles['assignments-list__item']}> | ||
<FormattedMessage | ||
id={entityTypePluralizedTranslationKeyMap[type]} | ||
values={{ count }} | ||
/> | ||
</span> | ||
)); | ||
} | ||
|
||
render() { | ||
return ( | ||
<Fragment> | ||
{this.renderReferredRecord()} | ||
{this.renderEntityTypesAssignmentsList()} | ||
</Fragment> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './AssignmentsList'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './navigation-modal'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { FormattedMessage } from 'react-intl'; | ||
import ReactRouterPropTypes from 'react-router-prop-types'; | ||
import { withRouter } from 'react-router'; | ||
|
||
import { | ||
Modal, | ||
ModalFooter, | ||
Button, | ||
} from '@folio/stripes-components'; | ||
|
||
const historyActions = { | ||
PUSH: 'PUSH', | ||
REPLACE: 'REPLACE', | ||
}; | ||
|
||
const INITIAL_MODAL_STATE = { | ||
nextLocation: null, | ||
openModal: false, | ||
}; | ||
|
||
class NavigationModal extends Component { | ||
static propTypes = { | ||
history: ReactRouterPropTypes.history.isRequired, | ||
historyAction: PropTypes.string, | ||
when: PropTypes.bool.isRequired | ||
}; | ||
|
||
constructor(props) { | ||
super(props); | ||
this.state = INITIAL_MODAL_STATE; | ||
} | ||
|
||
componentDidMount() { | ||
this.unblock = this.props.history.block((nextLocation) => { | ||
if (this.props.when) { | ||
this.setState({ | ||
openModal: true, | ||
nextLocation | ||
}); | ||
} | ||
return !this.props.when; | ||
}); | ||
} | ||
|
||
componentWillUnmount() { | ||
this.unblock(); | ||
} | ||
|
||
submit = (event) => { | ||
event.preventDefault(); | ||
this.onCancel(); | ||
}; | ||
|
||
onCancel = () => { | ||
this.setState(INITIAL_MODAL_STATE); | ||
}; | ||
|
||
onConfirm = () => { | ||
this.navigateToNextLocation(); | ||
}; | ||
|
||
navigateToNextLocation() { | ||
const { | ||
historyAction, | ||
history: { | ||
action, | ||
replace, | ||
push, | ||
}, | ||
} = this.props; | ||
|
||
const { nextLocation } = this.state; | ||
|
||
this.unblock(); | ||
|
||
const replaceActionRequired = | ||
(historyAction && historyAction === historyActions.REPLACE) | ||
|| action === historyActions.REPLACE; | ||
|
||
if (replaceActionRequired) { | ||
replace(nextLocation); | ||
} else { | ||
push(nextLocation); | ||
} | ||
} | ||
|
||
render() { | ||
return ( | ||
<Modal | ||
id="navigation-modal" | ||
size="small" | ||
open={this.state.openModal} | ||
label={<FormattedMessage id="ui-eholdings.navModal.modalLabel" />} | ||
wrappingElement="form" | ||
onClose={this.onCancel} | ||
onSubmit={this.submit} | ||
footer={( | ||
<ModalFooter> | ||
<Button | ||
data-test-navigation-modal-dismiss | ||
buttonStyle="primary" | ||
type="submit" | ||
> | ||
<FormattedMessage id="ui-eholdings.navModal.dismissLabel" /> | ||
</Button> | ||
<Button | ||
data-test-navigation-modal-continue | ||
onClick={this.onConfirm} | ||
> | ||
<FormattedMessage id="ui-eholdings.navModal.continueLabel" /> | ||
</Button> | ||
</ModalFooter> | ||
)} | ||
> | ||
<FormattedMessage id="ui-eholdings.navModal.unsavedChangesMsg" /> | ||
</Modal> | ||
); | ||
} | ||
} | ||
|
||
export default withRouter(NavigationModal); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.note-form-content { | ||
margin: 0 auto; | ||
max-width: 50rem; | ||
} |
Oops, something went wrong.