Skip to content
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

Show search action buttons #51445

Merged
merged 57 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
d726dcb
add consts
luacmartins Oct 24, 2024
2f4c980
create getAction
luacmartins Oct 24, 2024
584a539
create canReportBeSubmitted
luacmartins Oct 24, 2024
7724e84
fix lint
luacmartins Oct 24, 2024
def5f27
add more logic
luacmartins Oct 24, 2024
2822472
fix some ts
luacmartins Oct 24, 2024
89b9c6b
add types
luacmartins Oct 24, 2024
a3302a8
add more types
luacmartins Oct 24, 2024
d38592d
create searchpolicy type
luacmartins Oct 24, 2024
d759345
update searchpolicy type
luacmartins Oct 24, 2024
ad9081a
update button logic and styles
luacmartins Oct 25, 2024
21cf24d
use getActions in reports
luacmartins Oct 25, 2024
a1bcb5d
update isSettled
luacmartins Oct 25, 2024
bd272b4
add done condition
luacmartins Oct 25, 2024
f87db13
fix logic for all transactions
luacmartins Oct 25, 2024
1de744c
enable approve logic
luacmartins Oct 25, 2024
53421fc
refactor code
luacmartins Oct 25, 2024
c52a9f7
Merge branch 'main' into cmartins-showButtons
luacmartins Oct 28, 2024
82a7f0c
fix some ts errors
luacmartins Oct 28, 2024
4445a3a
fix more ts errors
luacmartins Oct 29, 2024
f9055ad
fix more ts errors
luacmartins Oct 29, 2024
b8568f4
fix lint
luacmartins Oct 29, 2024
fc064fa
Merge branch 'main' into cmartins-showButtons
luacmartins Oct 29, 2024
97ee8fc
finish requirements for pay action
luacmartins Oct 29, 2024
8be0507
finish approve
luacmartins Oct 29, 2024
faa0ba4
pass violations to submit
luacmartins Oct 29, 2024
69e1aa9
add review action
luacmartins Oct 29, 2024
d627ded
Merge branch 'main' into cmartins-showButtons
luacmartins Oct 30, 2024
6f9d848
fix prettier, lint
luacmartins Oct 30, 2024
65b00e3
fix types
luacmartins Oct 30, 2024
d259dc8
fix more types
luacmartins Oct 30, 2024
7919753
fix violations types
luacmartins Oct 30, 2024
88f199e
fix lint
luacmartins Oct 30, 2024
c5b8740
refactor code for performance
luacmartins Oct 30, 2024
17ce03d
rm violations code since its not ready yet
luacmartins Oct 30, 2024
01aa98f
add callbacks
luacmartins Oct 30, 2024
dd8438a
Merge branch 'main' into cmartins-showButtons
luacmartins Oct 30, 2024
0ad354c
create action to handle callbacks
luacmartins Oct 30, 2024
89f4ebe
add callback to transaction list item
luacmartins Oct 30, 2024
4a4481f
rename param
luacmartins Oct 31, 2024
ee12a89
fix payment method
luacmartins Oct 31, 2024
3ee97f8
revert unrelated change
luacmartins Oct 31, 2024
77ae5ef
fix tscheck
luacmartins Oct 31, 2024
a49494b
rm violations code because its not ready
luacmartins Nov 1, 2024
3d82143
Merge branch 'main' into cmartins-showButtons
luacmartins Nov 1, 2024
877a634
Merge branch 'main' into cmartins-showButtons
luacmartins Nov 4, 2024
e5ebd97
fix selected color
luacmartins Nov 4, 2024
b8e08b3
resolve conflicts
luacmartins Nov 5, 2024
ca22276
update code to handle array in pay action
luacmartins Nov 5, 2024
148c72b
update docs
luacmartins Nov 5, 2024
a321c54
resolve conflicts
luacmartins Nov 6, 2024
8d2222f
add loading indicator
luacmartins Nov 8, 2024
c46c571
pass more props
luacmartins Nov 8, 2024
e5b5ed2
update callback to handle single transaction reports
luacmartins Nov 8, 2024
66acf61
add loading for pay action
luacmartins Nov 8, 2024
7c20342
add comment
luacmartins Nov 8, 2024
ea0ae14
delete empty file
luacmartins Nov 8, 2024
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
3 changes: 3 additions & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5853,6 +5853,9 @@ const CONST = {
ACTION_TYPES: {
VIEW: 'view',
REVIEW: 'review',
SUBMIT: 'submit',
APPROVE: 'approve',
PAY: 'pay',
DONE: 'done',
PAID: 'paid',
},
Expand Down
2 changes: 1 addition & 1 deletion src/components/Search/SearchPageHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ function SearchPageHeader({queryJSON, hash}: SearchPageHeaderProps) {
return;
}

const reportIDList = (selectedReports?.filter((report) => !!report) as string[]) ?? [];
const reportIDList = selectedReports?.filter((report) => !!report) ?? [];
SearchActions.exportSearchItemsToCSV(
{query: status, jsonQuery: JSON.stringify(queryJSON), reportIDList, transactionIDList: selectedTransactionsKeys, policyIDs: [activeWorkspaceID ?? '']},
() => {
Expand Down
8 changes: 8 additions & 0 deletions src/components/Search/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ type SelectedTransactionInfo = {
/** Model of selected results */
type SelectedTransactions = Record<string, SelectedTransactionInfo>;

/** Model of payment data used by Search bulk actions */
type PaymentData = {
reportID: string;
amount: number;
paymentType: ValueOf<typeof CONST.IOU.PAYMENT_TYPE>;
};

type SortOrder = ValueOf<typeof CONST.SEARCH.SORT_ORDER>;
type SearchColumnType = ValueOf<typeof CONST.SEARCH.TABLE_COLUMNS>;
type ExpenseSearchStatus = ValueOf<typeof CONST.SEARCH.STATUS.EXPENSE>;
Expand Down Expand Up @@ -117,5 +124,6 @@ export type {
TripSearchStatus,
ChatSearchStatus,
SearchAutocompleteResult,
PaymentData,
SearchAutocompleteQueryRange,
};
40 changes: 26 additions & 14 deletions src/components/SelectionList/Search/ActionCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import type {SearchTransactionAction} from '@src/types/onyx/SearchResults';
const actionTranslationsMap: Record<SearchTransactionAction, TranslationPaths> = {
view: 'common.view',
review: 'common.review',
submit: 'common.submit',
approve: 'iou.approve',
pay: 'iou.pay',
done: 'common.done',
paid: 'iou.settledExpensify',
};
Expand All @@ -26,9 +29,18 @@ type ActionCellProps = {
goToItem: () => void;
isChildListItem?: boolean;
parentAction?: string;
isLoading?: boolean;
};

function ActionCell({action = CONST.SEARCH.ACTION_TYPES.VIEW, isLargeScreenWidth = true, isSelected = false, goToItem, isChildListItem = false, parentAction = ''}: ActionCellProps) {
function ActionCell({
action = CONST.SEARCH.ACTION_TYPES.VIEW,
isLargeScreenWidth = true,
isSelected = false,
goToItem,
isChildListItem = false,
parentAction = '',
isLoading = false,
}: ActionCellProps) {
const {translate} = useLocalize();
const theme = useTheme();
const styles = useThemeStyles();
Expand Down Expand Up @@ -61,9 +73,8 @@ function ActionCell({action = CONST.SEARCH.ACTION_TYPES.VIEW, isLargeScreenWidth
);
}

const buttonInnerStyles = isSelected ? styles.buttonDefaultHovered : {};

if (action === CONST.SEARCH.ACTION_TYPES.VIEW || shouldUseViewAction) {
const buttonInnerStyles = isSelected ? styles.buttonDefaultHovered : {};
return isLargeScreenWidth ? (
<Button
text={translate(actionTranslationsMap[CONST.SEARCH.ACTION_TYPES.VIEW])}
Expand All @@ -77,17 +88,18 @@ function ActionCell({action = CONST.SEARCH.ACTION_TYPES.VIEW, isLargeScreenWidth
) : null;
}

if (action === CONST.SEARCH.ACTION_TYPES.REVIEW) {
return (
<Button
text={text}
onPress={goToItem}
small
style={[styles.w100]}
innerStyles={buttonInnerStyles}
/>
);
}
const buttonInnerStyles = isSelected ? styles.buttonSuccessHovered : {};
return (
<Button
text={text}
onPress={goToItem}
small
style={[styles.w100]}
innerStyles={buttonInnerStyles}
isLoading={isLoading}
success
/>
);
}

ActionCell.displayName = 'ActionCell';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type ExpenseItemHeaderNarrowProps = {
isDisabled?: boolean | null;
isDisabledCheckbox?: boolean;
handleCheckboxPress?: () => void;
isLoading?: boolean;
};

function ExpenseItemHeaderNarrow({
Expand All @@ -44,6 +45,7 @@ function ExpenseItemHeaderNarrow({
isDisabled,
handleCheckboxPress,
text,
isLoading = false,
}: ExpenseItemHeaderNarrowProps) {
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
Expand Down Expand Up @@ -102,6 +104,7 @@ function ExpenseItemHeaderNarrow({
goToItem={onButtonPress}
isLargeScreenWidth={false}
isSelected={isSelected}
isLoading={isLoading}
/>
</View>
</View>
Expand Down
7 changes: 6 additions & 1 deletion src/components/SelectionList/Search/ReportListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import {View} from 'react-native';
import Checkbox from '@components/Checkbox';
import {useSearchContext} from '@components/Search/SearchContext';
import BaseListItem from '@components/SelectionList/BaseListItem';
import type {ListItem, ReportListItemProps, ReportListItemType, TransactionListItemType} from '@components/SelectionList/types';
import Text from '@components/Text';
Expand All @@ -10,6 +11,7 @@ import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import {handleActionButtonPress} from '@libs/actions/Search';
import * as CurrencyUtils from '@libs/CurrencyUtils';
import Navigation from '@libs/Navigation/Navigation';
import variables from '@styles/variables';
Expand Down Expand Up @@ -69,6 +71,7 @@ function ReportListItem<TItem extends ListItem>({
const styles = useThemeStyles();
const {isLargeScreenWidth} = useResponsiveLayout();
const StyleUtils = useStyleUtils();
const {currentSearchHash} = useSearchContext();

const animatedHighlightStyle = useAnimatedHighlightStyle({
borderRadius: variables.componentBorderRadius,
Expand All @@ -93,7 +96,7 @@ function ReportListItem<TItem extends ListItem>({
];

const handleOnButtonPress = () => {
onSelectRow(item);
handleActionButtonPress(currentSearchHash, reportItem, () => onSelectRow(item));
};

const openReportInRHP = (transactionItem: TransactionListItemType) => {
Expand Down Expand Up @@ -165,6 +168,7 @@ function ReportListItem<TItem extends ListItem>({
action={reportItem.action}
onButtonPress={handleOnButtonPress}
containerStyle={[styles.ph3, styles.pt1half, styles.mb1half]}
isLoading={reportItem.isActionLoading}
/>
)}
<View style={[styles.flex1, styles.flexRow, styles.alignItemsCenter, styles.gap3, styles.ph3, styles.pv1half]}>
Expand Down Expand Up @@ -199,6 +203,7 @@ function ReportListItem<TItem extends ListItem>({
action={reportItem.action}
goToItem={handleOnButtonPress}
isSelected={item.isSelected}
isLoading={reportItem.isActionLoading}
/>
</View>
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import React from 'react';
import {useSearchContext} from '@components/Search/SearchContext';
import BaseListItem from '@components/SelectionList/BaseListItem';
import type {ListItem, TransactionListItemProps, TransactionListItemType} from '@components/SelectionList/types';
import useAnimatedHighlightStyle from '@hooks/useAnimatedHighlightStyle';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import {handleActionButtonPress} from '@libs/actions/Search';
import variables from '@styles/variables';
import TransactionListItemRow from './TransactionListItemRow';

Expand All @@ -26,6 +28,7 @@ function TransactionListItem<TItem extends ListItem>({
const theme = useTheme();

const {isLargeScreenWidth} = useResponsiveLayout();
const {currentSearchHash} = useSearchContext();

const listItemPressableStyle = [
styles.selectionListPressableItemWrapper,
Expand Down Expand Up @@ -75,13 +78,14 @@ function TransactionListItem<TItem extends ListItem>({
item={transactionItem}
showTooltip={showTooltip}
onButtonPress={() => {
onSelectRow(item);
handleActionButtonPress(currentSearchHash, transactionItem, () => onSelectRow(item));
}}
onCheckboxPress={() => onCheckboxPress?.(item)}
isDisabled={!!isDisabled}
canSelectMultiple={!!canSelectMultiple}
isButtonSelected={item.isSelected}
shouldShowTransactionCheckbox={false}
isLoading={transactionItem.isActionLoading}
/>
</BaseListItem>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type TransactionListItemRowProps = {
isButtonSelected?: boolean;
parentAction?: string;
shouldShowTransactionCheckbox?: boolean;
isLoading?: boolean;
};

const getTypeIcon = (type?: SearchTransactionType) => {
Expand Down Expand Up @@ -257,6 +258,7 @@ function TransactionListItemRow({
isButtonSelected = false,
parentAction = '',
shouldShowTransactionCheckbox,
isLoading = false,
}: TransactionListItemRowProps) {
const styles = useThemeStyles();
const {isLargeScreenWidth} = useResponsiveLayout();
Expand All @@ -280,6 +282,7 @@ function TransactionListItemRow({
isDisabled={item.isDisabled}
isDisabledCheckbox={item.isDisabledCheckbox}
handleCheckboxPress={onCheckboxPress}
isLoading={isLoading}
/>
)}

Expand Down Expand Up @@ -445,6 +448,7 @@ function TransactionListItemRow({
isChildListItem={isChildListItem}
parentAction={parentAction}
goToItem={onButtonPress}
isLoading={isLoading}
/>
</View>
</View>
Expand Down
Empty file.
5 changes: 2 additions & 3 deletions src/libs/API/parameters/PayMoneyRequestOnSearchParams.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
type PayMoneyRequestOnSearchParams = {
hash: number;
paymentType: string;
/**
* Stringified JSON object with type of following structure:
* Array<{reportID: string, amount: number}>
* Array<{reportID: string, amount: number, paymentType: string}>
*/
reportsAndAmounts: string;
paymentData: string;
};

export default PayMoneyRequestOnSearchParams;
11 changes: 6 additions & 5 deletions src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import type {
Tenant,
} from '@src/types/onyx/Policy';
import type PolicyEmployee from '@src/types/onyx/PolicyEmployee';
import type {SearchPolicy} from '@src/types/onyx/SearchResults';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import {hasSynchronizationErrorMessage} from './actions/connections';
import * as Localize from './Localize';
Expand Down Expand Up @@ -175,7 +176,7 @@ function getPolicyBrickRoadIndicatorStatus(policy: OnyxEntry<Policy>, isConnecti
return undefined;
}

function getPolicyRole(policy: OnyxInputOrEntry<Policy>, currentUserLogin: string | undefined) {
function getPolicyRole(policy: OnyxInputOrEntry<Policy> | SearchPolicy, currentUserLogin: string | undefined) {
return policy?.role ?? policy?.employeeList?.[currentUserLogin ?? '-1']?.role;
}

Expand Down Expand Up @@ -208,7 +209,7 @@ const isUserPolicyAdmin = (policy: OnyxInputOrEntry<Policy>, login?: string) =>
/**
* Checks if the current user is an admin of the policy.
*/
const isPolicyAdmin = (policy: OnyxInputOrEntry<Policy>, currentUserLogin?: string): boolean => getPolicyRole(policy, currentUserLogin) === CONST.POLICY.ROLE.ADMIN;
const isPolicyAdmin = (policy: OnyxInputOrEntry<Policy> | SearchPolicy, currentUserLogin?: string): boolean => getPolicyRole(policy, currentUserLogin) === CONST.POLICY.ROLE.ADMIN;

/**
* Checks if the current user is of the role "user" on the policy.
Expand Down Expand Up @@ -369,7 +370,7 @@ function isPendingDeletePolicy(policy: OnyxEntry<Policy>): boolean {
return policy?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE;
}

function isPaidGroupPolicy(policy: OnyxEntry<Policy>): boolean {
function isPaidGroupPolicy(policy: OnyxEntry<Policy> | SearchPolicy): boolean {
return policy?.type === CONST.POLICY.TYPE.TEAM || policy?.type === CONST.POLICY.TYPE.CORPORATE;
}

Expand All @@ -394,7 +395,7 @@ function isTaxTrackingEnabled(isPolicyExpenseChat: boolean, policy: OnyxEntry<Po
* Checks if policy's scheduled submit / auto reporting frequency is "instant".
* Note: Free policies have "instant" submit always enabled.
*/
function isInstantSubmitEnabled(policy: OnyxInputOrEntry<Policy>): boolean {
function isInstantSubmitEnabled(policy: OnyxInputOrEntry<Policy> | SearchPolicy): boolean {
return policy?.autoReporting === true && policy?.autoReportingFrequency === CONST.POLICY.AUTO_REPORTING_FREQUENCIES.INSTANT;
}

Expand Down Expand Up @@ -424,7 +425,7 @@ function getCorrectedAutoReportingFrequency(policy: OnyxInputOrEntry<Policy>): V
/**
* Checks if policy's approval mode is "optional", a.k.a. "Submit & Close"
*/
function isSubmitAndClose(policy: OnyxInputOrEntry<Policy>): boolean {
function isSubmitAndClose(policy: OnyxInputOrEntry<Policy> | SearchPolicy): boolean {
return policy?.approvalMode === CONST.POLICY.APPROVAL_MODE.OPTIONAL;
}

Expand Down
Loading
Loading