diff --git a/CommonServer/Types/FunctionTypes.ts b/CommonServer/Types/FunctionTypes.ts index b178017ffd..5a2d28cd93 100644 --- a/CommonServer/Types/FunctionTypes.ts +++ b/CommonServer/Types/FunctionTypes.ts @@ -1,7 +1,11 @@ -import { ExpressRequest, ExpressResponse, NextFunction } from "../Utils/Express"; +import { + ExpressRequest, + ExpressResponse, + NextFunction, +} from '../Utils/Express'; export type ExpressAPIFunctionType = ( req: ExpressRequest, res: ExpressResponse, next: NextFunction -) => Promise; \ No newline at end of file +) => Promise; diff --git a/CommonUI/src/Components/Forms/Fields/FormField.tsx b/CommonUI/src/Components/Forms/Fields/FormField.tsx index bed8109bf2..47bd5cedcc 100644 --- a/CommonUI/src/Components/Forms/Fields/FormField.tsx +++ b/CommonUI/src/Components/Forms/Fields/FormField.tsx @@ -28,7 +28,10 @@ import CategoryCheckbox from '../../CategoryCheckbox/Index'; import Typeof from 'Common/Types/Typeof'; import Modal from '../../Modal/Modal'; import Link from '../../Link/Link'; -import { GetReactElementFunctionType, GetReactElementOrStringFunctionType } from '../../../Types/FunctionTypes'; +import { + GetReactElementFunctionType, + GetReactElementOrStringFunctionType, +} from '../../../Types/FunctionTypes'; export interface ComponentProps { field: Field; @@ -193,7 +196,9 @@ const FormField: ( OneUptimeDate.getCurrentTimezoneString(); } - const getFieldDescription: GetReactElementOrStringFunctionType = (): ReactElement | string => { + const getFieldDescription: GetReactElementOrStringFunctionType = (): + | ReactElement + | string => { if ( props.field.fieldType === FormFieldSchemaType.MultiSelectDropdown && diff --git a/CommonUI/src/Components/ModelTable/BaseModelTable.tsx b/CommonUI/src/Components/ModelTable/BaseModelTable.tsx index dc1a17ac38..6ad46680f6 100644 --- a/CommonUI/src/Components/ModelTable/BaseModelTable.tsx +++ b/CommonUI/src/Components/ModelTable/BaseModelTable.tsx @@ -68,7 +68,6 @@ import AnalyticsBaseModel, { } from 'Common/AnalyticsModels/BaseModel'; import Sort from '../../Utils/BaseDatabase/Sort'; import { FormProps } from '../Forms/BasicForm'; -import { PromiseVoidFunctionType } from 'Common/Types/FunctionTypes'; export enum ShowTableAs { Table, @@ -475,7 +474,7 @@ const BaseModelTable: ( setColumns(columns); }; - const getFilterDropdownItems: PromiseVoidFunctionType = async (): Promise => { + const getFilterDropdownItems: Function = async () => { setTableFilterError(''); setIsTableFilterFetchLoading(true); @@ -568,7 +567,7 @@ const BaseModelTable: ( setIsTableFilterFetchLoading(false); }; - const fetchItems: PromiseVoidFunctionType = async (): Promise => { + const fetchItems: Function = async () => { setError(''); setIsLoading(true); @@ -1102,76 +1101,77 @@ const BaseModelTable: ( ); }; - const getOrderedStatesList: GetReactElementFunctionType = (): ReactElement => { - if (!props.orderedStatesListProps) { - throw new BadDataException( - 'props.orderedStatesListProps required when showTableAs === ShowTableAs.OrderedStatesList' + const getOrderedStatesList: GetReactElementFunctionType = + (): ReactElement => { + if (!props.orderedStatesListProps) { + throw new BadDataException( + 'props.orderedStatesListProps required when showTableAs === ShowTableAs.OrderedStatesList' + ); + } + + let getTitleElement: + | (( + item: JSONObject, + onBeforeFetchData?: JSONObject | undefined + ) => ReactElement) + | undefined = undefined; + let getDescriptionElement: + | ((item: JSONObject) => ReactElement) + | undefined = undefined; + + for (const column of props.columns) { + const key: string | undefined = Object.keys( + column.field as Object + )[0]; + + if (key === props.orderedStatesListProps.titleField) { + getTitleElement = column.getElement; + } + + if (key === props.orderedStatesListProps.descriptionField) { + getDescriptionElement = column.getElement; + } + } + + return ( + { + fetchItems(); + }} + onCreateNewItem={ + props.isCreateable + ? (order: number) => { + setOrderedStatesListNewItemOrder(order); + setModalType(ModalType.Create); + setShowModal(true); + } + : undefined + } + singularLabel={ + props.singularName || model.singularName || 'Item' + } + actionButtons={actionButtonSchema} + getTitleElement={getTitleElement} + getDescriptionElement={getDescriptionElement} + /> ); - } - - let getTitleElement: - | (( - item: JSONObject, - onBeforeFetchData?: JSONObject | undefined - ) => ReactElement) - | undefined = undefined; - let getDescriptionElement: - | ((item: JSONObject) => ReactElement) - | undefined = undefined; - - for (const column of props.columns) { - const key: string | undefined = Object.keys( - column.field as Object - )[0]; - - if (key === props.orderedStatesListProps.titleField) { - getTitleElement = column.getElement; - } - - if (key === props.orderedStatesListProps.descriptionField) { - getDescriptionElement = column.getElement; - } - } - - return ( - { - fetchItems(); - }} - onCreateNewItem={ - props.isCreateable - ? (order: number) => { - setOrderedStatesListNewItemOrder(order); - setModalType(ModalType.Create); - setShowModal(true); - } - : undefined - } - singularLabel={ - props.singularName || model.singularName || 'Item' - } - actionButtons={actionButtonSchema} - getTitleElement={getTitleElement} - getDescriptionElement={getDescriptionElement} - /> - ); - }; + }; const getList: GetReactElementFunctionType = (): ReactElement => { return ( diff --git a/CommonUI/src/Types/FunctionTypes.ts b/CommonUI/src/Types/FunctionTypes.ts index 04351ea8f8..154ada231f 100644 --- a/CommonUI/src/Types/FunctionTypes.ts +++ b/CommonUI/src/Types/FunctionTypes.ts @@ -1,5 +1,5 @@ -import { ReactElement } from "react"; +import { ReactElement } from 'react'; export type GetReactElementFunctionType = () => ReactElement; -export type GetReactElementOrStringFunctionType = () => ReactElement | string; \ No newline at end of file +export type GetReactElementOrStringFunctionType = () => ReactElement | string; diff --git a/Dashboard/src/Components/OnCallPolicy/OnCallScheduleLayer/RestrictionTimesFieldElement.tsx b/Dashboard/src/Components/OnCallPolicy/OnCallScheduleLayer/RestrictionTimesFieldElement.tsx index 20b0f45368..6a3d233745 100644 --- a/Dashboard/src/Components/OnCallPolicy/OnCallScheduleLayer/RestrictionTimesFieldElement.tsx +++ b/Dashboard/src/Components/OnCallPolicy/OnCallScheduleLayer/RestrictionTimesFieldElement.tsx @@ -40,200 +40,210 @@ const RestrictionTimesFieldElement: FunctionComponent = ( } }, [props.value]); - const getDailyRestriction: GetReactElementFunctionType = (): ReactElement => { - // show start time to end time input fields + const getDailyRestriction: GetReactElementFunctionType = + (): ReactElement => { + // show start time to end time input fields - return ( -
-
- - { - let date: Date = OneUptimeDate.getCurrentDate(); + return ( +
+
+ + { + let date: Date = OneUptimeDate.getCurrentDate(); - if (value instanceof Date) { - date = value; - } + if (value instanceof Date) { + date = value; + } - if (typeof value === Typeof.String) { - date = OneUptimeDate.fromString(value); - } + if (typeof value === Typeof.String) { + date = OneUptimeDate.fromString(value); + } - let tempRestrictionTimes: - | RestrictionTimes - | undefined = restrictionTimes; + let tempRestrictionTimes: + | RestrictionTimes + | undefined = restrictionTimes; - if (!tempRestrictionTimes) { - tempRestrictionTimes = new RestrictionTimes(); - } + if (!tempRestrictionTimes) { + tempRestrictionTimes = + new RestrictionTimes(); + } - if (!tempRestrictionTimes.dayRestrictionTimes) { - tempRestrictionTimes.dayRestrictionTimes = { - startTime: date, - endTime: date, - }; - } + if (!tempRestrictionTimes.dayRestrictionTimes) { + tempRestrictionTimes.dayRestrictionTimes = { + startTime: date, + endTime: date, + }; + } - tempRestrictionTimes.dayRestrictionTimes.startTime = - date; + tempRestrictionTimes.dayRestrictionTimes.startTime = + date; - updateRestrictionTimes(tempRestrictionTimes); - }} - /> + updateRestrictionTimes(tempRestrictionTimes); + }} + /> +
+
+ + { + let date: Date = OneUptimeDate.getCurrentDate(); + + if (value instanceof Date) { + date = value; + } + + if (typeof value === Typeof.String) { + date = OneUptimeDate.fromString(value); + } + + let tempRestrictionTimes: + | RestrictionTimes + | undefined = restrictionTimes; + + if (!tempRestrictionTimes) { + tempRestrictionTimes = + new RestrictionTimes(); + } + + if (!tempRestrictionTimes.dayRestrictionTimes) { + tempRestrictionTimes.dayRestrictionTimes = { + startTime: date, + endTime: date, + }; + } + + tempRestrictionTimes.dayRestrictionTimes.endTime = + date; + + updateRestrictionTimes(tempRestrictionTimes); + }} + /> +
+ ); + }; + + const getWeeklyTimeRestrictions: GetReactElementFunctionType = + (): ReactElement => { + return (
- - { - let date: Date = OneUptimeDate.getCurrentDate(); +
+ {/** LIST */} - if (value instanceof Date) { - date = value; - } + {restrictionTimes?.weeklyRestrictionTimes?.map( + ( + weeklyRestriction: WeeklyResctriction, + i: number + ) => { + return ( +
+
+ {getWeeklyTimeRestriction({ + weeklyRestriction, + onChange: ( + value: WeeklyResctriction + ) => { + let tempRestrictionTimes: + | RestrictionTimes + | undefined = restrictionTimes; - if (typeof value === Typeof.String) { - date = OneUptimeDate.fromString(value); - } + if (!tempRestrictionTimes) { + tempRestrictionTimes = + new RestrictionTimes(); + } - let tempRestrictionTimes: - | RestrictionTimes - | undefined = restrictionTimes; + if ( + !tempRestrictionTimes.weeklyRestrictionTimes + ) { + tempRestrictionTimes.weeklyRestrictionTimes = + []; + } - if (!tempRestrictionTimes) { - tempRestrictionTimes = new RestrictionTimes(); - } + tempRestrictionTimes.weeklyRestrictionTimes[ + i + ] = value; - if (!tempRestrictionTimes.dayRestrictionTimes) { - tempRestrictionTimes.dayRestrictionTimes = { - startTime: date, - endTime: date, - }; - } + updateRestrictionTimes( + tempRestrictionTimes + ); + }, + onDelete: () => { + let tempRestrictionTimes: + | RestrictionTimes + | undefined = restrictionTimes; - tempRestrictionTimes.dayRestrictionTimes.endTime = - date; + if (!tempRestrictionTimes) { + tempRestrictionTimes = + new RestrictionTimes(); + } - updateRestrictionTimes(tempRestrictionTimes); - }} - /> -
-
- ); - }; + if ( + !tempRestrictionTimes.weeklyRestrictionTimes + ) { + tempRestrictionTimes.weeklyRestrictionTimes = + []; + } - const getWeeklyTimeRestrictions: GetReactElementFunctionType = (): ReactElement => { - return ( -
-
- {/** LIST */} + tempRestrictionTimes.weeklyRestrictionTimes.splice( + i, + 1 + ); - {restrictionTimes?.weeklyRestrictionTimes?.map( - (weeklyRestriction: WeeklyResctriction, i: number) => { - return ( -
-
- {getWeeklyTimeRestriction({ - weeklyRestriction, - onChange: ( - value: WeeklyResctriction - ) => { - let tempRestrictionTimes: - | RestrictionTimes - | undefined = restrictionTimes; - - if (!tempRestrictionTimes) { - tempRestrictionTimes = - new RestrictionTimes(); - } - - if ( - !tempRestrictionTimes.weeklyRestrictionTimes - ) { - tempRestrictionTimes.weeklyRestrictionTimes = - []; - } - - tempRestrictionTimes.weeklyRestrictionTimes[ - i - ] = value; - - updateRestrictionTimes( - tempRestrictionTimes - ); - }, - onDelete: () => { - let tempRestrictionTimes: - | RestrictionTimes - | undefined = restrictionTimes; - - if (!tempRestrictionTimes) { - tempRestrictionTimes = - new RestrictionTimes(); - } - - if ( - !tempRestrictionTimes.weeklyRestrictionTimes - ) { - tempRestrictionTimes.weeklyRestrictionTimes = - []; - } - - tempRestrictionTimes.weeklyRestrictionTimes.splice( - i, - 1 - ); - - updateRestrictionTimes( - tempRestrictionTimes - ); - }, - })} + updateRestrictionTimes( + tempRestrictionTimes + ); + }, + })} +
-
- ); - } - )} -
- -
- {/** show add button */} -
- if (!tempRestrictionTimes.weeklyRestrictionTimes) { - tempRestrictionTimes.weeklyRestrictionTimes = - []; - } +
+ {/** show add button */} +
-
- ); - }; + ); + }; const getWeeklyTimeRestriction: Function = (params: { weeklyRestriction: WeeklyResctriction; diff --git a/Dashboard/src/Pages/StatusPages/View/Resources.tsx b/Dashboard/src/Pages/StatusPages/View/Resources.tsx index 83371d9a6b..e78ab2fa65 100644 --- a/Dashboard/src/Pages/StatusPages/View/Resources.tsx +++ b/Dashboard/src/Pages/StatusPages/View/Resources.tsx @@ -12,7 +12,6 @@ import ObjectID from 'Common/Types/ObjectID'; import StatusPageResource, { UptimePrecision, } from 'Model/Models/StatusPageResource'; -import { PromiseVoidFunctionType } from 'Common/Types/FunctionTypes'; import FieldType from 'CommonUI/src/Components/Types/FieldType'; import FormFieldSchemaType from 'CommonUI/src/Components/Forms/Types/FormFieldSchemaType'; import ModelTable from 'CommonUI/src/Components/ModelTable/ModelTable'; @@ -46,7 +45,7 @@ const StatusPageDelete: FunctionComponent = ( const [addMonitorGroup, setAddMonitorGroup] = useState(false); - const fetchGroups: PromiseVoidFunctionType = async (): Promise => { + const fetchGroups: Function = async () => { setError(''); setIsLoading(true); @@ -82,38 +81,39 @@ const StatusPageDelete: FunctionComponent = ( fetchGroups(); }, []); - const getFooterForMonitor: GetReactElementFunctionType = (): ReactElement => { - if (props.currentProject?.isFeatureFlagMonitorGroupsEnabled) { - if (!addMonitorGroup) { + const getFooterForMonitor: GetReactElementFunctionType = + (): ReactElement => { + if (props.currentProject?.isFeatureFlagMonitorGroupsEnabled) { + if (!addMonitorGroup) { + return ( + { + setAddMonitorGroup(true); + }} + className="mt-1 text-sm text-gray-500 underline" + > +
+

Add a Monitor Group instead.

+
+ + ); + } return ( { - setAddMonitorGroup(true); + setAddMonitorGroup(false); }} className="mt-1 text-sm text-gray-500 underline" >
-

Add a Monitor Group instead.

+

Add a Monitor instead.

); } - return ( - { - setAddMonitorGroup(false); - }} - className="mt-1 text-sm text-gray-500 underline" - > -
-

Add a Monitor instead.

-
- - ); - } - return <>; - }; + return <>; + }; let formFields: Array> = [ { diff --git a/Dashboard/src/Pages/Workflow/View/Builder.tsx b/Dashboard/src/Pages/Workflow/View/Builder.tsx index 6051910f7d..4f65f8cf8a 100644 --- a/Dashboard/src/Pages/Workflow/View/Builder.tsx +++ b/Dashboard/src/Pages/Workflow/View/Builder.tsx @@ -180,7 +180,12 @@ const Delete: FunctionComponent = ( setIsLoading(false); }; - const saveGraph: Function = async ( + type SaveGraphFunctionType = ( + nodes: Array, + edges: Array + ) => Promise; + + const saveGraph: SaveGraphFunctionType = async ( nodes: Array, edges: Array ): Promise => { diff --git a/Ingestor/API/IncomingRequest.ts b/Ingestor/API/IncomingRequest.ts index 000b4cf0b4..ae299a9ebd 100644 --- a/Ingestor/API/IncomingRequest.ts +++ b/Ingestor/API/IncomingRequest.ts @@ -12,7 +12,7 @@ import { JSONObject } from 'Common/Types/JSON'; import ObjectID from 'Common/Types/ObjectID'; import IncomingMonitorRequest from 'Common/Types/Monitor/IncomingMonitor/IncomingMonitorRequest'; import OneUptimeDate from 'Common/Types/Date'; -import {ExpressAPIFunctionType} from 'CommonServer/Types/FunctionTypes'; +import { ExpressAPIFunctionType } from 'CommonServer/Types/FunctionTypes'; const router: ExpressRouter = Express.getRouter(); diff --git a/StatusPage/src/Pages/Incidents/Detail.tsx b/StatusPage/src/Pages/Incidents/Detail.tsx index 72aa50748e..f58c5027fe 100644 --- a/StatusPage/src/Pages/Incidents/Detail.tsx +++ b/StatusPage/src/Pages/Incidents/Detail.tsx @@ -44,21 +44,22 @@ import Label from 'Model/Models/Label'; import Dictionary from 'Common/Types/Dictionary'; type GetIncidentEventItemFunctionProps = { - incident: Incident, - incidentPublicNotes: Array, - incidentStateTimelines: Array, - statusPageResources: Array, - monitorsInGroup: Dictionary>, - isPreviewPage: boolean, - isSummary: boolean + incident: Incident; + incidentPublicNotes: Array; + incidentStateTimelines: Array; + statusPageResources: Array; + monitorsInGroup: Dictionary>; + isPreviewPage: boolean; + isSummary: boolean; }; type GetIncidentEventItemFunctionType = ( - props: GetIncidentEventItemFunctionProps + props: GetIncidentEventItemFunctionProps ) => EventItemComponentProps; -export const getIncidentEventItem: GetIncidentEventItemFunctionType = (props: GetIncidentEventItemFunctionProps): EventItemComponentProps => { - +export const getIncidentEventItem: GetIncidentEventItemFunctionType = ( + props: GetIncidentEventItemFunctionProps +): EventItemComponentProps => { const { incident, incidentPublicNotes, diff --git a/TestServer/API/Main.ts b/TestServer/API/Main.ts index bfeee29969..20354e2e7d 100644 --- a/TestServer/API/Main.ts +++ b/TestServer/API/Main.ts @@ -10,7 +10,7 @@ import Sleep from 'Common/Types/Sleep'; import Typeof from 'Common/Types/Typeof'; import { JSONValue } from 'Common/Types/JSON'; import logger from 'CommonServer/Utils/Logger'; -import {ExpressAPIFunctionType} from 'CommonServer/Types/FunctionTypes'; +import { ExpressAPIFunctionType } from 'CommonServer/Types/FunctionTypes'; const router: ExpressRouter = Express.getRouter();