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

Implemented chat type in search #47690

Merged
merged 15 commits into from
Sep 6, 2024
Merged
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,7 @@ const CONST = {
ATTACHMENT_TYPE: {
REPORT: 'r',
NOTE: 'n',
SEARCH: 's',
},

IMAGE_HIGH_RESOLUTION_THRESHOLD: 7000,
Expand Down Expand Up @@ -5379,6 +5380,13 @@ const CONST = {
APPROVED: 'approved',
PAID: 'paid',
},
CHAT: {
ALL: 'all',
UNREAD: 'unread',
SENT: 'sent',
ATTACHMENTS: 'attachments',
LINKS: 'links',
},
},
CHAT_TYPES: {
LINK: 'link',
Expand Down
9 changes: 7 additions & 2 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,13 @@ const ROUTES = {
SEARCH_ADVANCED_FILTERS_IS: 'search/filters/is',

SEARCH_REPORT: {
route: 'search/view/:reportID',
getRoute: (reportID: string) => `search/view/${reportID}` as const,
route: 'search/view/:reportID/:reportActionID?',
getRoute: (reportID: string, reportActionID?: string) => {
if (reportActionID) {
return `search/view/${reportID}/${reportActionID}` as const;
}
return `search/view/${reportID}` as const;
},
},
TRANSACTION_HOLD_REASON_RHP: 'search/hold',

Expand Down
7 changes: 4 additions & 3 deletions src/components/AttachmentModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -246,13 +246,14 @@ function AttachmentModal({
}

if (typeof sourceURL === 'string') {
fileDownload(sourceURL, file?.name ?? '');
const fileName = type === CONST.ATTACHMENT_TYPE.SEARCH ? FileUtils.getFileName(`${sourceURL}`) : file?.name;
fileDownload(sourceURL, fileName ?? '');
}

// At ios, if the keyboard is open while opening the attachment, then after downloading
// the attachment keyboard will show up. So, to fix it we need to dismiss the keyboard.
Keyboard.dismiss();
}, [isAuthTokenRequiredState, sourceState, file]);
}, [isAuthTokenRequiredState, sourceState, file, type]);

