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

refactor(react-api-client): fix react query key object hashing for useAllCommandsAsPreSerializedList #15188

Merged
merged 1 commit into from
May 15, 2024
Merged
Changes from all commits
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
17 changes: 5 additions & 12 deletions react-api-client/src/runs/useAllCommandsAsPreSerializedList.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import mapValues from 'lodash/mapValues'
import { UseQueryResult, useQuery } from 'react-query'
import { getCommandsAsPreSerializedList } from '@opentrons/api-client'
import { useHost } from '../api'
Expand Down Expand Up @@ -28,18 +29,10 @@ export function useAllCommandsAsPreSerializedList<TError = Error>(
enabled: host !== null && runId != null && options.enabled !== false,
}
const { cursor, pageLength } = nullCheckedParams
// reduce hostKey into a new object to make nullish values play nicely with react-query key hash
const hostKey =
host != null
? Object.entries(host).reduce<Object>((acc, current) => {
const [key, val] = current
if (val != null) {
return { ...acc, [key]: val }
} else {
return { ...acc, [key]: 'no value' }
}
}, {})
: {}

// map undefined values to null to agree with react query caching
// TODO (nd: 05/15/2024) create sanitizer for react query key objects
const hostKey = mapValues(host, v => (v !== undefined ? v : null))

const query = useQuery<CommandsData, TError>(
[
Expand Down
Loading