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

Migrate components/post_view/post_flag_icon/post_flag_icon.tsx from class to function component #24187

Merged
merged 4 commits into from
Aug 11, 2023

Conversation

larkox
Copy link
Contributor

@larkox larkox commented Aug 4, 2023

Summary

Migrate components/post_view/post_flag_icon/post_flag_icon.tsx from class to function component

Ticket Link

None

Release Note

NONE

@larkox larkox added the 2: Dev Review Requires review by a developer label Aug 4, 2023
@larkox larkox requested a review from jespino August 4, 2023 08:46
@mm-cloud-bot mm-cloud-bot added the release-note-none Denotes a PR that doesn't merit a release note. label Aug 4, 2023
Comment on lines +29 to +37
const PostFlagIcon = ({
actions: {
flagPost,
unflagPost,
},
isFlagged,
postId,
location = Locations.CENTER,
}: Props) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expanded props to better track unused props.

const buttonRef = useRef<HTMLButtonElement>(null);
const [a11yActive, setA11yActive] = useState(false);

const handlePress = useCallback((e: React.MouseEvent) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useCallback to avoid passing a new function to children objects on every render.

Comment on lines 51 to 57
const handleA11yActivateEvent = () => {
setA11yActive(true);
};

handleA11yDeactivateEvent = () => {
this.setState({a11yActive: false});
const handleA11yDeactivateEvent = () => {
setA11yActive(false);
};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for useCallback since are only used on on mount/dismount

);
};

export default React.memo(PostFlagIcon);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rect.memo since the component used to be a Pure Component.


handleA11yActivateEvent = () => {
this.setState({a11yActive: true});
const handleA11yActivateEvent = () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this 2 functions should be defined inside the useEffect, that is the right scope for them, and there is not reason to have it outside.

Copy link
Member

@jespino jespino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a tiny improvement suggestion, but otherwise looks good to me.

@larkox larkox requested a review from jespino August 7, 2023 08:44
Copy link
Member

@jespino jespino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment on lines 52 to 57
const handleA11yActivateEvent = () => {
setA11yActive(true);
};
const handleA11yDeactivateEvent = () => {
setA11yActive(false);
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reasons why these are anonymous functions stored in a variable instead of plain functions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you mean why use const foo = () => {...} instead of using just () => {...} where needed, it is because I want to send the same reference to both add and remove listener.

If you mean why use const foo = () => {...} instead of func foo () {...}, no reason at all. Not sure if there is any real difference between both options.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes i meant latter, there is no difference anyways. We don't want to set expectations for contributors to always use anonymous functions instead of plain functions.

@@ -19,115 +19,97 @@ export type Actions = {
unflagPost: typeof unflagPost;
}

interface Props {
type Props = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the change here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was receiving a weird typescript error (maybe just on local) where the index file was complaining with the following error: Default export of the module has or is using private name 'Props'.. Moving it to a type fixed it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm thats interesting

@larkox
Copy link
Contributor Author

larkox commented Aug 9, 2023

@M-ZubairAhmed The failing test seems to be non related to this. Any chance it is a flaky test?

@M-ZubairAhmed
Copy link
Member

@M-ZubairAhmed The failing test seems to be non related to this. Any chance it is a flaky test?

Yes this is a flaky test, happens with my PRs randomly sometimes as well

src/components/confirm_modal_redux/confirm_modal_redux.test.tsx

@larkox larkox added 3: QA Review Requires review by a QA tester. May occur at the same time as Dev Review and removed 2: Dev Review Requires review by a developer labels Aug 10, 2023
@mattermost-build
Copy link
Contributor

E2E tests not automatically triggered, because the PR is not in a mergeable state. Please update the branch with the base branch and resolve outstanding conflicts.

@larkox
Copy link
Contributor Author

larkox commented Aug 10, 2023

@yasserfaraazkhan QA Notes:

The PostFlagIcon is the icon to mark a post as saved. It appears in the PostOptions component, which is the options that appear when you hover over a post.

No functionality should have changed.

@yasserfaraazkhan yasserfaraazkhan added the Setup Cloud Test Server Setup an on-prem test server label Aug 10, 2023
@larkox
Copy link
Contributor Author

larkox commented Aug 11, 2023

/update-branch

@yasserfaraazkhan yasserfaraazkhan added Setup Cloud + CWS Test Server Setup a test server linked to the CWS test portal and removed Setup Cloud Test Server Setup an on-prem test server labels Aug 11, 2023
@larkox larkox removed the 3: QA Review Requires review by a QA tester. May occur at the same time as Dev Review label Aug 11, 2023
This was referenced Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4: Reviews Complete All reviewers have approved the pull request Changelog/Not Needed Does not require a changelog entry Docs/Not Needed Does not require documentation kind/refactor Categorizes issue or PR as related to refactor of production code. release-note-none Denotes a PR that doesn't merit a release note. Setup Cloud + CWS Test Server Setup a test server linked to the CWS test portal
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants