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
5 changes: 0 additions & 5 deletions config/oxlint/oxlint.seatbelt.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,6 @@
"../../src/Expensify.tsx" "react-hooks/set-state-in-effect" 1
"../../src/GlobalModals.tsx" "no-restricted-syntax" 2
"../../src/hooks/useAdvancedSearchFilters.ts" "@typescript-eslint/no-unsafe-type-assertion" 1
"../../src/hooks/useAnimatedHighlightStyle/index.ts" "react-hooks/set-state-in-effect" 2
"../../src/hooks/useAssignCard.ts" "@typescript-eslint/no-unsafe-type-assertion" 1
"../../src/hooks/useAutocompleteSuggestions.ts" "@typescript-eslint/no-unsafe-type-assertion" 1
"../../src/hooks/useAutoCreateTrackWorkspace.ts" "no-restricted-imports" 1
Expand Down Expand Up @@ -529,7 +528,6 @@
"../../src/hooks/useLoadDepositAccountSetup.ts" "rulesdir/no-onyx-loading-status" 1
"../../src/hooks/useMarkdownStyle.ts" "rulesdir/no-raw-typography" 3
"../../src/hooks/useMergeResultConfirmationConfig.tsx" "rulesdir/no-onyx-loading-status" 1
"../../src/hooks/useNewTransactions.ts" "react-hooks/refs" 2
"../../src/hooks/useOnboardingFlow.ts" "rulesdir/no-onyx-loading-status" 3
"../../src/hooks/useOnyx.ts" "@typescript-eslint/no-unsafe-type-assertion" 9
"../../src/hooks/useOptimisticDraftTransactions.ts" "@typescript-eslint/no-unsafe-type-assertion" 1
Expand Down Expand Up @@ -1839,8 +1837,6 @@
"../../src/pages/workspace/rooms/WorkspaceRoomsPage.tsx" "no-restricted-imports" 1
"../../src/pages/workspace/rules/AgentRules/AddAgentRulePage.tsx" "react/no-unstable-nested-components" 1
"../../src/pages/workspace/rules/FlagForReviewRules/FlagForReviewRuleAmountPageBase.tsx" "@typescript-eslint/no-unnecessary-type-assertion" 1
"../../src/pages/workspace/rules/IndividualExpenseRulesSectionRevamp.tsx" "@typescript-eslint/no-deprecated/MenuItem" 1
"../../src/pages/workspace/rules/MerchantRules/ExpenseDefaultRulePageBase.tsx" "@typescript-eslint/no-deprecated/MenuItemWithTopDescription" 1
"../../src/pages/workspace/tags/DynamicEditTagPage.tsx" "no-restricted-imports" 1
"../../src/pages/workspace/tags/DynamicTagApproverPage.tsx" "no-restricted-imports" 1
"../../src/pages/workspace/tags/DynamicTagGLCodePage.tsx" "no-restricted-imports" 1
Expand Down Expand Up @@ -1902,7 +1898,6 @@
"../../src/pages/workspace/WorkspaceOverviewClientIDPage.tsx" "no-restricted-imports" 1
"../../src/pages/workspace/WorkspaceOverviewCurrencyPage.tsx" "no-restricted-imports" 1
"../../src/pages/workspace/WorkspaceOverviewDescriptionPage.tsx" "no-restricted-imports" 1
"../../src/pages/workspace/WorkspaceOverviewPage.tsx" "@typescript-eslint/no-deprecated/MenuItemWithTopDescription" 1
"../../src/pages/workspace/WorkspaceOverviewPage.tsx" "@typescript-eslint/no-unnecessary-type-assertion" 1
"../../src/pages/workspace/WorkspaceOverviewPage.tsx" "@typescript-eslint/no-unsafe-type-assertion" 2
"../../src/pages/workspace/WorkspaceOverviewSharePage.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1
Expand Down
10 changes: 7 additions & 3 deletions src/components/MenuItem/layout/MenuItemRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,23 @@ import {useMenuItemConfig} from '@components/MenuItem/MenuItemContext';
import useThemeStyles from '@hooks/useThemeStyles';

