Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RDFDisplay should get a dataset instead of a string to avoid overload…
…ing the browser memory
- Loading branch information
Showing
6 changed files
with
74 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,69 @@ | ||
// Copyright 2019 Stanford University see LICENSE for license | ||
|
||
import React from 'react' | ||
import { connect } from 'react-redux' | ||
import PropTypes from 'prop-types' | ||
import React, { useEffect, useState } from 'react' | ||
import { useSelector, useDispatch } from 'react-redux' | ||
import PanelResource from './property/PanelResource' | ||
import { selectErrors } from 'selectors/errors' | ||
import CopyToNewMessage from './CopyToNewMessage' | ||
import ResourceURIMessage from './ResourceURIMessage' | ||
import SaveAlert from './SaveAlert' | ||
import RDFDisplay from './RDFDisplay' | ||
import Alerts from '../Alerts' | ||
import { newResourceErrorKey } from './property/ResourceList' | ||
import { resourceEditErrorKey } from './Editor' | ||
import { selectCurrentResourceKey, selectCurrentResource } from 'selectors/resources' | ||
import { addError } from 'actions/errors' | ||
import { datasetFromN3 } from 'utilities/Utilities' | ||
import { selectCurrentResource } from 'selectors/resources' | ||
import { selectErrors } from 'selectors/errors' | ||
import { selectUnusedRDF } from 'selectors/modals' | ||
import _ from 'lodash' | ||
|
||
/** | ||
* This is the root component of the editor on the resource edit page | ||
*/ | ||
const ResourceComponent = (props) => { | ||
if (!_.isEmpty(props.errors)) { | ||
return (<Alerts errorKey={resourceEditErrorKey(props.resourceKey)} />) | ||
const ResourceComponent = () => { | ||
const dispatch = useDispatch() | ||
const resource = useSelector((state) => selectCurrentResource(state)) | ||
const resourceKey = resource.key | ||
const errors = useSelector((state) => selectErrors(state, resourceEditErrorKey(resourceKey))) | ||
const unusedRDF = useSelector((state) => selectUnusedRDF(state, resourceKey)) | ||
|
||
const [dataset, setDataset] = useState(null) | ||
|
||
useEffect(() => { | ||
if (_.isEmpty(unusedRDF)) return | ||
datasetFromN3(unusedRDF) | ||
.then((dataset) => setDataset(dataset)) | ||
.catch((err) => dispatch(addError(resourceEditErrorKey(resourceKey), err.message || err))) | ||
}, [unusedRDF, resourceKey, dispatch]) | ||
|
||
if (!_.isEmpty(errors)) { | ||
return (<Alerts errorKey={resourceEditErrorKey(resourceKey)} />) | ||
} | ||
if (!props.resource) { | ||
if (!resource) { | ||
return null | ||
} | ||
|
||
return ( | ||
<div className="ResourceTemplate"> | ||
<div id="resourceTemplate"> | ||
<Alerts errorKey={resourceEditErrorKey(props.resourceKey)} /> | ||
<Alerts errorKey={resourceEditErrorKey(resourceKey)} /> | ||
<Alerts errorKey={newResourceErrorKey} /> | ||
<section> | ||
<h3>{props.resource.subjectTemplate.label}</h3> | ||
<h3>{resource.subjectTemplate.label}</h3> | ||
<CopyToNewMessage /> | ||
<ResourceURIMessage /> | ||
<SaveAlert /> | ||
</section> | ||
{props.unusedRDF | ||
{dataset | ||
&& <div className="alert alert-warning" role="alert"> | ||
<strong>Unable to load the entire resource.</strong> The unused triples are: | ||
<RDFDisplay rdf={props.unusedRDF} /> | ||
<RDFDisplay dataset={dataset} /> | ||
</div> | ||
} | ||
<PanelResource resource={props.resource} /> | ||
<PanelResource resource={resource} /> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
ResourceComponent.propTypes = { | ||
errors: PropTypes.array, | ||
unusedRDF: PropTypes.string, | ||
resourceKey: PropTypes.string, | ||
resource: PropTypes.object, | ||
} | ||
|
||
const mapStateToProps = (state) => { | ||
const resourceKey = selectCurrentResourceKey(state) | ||
return { | ||
resourceKey, | ||
resource: selectCurrentResource(state), | ||
errors: selectErrors(state, resourceEditErrorKey(resourceKey)), | ||
unusedRDF: state.selectorReducer.editor.unusedRDF[resourceKey], | ||
} | ||
} | ||
|
||
export default connect(mapStateToProps)(ResourceComponent) | ||
export default ResourceComponent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters