Skip to content
Open
Show file tree
Hide file tree
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
19 changes: 12 additions & 7 deletions src/components/Rule/RuleBooleanBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ import {View} from 'react-native';

import RuleNotFoundPageWrapper from './RuleNotFoundPageWrapper';

/** Sentinel value for the "Don't change" option, kept local so it does not leak into CONST.SEARCH.BOOLEAN (shared with Search filters) */
const KEEP_UNCHANGED = 'dontChange';

type BooleanFilterItem = ListItem & {
value: ValueOf<typeof CONST.SEARCH.BOOLEAN>;
value: ValueOf<typeof CONST.SEARCH.BOOLEAN> | typeof KEEP_UNCHANGED;
};

type RuleBooleanBaseProps = {
Expand Down Expand Up @@ -55,24 +58,26 @@ function RuleBooleanBase({fieldID, titleKey, formID, onSelect, onBack, hash, use

const formValue = (form as Record<string, boolean | string | undefined>)?.[fieldID];

let selectedItem = null;
// When the field is unset the selector defaults to "Don't change" - it is a true radio group that can never be cleared to nothing
let selectedItem: ValueOf<typeof CONST.SEARCH.BOOLEAN> | typeof KEEP_UNCHANGED = KEEP_UNCHANGED;
if (formValue !== undefined && formValue !== '') {
// Handle both string ('true'/'false') and boolean (true/false) values
const isTruthy = useStringValues ? formValue === 'true' : formValue === true;
const booleanValue = isTruthy ? CONST.SEARCH.BOOLEAN.YES : CONST.SEARCH.BOOLEAN.NO;
selectedItem = booleanValues.find((value) => booleanValue === value) ?? null;
selectedItem = isTruthy ? CONST.SEARCH.BOOLEAN.YES : CONST.SEARCH.BOOLEAN.NO;
}

const items = booleanValues.map((value) => ({
const selectableValues: Array<ValueOf<typeof CONST.SEARCH.BOOLEAN> | typeof KEEP_UNCHANGED> = [KEEP_UNCHANGED, ...booleanValues];

const items = selectableValues.map((value) => ({
value,
keyForList: value,
text: translate(`common.${value}`),
isSelected: selectedItem === value,
}));

const onSelectItem = (selectedValue: BooleanFilterItem) => {
// If clicking on already-selected item, unselect it (set to undefined)
if (selectedValue.isSelected) {
// Picking "Don't change" clears the field (the existing "no action" state)
if (selectedValue.value === KEEP_UNCHANGED) {
onSelect(fieldID, null);
return;
}
Expand Down
1 change: 1 addition & 0 deletions src/languages/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const translations: TranslationDeepObject<typeof en> = {
unshare: 'Freigabe aufheben',
yes: 'Ja',
no: 'Nein',
dontChange: 'Nicht ändern',
ok: 'OK',
notNow: 'Nicht jetzt',
noThanks: 'Nein danke',
Expand Down
1 change: 1 addition & 0 deletions src/languages/el.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const translations: TranslationDeepObject<typeof en> = {
unshare: 'Αναίρεση κοινής χρήσης',
yes: 'Ναι',
no: 'Όχι',
dontChange: 'Να μην αλλάξει',
ok: 'OK',
notNow: 'Όχι τώρα',
noThanks: 'Όχι, ευχαριστώ',
Expand Down
1 change: 1 addition & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const translations = {
unshare: 'Unshare',
yes: 'Yes',
no: 'No',
dontChange: 'Don’t change',
// @context Universal confirmation button. Keep the UI-standard term “OK” unless the locale strongly prefers an alternative.
ok: 'OK',
notNow: 'Not now',
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const translations: TranslationDeepObject<typeof en> = {
unshare: 'Dejar de compartir',
yes: 'Sí',
no: 'No',
dontChange: 'No cambiar',
ok: 'OK',
notNow: 'Ahora no',
noThanks: 'No, gracias',
Expand Down
1 change: 1 addition & 0 deletions src/languages/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const translations: TranslationDeepObject<typeof en> = {
unshare: 'Arrêter le partage',
yes: 'Oui',
no: 'Non',
dontChange: 'Ne pas modifier',
ok: 'OK',
notNow: 'Pas maintenant',
noThanks: 'Non merci',
Expand Down
1 change: 1 addition & 0 deletions src/languages/it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const translations: TranslationDeepObject<typeof en> = {
unshare: 'Rimuovi condivisione',
yes: 'Sì',
no: 'No',
dontChange: 'Non modificare',
ok: 'OK',
notNow: 'Non ora',
noThanks: 'No, grazie',
Expand Down
1 change: 1 addition & 0 deletions src/languages/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const translations: TranslationDeepObject<typeof en> = {
unshare: '共有を解除',
yes: 'はい',
no: 'いいえ',
dontChange: '変更しない',
ok: 'OK',
notNow: '今はしない',
noThanks: '結構です',
Expand Down
1 change: 1 addition & 0 deletions src/languages/nl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const translations: TranslationDeepObject<typeof en> = {
unshare: 'Delen stoppen',
yes: 'Ja',
no: 'Nee',
dontChange: 'Niet wijzigen',
ok: 'OK',
notNow: 'Nu niet',
noThanks: 'Nee, dank je',
Expand Down
1 change: 1 addition & 0 deletions src/languages/pl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const translations: TranslationDeepObject<typeof en> = {
unshare: 'Cofnij udostępnianie',
yes: 'Tak',
no: 'Nie',
dontChange: 'Nie zmieniaj',
ok: 'OK',
notNow: 'Nie teraz',
noThanks: 'Nie, dziękuję',
Expand Down
1 change: 1 addition & 0 deletions src/languages/pt-BR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const translations: TranslationDeepObject<typeof en> = {
unshare: 'Deixar de compartilhar',
yes: 'Sim',
no: 'Não',
dontChange: 'Não alterar',
ok: 'OK',
notNow: 'Agora não',
noThanks: 'Não, obrigado',
Expand Down
1 change: 1 addition & 0 deletions src/languages/zh-hans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const translations: TranslationDeepObject<typeof en> = {
unshare: '取消共享',
yes: '是',
no: '否',
dontChange: '不更改',
ok: 'OK',
notNow: '暂不处理',
noThanks: '不用了,谢谢',
Expand Down
4 changes: 2 additions & 2 deletions src/pages/settings/Rules/RulePageBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,13 @@ function RulePageBase({titleKey, testID, hash}: RulePageBaseProps) {
{
key: 'reimbursable',
description: translate('common.reimbursable'),
title: form?.reimbursable ? translate(form.reimbursable === 'true' ? 'common.yes' : 'common.no') : '',
title: form?.reimbursable ? translate(form.reimbursable === 'true' ? 'common.yes' : 'common.no') : translate('common.dontChange'),
onPress: () => navigateTo(EXPENSE_RULE_INPUT_IDS.REIMBURSABLE, hash),
},
{
key: 'billable',
description: translate('common.billable'),
title: form?.billable ? translate(form.billable === 'true' ? 'common.yes' : 'common.no') : '',
title: form?.billable ? translate(form.billable === 'true' ? 'common.yes' : 'common.no') : translate('common.dontChange'),
onPress: () => navigateTo(EXPENSE_RULE_INPUT_IDS.BILLABLE, hash),
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ type SectionType = {

const getBooleanTitle = (value: boolean | undefined, translate: LocalizedTranslate): string => {
if (value === undefined) {
return '';
return translate('common.dontChange');
}
return translate(value ? 'common.yes' : 'common.no');
};
Expand Down
Loading