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

fixed: Web - Desktop Attachments - Cannot attach a photo when the NEW ( green plus) button is pressed #9021

Merged
merged 9 commits into from
Jun 7, 2022

Conversation

metehanozyurt
Copy link
Contributor

Details

When user click Create icon open menu and events drag/drop wont work. This PR fix this issue.

Fixed Issues

$ #8842

Tests

  1. Open Expensify account on Web
  2. Select any chat room in your list
  3. Tap the NEW (green plus) button on the bottom left of the screen
  4. Open the folder with the desired file on your computer
  5. Drag a photo from the folder to the chat room
  6. Notice that opened menu closed and user can drop file to the chat
  7. Open Expensify account on Web
  8. Select any chat room in your list
  9. Tap the NEW (green plus) button on the bottom left of the screen
  10. Open the folder with the desired file on your computer
  11. Drag a photo from the folder to the chat room
  12. Notice that opened menu closed and user can drop file to the chat
  13. mWebs, ios native, android native are not affected by this PR.
  • Verify that no errors appear in the JS console

PR Review Checklist

Contributor (PR Author) Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • iOS / native
    • Android / native
    • iOS / Safari
    • Android / Chrome
    • MacOS / Chrome
    • MacOS / Desktop
  • I verified there are no console errors (if there’s a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained “why” the code was doing something instead of only explaining “what” the code was doing.
    • I verified any copy / text shown in the product was added in all src/languages/* files
    • I verified any copy / text that was added to the app is correct English and approved by marketing by tagging the marketing team on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named “index.js”. All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • Any functional components have the displayName property
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose and it is
  • If a new CSS style is added I verified that:
    • A similar style doesn’t already exist
    • The style can’t be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.

PR Reviewer Checklist

  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I verified tests pass on all platforms & I tested again on:
    • iOS / native
    • Android / native
    • iOS / Safari
    • Android / Chrome
    • MacOS / Chrome
    • MacOS / Desktop
  • I verified there are no console errors (if there’s a console error not related to the PR, report it or open an issue for it to be fixed)
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained “why” the code was doing something instead of only explaining “what” the code was doing.
    • I verified any copy / text shown in the product was added in all src/languages/* files
    • I verified any copy / text that was added to the app is correct English and approved by marketing by tagging the marketing team on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named “index.js”. All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • Any functional components have the displayName property
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose and it is broken down into smaller components in order to separate concerns and functions
  • If a new CSS style is added I verified that:
    • A similar style doesn’t already exist
    • The style can’t be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.

QA Steps

  1. Open Expensify account on Web
  2. Select any chat room in your list
  3. Tap the NEW (green plus) button on the bottom left of the screen
  4. Open the folder with the desired file on your computer
  5. Drag a photo from the folder to the chat room
  6. Notice that opened menu closed and user can drop file to the chat
  7. Open Expensify account on Web
  8. Select any chat room in your list
  9. Tap the NEW (green plus) button on the bottom left of the screen
  10. Open the folder with the desired file on your computer
  11. Drag a photo from the folder to the chat room
  12. Notice that opened menu closed and user can drop file to the chat
  13. mWebs, ios native, android native are not affected by this PR.
  • Verify that no errors appear in the JS console

Screenshots

Web

web-Screen-Recording-2022-05-15-at-11.18.56.mp4

Mobile Web

ios-web-Screen-Recording-2022-05-15-at-11.45.22.mp4
android-web-Screen-Recording-2022-05-15-at-11.56.02.mp4

Desktop

desktop-Screen-Recording-2022-05-15-at-11.25.57.mp4

iOS

ios-native-Screen-Recording-2022-05-15-at-11.40.11.mp4

Android

android-native-Screen-Recording-2022-05-15-at-11.54.34.mp4

@metehanozyurt metehanozyurt requested a review from a team as a code owner May 15, 2022 09:10
@melvin-bot melvin-bot bot requested review from Luke9389 and mananjadhav and removed request for a team May 15, 2022 09:10
@@ -83,6 +89,9 @@ class SidebarScreen extends Component {
* Selecting an item on CreateMenu or closing it by clicking outside of the modal component
*/
hideCreateMenu() {
if (window.document) {
window.document.removeEventListener('dragover', this.dragOverListener);
Copy link
Collaborator

Choose a reason for hiding this comment

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

We need to refactor this component to have web platform-specific changes in the index.web.js.

Please check the the guidelines here: https://github.com/Expensify/App#platform-specific-file-extensions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for your comment @mananjadhav .
When I saw that it didn't work on android and ios, I wanted to do this too. Frankly, I was afraid to repeat too much code for 10 lines. If code duplication is not a problem, I would like to do it as follows, if you see fit.
I'm a little afraid that the same codes will repeat. I wanted to get your permission before I did it.

WhatsApp Image 2022-05-15 at 22 22 59

Copy link
Collaborator

@mananjadhav mananjadhav May 15, 2022

Choose a reason for hiding this comment

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

Thanks for the update. In these cases we should push all the common code to a component say BaseSidebarScreen. We then add/override only platform-specific functions and noops in others. This will avoid duplication and code will be cleaner.

A quick small example would look like this:

BaseSidebarScreen.js

const propTypes = {
      beforeHideCreateMenu: PropTypes.func,
}

class BaseSidebarScreen {

    hideCreateMenu() {
       if(this.props.beforeHideCreateMenu) { 
           this.props.beforeHideCreateMenu();
      }. 

       this.setState({
            isCreateMenuActive: false,
        });
    }
   

}

index.web.js
class SidebarScreen {   
    render() {
       return <BaseSidebarScreen ... />
    }
}


`index.js`
class SidebarScreen {   
    render() {
       return <BaseSidebarScreen ... beforeHideCreateMenu={() => { document.removeEventListener('dragover', this.dragOverListener); }} />
    }
}

I hope this helps, do reach out if you have any other questions :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you so much helps a lot 🙏 . I will try to do as you say. thank you so much.

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 made a change as you said in the light of the guidance. I hope you will like it @mananjadhav 🙏 👼 .

if (this.props.beforeHideCreateMenu) {
            this.props.beforeHideCreateMenu();
        }
if (this.props.afterShowCreateMenu) {
            this.props.afterShowCreateMenu(this);
        }

These conditions may have been extra. I need your opinion as I am not sure. Because I defined it as default props.
Thank you for your help again. I wouldn't dare to change the files 😅.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thank you for your help again. I wouldn't dare to change the files

Anytime. That's what we're here for :) Don't hesitate in asking any questions. Thank you for your time.

@@ -68,6 +77,9 @@ class SidebarScreen extends Component {
this.setState({
isCreateMenuActive: true,
});
if (this.props.afterShowCreateMenu) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can remove this check.

@@ -68,6 +77,9 @@ class SidebarScreen extends Component {
this.setState({
isCreateMenuActive: true,
});
if (this.props.afterShowCreateMenu) {
this.props.afterShowCreateMenu(this);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would recommend removing this from the parameters. Instead pass a ref in the SidebarScreen/index.js

@@ -83,6 +95,9 @@ class SidebarScreen extends Component {
* Selecting an item on CreateMenu or closing it by clicking outside of the modal component
*/
hideCreateMenu() {
if (this.props.beforeHideCreateMenu) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove the if check

*
* @param {Object} e native Event
*/
dragOverListener() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this function required here?

* @param {BaseSidebarScreen} baseComponent
*/
createDragoverListener= (baseComponent) => {
this.dragOverListener = this.dragOverListener.bind(baseComponent);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't pass baseComponent. Instead add a ref to BaseSidebarScreen and use that.

import React, {PureComponent} from 'react';
import BaseSidebarScreen from './BaseSidebarScreen';

class SidebarScreen extends PureComponent {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we can change this Function component. We're not using setState and hence don't need this to be a Class Component


const propTypes = {

/* Create Listener callback */
afterShowCreateMenu: PropTypes.func,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know I suggested this name, but generally, I avoid before or after naming conventions, and rather use onHide, etc. Let me think if we can name it better. Do let me know if you have better suggestions.

import React, {PureComponent} from 'react';
import BaseSidebarScreen from './BaseSidebarScreen';

class SidebarScreen extends PureComponent {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Like the web component, this can be a Function component.

Copy link
Collaborator

@mananjadhav mananjadhav left a comment

Choose a reason for hiding this comment

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

Thanks for the changes @metehanozyurt. Looks better, have left a few comments.

Do ping if you need any help.

@metehanozyurt
Copy link
Contributor Author

I'm so sorry for being late @mananjadhav.

  • Removed unnecessary if conditions.
  • Class components changed to function components.
  • Used for ref to call hideCreateMenu function.
  • Deleted dragOverListener function on BaseSidebarScreen and index and connect ref instead.
  • Renamed functions to onHideCreateMenu and onShowCreateMenu now.

I hope you like these changes. Thank you very much for your time and helps 🙏 👼 .

import React from 'react';
import BaseSidebarScreen from './BaseSidebarScreen';

export default function SidebarScreen(props) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add displayName, propTypes for SidebarScreen.

Copy link
Contributor Author

@metehanozyurt metehanozyurt May 17, 2022

Choose a reason for hiding this comment

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

When I add propTypes I had to add this lines (for warnings) so that the required fields come . But I removed it from baseSidebarScreen.

export default compose(
    withNavigation,
    withLocalize,
    withWindowDimensions,
    withOnyx({
        allPolicies: {
            key: ONYXKEYS.COLLECTION.POLICY,
        },
        betas: {
            key: ONYXKEYS.BETAS,
        },
        isCreatingWorkspace: {
            key: ONYXKEYS.IS_CREATING_WORKSPACE,
        },
    }),
)(SidebarScreen);

import React, {useRef} from 'react';
import BaseSidebarScreen from './BaseSidebarScreen';

export default function (props) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Name the function

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 am very embarrassed for the mistake I made. Please accept my apology :( .

Copy link
Collaborator

Choose a reason for hiding this comment

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

No worries. Happens with the best of us.


/* Remove Listener callback */
onHideCreateMenu: PropTypes.func,

/* Beta features list */
betas: PropTypes.arrayOf(PropTypes.string).isRequired,
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can come from the sidebarPropTypes

@@ -59,6 +64,9 @@ class SidebarScreen extends Component {

const routes = lodashGet(this.props.navigation.getState(), 'routes', []);
Welcome.show({routes, showCreateMenu: this.showCreateMenu});
if (this.props.innerRef) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't need the ref here. Please check my comment below.

import BaseSidebarScreen from './BaseSidebarScreen';

const SidebarScreen = (props) => {
const BaseSidebarScreenRef = useRef(null);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
const BaseSidebarScreenRef = useRef(null);
let baseSidebarScreen = null;

* Method create event listener
*/
const createDragoverListener = () => {
document.addEventListener('dragover', BaseSidebarScreenRef.current.hideCreateMenu);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
document.addEventListener('dragover', BaseSidebarScreenRef.current.hideCreateMenu);
document.addEventListener('dragover', baseSidebarScreen.hideCreateMenu);

* Method remove event listener.
*/
const removeDragoverListener = () => {
document.removeEventListener('dragover', BaseSidebarScreenRef.current.hideCreateMenu);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
document.removeEventListener('dragover', BaseSidebarScreenRef.current.hideCreateMenu);
document.removeEventListener('dragover', baseSidebarScreen.hideCreateMenu);

};
return (
<BaseSidebarScreen
innerRef={BaseSidebarScreenRef}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
innerRef={BaseSidebarScreenRef}
ref={el => baseSidebarScreen = el}

Copy link
Collaborator

@mananjadhav mananjadhav left a comment

Choose a reason for hiding this comment

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

PR has made good progress. Thanks, @metehanozyurt. Few more suggestions and we should be good to merge.

@metehanozyurt
Copy link
Contributor Author

I made the changes based on your suggestions @mananjadhav . Thank you very much for your valuable time and support 🙏 . You can be sure that I will do my best not to make the mistakes I have made in my next works.

/* Create Listener callback */
    onShowCreateMenu: PropTypes.func,

    /* Remove Listener callback */
    onHideCreateMenu: PropTypes.func,

I did not move these two properties into sidebarPropTypes. I did it like this because it is not used in native code. If you want me to do that, I can do it right away.


/* Is workspace is being created by the user? */
isCreatingWorkspace: PropTypes.bool,
/* Create Listener callback */
Copy link
Contributor

Choose a reason for hiding this comment

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

This could be more descriptive

src/pages/home/sidebar/SidebarScreen/index.js Show resolved Hide resolved
@metehanozyurt
Copy link
Contributor Author

I think the change notification did not come, so I wanted to write.
descriptive comment added like this.

 /* A callback to call when we show create menu */
    onShowCreateMenu: PropTypes.func,
 /* A callback to call when we hide create menu */
    onHideCreateMenu: PropTypes.func,

If I did something else that could cause problems, I'd be happy to replace it. Thank you for your time @mananjadhav 🙏 .

Copy link
Collaborator

@mananjadhav mananjadhav left a comment

Choose a reason for hiding this comment

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

@metehanozyurt Sorry for the delay. I've slightly changed the language of the comment in the suggestion. Rest all it looks good to me.

Also can you pull the latest main branch?


/* Is workspace is being created by the user? */
isCreatingWorkspace: PropTypes.bool,
/* A callback to call when we show create menu */
Copy link
Collaborator

@mananjadhav mananjadhav Jun 1, 2022

Choose a reason for hiding this comment

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

Suggested change
/* A callback to call when we show create menu */
/* Callback function when the menu is shown */


...windowDimensionsPropTypes,
/* A callback to call when we hide create menu */
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
/* A callback to call when we hide create menu */
/* Callback function before the menu is hidden*/

@metehanozyurt
Copy link
Contributor Author

Thank you @mananjadhav I changed comments and pulled the latest main branch.
but Some checks were not successful . Is there anything I can do about this? It didn't give an error in the code I added 😟.

@mananjadhav
Copy link
Collaborator

Changes look fine, but I am not sure about the break in the GH action. Neither do I have an option to rerun the workflow. @Luke9389 can you help here?

PR Review done

🎀 👀 🎀
C+ reviewed

@Luke9389
Copy link
Contributor

Luke9389 commented Jun 6, 2022

Re-ran the GH action and it passed ✅
I'll review this first thing tomorrow. Thanks y'all!

Copy link
Contributor

@Luke9389 Luke9389 left a comment

Choose a reason for hiding this comment

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

lookin good, thanks!

@Luke9389 Luke9389 merged commit 1fc4089 into Expensify:main Jun 7, 2022
@OSBotify
Copy link
Contributor

OSBotify commented Jun 7, 2022

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify
Copy link
Contributor

OSBotify commented Jun 8, 2022

🚀 Deployed to staging by @Luke9389 in version: 1.1.74-0 🚀

platform result
🤖 android 🤖 failure ❌
🖥 desktop 🖥 failure ❌
🍎 iOS 🍎 cancelled 🔪
🕸 web 🕸 failure ❌

@OSBotify
Copy link
Contributor

OSBotify commented Jun 9, 2022

🚀 Deployed to production by @yuwenmemon in version: 1.1.74-2 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants