Skip to content

Commit

Permalink
don't call ensureResource after component updates
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-deboer committed Oct 30, 2017
1 parent 60bc9c0 commit 5cd0004
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 52 deletions.
51 changes: 6 additions & 45 deletions pkg/ui/src/containers/ClusterInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import ResourceInfoPage from '../components/ResourceInfoPage'
import LoadingSpinner from '../components/LoadingSpinner'
import LogFollower from '../utils/LogFollower'
import ResourceNotFoundPage from '../components/ResourceNotFoundPage'
import { sameResource, resourceMatchesParams } from '../utils/resource-utils'
import { sameResourceVersion, sameResource, resourceMatchesParams } from '../utils/resource-utils'
import Loadable from 'react-loadable'
import LoadingComponentStub from '../components/LoadingComponentStub'

Expand Down Expand Up @@ -92,38 +92,6 @@ class ClusterInfo extends React.Component {
this.logs = new LogFollower.Buffer()

this.ensureResource(props)
this.watchLogs()
}

watchLogs = () => {
let { props } = this
if (!!this.state.resource && !!props.logPodContainers) {
let oldFollowers = this.logFollowers
this.logFollowers = {}
for (let key of props.logPodContainers) {
let lf = oldFollowers[key]
let [pod, cnt] = key.split('/')
if (lf) {
this.logFollowers[key] = lf
delete oldFollowers[key]
} else {
// Add new follower
this.logFollowers[key] = new LogFollower({
logs: this.logs,
namespace: this.state.resource.metadata.namespace,
pod: pod,
container: cnt,
dispatch: props.dispatch,
})
}
}

for (let key in oldFollowers) {
// clean up no-longer-selected followers
let lf = oldFollowers[key]
lf && lf.destroy()
}
}
}

ensureResource = (props) => {
Expand All @@ -138,33 +106,26 @@ class ClusterInfo extends React.Component {

componentWillReceiveProps = (props) => {

if (!sameResource(props.resource, this.state.resource) || (props.editor.contents !== this.props.editor.contents)) {
if (!sameResourceVersion(this.state.resource,props.resource)
|| (props.editor.contents !== this.props.editor.contents)
|| (props.resource && this.state.resource && props.resource.metadata.resourceVersion )
) {
this.setState({
resource: props.resource,
editor: props.editor,
})
}
this.ensureResource(props)
}

shouldComponentUpdate = (nextProps, nextState) => {
return !sameResource(this.state.resource, nextProps.resource)
|| this.props.isFetching !== nextProps.isFetching
|| this.props.user !== nextProps.user
|| this.state.editor.contents !== nextProps.editor.contents
|| this.props.location !== nextProps.location
|| this.props.events !== nextProps.events
}

componentDidMount = () => {
this.ensureResource(this.props)
this.watchLogs()
}

componentDidUpdate = () => {
// this.ensureResource(this.props)
// this.watchLogs()
}

componentWillUnmount = () => {
for (let key in this.logFollowers) {
let logFollower = this.logFollowers[key]
Expand Down
13 changes: 6 additions & 7 deletions pkg/ui/src/containers/WorkloadInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class WorkloadInfo extends React.Component {
let { params } = props.match
if (editing && !props.editor.contents) {
props.editResource(params.namespace, params.kind, params.name)
} else if (!!props.user && !resourceMatchesParams(props.resource, params) && !props.resourceNotFound) {
} else if (!!props.user && !resourceMatchesParams(props.resource, params)) {
props.requestResource(params.namespace, params.kind, params.name)
}
}
Expand All @@ -177,26 +177,25 @@ class WorkloadInfo extends React.Component {
editor: props.editor,
})
}
this.ensureResource(props)
}

// TODO: consider removing this entirely...
shouldComponentUpdate = (nextProps, nextState) => {
let shouldUpdate = (this.props.resourceRevision !== nextProps.resourceRevision
|| !sameResourceVersion(this.state.resource,nextProps.resource)
|| this.props.fetching !== nextProps.fetching
|| this.props.user !== nextProps.user
|| this.state.editor.contents !== nextProps.editor.contents
|| this.props.location !== nextProps.location
|| this.props.events !== nextProps.events
|| this.props.resourceNotFound !== nextProps.resourceNotFound
)
return shouldUpdate
}

componentDidUpdate = () => {
this.ensureResource(this.props)
this.watchLogs()
}
// componentDidUpdate = () => {
// this.ensureResource(this.props)
// this.watchLogs()
// }

componentWillUnmount = () => {
for (let key in this.logFollowers) {
Expand Down

0 comments on commit 5cd0004

Please sign in to comment.