Skip to content

[HOLD] Revert "Fix anchor renderer for links in report messages & clean up" #10433

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

Closed
wants to merge 2 commits into from
Closed
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

This file was deleted.

This file was deleted.

12 changes: 0 additions & 12 deletions src/components/AnchorForAttachmentsOnly/index.js

This file was deleted.

13 changes: 0 additions & 13 deletions src/components/AnchorForAttachmentsOnly/index.native.js

This file was deleted.

107 changes: 0 additions & 107 deletions src/components/AnchorForCommentsOnly.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import _ from 'underscore';
import React from 'react';
import {Pressable, StyleSheet} from 'react-native';
import lodashGet from 'lodash/get';
import Str from 'expensify-common/lib/str';
import Text from '../../Text';
import {propTypes, defaultProps} from '../anchorForCommentsOnlyPropTypes';
import PressableWithSecondaryInteraction from '../../PressableWithSecondaryInteraction';
import * as ReportActionContextMenu from '../../../pages/home/report/ContextMenu/ReportActionContextMenu';
import * as ContextMenuActions from '../../../pages/home/report/ContextMenu/ContextMenuActions';
import AttachmentView from '../../AttachmentView';
import fileDownload from '../../../libs/fileDownload';
import Tooltip from '../../Tooltip';
import canUseTouchScreen from '../../../libs/canUseTouchscreen';
import styles from '../../../styles/styles';

/*
* This is a default anchor component for regular links.
*/
class BaseAnchorForCommentsOnly extends React.Component {
constructor(props) {
super(props);

this.state = {
isDownloading: false,
};
this.processDownload = this.processDownload.bind(this);
}

/**
* Initiate file downloading and update downloading flags
*
* @param {String} href
* @param {String} fileName
*/
processDownload(href, fileName) {
this.setState({isDownloading: true});
fileDownload(href, fileName).then(() => this.setState({isDownloading: false}));
}

render() {
let linkRef;
const rest = _.omit(this.props, _.keys(propTypes));
const defaultTextStyle = canUseTouchScreen() || this.props.isSmallScreenWidth ? {} : styles.userSelectText;

return (
this.props.isAttachment
? (
<Pressable onPress={() => {
if (this.state.isDownloading) {
return;
}
this.processDownload(this.props.href, this.props.displayName);
}}
>
<AttachmentView
sourceURL={this.props.href}
file={{name: this.props.displayName}}
shouldShowDownloadIcon
shouldShowLoadingSpinnerIcon={this.state.isDownloading}
/>
</Pressable>
)
: (
<PressableWithSecondaryInteraction
inline
onSecondaryInteraction={
(event) => {
ReportActionContextMenu.showContextMenu(
Str.isValidEmail(this.props.displayName) ? ContextMenuActions.CONTEXT_MENU_TYPES.EMAIL : ContextMenuActions.CONTEXT_MENU_TYPES.LINK,
event,
this.props.href,
lodashGet(linkRef, 'current'),
);
}
}
>
<Tooltip text={Str.isValidEmail(this.props.displayName) ? '' : this.props.href}>
<Text
ref={el => linkRef = el}
style={StyleSheet.flatten([this.props.style, defaultTextStyle])}
accessibilityRole="link"
href={this.props.href}
hrefAttrs={{
rel: this.props.rel,
target: this.props.target,
}}
// eslint-disable-next-line react/jsx-props-no-spreading
{...rest}
>
{this.props.children}
</Text>
</Tooltip>
</PressableWithSecondaryInteraction>
)
);
}
}

BaseAnchorForCommentsOnly.propTypes = propTypes;
BaseAnchorForCommentsOnly.defaultProps = defaultProps;
BaseAnchorForCommentsOnly.displayName = 'BaseAnchorForCommentsOnly';

export default BaseAnchorForCommentsOnly;
Loading