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

[TS migration] Migrate 'ReportReactionList' component to TypeScript #34549

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
ec74f83
chore: migrates reactionPropTypes, BaseReactionList and HeaderReactio…
vadymbokatov Jan 15, 2024
0972c81
Merge branch 'Expensify:main' into 31976-report-reaction-list-migration
vadymbokatov Jan 15, 2024
baaa5a5
chore: migrates BasePopoverReactionList and ReactionList to TS
vadymbokatov Jan 16, 2024
28dfadc
Update src/pages/home/report/ReactionList/HeaderReactionList.tsx
vadymbokatov Jan 16, 2024
4bee7c6
Merge branch 'Expensify:main' into 31976-report-reaction-list-migration
vadymbokatov Jan 16, 2024
952c523
chore: renames the types file and fixes its linting errors
vadymbokatov Jan 16, 2024
efe9d72
chore: removes any typed and fixes linting errors on the index file
vadymbokatov Jan 16, 2024
a303a5e
fix: some linting errors and any types
vadymbokatov Jan 16, 2024
006f1f7
Merge branch 'Expensify:main' into 31976-report-reaction-list-migration
vadymbokatov Jan 18, 2024
846f5c8
Merge branch 'Expensify:main' into 31976-report-reaction-list-migration
vadymbokatov Jan 22, 2024
0129e58
chore: converts BasePopoverReactionList to functional component
vadymbokatov Jan 23, 2024
29f41f2
Merge branch 'Expensify:main' into 31976-report-reaction-list-migration
vadymbokatov Jan 23, 2024
85dcf30
Merge branch 'Expensify:main' into 31976-report-reaction-list-migration
vadymbokatov Jan 24, 2024
1954ddc
chore: fixes the linting error regarding the named export
vadymbokatov Jan 24, 2024
ffe26d6
Update src/pages/home/report/ReactionList/PopoverReactionList/index.tsx
vadymbokatov Jan 24, 2024
a1a4f17
Update src/pages/home/report/ReactionList/BaseReactionList.tsx
vadymbokatov Jan 24, 2024
1059ccf
Update src/pages/home/report/ReactionList/BaseReactionList.tsx
vadymbokatov Jan 24, 2024
8765899
Update src/pages/home/report/ReactionList/PopoverReactionList/BasePop…
vadymbokatov Jan 24, 2024
37b6250
Merge branch 'Expensify:main' into 31976-report-reaction-list-migration
vadymbokatov Jan 24, 2024
ffca03e
fix: ref object not getting passed as the second arg
vadymbokatov Jan 24, 2024
32b3695
fix: types naming convention
vadymbokatov Jan 24, 2024
cebd4dc
chore: removes unneeded JSDocs
vadymbokatov Jan 24, 2024
3f82336
chore: makes isVisible prop optional
vadymbokatov Jan 24, 2024
ac5f088
fix: menu ref not getting forwarded and menu not showing up
vadymbokatov Jan 24, 2024
f2e0f53
Merge branch 'Expensify:main' into 31976-report-reaction-list-migration
vadymbokatov Jan 26, 2024
5af50d4
chore: makes hasUserReacted optional with default value
vadymbokatov Jan 26, 2024
ce370cd
chore: removes unneeded JSDocs returns and comments
vadymbokatov Jan 26, 2024
3fa2b09
fix: reuses the AnchorPosition type
vadymbokatov Jan 26, 2024
bceaca2
Merge branch 'Expensify:main' into 31976-report-reaction-list-migration
vadymbokatov Jan 31, 2024
19401b7
Merge branch 'Expensify:main' into 31976-report-reaction-list-migration
vadymbokatov Feb 1, 2024
288a67c
Merge branch 'Expensify:main' into 31976-report-reaction-list-migration
vadymbokatov Feb 2, 2024
ba47730
Merge branch 'Expensify:main' into 31976-report-reaction-list-migration
vadymbokatov Feb 5, 2024
b1b7451
Update src/hooks/useBasePopoverReactionList/index.ts
vadymbokatov Feb 8, 2024
ecccc96
Merge branch 'Expensify:main' into 31976-report-reaction-list-migration
vadymbokatov Feb 8, 2024
e9761c3
fix: adds the missing dependencies in the useEffect
vadymbokatov Feb 8, 2024
a2d1c03
Merge branch 'Expensify:main' into 31976-report-reaction-list-migration
vadymbokatov Feb 13, 2024
1925a11
fix: popover position
vadymbokatov Feb 13, 2024
cd2a45c
Merge branch 'Expensify:main' into 31976-report-reaction-list-migration
vadymbokatov Feb 15, 2024
b083179
chore: adds white space for better readability
vadymbokatov Feb 15, 2024
2bbe9cb
Merge branch 'Expensify:main' into 31976-report-reaction-list-migration
vadymbokatov Feb 19, 2024
2916ba2
Update src/pages/home/report/ReactionList/types.ts
vadymbokatov Feb 19, 2024
5dbe827
chore: removes unnecessary comments
vadymbokatov Feb 19, 2024
e5ded33
chore: removes unnecessary variable
vadymbokatov Feb 19, 2024
e4a843a
chore: removes unnecessary comments
vadymbokatov Feb 20, 2024
9dfd657
Merge branch 'Expensify:main' into 31976-report-reaction-list-migration
vadymbokatov Feb 20, 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
Original file line number Diff line number Diff line change
@@ -1,45 +1,43 @@
/* eslint-disable rulesdir/onyx-props-must-have-default */
import Str from 'expensify-common/lib/str';
import PropTypes from 'prop-types';
import React from 'react';
import {FlatList} from 'react-native';
import {FlatList, type FlatListProps} from 'react-native';

