Skip to content

Commit

Permalink
display pastures in boxes
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyubinhan committed Nov 22, 2018
1 parent e8911b5 commit 0ce7879
Show file tree
Hide file tree
Showing 5 changed files with 280 additions and 83 deletions.
89 changes: 89 additions & 0 deletions src/components/rangeUsePlan/pastures/PastureBox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { Icon } from 'semantic-ui-react';
import { TextField } from '../../common';
import {
ALLOWABLE_AUMS, PRIVATE_LAND_DEDUCTION, GRACE_DAYS,
PASTURE_NOTES,
} from '../../../constants/strings';

class PastureBox extends Component {
static propTypes = {
pasture: PropTypes.shape({}).isRequired,
pastureIndex: PropTypes.number.isRequired,
activePastureIndex: PropTypes.number.isRequired,
onPastureClicked: PropTypes.func.isRequired,
}

render() {
const {
pasture,
pastureIndex,
activePastureIndex,
onPastureClicked,
} = this.props;

const {
id,
name,
allowableAum,
pldPercent,
graceDays,
notes,
} = pasture;

const pld = pldPercent && Math.floor(pldPercent * 100);
const isActive = activePastureIndex === pastureIndex;

return (
<li key={id} className="rup__pasture">
<div className="rup__pasture__header">
<button
className="rup__pasture__header__title"
onClick={onPastureClicked(pastureIndex)}
>
<div>
{`Pasture: ${name}`}
</div>
<div className="rup__pasture__header__right">
{ isActive
? <Icon style={{ marginLeft: '10px' }} name="chevron up" />
: <Icon style={{ marginLeft: '10px' }} name="chevron down" />
}
</div>
</button>
</div>

<div className={classnames('rup__pasture__content', { 'rup__pasture__content__hidden': !isActive })}>
<div className="rup__row">
<div className="rup__cell-4">
<TextField
label={ALLOWABLE_AUMS}
text={allowableAum}
/>
</div>
<div className="rup__cell-4">
<TextField
label={PRIVATE_LAND_DEDUCTION}
text={pld}
/>
</div>
<div className="rup__cell-4">
<TextField
label={GRACE_DAYS}
text={graceDays}
/>
</div>
</div>
<TextField
label={PASTURE_NOTES}
text={notes}
/>
</div>
</li>
);
}
}

export default PastureBox;
113 changes: 35 additions & 78 deletions src/components/rangeUsePlan/pastures/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
// import { Icon, Dropdown } from 'semantic-ui-react';
import { TextField } from '../../common';
import {
ALLOWABLE_AUMS, PRIVATE_LAND_DEDUCTION, GRACE_DAYS,
PASTURE_NOTES, NOT_PROVIDED,
} from '../../../constants/strings';
import classnames from 'classnames';
import { NOT_PROVIDED } from '../../../constants/strings';
import PastureBox from './PastureBox';

