Home / File/ SnapshotCommitListItem.js — react Source File

SnapshotCommitListItem.js — react Source File

Architecture documentation for SnapshotCommitListItem.js, a javascript file in the react codebase. 5 imports, 1 dependents.

File javascript BabelCompiler Validation 5 imports 1 dependents 1 functions

Entity Profile

Dependency Diagram

graph LR
  f9d9b314_a982_02a0_eb8d_ad21d4bcbd3b["SnapshotCommitListItem.js"]
  0f941e70_3fdb_aa42_7939_2878d5d4125b["utils.js"]
  f9d9b314_a982_02a0_eb8d_ad21d4bcbd3b --> 0f941e70_3fdb_aa42_7939_2878d5d4125b
  ca8cf772_1215_be91_d7d6_71a7beaf3771["SnapshotCommitListItem.css"]
  f9d9b314_a982_02a0_eb8d_ad21d4bcbd3b --> ca8cf772_1215_be91_d7d6_71a7beaf3771
  76384bd4_08c7_de17_1f91_2937028def49["SnapshotCommitList.js"]
  f9d9b314_a982_02a0_eb8d_ad21d4bcbd3b --> 76384bd4_08c7_de17_1f91_2937028def49
  ac587885_e294_a1e9_b13f_5e7b920fdb42["react"]
  f9d9b314_a982_02a0_eb8d_ad21d4bcbd3b --> ac587885_e294_a1e9_b13f_5e7b920fdb42
  74ef1e61_51ba_b12a_3785_620fbf571ab2["react-window"]
  f9d9b314_a982_02a0_eb8d_ad21d4bcbd3b --> 74ef1e61_51ba_b12a_3785_620fbf571ab2
  76384bd4_08c7_de17_1f91_2937028def49["SnapshotCommitList.js"]
  76384bd4_08c7_de17_1f91_2937028def49 --> f9d9b314_a982_02a0_eb8d_ad21d4bcbd3b
  style f9d9b314_a982_02a0_eb8d_ad21d4bcbd3b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/**
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 * @flow
 */

import * as React from 'react';
import {memo} from 'react';
import {areEqual} from 'react-window';
import {getGradientColor} from './utils';

import styles from './SnapshotCommitListItem.css';

import type {ItemData} from './SnapshotCommitList';

type Props = {
  data: ItemData,
  index: number,
  style: Object,
  ...
};

function SnapshotCommitListItem({data: itemData, index, style}: Props) {
  const {
    filteredCommitIndices,
    maxDuration,
    selectedCommitIndex,
    selectCommitIndex,
    setHoveredCommitIndex,
    startCommitDrag,
    totalDurations,
  } = itemData;

  index = filteredCommitIndices[index];

  const totalDuration = totalDurations[index];

  // Use natural cbrt for bar height.
  // This prevents one (or a few) outliers from squishing the majority of other commits.
  // So rather than e.g. _█_ we get something more like e.g. ▄█_
  const heightScale =
    Math.min(
      1,
      Math.max(0, Math.cbrt(totalDuration) / Math.cbrt(maxDuration)),
    ) || 0;

  // Use a linear scale for color.
  // This gives some visual contrast between cheaper and more expensive commits
  // and somewhat compensates for the cbrt scale height.
  const colorScale = Math.min(1, Math.max(0, totalDuration / maxDuration)) || 0;

  const isSelected = selectedCommitIndex === index;

  // Leave a 1px gap between snapshots
  const width = parseFloat(style.width) - 1;

  const handleMouseDown = ({buttons, target}: any) => {
    if (buttons === 1) {
      selectCommitIndex(index);
      startCommitDrag({
        commitIndex: index,
        left: target.getBoundingClientRect().left,
        sizeIncrement: parseFloat(style.width),
      });
    }
  };

  let backgroundColor;
  if (!isSelected && totalDuration > 0) {
    backgroundColor = getGradientColor(colorScale);
  }

  return (
    <div
      className={styles.Outer}
      onMouseDown={handleMouseDown}
      onMouseEnter={() => setHoveredCommitIndex(index)}
      style={{
        ...style,
        width,
        borderBottom: isSelected
          ? '3px solid var(--color-tab-selected-border)'
          : undefined,
      }}>
      <div
        className={isSelected ? styles.InnerSelected : styles.Inner}
        style={{
          height: `${Math.round(heightScale * 100)}%`,
          backgroundColor,
        }}
      />
    </div>
  );
}

export default (memo(SnapshotCommitListItem, areEqual): component(
  ...props: Props
));

Domain

Subdomains

Frequently Asked Questions

What does SnapshotCommitListItem.js do?
SnapshotCommitListItem.js is a source file in the react codebase, written in javascript. It belongs to the BabelCompiler domain, Validation subdomain.
What functions are defined in SnapshotCommitListItem.js?
SnapshotCommitListItem.js defines 1 function(s): SnapshotCommitListItem.
What does SnapshotCommitListItem.js depend on?
SnapshotCommitListItem.js imports 5 module(s): SnapshotCommitList.js, SnapshotCommitListItem.css, react, react-window, utils.js.
What files import SnapshotCommitListItem.js?
SnapshotCommitListItem.js is imported by 1 file(s): SnapshotCommitList.js.
Where is SnapshotCommitListItem.js in the architecture?
SnapshotCommitListItem.js is located at packages/react-devtools-shared/src/devtools/views/Profiler/SnapshotCommitListItem.js (domain: BabelCompiler, subdomain: Validation, directory: packages/react-devtools-shared/src/devtools/views/Profiler).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free