Check failure on line 4 in src/pages/home/report/ReactionList/BaseReactionList.tsx

View workflow job for this annotation

GitHub Actions / lint

Prefer using a top-level type-only import instead of inline type specifiers
vadymbokatov marked this conversation as resolved.
Show resolved Hide resolved
import OptionRow from '@components/OptionRow';
import participantPropTypes from '@components/participantPropTypes';
import withWindowDimensions from '@components/withWindowDimensions';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import Navigation from '@libs/Navigation/Navigation';
import * as UserUtils from '@libs/UserUtils';
import variables from '@styles/variables';
import CONST from '@src/CONST';
import ROUTES from '@src/ROUTES';
import type {PersonalDetails} from '@src/types/onyx';
import HeaderReactionList from './HeaderReactionList';
import reactionPropTypes from './reactionPropTypes';
import type {ReactionListProps} from './reactionPropTypes';

const propTypes = {
type BaseReactionListProps = ReactionListProps & {
/**
* Array of personal detail objects
*/
users: PropTypes.arrayOf(participantPropTypes).isRequired,
users: PersonalDetails[];

/**
* Returns true if the current account has reacted to the report action (with the given skin tone).
vadymbokatov marked this conversation as resolved.
Show resolved Hide resolved
*/
hasUserReacted: PropTypes.bool,
hasUserReacted: boolean;
vadymbokatov marked this conversation as resolved.
Show resolved Hide resolved

...reactionPropTypes,
};

const defaultProps = {
hasUserReacted: false,
/**
* Returns true if the reaction list is visible
*/
isVisible: boolean;
vadymbokatov marked this conversation as resolved.
Show resolved Hide resolved
};

/**
* Create a unique key for each action in the FlatList.
* @param {Object} item

Check failure on line 36 in src/pages/home/report/ReactionList/BaseReactionList.tsx

View workflow job for this annotation

GitHub Actions / lint

Types are not permitted on @param
* @param {Number} index

Check failure on line 37 in src/pages/home/report/ReactionList/BaseReactionList.tsx

View workflow job for this annotation

GitHub Actions / lint

Types are not permitted on @param
* @return {String}

Check failure on line 38 in src/pages/home/report/ReactionList/BaseReactionList.tsx

View workflow job for this annotation

GitHub Actions / lint

Types are not permitted on @return
*/
const keyExtractor = (item, index) => `${item.login}+${index}`;
const keyExtractor: FlatListProps<PersonalDetails>['keyExtractor'] = (item, index) => `${item.login}+${index}`;

/**
* This function will be used with FlatList getItemLayout property for optimization purpose that allows skipping
Expand All @@ -47,18 +45,19 @@
* Generate and return an object with properties length(height of each individual row),
* offset(distance of the current row from the top of the FlatList), index(current row index)
*
* @param {*} _ FlatList item

Check failure on line 48 in src/pages/home/report/ReactionList/BaseReactionList.tsx

View workflow job for this annotation

GitHub Actions / lint

Types are not permitted on @param
* @param {Number} index row index

Check failure on line 49 in src/pages/home/report/ReactionList/BaseReactionList.tsx

View workflow job for this annotation

GitHub Actions / lint

Types are not permitted on @param
* @returns {Object}

Check failure on line 50 in src/pages/home/report/ReactionList/BaseReactionList.tsx

View workflow job for this annotation

GitHub Actions / lint

Types are not permitted on @returns
*/
const getItemLayout = (_, index) => ({
const getItemLayout = (_: any, index: number): {length: number; offset: number; index: number} => ({

Check failure on line 52 in src/pages/home/report/ReactionList/BaseReactionList.tsx

View workflow job for this annotation

GitHub Actions / lint

Parameter name `_` must match one of the following formats: camelCase, PascalCase

Check failure on line 52 in src/pages/home/report/ReactionList/BaseReactionList.tsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
index,
length: variables.listItemHeightNormal,
offset: variables.listItemHeightNormal * index,
});

function BaseReactionList(props) {
const styles = useThemeStyles();
function BaseReactionList(props: BaseReactionListProps) {
const {isSmallScreenWidth} = useWindowDimensions();
const {hoveredComponentBG, reactionListContainer, reactionListContainerFixedWidth, pv2} = useThemeStyles();
if (!props.isVisible) {
return null;
}
Expand All @@ -68,29 +67,29 @@
* Items with the code "SPACER" return nothing and are used to fill rows up to 8
* so that the sticky headers function properly
*
* @param {Object} params

Check failure on line 70 in src/pages/home/report/ReactionList/BaseReactionList.tsx

View workflow job for this annotation

GitHub Actions / lint

Types are not permitted on @param
* @param {Object} params.item
* @return {React.Component}
*/
const renderItem = ({item}) => (
const renderItem: FlatListProps<PersonalDetails>['renderItem'] = ({item}) => (
<OptionRow
item={item}
boldStyle
style={{maxWidth: variables.mobileResponsiveWidthBreakpoint}}
hoverStyle={styles.hoveredComponentBG}
hoverStyle={hoveredComponentBG}
onSelectRow={() => {
props.onClose();
props.onClose && props.onClose();
Navigation.navigate(ROUTES.PROFILE.getRoute(item.accountID));
}}
option={{
text: Str.removeSMSDomain(item.displayName),
reportID: String(item.accountID),
text: Str.removeSMSDomain(item.displayName || ''),
alternateText: Str.removeSMSDomain(item.login || ''),
participantsList: [item],
icons: [
{
id: item.accountID,
source: UserUtils.getAvatar(item.avatar, item.accountID),
vadymbokatov marked this conversation as resolved.
Show resolved Hide resolved
name: item.login,
name: item.login || '',
type: CONST.ICON_TYPE_AVATAR,
},
],
Expand All @@ -113,15 +112,13 @@
renderItem={renderItem}
keyExtractor={keyExtractor}
getItemLayout={getItemLayout}
contentContainerStyle={styles.pv2}
style={[styles.reactionListContainer, !props.isSmallScreenWidth && styles.reactionListContainerFixedWidth]}
contentContainerStyle={pv2}
style={[reactionListContainer, !isSmallScreenWidth && reactionListContainerFixedWidth]}
/>
</>
);
}

BaseReactionList.propTypes = propTypes;
BaseReactionList.defaultProps = defaultProps;
BaseReactionList.displayName = 'BaseReactionList';

export default withWindowDimensions(BaseReactionList);
export default BaseReactionList;
48 changes: 0 additions & 48 deletions src/pages/home/report/ReactionList/HeaderReactionList.js

This file was deleted.

48 changes: 48 additions & 0 deletions src/pages/home/report/ReactionList/HeaderReactionList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import {View} from 'react-native';
import Text from '@components/Text';
import useLocalize from '@hooks/useLocalize';
import useStyleUtils from '@hooks/useStyleUtils';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import * as EmojiUtils from '@libs/EmojiUtils';
import type {ReactionListProps} from './reactionPropTypes';

type HeaderReactionListProps = ReactionListProps & {
/**
* Returns true if the current account has reacted to the report action (with the given skin tone).
*/
vadymbokatov marked this conversation as resolved.
Show resolved Hide resolved
hasUserReacted: boolean;
vadymbokatov marked this conversation as resolved.
Show resolved Hide resolved
};

function HeaderReactionList(props: HeaderReactionListProps) {
const {
flexRow,
justifyContentBetween,
alignItemsCenter,
emojiReactionListHeader,
pt4,
emojiReactionListHeaderBubble,
miniQuickEmojiReactionText,
reactionCounterText,
reactionListHeaderText,
} = useThemeStyles();
const {getEmojiReactionBubbleStyle, getEmojiReactionBubbleTextStyle, getEmojiReactionCounterTextStyle} = useStyleUtils();
const {preferredLocale} = useLocalize();
const {isSmallScreenWidth} = useWindowDimensions();

return (
<View style={[flexRow, justifyContentBetween, alignItemsCenter, emojiReactionListHeader, !isSmallScreenWidth && pt4]}>
<View style={flexRow}>
<View style={[emojiReactionListHeaderBubble, getEmojiReactionBubbleStyle(false, props.hasUserReacted)]}>
<Text style={[miniQuickEmojiReactionText, getEmojiReactionBubbleTextStyle(true)]}>{props.emojiCodes.join('')}</Text>
<Text style={[reactionCounterText, getEmojiReactionCounterTextStyle(props.hasUserReacted)]}>{props.emojiCount}</Text>
</View>
<Text style={reactionListHeaderText}>{`:${EmojiUtils.getLocalizedEmojiName(props.emojiName, preferredLocale)}:`}</Text>
</View>
</View>
);
}

HeaderReactionList.displayName = 'HeaderReactionList';

export default HeaderReactionList;
Loading
Loading