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

[HOLD for payment 2023-09-07] [$1000] Chat - MagicCodeInput stories are broken #24287

Closed
1 of 6 tasks
lanitochka17 opened this issue Aug 8, 2023 · 28 comments
Closed
1 of 6 tasks
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Weekly KSv2

Comments

@lanitochka17
Copy link

lanitochka17 commented Aug 8, 2023

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Action Performed:

  1. Run npm run storybook
    https://staging.new.expensify.com/docs/index.html?path=/story/components-magiccodeinput--auto-focus
  2. Navigate to the MagicCodeInput stories by clicking on 'MagicCodeInput' under components in the left-hand menu

Expected Result:

The MagicCodeInput stories should not be broken

Actual Result:

The MagicCodeInput stories are broken

Workaround:

Unknown

Platforms:

Which of our officially supported platforms is this issue occurring on?

  • Android / native
  • Android / Chrome
  • iOS / native
  • iOS / Safari
  • Windows / Chrome
  • MacOS / Desktop

Version Number: 1.3.50.2

Reproducible in staging?: Yes

Reproducible in production?: Yes

If this was caught during regression testing, add the test name, ID and link from TestRail:

Email or phone of affected tester (no customers):

Logs: https://stackoverflow.com/c/expensify/questions/4856

Notes/Photos/Videos: Any additional supporting documentation

Recording.5768.mp4

Screenshot 2023-08-01 at 21 35 51 (1)

Screenshot 2023-08-01 at 21 36 06 (1)

Expensify/Expensify Issue URL:

Issue reported by: @joh42

Slack conversation: https://expensify.slack.com/archives/C049HHMV9SM/p1690918863039709

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~011893a5d0539986e8
  • Upwork Job ID: 1690367506169479168
  • Last Price Increase: 2023-08-12
  • Automatic offers:
    • bernhardoj | Contributor | 26201931
    • joh42 | Reporter | 26201932
@lanitochka17 lanitochka17 added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Aug 8, 2023
@melvin-bot
Copy link

melvin-bot bot commented Aug 8, 2023

