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

Fix SDK interactive question showing no question error incorrectly #42400

Merged

Conversation

WiNloSt
Copy link
Member

@WiNloSt WiNloSt commented May 8, 2024

Closes #42352

Description

The problem happened because we only relied on loading which indicates whether the initial question has been loaded or not, after that there could be another loading state when users drills down.

How to verify

  1. Using Customer Zero app.
  2. Go to Products > click on a product > Drills on the first bar chart. And there should be no question error state anymore.
  3. Click other page on the nav bar e.g. kitchen sink.
  4. Click Products again > click on a probuct and there should be no question error state.

Demo

Before

CleanShot.2567-05-08.at.15.57.13.mp4

After

https://www.loom.com/share/65437958d8ff461796e73de630a763b6

Checklist

  • Tests have been added/updated to cover changes in this PR

Copy link

replay-io bot commented May 8, 2024

Status Complete ↗︎
Commit 4654ee2
Results
⚠️ 11 Flaky
2471 Passed

@@ -65,7 +65,7 @@ export const _InteractiveQuestion = ({
const hasQuestionChanges =
card && (!card.id || card.id !== card.original_card_id);

const [loading, setLoading] = useState(true);
const [isQuestionLoading, setIsQuestionLoading] = useState(true);
Copy link
Member Author

Choose a reason for hiding this comment

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

Renaming to make is obvious this means it's loading a question not running a question query

}
}, [queryResults]);

if (loading) {
if (isQuestionLoading || isRunning) {
Copy link
Member Author

Choose a reason for hiding this comment

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

here's the key fix. We should display loading sprinner when either

  1. the question is loading
  2. the query is running

}),
storeInitialState: state,
});
return renderWithProviders(
Copy link
Member Author

Choose a reason for hiding this comment

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

return the result from renderWithProvider so I could access store and use it to dispatch actions.

Comment on lines +126 to +130
const storeDispatch = store.dispatch as unknown as ThunkDispatch<
State,
void,
AnyAction
>;
Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't manage to find a way to use this without casting, let me know if there's any better way.

Comment on lines +131 to +132
storeDispatch(clearQueryResult());
storeDispatch(runQuestionQuery());
Copy link
Member Author

Choose a reason for hiding this comment

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

These 2 actions do:

  1. clear the results so it's as if we're about to query a new question when we're drilling
  2. query again

@@ -98,6 +107,37 @@ describe("InteractiveQuestion", () => {
).toBeInTheDocument();
});

it("should render loading state when drilling down", async () => {
Copy link
Member Author

Choose a reason for hiding this comment

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

This test is tested with the previous version and it failed as expected.

@WiNloSt WiNloSt added the no-backport Do not backport this PR to any branch label May 9, 2024
@WiNloSt WiNloSt requested a review from a team May 9, 2024 10:54
Copy link
Contributor

@heypoom heypoom left a comment

Choose a reason for hiding this comment

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

The fix works on the demo app, nice! Verified that all three cases (drill-down, reset view, navigate back and forth) does not result in a Question Not Found error.

The renaming is a good idea too - I like that it semantically distinguishes query vs question.

(Ignore the height of the second container)

CleanShot.2567-05-09.at.18.13.49.mp4

@WiNloSt WiNloSt merged commit b4ed5a3 into master May 10, 2024
110 checks passed
@WiNloSt WiNloSt deleted the 42352-fix-interactive-question-incorrect-loading-state branch May 10, 2024 06:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-backport Do not backport this PR to any branch .Team/Embedding
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Drill down to see records results in uncaught runtime errors
2 participants