Skip to content

Commit 8badeaa

Browse files
committed
Add network component to list of supported components for link sharing
1 parent c2290d6 commit 8badeaa

File tree

3 files changed

+60
-7
lines changed

3 files changed

+60
-7
lines changed

src/client/components/facet_results/ExportLink.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,25 +59,25 @@ class ExportLink extends React.Component {
5959
}
6060

6161
componentDidMount = () => {
62-
this.setState({ downloadLink: this.createDownloadLink() })
62+
this.setState({ downloadLink: this.createLink() })
6363
}
6464

6565
componentDidUpdate = prevProps => {
6666
// check if filters have changed
6767
if (prevProps.facetUpdateID !== this.props.facetUpdateID) {
68-
this.setState({ downloadLink: this.createDownloadLink() })
68+
this.setState({ downloadLink: this.createLink() })
6969
}
7070
}
7171

72-
createDownloadLink = () => {
72+
createLink = () => {
7373
const params = stateToUrl({
7474
facetClass: this.props.facetClass,
7575
facets: this.props.facets
7676
})
7777

7878
const constraints = params.constraints ? params.constraints : []
7979
const mappedConstraints = []
80-
// go through constraints:
80+
// go through constraints
8181
for (const constraint of constraints) {
8282
const facetId = constraint.facetID
8383
const filterType = constraint.filterType
@@ -133,7 +133,7 @@ class ExportLink extends React.Component {
133133
}
134134

135135
updateDownloadLink = () => {
136-
this.setState({ downloadLink: this.createDownloadLink() })
136+
this.setState({ downloadLink: this.createLink() })
137137
}
138138

139139
handleViewChange (event) {
@@ -151,7 +151,7 @@ class ExportLink extends React.Component {
151151
const errorBody = intl.getHTML('exportLink.errorBody') ? intl.getHTML('exportLink.errorBody') : parse('The current length of the generated link is more than 15,800 characters. <strong>The server will refuse to handle requests that go over certain length limits</strong> — you can reduce the length of the link by deselecting some facet options.')
152152
const copyLinkToClipboard = intl.get('exportLink.copyLinkToClipboard') ? intl.get('exportLink.copyLinkToClipboard') : 'Copy link to clipboard'
153153

154-
const acceptedComponentTypes = ['ApexCharts', 'ApexChartsDouble', 'LeafletMap', 'Deck']
154+
const acceptedComponentTypes = ['ApexCharts', 'ApexChartsDouble', 'LeafletMap', 'Deck', 'Network']
155155
const defaultTab = this.props.perspectiveConfig.resultClasses[this.props.perspectiveConfig.id].paginatedResultsConfig
156156
const suitableResultClasses = Object.values(this.props.perspectiveConfig.resultClasses).filter(resultClass => acceptedComponentTypes.includes(resultClass.component))
157157
return (

src/client/components/facet_results/Network.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'cytoscape-panzoom/cytoscape.js-panzoom.css'
88
import CircularProgress from '@mui/material/CircularProgress'
99
import { library, dom } from '@fortawesome/fontawesome-svg-core'
1010
import { faMinus, faPlus, faExpand } from '@fortawesome/free-solid-svg-icons'
11+
import querystring from 'querystring'
1112

1213
const zoomControlOptions = {
1314
zoomFactor: 0.05, // zoom factor per zoom tick
@@ -44,9 +45,41 @@ class Network extends React.Component {
4445
constructor (props) {
4546
super(props)
4647
this.cyRef = React.createRef()
48+
this.state = {
49+
defaultFacetFetchingRequired: false
50+
}
4751
}
4852

4953
componentDidMount = () => {
54+
let constraints = []
55+
56+
// first check if page or constraints were given as url parameter
57+
if (this.props.location && this.props.location.search !== '') {
58+
const qs = this.props.location.search.replace('?', '')
59+
const parsedConstraints = querystring.parse(qs).constraints
60+
constraints = parsedConstraints ? JSON.parse(decodeURIComponent(parsedConstraints)) : []
61+
}
62+
63+
// update imported facets
64+
for (const constraint of constraints) {
65+
this.props.updateFacetOption({
66+
facetClass: this.props.facetClass,
67+
facetID: constraint.facetId,
68+
option: constraint.filterType,
69+
value: constraint.value
70+
})
71+
}
72+
73+
// check if default facets need to be refetched due to imported facets
74+
if (constraints.length > 0) {
75+
// remove query from URL
76+
history.replace({
77+
pathname: `${this.props.rootUrl}/${this.props.facetClass}/faceted-search/${this.props.tabPath}`
78+
})
79+
80+
this.setState({ defaultFacetFetchingRequired: true })
81+
}
82+
5083
this.props.fetchResults({
5184
perspectiveID: this.props.perspectiveConfig.id,
5285
resultClass: this.props.resultClass,
@@ -106,6 +139,20 @@ class Network extends React.Component {
106139
(prevProps.fetching && !this.props.fetching)) {
107140
this.renderCytocape()
108141
}
142+
143+
// check if facets are still fetching
144+
let someFacetIsFetching = false
145+
if (this.props.pageType === 'facetResults' && this.props.facetState) Object.values(this.props.facetState.facets).forEach(facet => { if (facet.isFetching) { someFacetIsFetching = true } })
146+
147+
// refetch default facets (excl. text facets) when facets have been updated
148+
if (this.state.defaultFacetFetchingRequired && this.props.facetUpdateID > 0 && !someFacetIsFetching) {
149+
const defaultFacets = this.props.perspectiveConfig.defaultActiveFacets
150+
for (const facet of defaultFacets) {
151+
if (this.props.perspectiveConfig.facets[facet].filterType !== 'textFilter') this.props.fetchFacet({ facetClass: this.props.facetClass, facetID: facet })
152+
}
153+
this.setState({ defaultFacetFetchingRequired: false })
154+
}
155+
109156
// check if filters have changed
110157
if (prevProps.facetUpdateID !== this.props.facetUpdateID) {
111158
this.props.fetchResults({

src/client/components/facet_results/ResultClassRoute.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,13 @@ const ResultClassRoute = props => {
367367
fitLayout,
368368
...(style && { style }),
369369
...(layout && { layout }),
370-
...(preprocess && { preprocess: networkConfig[preprocess] })
370+
...(preprocess && { preprocess: networkConfig[preprocess] }),
371+
updateFacetOption: props.updateFacetOption,
372+
fetchFacet: props.fetchFacet,
373+
facetState: props.facetState,
374+
location: useLocation(),
375+
rootUrl: rootUrl,
376+
tabPath: resultClassConfig.tabPath
371377
}
372378
if (pageType === 'facetResults') {
373379
networkProps = {

0 commit comments

Comments
 (0)