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 a644b13 commit d8e9bcd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
34 changes: 19 additions & 15 deletions dashboard/src/hooks/useToast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,28 @@ function genId(): string {
return count.toString();
}

type ActionType = {
ADD_TOAST: 'ADD_TOAST';
UPDATE_TOAST: 'UPDATE_TOAST';
DISMISS_TOAST: 'DISMISS_TOAST';
REMOVE_TOAST: 'REMOVE_TOAST';
};
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 @@ -58,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 @@ -118,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 @@ -145,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 @@ -191,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 d8e9bcd

Please sign in to comment.