Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const defaultExpansionState =
props.hideCurrencyExpansionControls ||
props.defaultExpandCurrencies ||
// default to `false`, because useToggleState defaults to `true`
false;
const [areCurrenciesExpanded, toggleCurrencies] = useToggleState(
defaultExpansionState
);
const id = useFieldId(props.id, sequentialId);
const hasErrorInRemainingCurrencies =
props.hasError ||
getHasErrorOnRemainingLanguages(props.errors, props.selectedCurrency);
const hasWarningInRemainingCurrencies =
props.hasWarning ||
getHasWarningOnRemainingLanguages(props.warnings, props.selectedCurrency);
if (hasErrorInRemainingCurrencies || hasWarningInRemainingCurrencies) {
// this update within render replaces the old `getDerivedStateFromProps` functionality
// https://reactjs.org/docs/hooks-faq.html#how-do-i-implement-getderivedstatefromprops
if (!areCurrenciesExpanded) {
toggleCurrencies();
}
}
const currencies = sortCurrencies(
props.selectedCurrency,
Object.keys(props.value)
false;
const [areLanguagesExpanded, toggleLanguages] = useToggleState(
defaultExpansionState
);
const languages = sortLanguages(
props.selectedLanguage,
Object.keys(props.value)
);
const id = useFieldId(props.id, sequentialId);
const hasErrorInRemainingLanguages =
props.hasError ||
getHasErrorOnRemainingLanguages(props.errors, props.selectedLanguage);
if (hasErrorInRemainingLanguages) {
// this update within render replaces the old `getDerivedStateFromProps` functionality
// https://reactjs.org/docs/hooks-faq.html#how-do-i-implement-getderivedstatefromprops
if (hasErrorInRemainingLanguages !== areLanguagesExpanded) {
toggleLanguages();
}
}
return (
{languages.map((language, index) => {
const isFirstLanguage = index === 0;
const isLastLanguage = index === languages.length - 1;
const hasRemainingLanguages = languages.length > 1;
const toggleLanguage = React.useCallback(
language => {
expandedTranslationsDispatch({ type: 'toggle', payload: language });
},
[expandedTranslationsDispatch]
);
const languages = sortLanguages(
props.selectedLanguage,
Object.keys(props.value)
);
const hasErrorInRemainingLanguages =
props.hasError ||
getHasErrorOnRemainingLanguages(props.errors, props.selectedLanguage);
const hasWarningInRemainingLanguages =
props.hasWarning ||
getHasWarningOnRemainingLanguages(props.warnings, props.selectedLanguage);
if (hasErrorInRemainingLanguages || hasWarningInRemainingLanguages) {
if (!areLanguagesOpened) {
// this update within render replaces the old `getDerivedStateFromProps` functionality
// https://reactjs.org/docs/hooks-faq.html#how-do-i-implement-getderivedstatefromprops
toggleLanguages();
}
}
return (
{languages.map((language, index) => {
const toggleLanguage = React.useCallback(
language => {
expandedTranslationsDispatch({ type: 'toggle', payload: language });
},
[expandedTranslationsDispatch]
);
const languages = sortLanguages(
props.selectedLanguage,
Object.keys(props.value)
);
const hasErrorInRemainingLanguages =
props.hasError ||
getHasErrorOnRemainingLanguages(props.errors, props.selectedLanguage);
const hasWarningInRemainingLanguages =
props.hasWarning ||
getHasWarningOnRemainingLanguages(props.warnings, props.selectedLanguage);
if (hasErrorInRemainingLanguages || hasWarningInRemainingLanguages) {
if (!areLanguagesOpened) {
// this update within render replaces the old `getDerivedStateFromProps` functionality
// https://reactjs.org/docs/hooks-faq.html#how-do-i-implement-getderivedstatefromprops
toggleLanguages();
}
}
return (
{languages.map((language, index) => {
const isFirstLanguage = index === 0;
if (!isFirstLanguage && !areLanguagesOpened) return null;
const isLastLanguage = index === languages.length - 1;
const hasRemainingLanguages = languages.length > 1;
const hasErrorOnRemainingLanguages =
props.hasError ||
getHasErrorOnRemainingLanguages(
props.errors,
props.selectedLanguage
);
const hasWarningOnRemainingLanguages =
props.hasWarning ||
getHasWarningOnRemainingLanguages(
props.warnings,
props.selectedLanguage
);
return (
{currencies.map((currency, index) => {
const isFirstCurrency = index === 0;
if (!isFirstCurrency && !areCurrenciesExpanded) return null;
const isLastCurrency = index === currencies.length - 1;
const hasRemainingCurrencies = currencies.length > 1;
const hasErrorOnRemainingCurrencies =
props.hasError ||
getHasErrorOnRemainingLanguages(
props.errors,
props.selectedCurrency
);
const hasWarningOnRemainingCurrencies =
props.hasWarning ||
getHasWarningOnRemainingLanguages(
props.warnings,
props.selectedCurrency
);
return (
{languages.map((language, index) => {
const isFirstLanguage = index === 0;
if (!isFirstLanguage && !areLanguagesOpened) return null;
const isLastLanguage = index === languages.length - 1;
const hasRemainingLanguages = languages.length > 1;
const hasErrorOnRemainingLanguages =
props.hasError ||
getHasErrorOnRemainingLanguages(
props.errors,
props.selectedLanguage
);
const hasWarningOnRemainingLanguages =
props.hasWarning ||
getHasWarningOnRemainingLanguages(
props.warnings,
props.selectedLanguage
);
return (
{languages.map((language, index) => {
const isFirstLanguage = index === 0;
const isLastLanguage = index === languages.length - 1;
const hasRemainingLanguages = languages.length > 1;
const hasErrorOnRemainingLanguages =
props.hasError ||
getHasErrorOnRemainingLanguages(
props.errors,
props.selectedLanguage
);
if (!isFirstLanguage && !areLanguagesExpanded) return null;
return (
<div>
</div>