import type {PropsWithChildren} from 'react';
import type {StyleProp, ViewStyle} from 'react-native';

import React from 'react';
import {View} from 'react-native';

type MenuItemRowProps = PropsWithChildren;
type MenuItemRowProps = PropsWithChildren<{
/** Overrides the row layout when a caller needs different spacing between its cells */
style?: StyleProp<ViewStyle>;
}>;

/** The main horizontal line of a menu item */
function MenuItemRow({children}: MenuItemRowProps) {
function MenuItemRow({children, style}: MenuItemRowProps) {
const styles = useThemeStyles();
const {isDisabled} = useMenuItemConfig();
const isCompactPopover = useIsCompactPopover();

return <View style={[styles.menuItemRow, isDisabled && styles.cursorDisabled, isCompactPopover && styles.alignItemsCenter]}>{children}</View>;
return <View style={[styles.menuItemRow, style, isDisabled && styles.cursorDisabled, isCompactPopover && styles.alignItemsCenter]}>{children}</View>;
}

export default MenuItemRow;
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,16 @@ import React from 'react';
import type {BaseMenuItemTextProps, MenuItemPrimaryTextProps} from './types';

/** Base of the full-contrast leaves */
function BaseMenuItemPrimaryText({children, accessibilityLabel, numberOfLines = 1, isSelectable = false, slot, style, forwardedFSClass}: MenuItemPrimaryTextProps & BaseMenuItemTextProps) {
function BaseMenuItemPrimaryText({
children,
accessibilityLabel,
accessibilityRole,
numberOfLines = 1,
isSelectable = false,
slot,
style,
forwardedFSClass,
}: MenuItemPrimaryTextProps & BaseMenuItemTextProps) {
const styles = useThemeStyles();
const {isDisabled, isInteractive} = useMenuItemConfig();
const shouldHideTextFromSelection = isInteractive && isDisabled;
Expand Down Expand Up @@ -50,6 +59,7 @@ function BaseMenuItemPrimaryText({children, accessibilityLabel, numberOfLines =
<Text
style={textStyle}
numberOfLines={numberOfLines}
accessibilityRole={accessibilityRole}
dataSet={selectionDataSet}
fsClass={forwardedFSClass}
>
Expand Down
5 changes: 4 additions & 1 deletion src/components/MenuItem/leaves/content/base/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {MenuItemLabelSlot} from '@components/MenuItem/MenuItemAccessibility
import type {ForwardedFSClassProps} from '@libs/Fullstory/types';

import type {ReactElement} from 'react';
import type {StyleProp, TextStyle} from 'react-native';
import type {AccessibilityRole, StyleProp, TextStyle} from 'react-native';

/** Props of the full-contrast leaves */
type MenuItemPrimaryTextProps = (
Expand All @@ -27,6 +27,9 @@ type MenuItemPrimaryTextProps = (

/** Whether this text can start native browser text selection inside an interactive row */
isSelectable?: boolean;

/** Semantic role of the value text, e.g. a workspace name that is also a heading */
accessibilityRole?: AccessibilityRole;
};

/** Props of the muted leaves */
Expand Down
35 changes: 22 additions & 13 deletions src/pages/workspace/WorkspaceOverviewPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {useLockedAccountActions, useLockedAccountState} from '@components/Locked
import MenuItem from '@components/MenuItem';
import MenuItemField from '@components/MenuItem/presets/MenuItemField';
import MenuItemSectionRoot from '@components/MenuItem/presets/MenuItemSectionRoot';
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
import {ModalActions} from '@components/Modal/Global/ModalContext';
import OfflineWithFeedback from '@components/OfflineWithFeedback';
import {usePersonalDetails} from '@components/OnyxListItemProvider';
Expand Down Expand Up @@ -642,19 +641,29 @@ function WorkspaceOverviewPage({policyDraft, policy: policyProp, route}: Workspa
errorRowStyles={styles.mt3}
/>
<OfflineWithFeedback pendingAction={policy?.pendingFields?.name}>
<MenuItemWithTopDescription
title={policyName}
titleStyle={styles.workspaceTitleStyle}
description={translate('workspace.common.workspaceName')}
<MenuItem.Root
sentryLabel={CONST.SENTRY_LABEL.WORKSPACE.OVERVIEW.NAME}
shouldShowRightIcon={!readOnly}
interactive={!readOnly}
wrapperStyle={[styles.sectionMenuItemTopDescription, shouldUseNarrowLayout ? styles.mt3 : {}]}
onPress={onPressName}
shouldBreakWord
numberOfLinesTitle={0}
titleAccessibilityRole={CONST.ROLE.HEADER}
/>
style={[styles.sectionMenuItemTopDescription, shouldUseNarrowLayout && styles.mt3]}
onPress={readOnly ? undefined : callIfAuthenticated(onPressName, session)}
>
<MenuItem.Row style={styles.gap0}>
<MenuItem.Content>
<MenuItem.FieldName>{translate('workspace.common.workspaceName')}</MenuItem.FieldName>
<MenuItem.FieldValue
style={[styles.workspaceTitleStyle, styles.breakWord]}
numberOfLines={0}
accessibilityRole={CONST.ROLE.HEADER}
>
{policyName}
</MenuItem.FieldValue>
</MenuItem.Content>
{!readOnly && (
<MenuItem.Trailing>
<MenuItem.Chevron />
</MenuItem.Trailing>
)}
</MenuItem.Row>
</MenuItem.Root>
</OfflineWithFeedback>
{(!StringUtils.isEmptyString(policy?.description ?? '') || !readOnly || (prevIsPendingDelete && !isPendingDelete)) && (
<OfflineWithFeedback
Expand Down
65 changes: 42 additions & 23 deletions src/pages/workspace/rules/IndividualExpenseRulesSectionRevamp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {getTagListLabel, getTagLists, hasPerTagListRequired, isAttendeeTrackingE

import ToggleSettingOptionRow from '@pages/workspace/workflows/ToggleSettingsOptionRow';

import variables from '@styles/variables';
import {callIfAuthenticated} from '@userActions/Session';

import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand All @@ -33,6 +33,7 @@ import type {PendingAction} from '@src/types/onyx/OnyxCommon';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import type IconAsset from '@src/types/utils/IconAsset';

import {authTokenTypeSelector} from '@selectors/Session';
import React, {useEffect} from 'react';
import {View} from 'react-native';

Expand Down Expand Up @@ -64,11 +65,47 @@ type BasicRuleMenuItem = {

const COLLECT_ALLOWED_RULE_KEYS = new Set<string>([RULE_MENU_ITEM_KEYS.REQUIRE_FIELDS, RULE_MENU_ITEM_KEYS.BILLABLE_EXPENSES]);

type IndividualExpenseRuleRowProps = {
item: BasicRuleMenuItem;
onPress?: () => void;
};

function IndividualExpenseRuleRow({item, onPress}: IndividualExpenseRuleRowProps) {
const styles = useThemeStyles();
return (
<OfflineWithFeedback pendingAction={item.pendingAction}>
<MenuItem.Root
onPress={onPress}
style={styles.sectionMenuItemTopDescription}
sentryLabel={CONST.SENTRY_LABEL.WORKSPACE.RULES.INDIVIDUAL_EXPENSES_MENU_ITEM}
>
<MenuItem.Row style={styles.gap0}>
<MenuItem.Leading>
<View style={styles.mr5}>
<MenuItem.IconNarrow src={item.icon} />
</View>
</MenuItem.Leading>
<MenuItem.Content>
<MenuItem.Title style={[styles.fontWeightNormal, !item.description && styles.colorMuted]}>{item.title}</MenuItem.Title>
{!!item.description && <MenuItem.Description numberOfLines={1}>{item.description}</MenuItem.Description>}
</MenuItem.Content>
{!!onPress && (
<MenuItem.Trailing>
<MenuItem.Chevron />
</MenuItem.Trailing>
)}
</MenuItem.Row>
</MenuItem.Root>
</OfflineWithFeedback>
);
}

function IndividualExpenseRulesSectionRevamp({policyID, canWriteRules}: IndividualExpenseRulesSectionRevampProps) {
const {convertToDisplayString} = useCurrencyListActions();
const {translate} = useLocalize();
const styles = useThemeStyles();
const policy = usePolicy(policyID);
const [session] = useOnyx(ONYXKEYS.SESSION, {selector: authTokenTypeSelector});
// Every toggle here owes a locked-out member the read-only modal, the way the pre-revamp section gave all four of
// them. Splitting this section out dropped it, so a member saw a lock with nothing explaining it. Only the modal is
// taken from the hook: its `canWrite` is the `canWriteRules` prop already.
Expand Down Expand Up @@ -241,29 +278,11 @@ function IndividualExpenseRulesSectionRevamp({policyID, canWriteRules}: Individu

const renderMenuItems = (items: BasicRuleMenuItem[]) =>
items.map((item) => (
<OfflineWithFeedback
pendingAction={item.pendingAction}
<IndividualExpenseRuleRow
key={item.key}
>
<MenuItem
title={item.title}
description={item.description}
icon={item.icon}
iconWidth={variables.iconSizeNormal}
iconHeight={variables.iconSizeNormal}
shouldIconUseAutoWidthStyle
shouldShowBasicTitle
innerContainerStyle={styles.gap5}
titleStyle={[styles.ml0, !item.description && styles.colorMuted]}
descriptionTextStyle={[styles.ml0, styles.breakWord]}
shouldShowRightIcon={canWriteRules}
onPress={() => handleMenuItemPress(item)}
interactive={canWriteRules}
wrapperStyle={[styles.sectionMenuItemTopDescription]}
sentryLabel={CONST.SENTRY_LABEL.WORKSPACE.RULES.INDIVIDUAL_EXPENSES_MENU_ITEM}
numberOfLinesDescription={1}
/>
</OfflineWithFeedback>
item={item}
onPress={canWriteRules ? callIfAuthenticated(() => handleMenuItemPress(item), session) : undefined}
Comment on lines 279 to +284

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Compose fixed rule rows without a configuration-driven renderer

The newly extracted IndividualExpenseRuleRow still interprets the fixed policyControlItems and productDefaultItems configuration arrays, so adding or changing a rule continues to require updating a configuration schema and its generic renderer rather than composing a dedicated row. AGENTS.md requires the app coding standards; CLEAN-REACT-PATTERNS-1 explicitly covers refactorings that create configuration-driven components and states that compound components inside a static-array mapping do not resolve the violation. Declare these finite rule rows as JSX or dedicated components instead. The new ExpenseDefaultRuleField extraction has the same issue for the statically defined fields; the runtime-generated tag rows can remain mapped.

AGENTS.md reference: AGENTS.md:L7-L9

Useful? React with 👍 / 👎.

/>
));

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
import Header from '@components/Header';
import HeaderWithBackButtonAndTitle from '@components/Header/composed/HeaderWithBackButtonAndTitle';
import type {LocalizedTranslate} from '@components/LocaleContextProvider';
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
import MenuItem from '@components/MenuItem';
import {ModalActions} from '@components/Modal/Global/ModalContext';
import ScreenWrapper from '@components/ScreenWrapper';
import ScrollView from '@components/ScrollView';
Expand Down Expand Up @@ -59,7 +59,7 @@ import DescribeRuleButton from '@pages/workspace/rules/DescribeRuleButton';
import DescribeRuleModal from '@pages/workspace/rules/DescribeRuleModal';
import useRuleDeleteHeaderProps from '@pages/workspace/rules/useRuleDeleteHeaderProps';

import variables from '@styles/variables';
import {callIfAuthenticated} from '@userActions/Session';

import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand All @@ -75,6 +75,7 @@ import type IconAsset from '@src/types/utils/IconAsset';
import type {ValueOf} from 'type-fest';

import {useFocusEffect} from '@react-navigation/native';
import {authTokenTypeSelector} from '@selectors/Session';
import React, {useCallback, useEffect, useRef, useState} from 'react';
import {View} from 'react-native';

Expand Down Expand Up @@ -110,6 +111,67 @@ type SectionType = {
items: Array<SectionItemType | undefined>;
};

type ExpenseDefaultRuleFieldProps = {
item: SectionItemType;
canWriteRules: boolean;
shouldShowError: boolean;
};

function ExpenseDefaultRuleField({item, canWriteRules, shouldShowError}: ExpenseDefaultRuleFieldProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const [session] = useOnyx(ONYXKEYS.SESSION, {selector: authTokenTypeSelector});
const canEditItem = canWriteRules && !item.isLocked;
const errorText = canEditItem && shouldShowError && item.required && !item.title ? translate('common.error.fieldRequired') : '';
return (
<MenuItem.Root
onPress={canEditItem ? callIfAuthenticated(item.onPress, session) : undefined}
sentryLabel={CONST.SENTRY_LABEL.WORKSPACE.RULES.MERCHANT_RULE_SECTION_ITEM}
>
<MenuItem.Row style={styles.gap0}>
{!!item.icon && (
<MenuItem.Leading>
<View style={styles.mr3}>
<MenuItem.IconNarrow src={item.icon} />
</View>
</MenuItem.Leading>
)}
<MenuItem.Content>
{item.title ? (
<>
<MenuItem.FieldName>{item.description}</MenuItem.FieldName>
{item.shouldRenderAsHTML ? (
<MenuItem.FieldValueHTML>{item.title}</MenuItem.FieldValueHTML>
) : (
<MenuItem.FieldValue
numberOfLines={2}
style={styles.flex1}
>
{item.title}
</MenuItem.FieldValue>
)}
</>
) : (
<MenuItem.FieldNamePlaceholder>{item.description}</MenuItem.FieldNamePlaceholder>
)}
</MenuItem.Content>
{canEditItem && (
<MenuItem.Trailing>
{!!item.required && !item.title && !errorText && <MenuItem.RightLabel>{translate('common.required')}</MenuItem.RightLabel>}
<MenuItem.Chevron />
</MenuItem.Trailing>
)}
</MenuItem.Row>
{!!errorText && (
<MenuItem.HelpText
isError
message={errorText}
/>
)}
</MenuItem.Root>
);
}

const getBooleanTitle = (value: boolean | undefined, translate: LocalizedTranslate): string => {
if (value === undefined) {
return translate('common.dontChange');
Expand Down Expand Up @@ -653,28 +715,12 @@ function ExpenseDefaultRulePageBase({
) : null;

const renderSectionItem = (item: SectionItemType) => {
const canEditItem = canWriteRules && !item.isLocked;
return (
<MenuItemWithTopDescription
<ExpenseDefaultRuleField
key={item.key}
description={item.description}
errorText={canEditItem && shouldShowError && item.required && !item.title ? translate('common.error.fieldRequired') : ''}
onPress={canEditItem ? item.onPress : undefined}
rightLabel={canEditItem && item.required ? translate('common.required') : undefined}
shouldShowRightIcon={canEditItem}
interactive={canEditItem}
title={item.title}
numberOfLinesTitle={2}
titleStyle={styles.flex1}
shouldRenderAsHTML={item.shouldRenderAsHTML}
shouldApplyIconPaddingToHTMLTitle={!!item.icon && !!item.shouldRenderAsHTML}
icon={item.icon}
{...(item.icon && {
iconWidth: variables.iconSizeNormal,
iconHeight: variables.iconSizeNormal,
shouldIconUseAutoWidthStyle: true,
})}
sentryLabel={CONST.SENTRY_LABEL.WORKSPACE.RULES.MERCHANT_RULE_SECTION_ITEM}
item={item}
canWriteRules={canWriteRules}
shouldShowError={shouldShowError}
/>
);
};
Expand Down
4 changes: 4 additions & 0 deletions src/styles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5925,6 +5925,10 @@ const staticStyles = (theme: ThemeColors) =>
width: variables.iconSizeNormal,
},

gap0: {
gap: 0,
},

menuItemRow: {
...flex.flexRow,
...pointerEventsAuto,
Expand Down
Loading
Loading