-
Notifications
You must be signed in to change notification settings - Fork 167
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: Print a warning when both I18nProvider and own i18n string are missing #3172
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -77,9 +77,7 @@ const InternalAutosuggest = React.forwardRef((props: InternalAutosuggestProps, r | |||||||||
); | ||||||||||
|
||||||||||
const i18n = useInternalI18n('autosuggest'); | ||||||||||
const errorIconAriaLabel = i18n('errorIconAriaLabel', restProps.errorIconAriaLabel); | ||||||||||
const selectedAriaLabel = i18n('selectedAriaLabel', restProps.selectedAriaLabel); | ||||||||||
const recoveryText = i18n('recoveryText', restProps.recoveryText); | ||||||||||
|
||||||||||
if (restProps.recoveryText && !onLoadItems) { | ||||||||||
warnOnce('Autosuggest', '`onLoadItems` must be provided for `recoveryText` to be displayed.'); | ||||||||||
|
@@ -188,8 +186,8 @@ const InternalAutosuggest = React.forwardRef((props: InternalAutosuggestProps, r | |||||||||
...props, | ||||||||||
isEmpty, | ||||||||||
isFiltered, | ||||||||||
recoveryText, | ||||||||||
errorIconAriaLabel, | ||||||||||
getRecoveryText: () => i18n('errorIconAriaLabel', restProps.errorIconAriaLabel), | ||||||||||
getErrorIconAriaLabel: () => i18n('recoveryText', restProps.recoveryText), | ||||||||||
Comment on lines
+189
to
+190
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The property names seem to have gotten mixed up here
Suggested change
|
||||||||||
onRecoveryClick: handleRecoveryClick, | ||||||||||
filteringResultsText: filteredText, | ||||||||||
hasRecoveryCallback: !!onLoadItems, | ||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,9 @@ | |
|
||
import React, { useContext } from 'react'; | ||
|
||
import { warnOnce } from '@cloudscape-design/component-toolkit/internal'; | ||
|
||
import { isDevelopment } from '../internal/is-development'; | ||
import { I18nFormatArgTypes } from './messages-types'; | ||
|
||
export type CustomHandler<ReturnValue, FormatFnArgs> = (formatFn: (args: FormatFnArgs) => string) => ReturnValue; | ||
|
@@ -20,7 +23,15 @@ interface InternalI18nContextProps { | |
|
||
export const InternalI18nContext = React.createContext<InternalI18nContextProps>({ | ||
locale: null, | ||
format: <T>(_namespace: string, _component: string, _key: string, provided: T) => provided, | ||
format: <T>(_namespace: string, component: string, key: string, provided: T) => { | ||
if (isDevelopment && !provided) { | ||
warnOnce( | ||
component, | ||
`Localization is not provided for key ${key}. Provide the value as a prop or use I18nProvider` | ||
); | ||
Comment on lines
+28
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the change. Everything else is to fix appeared warnings |
||
} | ||
return provided; | ||
}, | ||
}); | ||
|
||
export function useLocale(): string | null { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ import styles from './styles.css.js'; | |
|
||
export { DropdownStatusProps }; | ||
|
||
export interface DropdownStatusPropsExtended extends DropdownStatusProps { | ||
export interface DropdownStatusPropsExtended extends Omit<DropdownStatusProps, 'recoveryText' | 'errorIconAriaLabel'> { | ||
isEmpty?: boolean; | ||
isNoMatch?: boolean; | ||
isFiltered?: boolean; | ||
|
@@ -30,27 +30,16 @@ export interface DropdownStatusPropsExtended extends DropdownStatusProps { | |
* in case recoveryText was automatically provided by i18n. | ||
*/ | ||
hasRecoveryCallback?: boolean; | ||
|
||
getErrorIconAriaLabel: () => string | undefined; | ||
getRecoveryText: () => string | undefined; | ||
} | ||
|
||
function DropdownStatus({ children }: { children: React.ReactNode }) { | ||
return <div className={styles.root}>{children}</div>; | ||
} | ||
|
||
type UseDropdownStatus = ({ | ||
statusType, | ||
empty, | ||
loadingText, | ||
finishedText, | ||
filteringResultsText, | ||
errorText, | ||
recoveryText, | ||
isEmpty, | ||
isNoMatch, | ||
isFiltered, | ||
noMatch, | ||
hasRecoveryCallback, | ||
onRecoveryClick, | ||
Comment on lines
-40
to
-52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no point to destructure the object in a type declaration |
||
}: DropdownStatusPropsExtended) => DropdownStatusResult; | ||
type UseDropdownStatus = (statusProps: DropdownStatusPropsExtended) => DropdownStatusResult; | ||
|
||
export interface DropdownStatusResult { | ||
isSticky: boolean; | ||
|
@@ -65,29 +54,30 @@ export const useDropdownStatus: UseDropdownStatus = ({ | |
finishedText, | ||
filteringResultsText, | ||
errorText, | ||
recoveryText, | ||
getRecoveryText, | ||
isEmpty, | ||
isNoMatch, | ||
isFiltered, | ||
noMatch, | ||
onRecoveryClick, | ||
hasRecoveryCallback = false, | ||
errorIconAriaLabel, | ||
getErrorIconAriaLabel, | ||
}): DropdownStatusResult => { | ||
const previousStatusType = usePrevious(statusType); | ||
const statusResult: DropdownStatusResult = { isSticky: true, content: null, hasRecoveryButton: false }; | ||
|
||
if (statusType === 'loading') { | ||
statusResult.content = <InternalStatusIndicator type={'loading'}>{loadingText}</InternalStatusIndicator>; | ||
} else if (statusType === 'error') { | ||
const recoveryText = getRecoveryText(); | ||
statusResult.hasRecoveryButton = !!recoveryText && hasRecoveryCallback; | ||
statusResult.content = ( | ||
<span> | ||
<InternalStatusIndicator | ||
type="error" | ||
__display="inline" | ||
__animate={previousStatusType !== 'error'} | ||
iconAriaLabel={errorIconAriaLabel} | ||
iconAriaLabel={getErrorIconAriaLabel()} | ||
> | ||
{errorText} | ||
</InternalStatusIndicator>{' '} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make recovery text and error label lazy-loadable, only when this feature is used