/**
* Execute the onConfirm callback and close the modal.
Expand Down Expand Up @@ -460,7 +461,7 @@ function AttachmentModal({
let headerTitleNew = headerTitle;
let shouldShowDownloadButton = false;
let shouldShowThreeDotsButton = false;
if (!isEmptyObject(report)) {
if (!isEmptyObject(report) || type === CONST.ATTACHMENT_TYPE.SEARCH) {
headerTitleNew = translate(isReceiptAttachment ? 'common.receipt' : 'common.attachment');
shouldShowDownloadButton = allowDownload && isDownloadButtonReadyToBeShown && !shouldShowNotFoundPage && !isReceiptAttachment && !isOffline && !isLocalSource;
shouldShowThreeDotsButton = isReceiptAttachment && isModalOpen && threeDotsMenuItems.length !== 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,8 @@ function ImageRenderer({tnode}: ImageRendererProps) {
return;
}

if (reportID) {
const route = ROUTES.ATTACHMENTS?.getRoute(reportID, type, source, accountID);
Navigation.navigate(route);
}
const route = ROUTES.ATTACHMENTS?.getRoute(reportID ?? '-1', type, source, accountID);
Navigation.navigate(route);
}}
onLongPress={(event) =>
showContextMenuForReport(event, anchor, report?.reportID ?? '-1', action, checkIfContextMenuActive, ReportUtils.isArchivedRoom(report, reportNameValuePairs))
Expand Down
34 changes: 21 additions & 13 deletions src/components/HTMLEngineProvider/HTMLRenderers/VideoRenderer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import type {CustomRendererProps, TBlock} from 'react-native-render-html';
import {AttachmentContext} from '@components/AttachmentContext';
import {ShowContextMenuContext} from '@components/ShowContextMenuContext';
import VideoPlayerPreview from '@components/VideoPlayerPreview';
import useCurrentReportID from '@hooks/useCurrentReportID';
Expand Down Expand Up @@ -28,19 +29,26 @@ function VideoRenderer({tnode, key}: VideoRendererProps) {
return (
<ShowContextMenuContext.Consumer>
{({report}) => (
<VideoPlayerPreview
key={key}
videoUrl={sourceURL}
reportID={currentReportIDValue?.currentReportID ?? '-1'}
fileName={fileName}
thumbnailUrl={thumbnailUrl}
videoDimensions={{width, height}}
videoDuration={duration}
onShowModalPress={() => {
const route = ROUTES.ATTACHMENTS.getRoute(report?.reportID ?? '-1', CONST.ATTACHMENT_TYPE.REPORT, sourceURL);
Navigation.navigate(route);
}}
/>
<AttachmentContext.Consumer>
{({accountID, type}) => (
<VideoPlayerPreview
key={key}
videoUrl={sourceURL}
reportID={currentReportIDValue?.currentReportID ?? '-1'}
fileName={fileName}
thumbnailUrl={thumbnailUrl}
videoDimensions={{width, height}}
videoDuration={duration}
onShowModalPress={() => {
if (!sourceURL || !type) {
return;
}
const route = ROUTES.ATTACHMENTS.getRoute(report?.reportID ?? '-1', type, sourceURL, accountID);
Navigation.navigate(route);
}}
/>
)}
</AttachmentContext.Consumer>
)}
</ShowContextMenuContext.Consumer>
);
Expand Down
2 changes: 2 additions & 0 deletions src/components/Icon/Illustrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import CheckmarkCircle from '@assets/images/simple-illustrations/simple-illustra
import CoffeeMug from '@assets/images/simple-illustrations/simple-illustration__coffeemug.svg';
import Coins from '@assets/images/simple-illustrations/simple-illustration__coins.svg';
import CommentBubbles from '@assets/images/simple-illustrations/simple-illustration__commentbubbles.svg';
import CommentBubblesBlue from '@assets/images/simple-illustrations/simple-illustration__commentbubbles_blue.svg';
import ConciergeBubble from '@assets/images/simple-illustrations/simple-illustration__concierge-bubble.svg';
import ConciergeNew from '@assets/images/simple-illustrations/simple-illustration__concierge.svg';
import CreditCardsNew from '@assets/images/simple-illustrations/simple-illustration__credit-cards.svg';
Expand Down Expand Up @@ -182,6 +183,7 @@ export {
SmartScan,
Hourglass,
CommentBubbles,
CommentBubblesBlue,
TrashCan,
TeleScope,
Profile,
Expand Down
7 changes: 5 additions & 2 deletions src/components/Search/SearchPageHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type HeaderWithBackButtonProps from '@components/HeaderWithBackButton/typ
import Icon from '@components/Icon';
import * as Expensicons from '@components/Icon/Expensicons';
import * as Illustrations from '@components/Icon/Illustrations';
import type {ReportListItemType, TransactionListItemType} from '@components/SelectionList/types';
import type {ReportActionListItemType, ReportListItemType, TransactionListItemType} from '@components/SelectionList/types';
import Text from '@components/Text';
import useActiveWorkspace from '@hooks/useActiveWorkspace';
import useLocalize from '@hooks/useLocalize';
Expand Down Expand Up @@ -95,7 +95,7 @@ type SearchPageHeaderProps = {
onSelectDeleteOption?: (itemsToDelete: string[]) => void;
setOfflineModalOpen?: () => void;
setDownloadErrorModalOpen?: () => void;
data?: TransactionListItemType[] | ReportListItemType[];
data?: TransactionListItemType[] | ReportListItemType[] | ReportActionListItemType[];
};

type SearchHeaderOptionValue = DeepValueOf<typeof CONST.SEARCH.BULK_ACTION_TYPES> | undefined;
Expand All @@ -111,6 +111,8 @@ function getHeaderContent(type: SearchDataTypes): HeaderContent {
return {icon: Illustrations.EnvelopeReceipt, titleText: 'workspace.common.invoices'};
case CONST.SEARCH.DATA_TYPES.TRIP:
return {icon: Illustrations.Luggage, titleText: 'travel.trips'};
case CONST.SEARCH.DATA_TYPES.CHAT:
return {icon: Illustrations.CommentBubblesBlue, titleText: 'common.chats'};
case CONST.SEARCH.DATA_TYPES.EXPENSE:
default:
return {icon: Illustrations.MoneyReceipts, titleText: 'common.expenses'};
Expand All @@ -135,6 +137,7 @@ function SearchPageHeader({queryJSON, hash, onSelectDeleteOption, setOfflineModa
.filter(
(item) =>
!SearchUtils.isTransactionListItemType(item) &&
!SearchUtils.isReportActionListItemType(item) &&
item.reportID &&
item.transactions.every((transaction: {keyForList: string | number}) => selectedTransactions[transaction.keyForList]?.isSelected),
)
Expand Down
45 changes: 42 additions & 3 deletions src/components/Search/SearchStatusBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ import CONST from '@src/CONST';
import type {TranslationPaths} from '@src/languages/types';
import type {SearchDataTypes} from '@src/types/onyx/SearchResults';
import type IconAsset from '@src/types/utils/IconAsset';
import type {ExpenseSearchStatus, InvoiceSearchStatus, SearchQueryString, SearchStatus, TripSearchStatus} from './types';
import type {ChatSearchStatus, ExpenseSearchStatus, InvoiceSearchStatus, SearchQueryString, SearchStatus, TripSearchStatus} from './types';

type SearchStatusBarProps = {
type: SearchDataTypes;
status: SearchStatus;
resetOffset: () => void;
};

const expenseOptions: Array<{key: ExpenseSearchStatus; icon: IconAsset; text: TranslationPaths; query: SearchQueryString}> = [
Expand Down Expand Up @@ -107,19 +108,54 @@ const tripOptions: Array<{key: TripSearchStatus; icon: IconAsset; text: Translat
},
];

const chatOptions: Array<{key: ChatSearchStatus; icon: IconAsset; text: TranslationPaths; query: SearchQueryString}> = [
{
key: CONST.SEARCH.STATUS.CHAT.ALL,
icon: Expensicons.All,
text: 'common.all',
query: SearchUtils.buildCannedSearchQuery(CONST.SEARCH.DATA_TYPES.CHAT, CONST.SEARCH.STATUS.CHAT.ALL),
},
{
key: CONST.SEARCH.STATUS.CHAT.UNREAD,
icon: Expensicons.ChatBubbleUnread,
text: 'common.unread',
query: SearchUtils.buildCannedSearchQuery(CONST.SEARCH.DATA_TYPES.CHAT, CONST.SEARCH.STATUS.CHAT.UNREAD),
},
{
key: CONST.SEARCH.STATUS.CHAT.SENT,
icon: Expensicons.Send,
text: 'common.sent',
query: SearchUtils.buildCannedSearchQuery(CONST.SEARCH.DATA_TYPES.CHAT, CONST.SEARCH.STATUS.CHAT.SENT),
},
{
key: CONST.SEARCH.STATUS.CHAT.ATTACHMENTS,
icon: Expensicons.Document,
text: 'common.attachments',
query: SearchUtils.buildCannedSearchQuery(CONST.SEARCH.DATA_TYPES.CHAT, CONST.SEARCH.STATUS.CHAT.ATTACHMENTS),
},
{
key: CONST.SEARCH.STATUS.CHAT.LINKS,
icon: Expensicons.Paperclip,
text: 'common.links',
query: SearchUtils.buildCannedSearchQuery(CONST.SEARCH.DATA_TYPES.CHAT, CONST.SEARCH.STATUS.CHAT.LINKS),
},
];

function getOptions(type: SearchDataTypes) {
switch (type) {
case CONST.SEARCH.DATA_TYPES.INVOICE:
return invoiceOptions;
case CONST.SEARCH.DATA_TYPES.TRIP:
return tripOptions;
case CONST.SEARCH.DATA_TYPES.CHAT:
return chatOptions;
case CONST.SEARCH.DATA_TYPES.EXPENSE:
default:
return expenseOptions;
}
}

function SearchStatusBar({type, status}: SearchStatusBarProps) {
function SearchStatusBar({type, status, resetOffset}: SearchStatusBarProps) {
const {singleExecution} = useSingleExecution();
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
Expand All @@ -134,7 +170,10 @@ function SearchStatusBar({type, status}: SearchStatusBarProps) {
showsHorizontalScrollIndicator={false}
>
{options.map((item, index) => {
const onPress = singleExecution(() => Navigation.setParams({q: item.query}));
const onPress = singleExecution(() => {
resetOffset();
Navigation.setParams({q: item.query});
});
const isActive = status === item.key;
const isFirstItem = index === 0;
const isLastItem = index === options.length - 1;
Expand Down
Loading
Loading