Fix import formatting in various files

This commit is contained in:
Simon Larsen
2024-02-27 12:43:50 +00:00
parent 5da560f533
commit ac59d9fe2b
10 changed files with 307 additions and 282 deletions

View File

@@ -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<void>;
) => Promise<void>;

View File

@@ -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<T extends Object> {
field: Field<T>;
@@ -193,7 +196,9 @@ const FormField: <T extends Object>(
OneUptimeDate.getCurrentTimezoneString();
}
const getFieldDescription: GetReactElementOrStringFunctionType = (): ReactElement | string => {
const getFieldDescription: GetReactElementOrStringFunctionType = ():
| ReactElement
| string => {
if (
props.field.fieldType ===
FormFieldSchemaType.MultiSelectDropdown &&

View File

@@ -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: <TBaseModel extends BaseModel | AnalyticsBaseModel>(
setColumns(columns);
};
const getFilterDropdownItems: PromiseVoidFunctionType = async (): Promise<void> => {
const getFilterDropdownItems: Function = async () => {
setTableFilterError('');
setIsTableFilterFetchLoading(true);
@@ -568,7 +567,7 @@ const BaseModelTable: <TBaseModel extends BaseModel | AnalyticsBaseModel>(
setIsTableFilterFetchLoading(false);
};
const fetchItems: PromiseVoidFunctionType = async (): Promise<void> => {
const fetchItems: Function = async () => {
setError('');
setIsLoading(true);
@@ -1102,76 +1101,77 @@ const BaseModelTable: <TBaseModel extends BaseModel | AnalyticsBaseModel>(
);
};
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 (
<OrderedStatesList
error={error}
isLoading={isLoading}
data={props.callbacks.toJSONArray(data)}
id={props.id}
titleField={props.orderedStatesListProps?.titleField || ''}
descriptionField={
props.orderedStatesListProps?.descriptionField || ''
}
orderField={props.orderedStatesListProps?.orderField || ''}
shouldAddItemInTheBeginning={
props.orderedStatesListProps.shouldAddItemInTheBeginning
}
shouldAddItemInTheEnd={
props.orderedStatesListProps.shouldAddItemInTheEnd
}
noItemsMessage={props.noItemsMessage || ''}
onRefreshClick={() => {
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 (
<OrderedStatesList
error={error}
isLoading={isLoading}
data={props.callbacks.toJSONArray(data)}
id={props.id}
titleField={props.orderedStatesListProps?.titleField || ''}
descriptionField={
props.orderedStatesListProps?.descriptionField || ''
}
orderField={props.orderedStatesListProps?.orderField || ''}
shouldAddItemInTheBeginning={
props.orderedStatesListProps.shouldAddItemInTheBeginning
}
shouldAddItemInTheEnd={
props.orderedStatesListProps.shouldAddItemInTheEnd
}
noItemsMessage={props.noItemsMessage || ''}
onRefreshClick={() => {
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 (

View File

@@ -1,5 +1,5 @@
import { ReactElement } from "react";
import { ReactElement } from 'react';
export type GetReactElementFunctionType = () => ReactElement;
export type GetReactElementOrStringFunctionType = () => ReactElement | string;
export type GetReactElementOrStringFunctionType = () => ReactElement | string;

View File

@@ -40,200 +40,210 @@ const RestrictionTimesFieldElement: FunctionComponent<ComponentProps> = (
}
}, [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 (
<div className="flex space-x-3">
<div>
<FieldLabelElement title="From:" />
<Input
type={InputType.TIME}
value={OneUptimeDate.toString(
restrictionTimes?.dayRestrictionTimes?.startTime
)}
onChange={(value: any) => {
let date: Date = OneUptimeDate.getCurrentDate();
return (
<div className="flex space-x-3">
<div>
<FieldLabelElement title="From:" />
<Input
type={InputType.TIME}
value={OneUptimeDate.toString(
restrictionTimes?.dayRestrictionTimes?.startTime
)}
onChange={(value: any) => {
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);
}}
/>
</div>
<div>
<FieldLabelElement title="To:" />
<Input
type={InputType.TIME}
value={OneUptimeDate.toString(
restrictionTimes?.dayRestrictionTimes?.endTime
)}
onChange={(value: any) => {
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);
}}
/>
</div>
</div>
);
};
const getWeeklyTimeRestrictions: GetReactElementFunctionType =
(): ReactElement => {
return (
<div>
<FieldLabelElement title="To:" />
<Input
type={InputType.TIME}
value={OneUptimeDate.toString(
restrictionTimes?.dayRestrictionTimes?.endTime
)}
onChange={(value: any) => {
let date: Date = OneUptimeDate.getCurrentDate();
<div className="ml-8">
{/** LIST */}
if (value instanceof Date) {
date = value;
}
{restrictionTimes?.weeklyRestrictionTimes?.map(
(
weeklyRestriction: WeeklyResctriction,
i: number
) => {
return (
<div key={i} className="flex">
<div>
{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);
}}
/>
</div>
</div>
);
};
if (
!tempRestrictionTimes.weeklyRestrictionTimes
) {
tempRestrictionTimes.weeklyRestrictionTimes =
[];
}
const getWeeklyTimeRestrictions: GetReactElementFunctionType = (): ReactElement => {
return (
<div>
<div className="ml-8">
{/** LIST */}
tempRestrictionTimes.weeklyRestrictionTimes.splice(
i,
1
);
{restrictionTimes?.weeklyRestrictionTimes?.map(
(weeklyRestriction: WeeklyResctriction, i: number) => {
return (
<div key={i} className="flex">
<div>
{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
);
},
})}
</div>
</div>
</div>
);
}
)}
</div>
<div className="ml-5 mt-3">
{/** show add button */}
<Button
title="Add Restriction Time"
buttonStyle={ButtonStyleType.NORMAL}
icon={IconProp.Add}
onClick={() => {
let tempRestrictionTimes:
| RestrictionTimes
| undefined = restrictionTimes;
if (!tempRestrictionTimes) {
tempRestrictionTimes = new RestrictionTimes();
);
}
)}
</div>
if (!tempRestrictionTimes.weeklyRestrictionTimes) {
tempRestrictionTimes.weeklyRestrictionTimes =
[];
}
<div className="ml-5 mt-3">
{/** show add button */}
<Button
title="Add Restriction Time"
buttonStyle={ButtonStyleType.NORMAL}
icon={IconProp.Add}
onClick={() => {
let tempRestrictionTimes:
| RestrictionTimes
| undefined = restrictionTimes;
tempRestrictionTimes.weeklyRestrictionTimes.push(
RestrictionTimes.getDefaultWeeklyRestrictionTIme()
);
if (!tempRestrictionTimes) {
tempRestrictionTimes =
new RestrictionTimes();
}
updateRestrictionTimes(tempRestrictionTimes);
}}
/>
if (
!tempRestrictionTimes.weeklyRestrictionTimes
) {
tempRestrictionTimes.weeklyRestrictionTimes =
[];
}
tempRestrictionTimes.weeklyRestrictionTimes.push(
RestrictionTimes.getDefaultWeeklyRestrictionTIme()
);
updateRestrictionTimes(tempRestrictionTimes);
}}
/>
</div>
</div>
</div>
);
};
);
};
const getWeeklyTimeRestriction: Function = (params: {
weeklyRestriction: WeeklyResctriction;

View File

@@ -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<PageComponentProps> = (
const [addMonitorGroup, setAddMonitorGroup] = useState<boolean>(false);
const fetchGroups: PromiseVoidFunctionType = async (): Promise<void> => {
const fetchGroups: Function = async () => {
setError('');
setIsLoading(true);
@@ -82,38 +81,39 @@ const StatusPageDelete: FunctionComponent<PageComponentProps> = (
fetchGroups();
}, []);
const getFooterForMonitor: GetReactElementFunctionType = (): ReactElement => {
if (props.currentProject?.isFeatureFlagMonitorGroupsEnabled) {
if (!addMonitorGroup) {
const getFooterForMonitor: GetReactElementFunctionType =
(): ReactElement => {
if (props.currentProject?.isFeatureFlagMonitorGroupsEnabled) {
if (!addMonitorGroup) {
return (
<Link
onClick={() => {
setAddMonitorGroup(true);
}}
className="mt-1 text-sm text-gray-500 underline"
>
<div>
<p> Add a Monitor Group instead. </p>
</div>
</Link>
);
}
return (
<Link
onClick={() => {
setAddMonitorGroup(true);
setAddMonitorGroup(false);
}}
className="mt-1 text-sm text-gray-500 underline"
>
<div>
<p> Add a Monitor Group instead. </p>
<p> Add a Monitor instead. </p>
</div>
</Link>
);
}
return (
<Link
onClick={() => {
setAddMonitorGroup(false);
}}
className="mt-1 text-sm text-gray-500 underline"
>
<div>
<p> Add a Monitor instead. </p>
</div>
</Link>
);
}
return <></>;
};
return <></>;
};
let formFields: Array<ModelField<StatusPageResource>> = [
{

View File

@@ -180,7 +180,12 @@ const Delete: FunctionComponent<PageComponentProps> = (
setIsLoading(false);
};
const saveGraph: Function = async (
type SaveGraphFunctionType = (
nodes: Array<Node>,
edges: Array<Edge>
) => Promise<void>;
const saveGraph: SaveGraphFunctionType = async (
nodes: Array<Node>,
edges: Array<Edge>
): Promise<void> => {

View File

@@ -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();

View File

@@ -44,21 +44,22 @@ import Label from 'Model/Models/Label';
import Dictionary from 'Common/Types/Dictionary';
type GetIncidentEventItemFunctionProps = {
incident: Incident,
incidentPublicNotes: Array<IncidentPublicNote>,
incidentStateTimelines: Array<IncidentStateTimeline>,
statusPageResources: Array<StatusPageResource>,
monitorsInGroup: Dictionary<Array<ObjectID>>,
isPreviewPage: boolean,
isSummary: boolean
incident: Incident;
incidentPublicNotes: Array<IncidentPublicNote>;
incidentStateTimelines: Array<IncidentStateTimeline>;
statusPageResources: Array<StatusPageResource>;
monitorsInGroup: Dictionary<Array<ObjectID>>;
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,

View File

@@ -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();