Skip to content

Commit

Permalink
OpenConceptLab/ocl_issues#1931 | getting versions summary with versions
Browse files Browse the repository at this point in the history
  • Loading branch information
snyaggarwal committed Sep 19, 2024
1 parent e1c6fce commit 06dbfe4
Showing 1 changed file with 3 additions and 45 deletions.
48 changes: 3 additions & 45 deletions src/components/sources/SourceHome.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { CircularProgress } from '@mui/material';
import { includes, isEmpty, get, findIndex, isEqual, find, isObject, omit, forEach, isNumber, map } from 'lodash';
import { includes, isEmpty, get, findIndex, isEqual, find, isObject, isNumber, map } from 'lodash';
import APIService from '../../services/APIService';
import SourceHomeHeader from './SourceHomeHeader';
import Breadcrumbs from './Breadcrumbs';
Expand Down Expand Up @@ -116,39 +116,9 @@ class SourceHome extends React.Component {
APIService
.new()
.overrideURL(this.sourcePath + 'versions/')
.get(null, null, {verbose: true, limit: 1000, includeStates: isLoggedIn()})
.get(null, null, {verbose: true, limit: 1000, includeStates: isLoggedIn(), includeSummary: true})
.then(response => {
this.setState({versions: response.data, isLoadingVersions: false}, () => {
if(this.isVersionTabSelected())
this.fetchVersionsSummary()
})
})
})
}

setHEADSummary() {
if(this.state.source.summary) {
const newState = {...this.state}
const head = find(newState.versions, {id: 'HEAD'})
if(head) {
head.summary = this.state.source.summary
this.setState(newState)
}

}
}

fetchVersionsSummary() {
forEach(this.state.versions, version => {
if(version.id === 'HEAD') {
this.fetchSummary()
}
else
APIService.new().overrideURL(version.version_url).appendToUrl('summary/').get().then(response => {
const newState = {...this.state}
const _version = find(newState.versions, {uuid: version.uuid})
_version.summary = omit(response.data, ['id', 'uuid'])
this.setState(newState)
this.setState({versions: response.data, isLoadingVersions: false})
})
})
}
Expand All @@ -159,8 +129,6 @@ class SourceHome extends React.Component {
this.setState({tab: value, selected: null, width: false}, () => {
if(isEmpty(this.state.versions))
this.getVersions()
if(this.isVersionTabSelected())
this.fetchVersionsSummary()
if(this.isSummaryTabSelected())
this.fetchSelectedSourceVersionSummary()
})
Expand Down Expand Up @@ -222,16 +190,6 @@ class SourceHome extends React.Component {
})
}

fetchSummary() {
APIService.new()
.overrideURL(this.sourcePath)
.appendToUrl('summary/')
.get()
.then(response => this.setState({
source: {...this.state.source, summary: omit(response.data, ['id', 'uuid'])}
}, this.setHEADSummary))
}

onConfigChange = config => this.setState({selectedConfig: config}, () => {
const tab = this.getDefaultTabIndex()
if(tab === 0)
Expand Down

0 comments on commit 06dbfe4

Please sign in to comment.