import React, { useEffect } from 'react';
import { useAppDispatch, useAppSelector } from '@webapp/redux/hooks';
import Box from '@webapp/ui/Box';
import {
fetchDiffView,
selectContinuousState,
actions,
fetchTagValues,
selectQueries,
selectTimelineSides,
selectAnnotationsOrDefault,
} from '@webapp/redux/reducers/continuous';
import { FlamegraphRenderer } from '@pyroscope/flamegraph/src/FlamegraphRenderer';
import usePopulateLeftRightQuery from '@webapp/hooks/populateLeftRightQuery.hook';
import useTimelines, {
leftColor,
rightColor,
selectionColor,
} from '@webapp/hooks/timeline.hook';
import useTimeZone from '@webapp/hooks/timeZone.hook';
import useColorMode from '@webapp/hooks/colorMode.hook';
import useTags from '@webapp/hooks/tags.hook';
import Toolbar from '@webapp/components/Toolbar';
import TagsBar from '@webapp/components/TagsBar';
import TimelineChartWrapper from '@webapp/components/TimelineChart/TimelineChartWrapper';
import SyncTimelines from '@webapp/components/TimelineChart/SyncTimelines';
import useExportToFlamegraphDotCom from '@webapp/components/exportToFlamegraphDotCom.hook';
import { LoadingOverlay } from '@webapp/ui/LoadingOverlay';
import ExportData from '@webapp/components/ExportData';
import ChartTitle from '@webapp/components/ChartTitle';
import { isExportToFlamegraphDotComEnabled } from '@webapp/util/features';
import PageTitle from '@webapp/components/PageTitle';
import { formatTitle } from './formatTitle';
import { isLoadingOrReloading } from './loading';
function ComparisonDiffApp() {
const dispatch = useAppDispatch();
const { colorMode } = useColorMode();
const {
diffView,
refreshToken,
maxNodes,
leftFrom,
rightFrom,
leftUntil,
rightUntil,
} = useAppSelector(selectContinuousState);
const { leftQuery, rightQuery } = useAppSelector(selectQueries);
const annotations = useAppSelector(selectAnnotationsOrDefault('diffView'));
usePopulateLeftRightQuery();
const { leftTags, rightTags } = useTags();
const { leftTimeline, rightTimeline } = useTimelines();
const timelines = useAppSelector(selectTimelineSides);
const exportToFlamegraphDotComFn = useExportToFlamegraphDotCom(
diffView.profile
);
const { offset } = useTimeZone();
const timezone = offset === 0 ? 'utc' : 'browser';
const isLoading = isLoadingOrReloading([
diffView.type,
timelines.left.type,
timelines.right.type,
]);
useEffect(() => {
if (rightQuery && leftQuery) {
const fetchData = dispatch(
fetchDiffView({
leftQuery,
leftFrom,
leftUntil,
rightQuery,
rightFrom,
rightUntil,
})
);
return fetchData.abort;
}
return undefined;
}, [
leftFrom,
leftUntil,
leftQuery,
rightFrom,
rightUntil,
rightQuery,
refreshToken,
maxNodes,
]);
const exportData = diffView.profile && (