Skip to content

Commit

Permalink
fix: correcting typing
Browse files Browse the repository at this point in the history
  • Loading branch information
Francisco2002 committed Nov 4, 2024
1 parent a48b6c0 commit fe97526
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 24 deletions.
36 changes: 19 additions & 17 deletions dashboard/src/hooks/useToast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,35 @@ type ToasterToast = ToastProps & {
action?: ToastActionElement;
};

const actionTypes = {
ADD_TOAST: 'ADD_TOAST',
UPDATE_TOAST: 'UPDATE_TOAST',
DISMISS_TOAST: 'DISMISS_TOAST',
REMOVE_TOAST: 'REMOVE_TOAST',
} as const;

let count = 0;

function genId(): string {
count = (count + 1) % Number.MAX_SAFE_INTEGER;
return count.toString();
}

type ActionType = typeof actionTypes;
enum ActionType {
ADD_TOAST = 'ADD_TOAST',
UPDATE_TOAST = 'UPDATE_TOAST',
DISMISS_TOAST = 'DISMISS_TOAST',
REMOVE_TOAST = 'REMOVE_TOAST',
}

type Action =
| {
type: ActionType['ADD_TOAST'];
type: ActionType.ADD_TOAST;
toast: ToasterToast;
}
| {
type: ActionType['UPDATE_TOAST'];
type: ActionType.UPDATE_TOAST;
toast: Partial<ToasterToast>;
}
| {
type: ActionType['DISMISS_TOAST'];
type: ActionType.DISMISS_TOAST;
toastId?: ToasterToast['id'];
}
| {
type: ActionType['REMOVE_TOAST'];
type: ActionType.REMOVE_TOAST;
toastId?: ToasterToast['id'];
};

Expand All @@ -60,7 +58,7 @@ const addToRemoveQueue = (toastId: string): void => {
const timeout = setTimeout(() => {
toastTimeouts.delete(toastId);
dispatch({
type: 'REMOVE_TOAST',
type: ActionType.REMOVE_TOAST,
toastId: toastId,
});
}, TOAST_REMOVE_DELAY);
Expand Down Expand Up @@ -120,6 +118,8 @@ export const reducer = (state: State, action: Action): State => {
...state,
toasts: state.toasts.filter(t => t.id !== action.toastId),
};
default:
return state;
}
};

Expand Down Expand Up @@ -147,13 +147,14 @@ function toast({ ...props }: Toast): ToastStateProps {

const update = (toastProps: ToasterToast): void =>
dispatch({
type: 'UPDATE_TOAST',
type: ActionType.UPDATE_TOAST,
toast: { ...toastProps, id },
});
const dismiss = (): void => dispatch({ type: 'DISMISS_TOAST', toastId: id });
const dismiss = (): void =>
dispatch({ type: ActionType.DISMISS_TOAST, toastId: id });

dispatch({
type: 'ADD_TOAST',
type: ActionType.ADD_TOAST,
toast: {
...props,
id,
Expand Down Expand Up @@ -193,7 +194,8 @@ function useToast(): UseToastType {
return {
...state,
toast,
dismiss: (toastId?: string) => dispatch({ type: 'DISMISS_TOAST', toastId }),
dismiss: (toastId?: string) =>
dispatch({ type: ActionType.DISMISS_TOAST, toastId }),
};
}

Expand Down
14 changes: 7 additions & 7 deletions dashboard/src/pages/TreeDetails/Tabs/CommitNavigationGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,6 @@ const CommitNavigationGraph = (): JSX.Element => {

const messagesId: MessagesID = useMemo(() => {
switch (currentTreeDetailsTab) {
case 'treeDetails.builds':
return {
graphName: 'treeDetails.buildsHistory',
good: 'treeDetails.validBuilds',
bad: 'treeDetails.invalidBuilds',
mid: 'treeDetails.inconclusiveBuilds',
} as MessagesID;
case 'treeDetails.boots':
return {
graphName: 'treeDetails.bootsHistory',
Expand All @@ -82,6 +75,13 @@ const CommitNavigationGraph = (): JSX.Element => {
bad: 'treeDetails.testsFailed',
mid: 'treeDetails.testsInconclusive',
} as MessagesID;
default:
return {
graphName: 'treeDetails.buildsHistory',
good: 'treeDetails.validBuilds',
bad: 'treeDetails.invalidBuilds',
mid: 'treeDetails.inconclusiveBuilds',
} as MessagesID;
}
}, [currentTreeDetailsTab]);

Expand Down

0 comments on commit fe97526

Please sign in to comment.