Browse Source

feat(trace): disable/enable reset zoom (#70301)

Enable or disable the button based off the zoom state (previously always
enabled)
Jonas 10 months ago
parent
commit
0cc8b82ebb

+ 16 - 3
static/app/views/performance/newTraceDetails/index.tsx

@@ -51,7 +51,7 @@ import {
   type ViewManagerScrollAnchor,
   type ViewManagerScrollAnchor,
   VirtualizedViewManager,
   VirtualizedViewManager,
 } from 'sentry/views/performance/newTraceDetails/traceRenderers/virtualizedViewManager';
 } from 'sentry/views/performance/newTraceDetails/traceRenderers/virtualizedViewManager';
-import {TraceShortcuts} from 'sentry/views/performance/newTraceDetails/traceShortcuts';
+import {TraceShortcuts} from 'sentry/views/performance/newTraceDetails/traceShortcutsModal';
 import {
 import {
   loadTraceViewPreferences,
   loadTraceViewPreferences,
   storeTraceViewPreferences,
   storeTraceViewPreferences,
@@ -865,12 +865,25 @@ function TraceResetZoomButton(props: {
   }, [props.viewManager, props.organization]);
   }, [props.viewManager, props.organization]);
 
 
   return (
   return (
-    <Button size="xs" onClick={onResetZoom}>
+    <ResetZoomButton
+      size="xs"
+      onClick={onResetZoom}
+      ref={props.viewManager.registerResetZoomRef}
+    >
       {t('Reset Zoom')}
       {t('Reset Zoom')}
-    </Button>
+    </ResetZoomButton>
   );
   );
 }
 }
 
 
+const ResetZoomButton = styled(Button)`
+  transition: opacity 0.2s 0.5s ease-in-out;
+
+  &[disabled] {
+    cursor: not-allowed;
+    opacity: 0.65;
+  }
+`;
+
 const TraceExternalLayout = styled('div')`
 const TraceExternalLayout = styled('div')`
   display: flex;
   display: flex;
   flex-direction: column;
   flex-direction: column;

+ 13 - 0
static/app/views/performance/newTraceDetails/traceRenderers/virtualizedViewManager.tsx

@@ -87,6 +87,7 @@ export class VirtualizedViewManager {
 
 
   // HTML refs that we need to keep track of such
   // HTML refs that we need to keep track of such
   // that rendering can be done programmatically
   // that rendering can be done programmatically
+  reset_zoom_button: HTMLButtonElement | null = null;
   divider: HTMLElement | null = null;
   divider: HTMLElement | null = null;
   container: HTMLElement | null = null;
   container: HTMLElement | null = null;
   horizontal_scrollbar_container: HTMLElement | null = null;
   horizontal_scrollbar_container: HTMLElement | null = null;
@@ -157,6 +158,7 @@ export class VirtualizedViewManager {
       },
       },
     };
     };
 
 
+    this.registerResetZoomRef = this.registerResetZoomRef.bind(this);
     this.registerContainerRef = this.registerContainerRef.bind(this);
     this.registerContainerRef = this.registerContainerRef.bind(this);
     this.registerHorizontalScrollBarContainerRef =
     this.registerHorizontalScrollBarContainerRef =
       this.registerHorizontalScrollBarContainerRef.bind(this);
       this.registerHorizontalScrollBarContainerRef.bind(this);
@@ -334,6 +336,10 @@ export class VirtualizedViewManager {
     }
     }
   }
   }
 
 
+  registerResetZoomRef(ref: HTMLButtonElement | null) {
+    this.reset_zoom_button = ref;
+  }
+
   registerGhostRowRef(column: string, ref: HTMLElement | null) {
   registerGhostRowRef(column: string, ref: HTMLElement | null) {
     if (column === 'list' && ref) {
     if (column === 'list' && ref) {
       const scrollableElement = ref.children[0] as HTMLElement | undefined;
       const scrollableElement = ref.children[0] as HTMLElement | undefined;
@@ -744,6 +750,7 @@ export class VirtualizedViewManager {
     this.recomputeTimelineIntervals();
     this.recomputeTimelineIntervals();
     this.recomputeSpanToPxMatrix();
     this.recomputeSpanToPxMatrix();
     this.enqueueFOVQueryParamSync();
     this.enqueueFOVQueryParamSync();
+    this.syncResetZoomButton();
   }
   }
 
 
   enqueueFOVQueryParamSync() {
   enqueueFOVQueryParamSync() {
@@ -777,6 +784,12 @@ export class VirtualizedViewManager {
     }
     }
   }
   }
 
 
+  syncResetZoomButton() {
+    if (!this.reset_zoom_button) return;
+    this.reset_zoom_button.disabled =
+      this.trace_view.x === 0 && this.trace_view.width === this.trace_space.width;
+  }
+
   onHorizontalScrollbarScroll(_event: Event) {
   onHorizontalScrollbarScroll(_event: Event) {
     if (!this.scrolling_source) {
     if (!this.scrolling_source) {
       this.scrolling_source = 'fake scrollbar';
       this.scrolling_source = 'fake scrollbar';

+ 1 - 0
static/app/views/performance/newTraceDetails/traceShortcuts.tsx → static/app/views/performance/newTraceDetails/traceShortcutsModal.tsx

@@ -16,6 +16,7 @@ export function TraceShortcuts() {
     traceAnalytics.trackViewShortcuts(organization);
     traceAnalytics.trackViewShortcuts(organization);
     openModal(props => <TraceShortcutsModal {...props} />);
     openModal(props => <TraceShortcutsModal {...props} />);
   }, [organization]);
   }, [organization]);
+
   return (
   return (
     <Button size="xs" onClick={onOpenShortcutsClick} aria-label={t('Trace Shortcuts')}>
     <Button size="xs" onClick={onOpenShortcutsClick} aria-label={t('Trace Shortcuts')}>