Skip to content

Commit

Permalink
chore(xo-web/jobs): use addSubscriptions for all subs
Browse files Browse the repository at this point in the history
  • Loading branch information
julien-f committed Sep 12, 2023
1 parent 42aa19a commit c0843a8
Showing 1 changed file with 8 additions and 36 deletions.
44 changes: 8 additions & 36 deletions packages/xo-web/src/xo-app/jobs/overview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { addSubscriptions } from 'utils'
import { Container } from 'grid'
import { createSelector } from 'selectors'
import { Card, CardHeader, CardBlock } from 'card'
import { filter, find, forEach } from 'lodash'
import { filter, find, forEach, keyBy } from 'lodash'
import {
deleteSchedule,
deleteSchedules,
Expand Down Expand Up @@ -100,46 +100,18 @@ const ACTIONS = [
// ===================================================================

@addSubscriptions({
users: subscribeUsers,
jobs: [cb => subscribeJobs(jobs => cb(keyBy(jobs, 'id'))), {}],
schedules: [subscribeSchedules, []],
users: [subscribeUsers, []],
})
export default class Overview extends Component {
static contextTypes = {
router: PropTypes.object,
}

constructor(props) {
super(props)
this.state = {
jobs: {},
schedules: [],
}
}

componentWillMount() {
const unsubscribeJobs = subscribeJobs(jobs => {
const obj = {}
forEach(jobs, job => {
obj[job.id] = job
})

this.setState({
jobs: obj,
})
})

const unsubscribeSchedules = subscribeSchedules(schedules => {
this.setState({ schedules })
})

this.componentWillUnmount = () => {
unsubscribeJobs()
unsubscribeSchedules()
}
}

_getGenericSchedules = createSelector(
() => this.state.schedules,
() => this.state.jobs,
() => this.props.schedules,
() => this.props.jobs,

// Get only generic jobs
(schedules, jobs) =>
Expand All @@ -152,7 +124,7 @@ export default class Overview extends Component {
_getIsScheduleUserMissing = createSelector(
this._getGenericSchedules,
() => this.props.users,
() => this.state.jobs,
() => this.props.jobs,
(schedules, users, jobs) => {
const isScheduleUserMissing = {}

Expand Down Expand Up @@ -196,7 +168,7 @@ export default class Overview extends Component {
collection={this._getGenericSchedules()}
columns={SCHEDULES_COLUMNS}
data-isScheduleUserMissing={this._getIsScheduleUserMissing()}
data-jobs={this.state.jobs}
data-jobs={this.props.jobs}
individualActions={this._individualActions}
shortcutsTarget='body'
stateUrlParam='s'
Expand Down

0 comments on commit c0843a8

Please sign in to comment.