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

fix new tab opens when downloading offline #28114

Merged
merged 15 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from 12 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
4 changes: 3 additions & 1 deletion src/components/AttachmentModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import useWindowDimensions from '../hooks/useWindowDimensions';
import Navigation from '../libs/Navigation/Navigation';
import ROUTES from '../ROUTES';
import useNativeDriver from '../libs/useNativeDriver';
import useNetwork from '../hooks/useNetwork';

/**
* Modal render prop component that exposes modal launching triggers that can be used
Expand Down Expand Up @@ -121,6 +122,7 @@ function AttachmentModal(props) {
: undefined,
);
const {translate} = useLocalize();
const {isOffline} = useNetwork();

const onCarouselAttachmentChange = props.onCarouselAttachmentChange;

Expand Down Expand Up @@ -350,7 +352,7 @@ function AttachmentModal(props) {
<HeaderWithBackButton
title={props.headerTitle || translate(isAttachmentReceipt ? 'common.receipt' : 'common.attachment')}
shouldShowBorderBottom
shouldShowDownloadButton={props.allowDownload && shouldShowDownloadButton && !isAttachmentReceipt}
shouldShowDownloadButton={props.allowDownload && shouldShowDownloadButton && !isAttachmentReceipt && !isOffline}
onDownloadButtonPress={() => downloadAttachment(source)}
shouldShowCloseButton={!props.isSmallScreenWidth}
shouldShowBackButton={props.isSmallScreenWidth}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import ONYXKEYS from '../../../../ONYXKEYS';
import CONST from '../../../../CONST';
import useArrowKeyFocusManager from '../../../../hooks/useArrowKeyFocusManager';
import useKeyboardShortcut from '../../../../hooks/useKeyboardShortcut';
import useNetwork from '../../../../hooks/useNetwork';

const propTypes = {
/** String representing the context menu type [LINK, REPORT_ACTION] which controls context menu choices */
Expand Down Expand Up @@ -51,6 +52,7 @@ function BaseReportActionContextMenu(props) {
const menuItemRefs = useRef({});
const [shouldKeepOpen, setShouldKeepOpen] = useState(false);
const wrapperStyle = getReportActionContextMenuStyles(props.isMini, props.isSmallScreenWidth);
const {isOffline} = useNetwork();

const reportAction = useMemo(() => {
if (_.isEmpty(props.reportActions) || props.reportActionID === '0') {
Expand All @@ -60,7 +62,7 @@ function BaseReportActionContextMenu(props) {
}, [props.reportActions, props.reportActionID]);

const shouldShowFilter = (contextAction) =>
contextAction.shouldShow(props.type, reportAction, props.isArchivedRoom, props.betas, props.anchor, props.isChronosReport, props.reportID, props.isPinnedChat, props.isUnreadChat);
contextAction.shouldShow(props.type, reportAction, props.isArchivedRoom, props.betas, props.anchor, props.isChronosReport, props.reportID, props.isPinnedChat, props.isUnreadChat, isOffline);

const shouldEnableArrowNavigation = !props.isMini && (props.isVisible || shouldKeepOpen);
const filteredContextMenuActions = _.filter(ContextMenuActions, shouldShowFilter);
Expand Down
10 changes: 8 additions & 2 deletions src/pages/home/report/ContextMenu/ContextMenuActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,16 @@ export default [
icon: Expensicons.Download,
successTextTranslateKey: 'common.download',
successIcon: Expensicons.Download,
shouldShow: (type, reportAction) => {
shouldShow: (type, reportAction, isOffline) => {
const isAttachment = ReportActionsUtils.isReportActionAttachment(reportAction);
const messageHtml = lodashGet(reportAction, ['message', 0, 'html']);
return isAttachment && messageHtml !== CONST.ATTACHMENT_UPLOADING_MESSAGE_HTML && reportAction.reportActionID && !ReportActionsUtils.isMessageDeleted(reportAction);
return (
isAttachment &&
messageHtml !== CONST.ATTACHMENT_UPLOADING_MESSAGE_HTML &&
reportAction.reportActionID &&
!ReportActionsUtils.isMessageDeleted(reportAction) &&
!isOffline
);
},
onPress: (closePopover, {reportAction}) => {
const message = _.last(lodashGet(reportAction, 'message', [{}]));
Expand Down