Skip to content

Commit

Permalink
Merge branch 'release/v3.17.5' into v3.17.5-ImagesUISearchFix
Browse files Browse the repository at this point in the history
  • Loading branch information
jescalada authored Aug 5, 2024
2 parents dd2a7a5 + c57eaf6 commit 028c9c5
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 16 deletions.
11 changes: 8 additions & 3 deletions src/e2e/Dashboard/DashboardContent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,14 @@ test.describe('Dashboard', () => {
const month = date.getUTCMonth() + 1; // getUTCMonth() is zero-based
const day = date.getUTCDate();

const expectedText = `datetime(${year},${month},${day})<=run.created_at<datetime(${year},${month},${
day + 1
})`;
const nextDayDate = new Date(date);
nextDayDate.setUTCDate(day + 1);

const nextYear = nextDayDate.getUTCFullYear();
const nextMonth = nextDayDate.getUTCMonth() + 1; // getUTCMonth() is zero-based
const nextDay = nextDayDate.getUTCDate();

const expectedText = `datetime(${year},${month},${day})<=run.created_at<datetime(${nextYear},${nextMonth},${nextDay})`;

// Locate and click the current day cell in the heatmap
const heatmap = await page.$('.CalendarHeatmap');
Expand Down
3 changes: 3 additions & 0 deletions src/src/components/kit/Card/Card.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ export interface ICardProps {
withSearchBar?: boolean;
calcTableHeight?: boolean;
};
loadMore?: boolean;
loadMoreHandler?: () => void;
loadMoreText?: string;
}
5 changes: 5 additions & 0 deletions src/src/components/kit/Card/Card.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
margin-top: $space-xxxs;
margin-bottom: $space-xxxs;
}
&__loadMoreButton {
margin-top: $space-md;
margin-bottom: $space-sm * -1;
margin-left: 0;
}
}
&__tableWrapper {
height: toRem(356px);
Expand Down
17 changes: 16 additions & 1 deletion src/src/components/kit/Card/Card.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import classNames from 'classnames';

import { Text } from 'components/kit';
import { Button, Text } from 'components/kit';
import DataList from 'components/kit/DataList';

import { ICardProps } from './Card.d';
Expand Down Expand Up @@ -29,6 +29,9 @@ function Card({
className,
dataListProps,
children,
loadMore,
loadMoreHandler,
loadMoreText,
}: ICardProps): React.FunctionComponentElement<React.ReactNode> {
const tableRef = React.useRef<any>(null);

Expand All @@ -48,6 +51,18 @@ function Card({
{subtitle}
</Text>
)}
{loadMore && loadMoreHandler && (
<span>
<Button
onClick={loadMoreHandler}
className='Card__header__loadMoreButton'
color='primary'
variant='contained'
>
{loadMoreText || 'Load More'}
</Button>
</span>
)}
</div>
{children || (
<div className='Card__tableWrapper'>
Expand Down
13 changes: 13 additions & 0 deletions src/src/pages/RunDetail/RunOverviewTab/RunOverviewTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@ function RunOverviewTab({ runData, runHash }: IRunOverviewTabProps) {
const overviewSectionRef = React.useRef<HTMLElement | any>(null);
const overviewSectionContentRef = React.useRef<HTMLElement | any>(null);
const [containerHeight, setContainerHeight] = React.useState<number>(0);
const METRICS_FETCH_COUNT = 500;

const [startIndex, setStartIndex] = React.useState(0);

useRunMetricsBatch({
runTraces: runData.runTraces,
runHash,
startIndex,
count: METRICS_FETCH_COUNT,
});

React.useEffect(() => {
Expand Down Expand Up @@ -71,6 +76,12 @@ function RunOverviewTab({ runData, runHash }: IRunOverviewTabProps) {
sidebarRef?.current?.scrollTo(0, e.target.scrollTop);
}

function fetchMoreMetrics() {
if (runData.runMetricsBatch.length > startIndex + 1) {
setStartIndex((prevIndex) => prevIndex + METRICS_FETCH_COUNT);
}
}

return (
<ErrorBoundary>
<section
Expand Down Expand Up @@ -101,6 +112,8 @@ function RunOverviewTab({ runData, runHash }: IRunOverviewTabProps) {
isLoading={runData?.isRunBatchLoading}
type='metric'
runBatch={cardsData?.runMetricsBatch}
totalMetrics={runData?.runTraces?.metric?.length}
loadMoreHandler={fetchMoreMetrics}
/>
</ErrorBoundary>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ function RunOverviewTabMetricsCard({
isLoading,
runBatch,
type,
totalMetrics = 0,
loadMoreHandler,
}: {
isLoading: boolean;
runBatch: any;
type: 'metric' | 'systemMetric';
totalMetrics?: number;
loadMoreHandler?: () => void;
}) {
const tableData = React.useMemo(() => {
if (runBatch) {
Expand Down Expand Up @@ -49,7 +53,7 @@ function RunOverviewTabMetricsCard({
tint={50}
className='RunOverviewTab__cardBox__tableTitleCount'
>
({runBatch?.length})
({totalMetrics})
</Text>
</Text>
),
Expand Down Expand Up @@ -92,7 +96,7 @@ function RunOverviewTabMetricsCard({
),
},
],
[runBatch],
[totalMetrics],
);

return (
Expand All @@ -116,6 +120,9 @@ function RunOverviewTabMetricsCard({
title: 'No Results',
},
}}
loadMore={loadMoreHandler && totalMetrics > runBatch?.length}
loadMoreHandler={loadMoreHandler}
loadMoreText={`Load More (${runBatch?.length}/${totalMetrics})`}
/>
</ErrorBoundary>
);
Expand Down
35 changes: 25 additions & 10 deletions src/src/pages/RunDetail/hooks/useRunMetricsBatch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,35 @@ import React from 'react';

import runDetailAppModel from 'services/models/runs/runDetailAppModel';

function useRunMetricsBatch({ runTraces, runHash }: any) {
function useRunMetricsBatch({
runTraces,
runHash,
startIndex = 0,
count = 500, // Error occurs if count is greater than 1000
}: {
runTraces: any;
runHash: string;
startIndex?: number;
count?: number;
}) {
React.useEffect(() => {
const runsBatchRequestRef = runDetailAppModel.getRunMetricsBatch(
runTraces.metric,
runHash,
);
const fetchMetricsBatch = () => {
const runsBatchRequestRef = runDetailAppModel.getRunMetricsBatch(
startIndex !== undefined && count
? runTraces.metric.slice(startIndex, startIndex + count)
: runTraces.metric,
runHash,
);

runsBatchRequestRef.call();
runsBatchRequestRef.call();

return () => {
runsBatchRequestRef.abort();
return () => {
runsBatchRequestRef.abort();
};
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [runTraces, runHash]);

fetchMetricsBatch();
}, [runTraces, runHash, startIndex, count]);
}

export default useRunMetricsBatch;

0 comments on commit 028c9c5

Please sign in to comment.