Skip to content

Commit

Permalink
Merge pull request #22 from KPMP/KPMP-1884_File_Move_Button
Browse files Browse the repository at this point in the history
Kpmp 1884 file move button
  • Loading branch information
rlreamy authored Jul 2, 2020
2 parents dbe1cd6 + fc8c9e5 commit feae706
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/actions/Packages/packageActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ export const getPackages = () => {
};
}

export const movePackageFiles = (packageId) => {
return (dispatch) => {
api.post('/api/v1/packages/' + packageId + '/files/move')
.then(res => {
alert(res.data);
})
.catch(err => {
alert("There was a problem moving the files.");
});
}
}

export const setPackages = (packages) => {
return {
type: actionNames.SET_PACKAGES,
Expand Down
2 changes: 1 addition & 1 deletion src/components/PackageDashboard/PackageDashboardPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class PackageDashboardPage extends Component {
<Row className='mt-3'>
<Col sm={12}>
<PackageTable
packages={this.props.packages}
packages={this.props.packages} movePackageFiles={this.props.movePackageFiles}
/>
</Col>
</Row>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { connect } from 'react-redux';
import { getPackages } from "../../actions/Packages/packageActions";
import { getPackages, movePackageFiles } from "../../actions/Packages/packageActions";
import PackageDashboardPage from './PackageDashboardPage';

const mapStateToProps = (state, props) => ({
Expand All @@ -9,6 +9,9 @@ const mapStateToProps = (state, props) => ({
const mapDispatchToProps = (dispatch, props) => ({
getPackages() {
dispatch(getPackages());
},
movePackageFiles(packageId) {
dispatch(movePackageFiles(packageId));
}
});

Expand Down
23 changes: 23 additions & 0 deletions src/components/PackageDashboard/PackageTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import ReactGA from 'react-ga';
import PropTypes from 'prop-types';
import Moment from 'moment';
import stateMap from './stateMap';
import { Button } from 'reactstrap';

const PACKAGE_ID_LABEL = 'Package ID';
const PACKAGE_TYPE_LABEL = 'Package Type';
Expand All @@ -13,6 +14,7 @@ const DATE_SUBMITTED_LABEL = 'Date Submitted';
const PACKAGE_STATE_LABEL = 'Package State';
const SUBJECT_ID_LABEL = 'Subject Id';
const GLOBUS_LINK_LABEL = 'Globus Link';
const MOVE_PACKAGE_FILES_LABEL = 'Move Files to DLU';

const PACKAGE_ID = '_id';
const SUBMITTER_ID = 'displayName';
Expand Down Expand Up @@ -112,6 +114,23 @@ class PackageTable extends Component {
return '';
}
}
}, {
Header: MOVE_PACKAGE_FILES_LABEL,
accessor: 'button',
filterable: false,
Cell: (info) => {
let row = info.original;
// eslint-disable-next-line
if(row[PACKAGE_INFO_PROPERTY][LARGE_FILE_UPLOAD] && row.state[PACKAGE_STATE_ID] === 'METADATA_RECEIVED') {
return (
// eslint-disable-next-line
<Button color="primary" onClick={() => this.handleMoveFileClick(row[PACKAGE_INFO_PROPERTY][PACKAGE_ID])}>Move Files</Button>
);
} else {
// eslint-disable-next-line
return '';
}
}
}

];
Expand All @@ -137,6 +156,10 @@ class PackageTable extends Component {
});
}

handleMoveFileClick = (packageId) => {
this.props.movePackageFiles(packageId);
};

defaultFilterMethod(filter, row, column) {
return row[filter.id] && row[filter.id].toUpperCase().indexOf(filter.value.toUpperCase()) > -1;
}
Expand Down

0 comments on commit feae706

Please sign in to comment.