-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/app_odd-anonymous-localization-p…
…rovider' into oem-mode-integration
- Loading branch information
Showing
96 changed files
with
664 additions
and
700 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { GET, request } from '../request' | ||
|
||
import type { ResponsePromise } from '../request' | ||
import type { HostConfig } from '../types' | ||
import type { RobotSettingsResponse } from './types' | ||
|
||
export function getRobotSettings( | ||
config: HostConfig | ||
): ResponsePromise<RobotSettingsResponse> { | ||
return request<RobotSettingsResponse>(GET, '/settings', null, config) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import * as React from 'react' | ||
import { I18nextProvider } from 'react-i18next' | ||
import reduce from 'lodash/reduce' | ||
|
||
import { useRobotSettingsQuery } from '@opentrons/react-api-client' | ||
|
||
import { resources } from './assets/localization' | ||
import { i18n, i18nCb, i18nConfig } from './i18n' | ||
|
||
import type { RobotSettingsField } from '@opentrons/api-client' | ||
|
||
export interface OnDeviceLocalizationProviderProps { | ||
children?: React.ReactNode | ||
} | ||
|
||
const BRANDED_RESOURCE = 'branded' | ||
const ANONYMOUS_RESOURCE = 'anonymous' | ||
|
||
// TODO(bh, 2024-03-26): anonymization limited to ODD for now, may change in future OEM phases | ||
export function OnDeviceLocalizationProvider( | ||
props: OnDeviceLocalizationProviderProps | ||
): JSX.Element | null { | ||
const { settings } = useRobotSettingsQuery().data ?? {} | ||
const oemModeSetting = (settings ?? []).find( | ||
(setting: RobotSettingsField) => setting?.id === 'enableOEMMode' | ||
) | ||
const isOEMMode = oemModeSetting?.value ?? false | ||
|
||
// iterate through language resources, nested files, substitute anonymous file for branded file for OEM mode | ||
const anonResources = reduce( | ||
resources, | ||
(acc, resource, language) => { | ||
const anonFiles = reduce( | ||
resource, | ||
(acc, file, fileName) => { | ||
if (fileName === BRANDED_RESOURCE && isOEMMode) { | ||
return acc | ||
} else if (fileName === ANONYMOUS_RESOURCE) { | ||
return isOEMMode ? { ...acc, [BRANDED_RESOURCE]: file } : acc | ||
} else { | ||
return { ...acc, [fileName]: file } | ||
} | ||
}, | ||
{} | ||
) | ||
return { ...acc, [language]: anonFiles } | ||
}, | ||
{} | ||
) | ||
|
||
const anonI18n = i18n.createInstance( | ||
{ | ||
...i18nConfig, | ||
resources: anonResources, | ||
}, | ||
i18nCb | ||
) | ||
|
||
// block render until settings are fetched | ||
return settings != null ? ( | ||
<I18nextProvider i18n={anonI18n}>{props.children}</I18nextProvider> | ||
) : null | ||
} |
Oops, something went wrong.