diff --git a/package-lock.json b/package-lock.json index bc6f08664..31916f976 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8344,11 +8344,6 @@ "resolved": "https://registry.npmjs.org/lodash.cond/-/lodash.cond-4.5.2.tgz", "integrity": "sha1-9HGh2khr5g9quVXRcRVSPdHSVdU=" }, - "lodash.debounce": { - "version": "4.0.8", - "resolved": "https://registry.npmjs.org/lodash.debounce/-/lodash.debounce-4.0.8.tgz", - "integrity": "sha1-gteb/zCmfEAF/9XiUVMArZyk168=" - }, "lodash.defaults": { "version": "2.4.1", "resolved": "https://registry.npmjs.org/lodash.defaults/-/lodash.defaults-2.4.1.tgz", @@ -14663,6 +14658,11 @@ "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.2.1.tgz", "integrity": "sha512-jZnMwlb9Iku/O3smGWvZhauCf6cvvpKi4BKRiliS3cxnI+Gz9j5MEpTz2UFuXiKPJocb7gnsLHwiS05ige5BEA==" }, + "uuid-v4": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/uuid-v4/-/uuid-v4-0.1.0.tgz", + "integrity": "sha1-YtezEEBvbOz+oVKMafHo4LzsWjo=" + }, "v8flags": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/v8flags/-/v8flags-2.1.1.tgz", diff --git a/package.json b/package.json index 14b0b263c..161a39068 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,8 @@ "redux-logger": "^3.0.6", "redux-mock-store": "^1.5.3", "redux-thunk": "^2.2.0", - "semantic-ui-react": "^0.78.2" + "semantic-ui-react": "^0.78.2", + "uuid-v4": "^0.1.0" }, "devDependencies": { "@types/jest": "^22.2.2", diff --git a/src/components/rangeUsePlan/edit/EditRupGrazingSchedule.js b/src/components/rangeUsePlan/edit/EditRupGrazingSchedule.js new file mode 100644 index 000000000..7203ba303 --- /dev/null +++ b/src/components/rangeUsePlan/edit/EditRupGrazingSchedule.js @@ -0,0 +1,204 @@ +import React, { Component } from 'react'; +import PropTypes from 'prop-types'; +import classnames from 'classnames'; +// import cloneDeep from 'lodash.clonedeep'; +import { Table, Button, Icon, TextArea, Form, Dropdown, Message } from 'semantic-ui-react'; +// import { calcCrownTotalAUMs, roundTo1Decimal } from '../../../handlers'; +// import { handleGrazingScheduleValidation } from '../../../handlers/validation'; +import * as strings from '../../../constants/strings'; +import { roundTo1Decimal, getObjValues } from '../../../utils'; +import EditRupGrazingScheduleEntry from './EditRupGrazingScheduleEntry'; +// import { ConfirmationModal } from '../../common'; + +const propTypes = { + schedule: PropTypes.shape({ grazingScheduleEntries: PropTypes.array }).isRequired, + scheduleIndex: PropTypes.number.isRequired, + onScheduleClicked: PropTypes.func.isRequired, + activeScheduleIndex: PropTypes.number.isRequired, + grazingScheduleEntriesMap: PropTypes.shape({}).isRequired, + authorizedAUMs: PropTypes.number.isRequired, + crownTotalAUMs: PropTypes.number.isRequired, + yearOptions: PropTypes.arrayOf(PropTypes.object).isRequired, + pasturesMap: PropTypes.shape({}).isRequired, + livestockTypes: PropTypes.arrayOf(PropTypes.object).isRequired, + // usages: PropTypes.arrayOf(PropTypes.object).isRequired, + // yearOptions: PropTypes.arrayOf(PropTypes.object).isRequired, + // pastures: PropTypes.arrayOf(PropTypes.object).isRequired, + // handleScheduleChange: PropTypes.func.isRequired, + // handleScheduleDelete: PropTypes.func.isRequired, + // handleScheduleCopy: PropTypes.func.isRequired, + // deleteRupScheduleEntry: PropTypes.func.isRequired, + // isDeletingSchedule: PropTypes.bool.isRequired, + // isDeletingScheduleEntry: PropTypes.bool.isRequired, +}; + +class EditRupSchedule extends Component { + state = { + // isDeleteScheduleModalOpen: false, + } + + onScheduleClicked = () => { + const { scheduleIndex, onScheduleClicked } = this.props; + onScheduleClicked(scheduleIndex); + } + + onNarativeChanged = () => { + + } + onNewRowClick = (scheduleIndex) => () => { + + } + + onScheduleCopyClicked = () => () => { + + } + renderScheduleEntries = (grazingScheduleEntries = [], scheduleIndex) => { + const { + schedule, + pasturesMap, + livestockTypes, + isDeletingScheduleEntry, + } = this.props; + const { year } = schedule; + const pastures = getObjValues(pasturesMap); + const pastureOptions = pastures.map((pasture) => { + const { id, name } = pasture || {}; + return { + key: id, + value: id, + text: name, + }; + }); + const livestockTypeOptions = livestockTypes.map((lt) => { + const { id, name } = lt || {}; + return { + key: id, + value: id, + text: name, + }; + }); + + return grazingScheduleEntries.map((entry, entryIndex) => { + // const key = `schedule${scheduleIndex}entry${entry.key || entry.id}`; + return ( + + ); + }); + } + render() { + const { + schedule, + scheduleIndex, + activeScheduleIndex, + grazingScheduleEntriesMap, + authorizedAUMs, + crownTotalAUMs, + yearOptions, + } = this.props; + // const { isDeleteScheduleModalOpen } = this.state; + const { year, grazingScheduleEntries: ids } = schedule; + const grazingScheduleEntries = ids.map(id => grazingScheduleEntriesMap[id]); + const narative = (schedule && schedule.narative) || ''; + const isScheduleActive = activeScheduleIndex === scheduleIndex; + const roundedCrownTotalAUMs = roundTo1Decimal(crownTotalAUMs); + const copyOptions = yearOptions.map(o => ({ ...o, onClick: this.onScheduleCopyClicked(o) })) || []; + const isCrownTotalAUMsError = crownTotalAUMs > authorizedAUMs; + + return ( +
  • +
    + +
    + } + icon={null} + pointing="right" + loading={false} + disabled={false} + > + + + Delete + + +
    +
    + +
    + + + + {strings.PASTURE} + {strings.LIVESTOCK_TYPE} + {strings.NUM_OF_ANIMALS} +
    {strings.DATE_IN}
    +
    {strings.DATE_OUT}
    + {strings.DAYS} +
    {strings.GRACE_DAYS}
    + {strings.PLD} + {strings.CROWN_AUMS} + +
    + {this.renderScheduleEntries(grazingScheduleEntries, scheduleIndex)} +
    +
    + +
    +
    Authorized AUMs
    +
    {authorizedAUMs}
    +
    Total AUMs
    +
    + {roundedCrownTotalAUMs} +
    +
    +
    Schedule Description
    +
    +