class Pastures extends Component {
static propTypes = {
Expand All @@ -15,83 +12,43 @@ class Pastures extends Component {
className: PropTypes.string.isRequired,
};

renderPasture = (pasture) => {
// const options = [
// {
// key: 'edit',
// text: 'Edit',
// icon: 'edit',
// onClick: () => console.log('edit'),
// },
// {
// key: 'delete',
// text: 'Delete',
// icon: 'delete',
// onClick: () => console.log('delete'),
// },
// ];
const {
id,
name,
allowableAum,
pldPercent,
graceDays,
notes,
} = pasture || {};
const pld = pldPercent && Math.floor(pldPercent * 100);
state = {
activePastureIndex: 0,
}

onPastureClicked = pastureIndex => () => {
this.setState((prevState) => {
const newIndex = prevState.activePastureIndex === pastureIndex ? -1 : pastureIndex;
return {
activePastureIndex: newIndex,
};
});
}


renderPasture = (pasture, pastureIndex) => {
return (
<div className="rup__pasture" key={id}>
<div className="rup__pasture__header">
<div>
{`Pasture: ${name}`}
</div>
{/* <Dropdown
trigger={<Icon name="ellipsis vertical" />}
options={options}
icon={null}
pointing="top right"
/> */}
</div>
<div className="rup__row">
<div className="rup__cell-4">
<TextField
label={ALLOWABLE_AUMS}
text={allowableAum}
/>
</div>
<div className="rup__cell-4">
<TextField
label={PRIVATE_LAND_DEDUCTION}
text={pld}
/>
</div>
<div className="rup__cell-4">
<TextField
label={GRACE_DAYS}
text={graceDays}
/>
</div>
</div>
<TextField
label={PASTURE_NOTES}
text={notes}
/>
</div>
<PastureBox
key={pasture.id}
pasture={pasture}
pastureIndex={pastureIndex}
activePastureIndex={this.state.activePastureIndex}
onPastureClicked={this.onPastureClicked}
/>
);
}

renderPastures = (pastures = []) => (
<div className="rup__pastures">
{
pastures.length === 0 ? (
<div className="rup__section-not-found">{NOT_PROVIDED}</div>
) : (
pastures.map(this.renderPasture)
)
}
</div>
)
renderPastures = (pastures = []) => {
const isPastureEmpty = pastures.length === 0;

return isPastureEmpty ? (
<div className="rup__section-not-found">{NOT_PROVIDED}</div>
) : (
<ul className={classnames('rup__pastures', { 'rup__pastures--empty': isPastureEmpty })}>
{pastures.map(this.renderPasture)}
</ul>
);
}

render() {
const { elementId, plan, pasturesMap, className } = this.props;
Expand Down
111 changes: 111 additions & 0 deletions src/components/rangeUsePlan/pastures/oldindex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
// import { Icon, Dropdown } from 'semantic-ui-react';
import { TextField } from '../../common';
import {
ALLOWABLE_AUMS, PRIVATE_LAND_DEDUCTION, GRACE_DAYS,
PASTURE_NOTES, NOT_PROVIDED,
} from '../../../constants/strings';

class Pastures extends Component {
static propTypes = {
elementId: PropTypes.string.isRequired,
plan: PropTypes.shape({}).isRequired,
pasturesMap: PropTypes.shape({}).isRequired,
className: PropTypes.string.isRequired,
};

renderPasture = (pasture) => {
// const options = [
// {
// key: 'edit',
// text: 'Edit',
// icon: 'edit',
// onClick: () => console.log('edit'),
// },
// {
// key: 'delete',
// text: 'Delete',
// icon: 'delete',
// onClick: () => console.log('delete'),
// },
// ];
const {
id,
name,
allowableAum,
pldPercent,
graceDays,
notes,
} = pasture || {};
const pld = pldPercent && Math.floor(pldPercent * 100);

return (
<div className="rup__pasture" key={id}>
<div className="rup__pasture__header">
<div>
{`Pasture: ${name}`}
</div>
{/* <Dropdown
trigger={<Icon name="ellipsis vertical" />}
options={options}
icon={null}
pointing="top right"
/> */}
</div>
<div className="rup__row">
<div className="rup__cell-4">
<TextField
label={ALLOWABLE_AUMS}
text={allowableAum}
/>
</div>
<div className="rup__cell-4">
<TextField
label={PRIVATE_LAND_DEDUCTION}
text={pld}
/>
</div>
<div className="rup__cell-4">
<TextField
label={GRACE_DAYS}
text={graceDays}
/>
</div>
</div>
<TextField
label={PASTURE_NOTES}
text={notes}
/>
</div>
);
}

renderPastures = (pastures = []) => (
<div className="rup__pastures">
{
pastures.length === 0 ? (
<div className="rup__section-not-found">{NOT_PROVIDED}</div>
) : (
pastures.map(this.renderPasture)
)
}
</div>
)

render() {
const { elementId, plan, pasturesMap, className } = this.props;
const pastureIds = plan && plan.pastures;
const pastures = pastureIds && pastureIds.map(id => pasturesMap[id]);

return (
<div id={elementId} className={className}>
<div className="rup__content-title">Pastures</div>
<div className="rup__divider" />
{this.renderPastures(pastures)}
</div>
);
}
}

export default Pastures;
6 changes: 3 additions & 3 deletions src/styles/RupMinisterIssue.scss
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
.rup {
&__missues {
&__container {
margin-bottom: 20px;
}
margin: 10px 0;
list-style-type: none;
padding: 0;
border-radius: 5px;
border: 1px solid gainsboro;

&__container {
margin-bottom: 20px;
}
&--empty {
border: 0px;
}
Expand Down
Loading

0 comments on commit 0ce7879

Please sign in to comment.