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

Add OfflineWithFeedback component #9931

Merged
merged 15 commits into from
Jul 22, 2022
Merged

Add OfflineWithFeedback component #9931

merged 15 commits into from
Jul 22, 2022

Conversation

iwiznia
Copy link
Contributor

@iwiznia iwiznia commented Jul 14, 2022

Details

This PR is just introducing the new component. I tested it in the WorkspaceMembersPage by hardocding the error and pendingAction properties and then removed it before submitting this PR for final review.

Fixed Issues

$ https://github.com/Expensify/Expensify/issues/218716

Tests

  • Checked the component both online and offline and with/without error for :
  • Pending add
  • Pending update
  • Pending delete
  • Checked component for:
  • Failed add
  • Failed update
  • Failed delete

WhatsApp Image 2022-07-19 at 3 16 34 PM
WhatsApp Image 2022-07-19 at 3 16 33 PM (2)
WhatsApp Image 2022-07-19 at 3 16 33 PM (1)
WhatsApp Image 2022-07-19 at 3 16 33 PM
Screen Shot 2022-07-19 at 3 20 24 PM
Screen Shot 2022-07-19 at 3 21 44 PM
Screen Shot 2022-07-19 at 3 21 59 PM
Screen Shot 2022-07-19 at 3 22 32 PM
Screen Shot 2022-07-19 at 3 20 48 PM
Screen Shot 2022-07-19 at 3 22 41 PM
Screen Shot 2022-07-19 at 3 21 02 PM
Screen Shot 2022-07-19 at 3 23 08 PM

Screen Shot 2022-07-19 at 3 19 44 PM

Screen Shot 2022-07-19 at 3 19 52 PM

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 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.
  • I have checked off every checkbox in the PR author checklist, including those that don't apply to this PR.

PR Reviewer Checklist

The Contributor+ will copy/paste it into a new comment and complete it after the author checklist is completed

  • I have verified the author checklist is complete (all boxes are checked off).
  • 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 other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • 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.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

QA Steps

  • Verify that no errors appear in the JS console

Screenshots

Web

Mobile Web

Desktop

iOS

Android

@iwiznia iwiznia self-assigned this Jul 14, 2022
@iwiznia iwiznia force-pushed the ionatan_offlineFeedback branch from dca81f3 to 915c5a5 Compare July 14, 2022 21:17
@iwiznia iwiznia requested a review from aldo-expensify July 14, 2022 22:54
@iwiznia
Copy link
Contributor Author

iwiznia commented Jul 14, 2022

This is not ready yet, I need to do some more testing, but can you review this in the meantime?

style={[styles.peopleRowCell]}
isChecked={_.contains(this.state.selectedEmployees, item.login)}
disabled={!canBeRemoved}
<OfflineWithFeedback error="This is an errors This is an errors This is an errors This is an errors This is an errors This is an errors " style={styles.peopleRowOfflineFeedback} pendingAction="delete">
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is just for testing, I will either remove this from this PR or properly connect it to the Onyx data

},
error: {
flexDirection: 'row',
justifyContent: 'center',
Copy link
Contributor

Choose a reason for hiding this comment

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

NAB: I think this is unnecessary: justifyContent: 'center', but also should not cause bugs

Comment on lines 2388 to 2390
borderColor: themeColors.textError,
borderRadius: 6,
borderWidth: 2,
Copy link
Contributor

Choose a reason for hiding this comment

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

At least in web, these border properties seem to be unnecessary (except for borderRadius )

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 copied them from somewhere else... will do some tests in native and see if they make a difference there

Copy link
Contributor

Choose a reason for hiding this comment

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

One thing with the error dot - I think we want to wrap it in a view that has 2px padding. This way the total bound of the red dot is 16x16, which will match other small icons we use for this kind of icon + message pattern. So essentially we'd get something like this:
image

Let me know what you think about that. I know this isn't an "icon" per se, but all of our icons have a little bit of this white space around it.

Actually, that being said, what we might want to do is just supply this as an .svg and then serve it up just like the rest of the icon system? Thoughts?

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 unsure. I would think is better to do this than using svgs if the effect is the same?

Copy link
Contributor

Choose a reason for hiding this comment

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

But this would then become almost like an "exception" to the icon system, ya know?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah ok, consistency then. I am fine with making it SVG, but have no idea how to do that, any tips?

Copy link
Contributor

Choose a reason for hiding this comment

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

I got you! dot-indicator.svg.zip

So then just make sure this shows at 16x16, and uses red (danger) for the fill color.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah thanks! So I drop this in /assets/images?

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe so, you should see a bunch of other .svgs there

style: [],
};