Triggered auto assignment to @sonialiap (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.

@melvin-bot
Copy link

melvin-bot bot commented Aug 8, 2023

Bug0 Triage Checklist (Main S/O)

  • This "bug" occurs on a supported platform (ensure Platforms in OP are ✅)
  • This bug is not a duplicate report (check E/App issues and #expensify-bugs)
    • If it is, comment with a link to the original report, close the issue and add any novel details to the original issue instead
  • This bug is reproducible using the reproduction steps in the OP. S/O
    • If the reproduction steps are clear and you're unable to reproduce the bug, check with the reporter and QA first, then close the issue.
    • If the reproduction steps aren't clear and you determine the correct steps, please update the OP.
  • This issue is filled out as thoroughly and clearly as possible
    • Pay special attention to the title, results, platforms where the bug occurs, and if the bug happens on staging/production.
  • I have reviewed and subscribed to the linked Slack conversation to ensure Slack/Github stay in sync

@kushu7
Copy link
Contributor

kushu7 commented Aug 8, 2023

Proposal

Please re-state the problem that we are trying to solve in this issue.

Chat - MagicCodeInput stories are broken

What is the root cause of that problem?

We have defined default value as undefined here. and we are not passing value prop from story.

value: undefined,

and decomposeString gets called on component mount

const validateAndSubmit = () => {
const numbers = decomposeString(props.value, props.maxLength);
if (!props.shouldSubmitOnComplete || _.filter(numbers, (n) => ValidationUtils.isNumeric(n)).length !== props.maxLength || props.network.isOffline) {
return;
}
// Blurs the input and removes focus from the last input and, if it should submit
// on complete, it will call the onFulfill callback.
blurMagicCodeInput();
props.onFulfill(props.value);
};
useNetwork({onReconnect: validateAndSubmit});
useEffect(() => {
validateAndSubmit();
// We have not added:
// + the editIndex as the dependency because we don't want to run this logic after focusing on an input to edit it after the user has completed the code.
// + the props.onFulfill as the dependency because props.onFulfill is changed when the preferred locale changed => avoid auto submit form when preferred locale changed.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [props.value, props.shouldSubmitOnComplete]);

but we have value as undefined as we get error from here.

const decomposeString = (value, length) => {
let arr = _.map(value.split('').slice(0, length), (v) => (ValidationUtils.isNumeric(v) ? v : CONST.MAGIC_CODE_EMPTY_CHAR));
if (arr.length < length) {
arr = arr.concat(Array(length - arr.length).fill(CONST.MAGIC_CODE_EMPTY_CHAR));
}
return arr;
};

What changes do you think we should make in order to solve the problem?

we should add early return condition here

const decomposeString = (value, length) => {

if(!value) return [];

What alternative solutions did you explore? (Optional)

We can pass empty string as a value from MagicCodeInput story

@Pujan92
Copy link
Contributor

Pujan92 commented Aug 8, 2023

Proposal

Please re-state the problem that we are trying to solve in this issue.

MagicCodeInput stories are not working and broken.

What is the root cause of that problem?

We are not setting the required props correctly.

What changes do you think we should make in order to solve the problem?

We need to update the Template function with the needed props to work the stories correctly.

function Template(args) {
// eslint-disable-next-line react/jsx-props-no-spreading
return <MagicCodeInput {...args} />;
}

function Template(args) {
    const [value, setValue] = useState('');
    const ref = useRef();
    return <MagicCodeInput
        value={value}
        onChangeText={(val) => setValue(val)}
        ref={ref}
        // eslint-disable-next-line react/jsx-props-no-spreading
        {...args} 
    />;
}

Extra: If we need to provide some initial value then we can pass an extra arg called initialValue for the story and use above with the initial state useState(args.initialValue)

Result
Screen.Recording.2023-08-09.at.1.49.17.AM.mov

@joh42
Copy link
Contributor

joh42 commented Aug 8, 2023

Thanks for creating the issue! For some context, I discovered that the MagicCodeInput story was broken while going through the PR checklist after having modified the MagicCodeInput component. When asking about how broken stories should be handled, I got the suggestion of reporting it as a bug: https://app.slack.com/client/T03SC9DTT/C01GTK53T8Q/thread/C01GTK53T8Q-1690918046.950089

@bernhardoj
Copy link
Contributor

Proposal

Please re-state the problem that we are trying to solve in this issue.

MagicCodeInput stories throw some errors

What is the root cause of that problem?

The first error we can see is Cannot read properties of undefined (reading 'isOffline'). In MagicCodeInput, we use useNetwork hook that gets the network value from a context.

const {isOffline} = useContext(NetworkContext);

We already provide the context here (OnyxProvider).

const decorators = [
(Story) => (
<ComposeProviders components={[OnyxProvider, LocaleContextProvider, HTMLEngineProvider, SafeAreaProvider, PortalProvider]}>
<Story />
</ComposeProviders>
),
];

The problem is, the network context value is initially undefined. This is also true for all onyx contexts, that is personal details, preferred theme, etc.

We can only reproduce this first issue when we open the storybook for the first time with the Onyx still empty. If it's not empty, you can clear it first

The second error is Cannot read properties of undefined (reading 'split'). In MagiCodeInput, the value prop is optional and the default value is undefined. In the story, we didn't pass anything to the value prop. When MagicCodeInput is rendered, we call decomposeString(value) that will call split function on the value. Because value is undefined, an error is thrown.

const decomposeString = (value, length) => {
let arr = _.map(value.split('').slice(0, length), (v) => (ValidationUtils.isNumeric(v) ? v : CONST.MAGIC_CODE_EMPTY_CHAR));

What changes do you think we should make in order to solve the problem?

  1. Initialize the default value for the network context by adding
initialKeyStates: {
    [ONYXKEYS.NETWORK]: {isOffline: false},
},

to here

Onyx.init({
keys: ONYXKEYS,
});

We did this when initializing the app

App/src/setup/index.js

Lines 24 to 39 in 5510a95

Onyx.init({
keys: ONYXKEYS,
// Increase the cached key count so that the app works more consistently for accounts with large numbers of reports
maxCachedKeysCount: 10000,
safeEvictionKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
captureMetrics: Metrics.canCaptureOnyxMetrics(),
initialKeyStates: {
// Clear any loading and error messages so they do not appear on app startup
[ONYXKEYS.SESSION]: {loading: false},
[ONYXKEYS.ACCOUNT]: CONST.DEFAULT_ACCOUNT_DATA,
[ONYXKEYS.NETWORK]: {isOffline: false},
[ONYXKEYS.IS_SIDEBAR_LOADED]: false,
[ONYXKEYS.SHOULD_SHOW_COMPOSE_INPUT]: true,
},
});

  1. Change the default value of value prop to an empty string

This will fix the MagicCodeInput story, but I also see some errors on other stories. Read more below. Let me know if we should handle them all.

read more
  1. Checkbox
    accessibilityLabel is required but missing
    Solution: pass an empty string to the checkbox story
  2. Composer
    The component is not inside a navigation container
    Solution: wrap the composer with custom navigation context, the same thing we did with withNavigationFallback
  3. Header
    Cannot read properties of null (reading 'environment')
    Add EnvironmentProvider to the storybook
  4. HeaderWithBackButton
    Cannot read properties of null (reading 'isKeyboardShown')
    Add KeyboardStateProvider to the storybook

@melvin-bot melvin-bot bot added the Overdue label Aug 10, 2023
@sonialiap
Copy link
Contributor

I don't know what this tool is, but I can reproduce the behavior described. Triaging to external

@melvin-bot melvin-bot bot removed the Overdue label Aug 12, 2023
@sonialiap sonialiap added External Added to denote the issue can be worked on by a contributor Overdue labels Aug 12, 2023
@melvin-bot melvin-bot bot changed the title Chat - MagicCodeInput stories are broken [$1000] Chat - MagicCodeInput stories are broken Aug 12, 2023
@melvin-bot
Copy link

melvin-bot bot commented Aug 12, 2023

Job added to Upwork: https://www.upwork.com/jobs/~011893a5d0539986e8

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Aug 12, 2023
@sonialiap sonialiap removed the Overdue label Aug 12, 2023
@melvin-bot
Copy link

melvin-bot bot commented Aug 12, 2023

Current assignee @sonialiap is eligible for the External assigner, not assigning anyone new.

@melvin-bot
Copy link

melvin-bot bot commented Aug 12, 2023

Triggered auto assignment to Contributor-plus team member for initial proposal review - @rushatgabhane (External)

@rushatgabhane
Copy link
Member

i like @bernhardoj's proposal. Because it fixes the network error and undefined value prop
c+ reviewed 🎀 👀 🎀

@melvin-bot
Copy link

melvin-bot bot commented Aug 18, 2023

Triggered auto assignment to @Julesssss, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

@melvin-bot melvin-bot bot removed the Help Wanted Apply this label when an issue is open to proposals by contributors label Aug 18, 2023
@melvin-bot
Copy link

melvin-bot bot commented Aug 18, 2023

📣 @rushatgabhane Please request via NewDot manual requests for the Reviewer role ($1000)

@melvin-bot
Copy link

melvin-bot bot commented Aug 18, 2023

📣 @bernhardoj 🎉 An offer has been automatically sent to your Upwork account for the Contributor role 🎉 Thanks for contributing to the Expensify app!

Offer link
Upwork job
Please accept the offer and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review 🧑‍💻
Keep in mind: Code of Conduct | Contributing 📖

@melvin-bot
Copy link

melvin-bot bot commented Aug 18, 2023

📣 @joh42 🎉 An offer has been automatically sent to your Upwork account for the Reporter role 🎉 Thanks for contributing to the Expensify app!

Offer link
Upwork job

@bernhardoj
Copy link
Contributor

Can I have a confirmation whether we want to fix other storybook issue too?

@rushatgabhane @Julesssss

@melvin-bot melvin-bot bot added Reviewing Has a PR in review Weekly KSv2 and removed Daily KSv2 labels Aug 19, 2023
@bernhardoj
Copy link
Contributor

PR is ready
cc: @rushatgabhane

@Julesssss
Copy link
Contributor

FYI I am OOO this week. Feel free to reassign in the meantime, or I will be back on Monday 28th

@melvin-bot melvin-bot bot added Weekly KSv2 and removed Weekly KSv2 labels Aug 24, 2023
@melvin-bot
Copy link

melvin-bot bot commented Aug 29, 2023

Based on my calculations, the pull request did not get merged within 3 working days of assignment. Please, check out my computations here:

  • when @bernhardoj got assigned: 2023-08-18 17:39:03 Z
  • when the PR got merged: 2023-08-29 09:04:44 UTC
  • days elapsed: 6

On to the next one 🚀

@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Weekly KSv2 labels Aug 31, 2023
@melvin-bot melvin-bot bot changed the title [$1000] Chat - MagicCodeInput stories are broken [HOLD for payment 2023-09-07] [$1000] Chat - MagicCodeInput stories are broken Aug 31, 2023
@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Aug 31, 2023
@melvin-bot
Copy link

melvin-bot bot commented Aug 31, 2023

Reviewing label has been removed, please complete the "BugZero Checklist".

@melvin-bot
Copy link

melvin-bot bot commented Aug 31, 2023

The solution for this issue has been 🚀 deployed to production 🚀 in version 1.3.59-5 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

If no regressions arise, payment will be issued on 2023-09-07. 🎊

After the hold period is over and BZ checklist items are completed, please complete any of the applicable payments for this issue, and check them off once done.

  • External issue reporter
  • Contributor that fixed the issue
  • Contributor+ that helped on the issue and/or PR

For reference, here are some details about the assignees on this issue:

As a reminder, here are the bonuses/penalties that should be applied for any External issue:

  • Merged PR within 3 business days of assignment - 50% bonus
  • Merged PR more than 9 business days after assignment - 50% penalty

@melvin-bot
Copy link

melvin-bot bot commented Aug 31, 2023

BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:

  • [@rushatgabhane] The PR that introduced the bug has been identified. Link to the PR:
  • [@rushatgabhane] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake. Link to comment:
  • [@rushatgabhane] A discussion in #expensify-bugs has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner. Link to discussion:
  • [@rushatgabhane] Determine if we should create a regression test for this bug.
  • [@rushatgabhane] If we decide to create a regression test for the bug, please propose the regression test steps to ensure the same bug will not reach production again.
  • [@sonialiap] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:

@melvin-bot melvin-bot bot added the Overdue label Sep 11, 2023
@Julesssss
Copy link
Contributor

Not overdue, we're awaiting payment.

@melvin-bot melvin-bot bot removed the Overdue label Sep 11, 2023
@rushatgabhane
Copy link
Member

rushatgabhane commented Sep 12, 2023

  1. The PR that introduced the bug has been identified. Link to the PR: This issue is caused because the App implementation changes but we didn't test storybook. It not practical to find PR that caused this.

  2. The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake. Link to comment: N.A.

  3. A discussion in #expensify-bugs has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner. Link to discussion: This is a part of checklist

  4. Determine if we should create a regression test for this bug. - No

  5. If we decide to create a regression test for the bug, please propose the regression test steps to ensure the same bug will not reach production again - N.A.

@rushatgabhane
Copy link
Member

Created a manual request here - https://staging.new.expensify.com/r/4875420951036856

@bernhardoj
Copy link
Contributor

Waiting for payment

@sonialiap
Copy link
Contributor

@rushatgabhane review + bonus = $1500 - please request in NewDot
@bernhardoj fix + bonys = $1500 paid ✔️
@joh42 report = $250 paid ✔️

@JmillsExpensify
Copy link

$1,500 payment approved for @rushatgabhane based on BZ summary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Weekly KSv2
Projects
None yet
Development

No branches or pull requests

9 participants