Fix async/await usage in code

This commit is contained in:
Simon Larsen
2024-02-27 16:21:37 +00:00
parent ac9442e085
commit 5876aba680
12 changed files with 48 additions and 25 deletions

View File

@@ -47,7 +47,9 @@ const ModelDetail: <TBaseModel extends BaseModel>(
JSONObject | undefined
>(undefined);
const getSelectFields: Function = (): Select<TBaseModel> => {
type GetSelectFields = () => Select<TBaseModel>;
const getSelectFields: GetSelectFields = (): Select<TBaseModel> => {
const select: Select<TBaseModel> = {};
for (const field of props.fields) {
const key: string | null = field.field

View File

@@ -63,11 +63,15 @@ const ModelList: <TBaseModel extends BaseModel>(
}, [selectedList]);
useEffect(() => {
fetchItems().catch();
fetchItems().catch((err: Error) => {
setError(API.getFriendlyMessage(err));
});
}, [props.refreshToggle]);
useEffect(() => {
fetchItems().catch();
fetchItems().catch((err: Error) => {
setError(API.getFriendlyMessage(err));
});
}, []);
useEffect(() => {
@@ -256,13 +260,13 @@ const ModelList: <TBaseModel extends BaseModel>(
},
});
fetchItems();
await fetchItems();
}}
titleField={props.titleField}
onDelete={
props.isDeleteable
? async (item: TBaseModel) => {
deleteItem(item);
await deleteItem(item);
}
: undefined
}

View File

@@ -45,9 +45,11 @@ const ModelProgress: <TBaseModel extends BaseModel>(
};
useEffect(() => {
setIsLoading(true);
fetchCount();
setIsLoading(false);
fetchCount().catch((err: Error) => {
setError(API.getFriendlyMessage(err));
});
}, []);
return (

View File

@@ -630,7 +630,9 @@ const BaseModelTable: <TBaseModel extends BaseModel | AnalyticsBaseModel>(
useEffect(() => {
if (showTableFilter) {
getFilterDropdownItems();
getFilterDropdownItems().catch((err: Error) => {
setTableFilterError(API.getFriendlyMessage(err));
});
}
}, [showTableFilter]);
@@ -769,7 +771,9 @@ const BaseModelTable: <TBaseModel extends BaseModel | AnalyticsBaseModel>(
};
useEffect(() => {
fetchItems();
fetchItems().catch((err: Error) => {
setError(API.getFriendlyMessage(err));
});
}, [
currentPageNumber,
sortBy,
@@ -1182,8 +1186,8 @@ const BaseModelTable: <TBaseModel extends BaseModel | AnalyticsBaseModel>(
props.orderedStatesListProps.shouldAddItemInTheEnd
}
noItemsMessage={props.noItemsMessage || ''}
onRefreshClick={() => {
fetchItems();
onRefreshClick={async () => {
await fetchItems();
}}
onCreateNewItem={
props.isCreateable
@@ -1229,7 +1233,7 @@ const BaseModelTable: <TBaseModel extends BaseModel | AnalyticsBaseModel>(
},
});
fetchItems();
await fetchItems();
}}
dragDropIdField={'_id'}
dragDropIndexField={props.dragDropIndexField}
@@ -1248,15 +1252,17 @@ const BaseModelTable: <TBaseModel extends BaseModel | AnalyticsBaseModel>(
setItemsOnPage(itemsOnPage);
}}
noItemsMessage={props.noItemsMessage || ''}
onRefreshClick={() => {
fetchItems();
onRefreshClick={async () => {
await fetchItems();
}}
actionButtons={actionButtonSchema}
/>
);
};
const getCardTitle: Function = (
type GetCardTitleFunction = (title: ReactElement | string) => ReactElement;
const getCardTitle: GetCardTitleFunction = (
title: ReactElement | string
): ReactElement => {
const plan: PlanSelect | null = ProjectUtil.getCurrentPlan();

View File

@@ -14,7 +14,9 @@ describe('Card', () => {
description: 'description',
};
const renderComponent: Function = (props: ComponentProps): void => {
type RenderComponentFunction = (props: ComponentProps) => void;
const renderComponent: RenderComponentFunction = (props: ComponentProps): void => {
render(<Card {...props} />);
};

View File

@@ -165,8 +165,8 @@ const Layers: FunctionComponent<ComponentProps> = (
<Button
title="Add New Layer"
isLoading={isAddbuttonLoading}
onClick={() => {
addLayer();
onClick={async () => {
await addLayer();
}}
icon={IconProp.Add}
/>

View File

@@ -25,6 +25,7 @@ import ErrorMessage from 'CommonUI/src/Components/ErrorMessage/ErrorMessage';
import Statusbubble from 'CommonUI/src/Components/StatusBubble/StatusBubble';
import Color from 'Common/Types/Color';
import BaseModel from 'Common/Models/BaseModel';
import { PromiseVoidFunction } from 'Common/Types/FunctionTypes';
const MonitorGroupResources: FunctionComponent<PageComponentProps> = (
props: PageComponentProps

View File

@@ -47,6 +47,7 @@ import ResellerPlan from 'Model/Models/ResellerPlan';
import ErrorMessage from 'CommonUI/src/Components/ErrorMessage/ErrorMessage';
import Icon from 'CommonUI/src/Components/Icon/Icon';
import { GetReactElementFunction } from 'CommonUI/src/Types/FunctionTypes';
import { PromiseVoidFunction } from 'Common/Types/FunctionTypes';
export interface ComponentProps extends PageComponentProps {}

View File

@@ -80,7 +80,9 @@ const StatusPageDelete: FunctionComponent<PageComponentProps> = (
};
useEffect(() => {
fetchGroups();
fetchGroups().catch((err) => {
setError(API.getFriendlyMessage(err));
});
}, []);
const getFooterForMonitor: GetReactElementFunction = (): ReactElement => {

View File

@@ -60,7 +60,7 @@ router.post(
res: ExpressResponse,
next: NextFunction
): Promise<void> => {
await processIncomingRequest(req, res, next);
processIncomingRequest(req, res, next);
}
);
@@ -71,7 +71,7 @@ router.get(
res: ExpressResponse,
next: NextFunction
): Promise<void> => {
await processIncomingRequest(req, res, next);
processIncomingRequest(req, res, next);
}
);

View File

@@ -19,4 +19,7 @@ const main: PromiseVoidFunction = async (): Promise<void> => {
}
};
main();
main().catch((err: Error) => {
//eslint-disable-next-line no-console
console.error(err);
});

View File

@@ -21,7 +21,7 @@ router.get(
res: ExpressResponse,
next: NextFunction
): Promise<void> => {
await returnResponse(req, res, next);
returnResponse(req, res, next);
}
);
@@ -32,7 +32,7 @@ router.post(
res: ExpressResponse,
next: NextFunction
): Promise<void> => {
await returnResponse(req, res, next);
returnResponse(req, res, next);
}
);