New: Sort preferred words by score when displaying in the UI

pull/3072/head
Mark McDowall 6 years ago
parent 84a0a0743b
commit b3e019e7a0

@ -9,6 +9,10 @@ import ConfirmModal from 'Components/Modal/ConfirmModal';
import EditReleaseProfileModalConnector from './EditReleaseProfileModalConnector'; import EditReleaseProfileModalConnector from './EditReleaseProfileModalConnector';
import styles from './ReleaseProfile.css'; import styles from './ReleaseProfile.css';
function sortPreferred(preferred) {
return preferred.slice().sort((a, b) => b.value - a.value);
}
class ReleaseProfile extends Component { class ReleaseProfile extends Component {
// //
@ -18,11 +22,20 @@ class ReleaseProfile extends Component {
super(props, context); super(props, context);
this.state = { this.state = {
sortedPreferred: sortPreferred(props.preferred),
isEditReleaseProfileModalOpen: false, isEditReleaseProfileModalOpen: false,
isDeleteReleaseProfileModalOpen: false isDeleteReleaseProfileModalOpen: false
}; };
} }
componentDidUpdate(prevProps) {
const { preferred } = this.props;
if (prevProps.preferred !== preferred) {
this.setState({ sortedPreferred: sortPreferred(preferred) });
}
}
// //
// Listeners // Listeners
@ -57,11 +70,16 @@ class ReleaseProfile extends Component {
id, id,
required, required,
ignored, ignored,
preferred,
tags, tags,
tagList tagList
} = this.props; } = this.props;
const {
sortedPreferred,
isEditReleaseProfileModalOpen,
isDeleteReleaseProfileModalOpen
} = this.state;
return ( return (
<Card <Card
className={styles.releaseProfile} className={styles.releaseProfile}
@ -108,7 +126,7 @@ class ReleaseProfile extends Component {
<div> <div>
{ {
preferred.map((item) => { sortedPreferred.map((item) => {
const isPreferred = item.value >= 0; const isPreferred = item.value >= 0;
return ( return (
@ -130,13 +148,13 @@ class ReleaseProfile extends Component {
<EditReleaseProfileModalConnector <EditReleaseProfileModalConnector
id={id} id={id}
isOpen={this.state.isEditReleaseProfileModalOpen} isOpen={isEditReleaseProfileModalOpen}
onModalClose={this.onEditReleaseProfileModalClose} onModalClose={this.onEditReleaseProfileModalClose}
onDeleteReleaseProfilePress={this.onDeleteReleaseProfilePress} onDeleteReleaseProfilePress={this.onDeleteReleaseProfilePress}
/> />
<ConfirmModal <ConfirmModal
isOpen={this.state.isDeleteReleaseProfileModalOpen} isOpen={isDeleteReleaseProfileModalOpen}
kind={kinds.DANGER} kind={kinds.DANGER}
title="Delete ReleaseProfile" title="Delete ReleaseProfile"
message={'Are you sure you want to delete this releaseProfile?'} message={'Are you sure you want to delete this releaseProfile?'}

Loading…
Cancel
Save