Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(app, app-shell): add ability to disable discovery cache #5759

Merged
merged 10 commits into from
Jun 4, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion app-shell/src/discovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export function registerDiscovery(dispatch: Dispatch) {

config = getConfig('discovery')
store = new Store({ name: 'discovery', defaults: { services: [] } })
let disableCache = config.disableCache

client = createDiscoveryClient({
mcous marked this conversation as resolved.
Show resolved Hide resolved
pollInterval: SLOW_POLL_INTERVAL_MS,
Expand All @@ -51,6 +52,10 @@ export function registerDiscovery(dispatch: Dispatch) {
client.setCandidates(['[fd00:0:cafe:fefe::1]'].concat(value))
)

handleConfigChange('discovery.disableCache', value => {
disableCache = value
})

app.once('will-quit', () => client.stop())

return function handleIncomingAction(action: Action) {
Expand All @@ -73,7 +78,9 @@ export function registerDiscovery(dispatch: Dispatch) {
}

function handleServices() {
store.set('services', filterServicesToPersist(client.services))
if (!disableCache) {
store.set('services', filterServicesToPersist(client.services))
}
dispatch({
type: 'discovery:UPDATE_LIST',
payload: { robots: client.services },
Expand Down
2 changes: 2 additions & 0 deletions app/src/components/NetworkSettingsCard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import * as React from 'react'
import { Card } from '@opentrons/components'
import { AddManualIp } from './AddManualIp'
import { ClearDiscoveryCache } from './ClearDiscoveryCache'
import { CachingToggle } from './toggleDiscoveryCaching'
mcous marked this conversation as resolved.
Show resolved Hide resolved

// TODO(mc, 2020-04-27): i18n
const NETWORK_SETTINGS = 'Network Settings'

export const NetworkSettingsCard = () => (
<Card title={NETWORK_SETTINGS}>
<AddManualIp />
<CachingToggle />
<ClearDiscoveryCache />
</Card>
)
48 changes: 48 additions & 0 deletions app/src/components/NetworkSettingsCard/toggleDiscoveryCaching.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// @flow
import * as React from 'react'
import { connect } from 'react-redux'
mcous marked this conversation as resolved.
Show resolved Hide resolved
import { LabeledToggle } from '@opentrons/components'
import type { State, Dispatch } from '../../types'
import { getConfig, toggleDiscoveryCache } from '../../config'

type OP = {||}

type SP = {| cacheDisabled: boolean |}

type DP = {| toggleCacheDisable: () => mixed |}

type Props = {| ...SP, ...DP |}

export const CachingToggle = connect<Props, OP, _, _, _, _>(
mcous marked this conversation as resolved.
Show resolved Hide resolved
mapStateToProps,
mapDispatchToProps
)(CachingToggleComponent)

function CachingToggleComponent(props: Props) {
return (
<LabeledToggle
label="Disable robot caching"
toggledOn={props.cacheDisabled}
onClick={props.toggleCacheDisable}
>
<p>
Disable caching of discovered robots. The app will not remember
mcous marked this conversation as resolved.
Show resolved Hide resolved
previously discovered robots.
</p>
</LabeledToggle>
)
}

function mapStateToProps(state: State): SP {
const config = getConfig(state)

return {
cacheDisabled: config.discovery.disableCache,
}
}

function mapDispatchToProps(dispatch: Dispatch): DP {
return {
toggleCacheDisable: () => dispatch(toggleDiscoveryCache()),
}
}
6 changes: 6 additions & 0 deletions app/src/config/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ export function toggleDevInternalFlag(flag: DevInternalFlag): ThunkAction {
}
}

export function toggleDiscoveryCache(): ThunkAction {
mcous marked this conversation as resolved.
Show resolved Hide resolved
return (dispatch, getState) => {
const cacheDisabled = getConfig(getState()).discovery.disableCache
return dispatch(updateConfig('discovery.disableCache', !cacheDisabled))
}
}
// TODO(mc, 2020-02-05): move to `discovery` module
export function addManualIp(ip: string): ThunkAction {
return (dispatch, getState) => {
Expand Down