function applyStrikeThrough(children) {

This comment was marked as resolved.

@Julesssss
Copy link
Contributor

Julesssss commented Jul 19, 2022

I saw you we're struggling to test Android, so I tried to build it myself, but it looks like this PR is missing the indicator.svg. When it's out of WIP I'll give it another try

@iwiznia
Copy link
Contributor Author

iwiznia commented Jul 19, 2022

Thanks @Julesssss! Yes, I forgot to push that out, it's pushed now.
And I was able to test on android, the problem now is that it does not work 😄

aldo-expensify
aldo-expensify previously approved these changes Jul 19, 2022
Copy link
Contributor

@aldo-expensify aldo-expensify left a comment

Choose a reason for hiding this comment

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

Looks good to me. Would be good to have some instructions on how to test this now that you removed the hardcoded use case from WorkspaceMembersPage

src/pages/workspace/WorkspaceMembersPage.js Outdated Show resolved Hide resolved
@aldo-expensify aldo-expensify self-requested a review July 19, 2022 22:00
@iwiznia iwiznia marked this pull request as ready for review July 19, 2022 23:25
@iwiznia iwiznia requested a review from a team as a code owner July 19, 2022 23:25
@melvin-bot melvin-bot bot requested review from tgolen and removed request for a team July 19, 2022 23:25
error: PropTypes.string,

/** A function to run when the X button next to the error is clicked */
onClose: PropTypes.func.isRequired,
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens when I don't want anything to happen when I click the close button, do I need to strictly pass a method that does nothing?

Copy link
Contributor

Choose a reason for hiding this comment

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

I would think that you always want to do something with the X button. It would be weird to have an X button that does nothing :P

Copy link
Contributor Author

Choose a reason for hiding this comment

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

heh yes, I think you will always have to pass one, though now I realize that maybe we should have this component remove the error box by default and in that case maybe there are actions that do not require an onClose.... though not sure, I will leave this as required, we can remove the required later when we find a case that does not need it.

@iwiznia
Copy link
Contributor Author

iwiznia commented Jul 21, 2022

Updated to support multiple errors. Please re-review.

Looks good to me. Would be good to have some instructions on how to test this now that you removed the hardcoded use case from WorkspaceMembersPage

Enclose this with:
<OfflineWithFeedback errors={{one: 'one error that is long one error that is long one error that is long one error that is long one error that is long ', two: 'two error', three: 'three error and this one is medium length'}} pendingAction="add">

Then modify that pendingAction manually to update or delete and play around with adding/removing the error property.

@aldo-expensify
Copy link
Contributor

Reviewing... meanwhile, I wonder if the errors should be text errors should be aligned to the left instead of centered:

Center (current) Left
image image

@shawnborton

@iwiznia
Copy link
Contributor Author

iwiznia commented Jul 22, 2022

Oh good catch, we have them left aligned in the doc, so will switch it.

@shawnborton
Copy link
Contributor

Yup, I agree with that

const needsStrikeThrough = props.network.isOffline && props.pendingAction === 'delete';
const hideChildren = !props.network.isOffline && props.pendingAction === 'delete' && !props.errors;
let children = props.children;
const sortedErrors = _.map(_.sortBy(_.keys(props.errors)), key => props.errors[key]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const sortedErrors = _.map(_.sortBy(_.keys(props.errors)), key => props.errors[key]);
const sortedErrors = _.chain(props.errors)
.keys()
.sortBy()
.map(key => props.errors[key])
.value();

This may be more readable

@iwiznia
Copy link
Contributor Author

iwiznia commented Jul 22, 2022

Updated

{props.errors && (
<View style={styles.offlineFeedback.error}>
<View style={styles.offlineFeedback.errorDot}>
<Icon src={Expensicons.DotIndicator} fill={colors.red} height={16} width={16} />
Copy link
Contributor

Choose a reason for hiding this comment

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

NAB: replace 16 by variables.iconSizeSmall (import variables from '../styles/variables';)

<Icon src={Expensicons.DotIndicator} fill={colors.red} height={16} width={16} />
</View>
<View style={styles.offlineFeedback.textContainer}>
{_.map(sortedErrors, (error, i) => (
Copy link
Contributor

@aldo-expensify aldo-expensify Jul 22, 2022

Choose a reason for hiding this comment

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

NAB: because it is hard for me to tell if this has a real impact or not, but it is not recommended by the react doc.

It is not recommended to use indexes (i) as a key, from react doc:

We don’t recommend using indexes for keys if the order of items may change. This can negatively impact performance and may cause issues with component state. Check out Robin Pokorny’s article for an in-depth explanation on the negative impacts of using an index as a key. If you choose not to assign an explicit key to list items then React will default to using indexes as keys.

Not sure if it will have a real impact here... but an easy option to it would have been:

const sortedErrorKeys = _.chain(props.errors)
        .keys()
        .sortBy()
       // .map(key => props.errors[key]) Don't map this to values!
        .value();

then, in your map here you would use the error's key as the key:

{_.map(sortedErrorKeys, (errorKey) => (
    <Text key={errorKey} style={styles.offlineFeedback.text}>{props.errors[errorKey]}</Text>
))}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don’t recommend using indexes for keys if the order of items may change

The order of items will never change, so I think we are fine here, no?

Copy link
Contributor

Choose a reason for hiding this comment

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

hmm the index for one of the errors may change if one of the errors is deleted


const OfflineWithFeedback = (props) => {
const isOfflinePendingAction = props.network.isOffline && props.pendingAction;
const isUpdateOrDeleteError = props.errors && (props.pendingAction === 'delete' || props.pendingAction === 'update');
Copy link
Contributor

Choose a reason for hiding this comment

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

NAB: I think you are considering props.errors equal null when there are no errors. Just wondering if this should also consider {} as no errors

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe this should be left as it is and we should not expect {}... i don't like having two different things representing the same (no errors)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah good question... I think you are right and I should be using _.isEmpty. Changing it.

Copy link
Contributor Author

@iwiznia iwiznia Jul 22, 2022

Choose a reason for hiding this comment

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

To clarify, when we have fieldErrors (or errorFields don't recall what we settled in), then it's totally possible that this would end up being an empty object (since onyx can't really clear things)

aldo-expensify
aldo-expensify previously approved these changes Jul 22, 2022
Copy link
Contributor

@aldo-expensify aldo-expensify left a comment

Choose a reason for hiding this comment

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

Tested different cases in Android native and Web and didn't find any error. Left just some Nabs.

Some pics
Screen Shot 2022-07-22 at 1 31 12 PM
Screen Shot 2022-07-22 at 1 31 18 PM
Screen Shot 2022-07-22 at 1 31 27 PM

The text you can see like Test props: errors: 1 - delete - offline are just me adding a <Text> describing the props being passed to the case just below it.

In case it is of any use, I did the following to test random cases:

const errorsSeed = [
    null,
    {
        two: 'two error',
        three: 'three error and this one is medium length',
        one: 'one error that is long one error that is long one error that is long one error that is long one error that is long ',
    },
    {
        three: 'three error and this one is medium length',
    },
];

const offlineSeed = [true, false];
const pendingActionSeed = ['add', 'update', 'delete'];

const errors = _.sample(errorsSeed);
const offline = _.sample(offlineSeed);
const pendingAction = _.sample(pendingActionSeed);

const caseDescription = `Test props: errors: ${errors !== null ? Object.keys(errors).length : null} - ${pendingAction} - ${offline ? 'offline' : 'online'}`;

return (
    <View>
        <Text>{caseDescription}</Text>
        <OfflineWithFeedback
            pendingAction={pendingAction}
            isOffline={offline}
            errors={errors}
        >
            <Hoverable onHoverIn={() =>....
                ... rest of the code from WorkspaceMembersPage

@iwiznia
Copy link
Contributor Author

iwiznia commented Jul 22, 2022

In case it is of any use, I did the following to test random cases:

Damn you are smart! I did it manually LIKE A CAVEMAN!

@iwiznia
Copy link
Contributor Author

iwiznia commented Jul 22, 2022

Updated it again BTW.

@iwiznia
Copy link
Contributor Author

iwiznia commented Jul 22, 2022

Going to merge this to unblock other issues, if you have more comments, I will address them in a separate PR.

@iwiznia iwiznia merged commit 9364784 into main Jul 22, 2022
@iwiznia iwiznia deleted the ionatan_offlineFeedback branch July 22, 2022 21:25
@melvin-bot melvin-bot bot added the Emergency label Jul 22, 2022
@melvin-bot
Copy link

melvin-bot bot commented Jul 22, 2022

@iwiznia looks like this was merged without passing tests. Please add a note explaining why this was done and remove the Emergency label if this is not an emergency.

@iwiznia
Copy link
Contributor Author

iwiznia commented Jul 22, 2022

What? Go home Melvin, you are drunk!
image

But maybe I merged too fast by mistake and it was still running. Anyways, tests passed.

@iwiznia iwiznia removed the Emergency label Jul 22, 2022
@OSBotify
Copy link
Contributor

✋ 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

🚀 Deployed to staging by @iwiznia in version: 1.1.86-0 🚀

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

@OSBotify
Copy link
Contributor

OSBotify commented Aug 1, 2022

🚀 Deployed to production by @yuwenmemon in version: 1.1.86-5 🚀

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.

6 participants