chore(xo-web/settings/remotes): use groupBy (#3200)

This commit is contained in:
badrAZ 2018-07-19 09:46:23 +02:00 committed by Julien Fontanet
parent 7dfb1635c2
commit a1c829e393

View File

@ -1,12 +1,8 @@
import _, { messages } from 'intl' import _, { messages } from 'intl'
import ActionButton from 'action-button' import ActionButton from 'action-button'
import Component from 'base-component' import Component from 'base-component'
import filter from 'lodash/filter'
import Icon from 'icon' import Icon from 'icon'
import isEmpty from 'lodash/isEmpty'
import map from 'lodash/map'
import React from 'react' import React from 'react'
import some from 'lodash/some'
import SortedTable from 'sorted-table' import SortedTable from 'sorted-table'
import StateButton from 'state-button' import StateButton from 'state-button'
import Tooltip from 'tooltip' import Tooltip from 'tooltip'
@ -14,9 +10,10 @@ import { addSubscriptions } from 'utils'
import { alert, confirm } from 'modal' import { alert, confirm } from 'modal'
import { error } from 'notification' import { error } from 'notification'
import { format, parse } from 'xo-remote-parser' import { format, parse } from 'xo-remote-parser'
import { groupBy, map, isEmpty, some } from 'lodash'
import { injectIntl } from 'react-intl' import { injectIntl } from 'react-intl'
import { Number, Password, Text } from 'editable'
import { Number as InputNumber } from 'form' import { Number as InputNumber } from 'form'
import { Number, Password, Text } from 'editable'
import { import {
createRemote, createRemote,
@ -268,22 +265,22 @@ const FILTERS = {
@addSubscriptions({ @addSubscriptions({
remotes: cb => remotes: cb =>
subscribeRemotes(rawRemotes => { subscribeRemotes(remotes => {
rawRemotes = map(rawRemotes, remote => { cb(
try { groupBy(
return { map(remotes, remote => {
...remote, try {
...parse(remote.url), return {
} ...remote,
} catch (err) { ...parse(remote.url),
console.error('Remote parsing error:', remote, '\n', err) }
} } catch (err) {
}).filter(r => r !== undefined) console.error('Remote parsing error:', remote, '\n', err)
const remotes = {} }
for (const remoteType in remoteTypes) { }).filter(r => r !== undefined),
remotes[remoteType] = filter(rawRemotes, r => r.type === remoteType) 'type'
} )
cb(remotes) )
}), }),
}) })
@injectIntl @injectIntl