Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dashboard): adding dateTime on graphs #332

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 { formatDate } 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) +
' - ' +
formatDate(currentCommitData.earliestStartTime as string, true)
Copy link
Collaborator

@WilsonNet WilsonNet Sep 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

validate instead of using as, you can use z.string.parse().catch()

as is type unsafe, it is for times where you are time constrained

);
}

return `commitIndex-${value}`;
Expand Down
8 changes: 4 additions & 4 deletions dashboard/src/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { format } from 'date-fns';

export function formatDate(date: Date | string): string {
export function formatDate(date: Date | string, short?: boolean): string {
const options: Intl.DateTimeFormatOptions = {
year: 'numeric',
month: 'long',
year: short ? '2-digit' : 'numeric',
month: short ? 'numeric' : 'long',
day: 'numeric',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
timeZoneName: 'short',
timeZoneName: short ? undefined : 'short',
};

if (typeof date === 'string') date = new Date(date);
Expand Down
Loading