Skip to content

Commit

Permalink
feat(dashboard): adding dateTime on graphs
Browse files Browse the repository at this point in the history
Closes #229
  • Loading branch information
Lucas Bracher committed Sep 20, 2024
1 parent 22f3927 commit dda7cfa
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { useTreeCommitHistory } from '@/api/TreeDetails';
import type { TLineChartProps } from '@/components/LineChart/LineChart';
import QuerySwitcher from '@/components/QuerySwitcher/QuerySwitcher';
import { MessagesKey } from '@/locales/messages';
import { formatDateShort } from '@/utils/utils';

const graphDisplaySize = 7;

Expand Down Expand Up @@ -109,6 +110,7 @@ const CommitNavigationGraph = (): JSX.Element => {
type TCommitValue = {
commitHash: string;
commitName?: string;
earliestStartTime?: string;
};

const commitData: TCommitValue[] = [];
Expand Down Expand Up @@ -143,6 +145,7 @@ const CommitNavigationGraph = (): JSX.Element => {
commitData.unshift({
commitHash: item.git_commit_hash,
commitName: item.git_commit_name,
earliestStartTime: item.earliest_start_time,
});
xAxisIndexes.push(index);
});
Expand All @@ -155,7 +158,11 @@ const CommitNavigationGraph = (): JSX.Element => {
valueFormatter: (value: number, context): string => {
if (context.location == 'tooltip') {
const currentCommitData = commitData[value];
return currentCommitData.commitName ?? currentCommitData.commitHash;
return (
(currentCommitData.commitName ?? currentCommitData.commitHash) +
' - ' +
formatDateShort(currentCommitData.earliestStartTime as string)
);
}

return `commitIndex-${value}`;
Expand Down
16 changes: 16 additions & 0 deletions dashboard/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,22 @@ export function formatDate(date: Date | string): string {
return new Intl.DateTimeFormat('en-US', options).format(date);
}

export function formatDateShort(date: Date | string): string {
const options: Intl.DateTimeFormatOptions = {
year: '2-digit',
month: 'numeric',
day: 'numeric',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
};

if (typeof date === 'string') date = new Date(date);
if (isNaN(date.getTime())) return '-';

return new Intl.DateTimeFormat('en-US', options).format(date);
}

export const getDateOffset = (date: Date): string => {
return format(date, 'z');
};

0 comments on commit dda7cfa

Please sign in to comment.