Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PXD-1430 fix(core-metadata) #331

Merged
merged 4 commits into from
Aug 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/CoreMetadata/CoreMetadataHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class CoreMetadataHeader extends Component {
dateTransform = date => `Updated on ${date.substr(0, 10)}`;

render() {

if (this.props.metadata) {
// display the download button if the user can download this file
const { user, projectAvail } = this.props;
const projectId = this.props.metadata.project_id;
Expand Down Expand Up @@ -74,13 +76,30 @@ class CoreMetadataHeader extends Component {
</div>
);
}

// if there is no core metadata to display
else {
return (
<p className="body-typo">
Error: {this.props.error}
</p>
);
}

}
}

CoreMetadataHeader.propTypes = {
metadata: PropTypes.object.isRequired,
metadata: PropTypes.object,
error: PropTypes.string,
onDownloadFile: PropTypes.func.isRequired,
user: PropTypes.object.isRequired,
projectAvail: PropTypes.object.isRequired,
};

CoreMetadataHeader.defaultProps = {
metadata: null,
error: null,
};

export default CoreMetadataHeader;
22 changes: 14 additions & 8 deletions src/CoreMetadata/CoreMetadataTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ function fieldInTable(fieldName) {
}

class CoreMetadataTable extends Component {
dataTransform = metadata => Object.keys(metadata)
.sort() // alphabetical order
.filter(key => fieldInTable(key))
.map(key => [
<TitleCell>{firstCharToUppercase(key)}</TitleCell>,
metadata[key],
]);
dataTransform = metadata => metadata ?
Object.keys(metadata)
.sort() // alphabetical order
.filter(key => fieldInTable(key))
.map(key => [
<TitleCell>{firstCharToUppercase(key)}</TitleCell>,
metadata[key],
])
: [];

render() {
return (
Expand All @@ -42,7 +44,11 @@ class CoreMetadataTable extends Component {
}

CoreMetadataTable.propTypes = {
metadata: PropTypes.object.isRequired,
metadata: PropTypes.object,
};

CoreMetadataTable.defaultProps = {
metadata: null,
};

export default CoreMetadataTable;
5 changes: 3 additions & 2 deletions src/CoreMetadata/reduxer.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const fetchCoreMetadata = objectId =>
default:
return {
type: 'CORE_METADATA_ERROR',
error: data.error,
error: data,
};
}
})
Expand Down Expand Up @@ -58,6 +58,7 @@ const downloadFile = id => (dispatch) => {
export const ReduxCoreMetadataHeader = (() => {
const mapStateToProps = state => ({
metadata: state.coreMetadata.metadata,
error: state.coreMetadata.error,
user: state.user,
projectAvail: state.submission.projectAvail,
});
Expand All @@ -71,7 +72,7 @@ export const ReduxCoreMetadataHeader = (() => {

export const ReduxFileTypePicture = (() => {
const mapStateToProps = state => ({
data_format: state.coreMetadata.metadata.data_format,
metadata: state.coreMetadata.metadata,
});

const mapDispatchToProps = dispatch => ({
Expand Down
9 changes: 7 additions & 2 deletions src/components/FileTypePicture.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ function dataFormatToFileType(dictIcons, dataFormat) {

class FileTypePicture extends Component {
render() {
const fileType = dataFormatToFileType(this.props.dictIcons, this.props.data_format);
const dataFormat = this.props.metadata ? this.props.metadata.data_format : 'file'
const fileType = dataFormatToFileType(this.props.dictIcons, dataFormat);
if (!fileType) return null;
const content = (
<WhiteContainer>
Expand All @@ -43,8 +44,12 @@ class FileTypePicture extends Component {
}

FileTypePicture.propTypes = {
data_format: PropTypes.string.isRequired,
metadata: PropTypes.object,
dictIcons: PropTypes.object.isRequired,
};

FileTypePicture.defaultProps = {
metadata: null,
};

export default FileTypePicture;