Browse Source

fix(discover): Don't show more than 9 on toggling (#22137)

- This fixes a bug where toggling show prebuilt would keep the pervious
  state, so would either show less than 9 or more than 9 depending on
  which state you were moving to
William Mak 4 years ago
parent
commit
09a7d65451
1 changed files with 8 additions and 3 deletions
  1. 8 3
      src/sentry/static/sentry/app/views/eventsV2/landing.tsx

+ 8 - 3
src/sentry/static/sentry/app/views/eventsV2/landing.tsx

@@ -128,7 +128,12 @@ class DiscoverLanding extends AsyncComponent<Props, State> {
 
     const cursor = decodeScalar(location.query.cursor);
     let perPage = 9;
-    if (!cursor && shouldRenderPrebuilt()) {
+
+    const canRenderPrebuilt = this.state
+      ? this.state.renderPrebuilt
+      : shouldRenderPrebuilt();
+
+    if (!cursor && canRenderPrebuilt) {
       // invariant: we're on the first page
 
       if (searchQuery && searchQuery.length > 0) {
@@ -295,10 +300,10 @@ class DiscoverLanding extends AsyncComponent<Props, State> {
   togglePrebuilt = () => {
     const {renderPrebuilt} = this.state;
 
-    this.setState({renderPrebuilt: !renderPrebuilt}, function () {
+    this.setState({renderPrebuilt: !renderPrebuilt}, () => {
       setRenderPrebuilt(!renderPrebuilt);
+      this.fetchData({reloading: true});
     });
-    this.fetchData();
   };
 
   onGoLegacyDiscover = () => {