Fix formatting and remove unnecessary code

This commit is contained in:
Simon Larsen
2024-02-27 16:15:26 +00:00
parent 7e256ab68c
commit ac9442e085
13 changed files with 272 additions and 252 deletions

View File

@@ -38,7 +38,6 @@ app.set('port', process.env['PORT']);
app.set('view engine', 'ejs');
app.use(CookieParser());
const jsonBodyParserMiddleware: RequestHandler = ExpressJson({
limit: '50mb',
extended: true,

View File

@@ -86,7 +86,9 @@ const Button: FunctionComponent<ComponentProps> = ({
type HandleKeyboardFunction = (event: KeyboardEventProp) => void;
const handleKeyboard: HandleKeyboardFunction = (event: KeyboardEventProp): void => {
const handleKeyboard: HandleKeyboardFunction = (
event: KeyboardEventProp
): void => {
if (
event.target instanceof HTMLBodyElement &&
event.key &&

View File

@@ -23,7 +23,6 @@ export interface CategoryCheckboxProps
const CategoryCheckbox: FunctionComponent<CategoryCheckboxProps> = (
props: CategoryCheckboxProps
): ReactElement => {
type SanitizeInitialValuesFunction = (
value?: Array<CategoryCheckboxValue | BaseModel>
) => Array<CategoryCheckboxValue>;

View File

@@ -30,11 +30,11 @@ export interface ComponentProps {
const Detail: (props: ComponentProps) => ReactElement = (
props: ComponentProps
): ReactElement => {
type GetMarkdownViewerFunction = (text: string) => ReactElement | null;
const getMarkdownViewer: GetMarkdownViewerFunction = (text: string): ReactElement | null => {
const getMarkdownViewer: GetMarkdownViewerFunction = (
text: string
): ReactElement | null => {
if (!text) {
return null;
}
@@ -88,19 +88,25 @@ const Detail: (props: ComponentProps) => ReactElement = (
type GetColorFieldFunction = (color: Color) => ReactElement;
const getColorField: GetColorFieldFunction = (color: Color): ReactElement => {
const getColorField: GetColorFieldFunction = (
color: Color
): ReactElement => {
return <ColorViewer value={color} />;
};
type GetUSDCentsFieldFunction = (usdCents: number) => ReactElement;
const getUSDCentsField: GetUSDCentsFieldFunction = (usdCents: number): ReactElement => {
const getUSDCentsField: GetUSDCentsFieldFunction = (
usdCents: number
): ReactElement => {
return <div className="text-gray-900">{usdCents / 100} USD</div>;
};
type GetMinutesFieldFunction = (minutes: number) => ReactElement;
const getMinutesField: GetMinutesFieldFunction = (minutes: number): ReactElement => {
const getMinutesField: GetMinutesFieldFunction = (
minutes: number
): ReactElement => {
return (
<div className="text-gray-900">
{minutes} {minutes > 1 ? 'minutes' : 'minute'}
@@ -110,7 +116,10 @@ const Detail: (props: ComponentProps) => ReactElement = (
type GetFieldFunction = (field: Field, index: number) => ReactElement;
const getField: GetFieldFunction = (field: Field, index: number): ReactElement => {
const getField: GetFieldFunction = (
field: Field,
index: number
): ReactElement => {
const fieldKey: string = field.key;
if (!props.item) {

View File

@@ -20,8 +20,8 @@ export interface ComponentProps {
placeholder?: undefined | string;
className?: undefined | string;
onChange?:
| undefined
| ((value: DropdownValue | Array<DropdownValue> | null) => void);
| undefined
| ((value: DropdownValue | Array<DropdownValue> | null) => void);
value?: DropdownOption | undefined;
onFocus?: (() => void) | undefined;
onBlur?: (() => void) | undefined;
@@ -33,21 +33,19 @@ export interface ComponentProps {
const Dropdown: FunctionComponent<ComponentProps> = (
props: ComponentProps
): ReactElement => {
type GetDropdownOptionFromValueFunctionProps = undefined
type GetDropdownOptionFromValueFunctionProps =
| undefined
| DropdownValue
| DropdownOption
| Array<DropdownOption>
| Array<DropdownValue>;
type GetDropdownOptionFromValueFunction = (
value:
GetDropdownOptionFromValueFunctionProps
value: GetDropdownOptionFromValueFunctionProps
) => DropdownOption | Array<DropdownOption>;
const getDropdownOptionFromValue: GetDropdownOptionFromValueFunction = (
value:
GetDropdownOptionFromValueFunctionProps
value: GetDropdownOptionFromValueFunctionProps
): DropdownOption | Array<DropdownOption> => {
if (
Array.isArray(value) &&
@@ -73,10 +71,10 @@ const Dropdown: FunctionComponent<ComponentProps> = (
| DropdownOption
| undefined
| Array<DropdownOption> = props.options.find(
(option: DropdownOption) => {
return option.value === item;
}
) as DropdownOption | Array<DropdownOption>;
(option: DropdownOption) => {
return option.value === item;
}
) as DropdownOption | Array<DropdownOption>;
if (option) {
options.push(option as DropdownOption);
@@ -115,9 +113,10 @@ const Dropdown: FunctionComponent<ComponentProps> = (
return (
<div
className={`${props.className ||
className={`${
props.className ||
'relative mt-2 mb-1 rounded-md w-full overflow-visible'
}`}
}`}
onClick={() => {
props.onClick && props.onClick();
props.onFocus && props.onFocus();

View File

@@ -20,10 +20,11 @@ export interface ComponentProps {
const ListBody: FunctionComponent<ComponentProps> = (
props: ComponentProps
): ReactElement => {
type GetBodyFunction = (provided?: DroppableProvided) => ReactElement;
const getBody: GetBodyFunction = (provided?: DroppableProvided): ReactElement => {
const getBody: GetBodyFunction = (
provided?: DroppableProvided
): ReactElement => {
return (
<div
ref={provided?.innerRef}

View File

@@ -35,7 +35,6 @@ const StaticModelList: <TBaseModel extends BaseModel>(
) => ReactElement = <TBaseModel extends BaseModel>(
props: ComponentProps<TBaseModel>
): ReactElement => {
type GetRowFunction = (
model: TBaseModel,
isSelected: boolean,
@@ -123,9 +122,13 @@ const StaticModelList: <TBaseModel extends BaseModel>(
);
};
type GetBodyFunction = (provided?: DroppableProvided | undefined) => ReactElement;
type GetBodyFunction = (
provided?: DroppableProvided | undefined
) => ReactElement;
const getBody: GetBodyFunction = (provided?: DroppableProvided): ReactElement => {
const getBody: GetBodyFunction = (
provided?: DroppableProvided
): ReactElement => {
return (
<div ref={provided?.innerRef} {...provided?.droppableProps}>
{props.list &&

View File

@@ -25,7 +25,9 @@ const DocumentationViewer: FunctionComponent<ComponentProps> = (
type PopulateWithEnvVarsFunction = (text: string) => string;
const populateWithEnvVars: PopulateWithEnvVarsFunction = (text: string): string => {
const populateWithEnvVars: PopulateWithEnvVarsFunction = (
text: string
): string => {
text = text.replace('{{serverUrl}}', HOME_URL.toString());
text = text.replace('{{workflowId}}', props.workflowId.toString());

View File

@@ -31,8 +31,9 @@ export const loadComponentsAndCategories: LoadComponentsAndCategoriesFunction =
);
initCategories.push({
name: new model().singularName || 'Model',
description: `Interact with ${new model().singularName
} in your workflow.`,
description: `Interact with ${
new model().singularName
} in your workflow.`,
icon: new model().icon || IconProp.Database,
});
}
@@ -48,218 +49,219 @@ type ComponentInputTypeToFormFieldTypeFunction = (
dropdownOptions?: Array<DropdownOption> | undefined;
};
export const componentInputTypeToFormFieldType: ComponentInputTypeToFormFieldTypeFunction = (
componentInputType: ComponentInputType,
argValue: any
): {
fieldType: FormFieldSchemaType;
dropdownOptions?: Array<DropdownOption> | undefined;
} => {
// first priority.
export const componentInputTypeToFormFieldType: ComponentInputTypeToFormFieldTypeFunction =
(
componentInputType: ComponentInputType,
argValue: any
): {
fieldType: FormFieldSchemaType;
dropdownOptions?: Array<DropdownOption> | undefined;
} => {
// first priority.
if (componentInputType === ComponentInputType.BaseModel) {
return {
fieldType: FormFieldSchemaType.JSON,
};
}
if (componentInputType === ComponentInputType.BaseModel) {
return {
fieldType: FormFieldSchemaType.JSON,
};
}
if (componentInputType === ComponentInputType.BaseModelArray) {
return {
fieldType: FormFieldSchemaType.JSON,
};
}
if (componentInputType === ComponentInputType.BaseModelArray) {
return {
fieldType: FormFieldSchemaType.JSON,
};
}
if (componentInputType === ComponentInputType.JSON) {
return {
fieldType: FormFieldSchemaType.JSON,
};
}
if (componentInputType === ComponentInputType.JSON) {
return {
fieldType: FormFieldSchemaType.JSON,
};
}
if (componentInputType === ComponentInputType.JSONArray) {
return {
fieldType: FormFieldSchemaType.JSON,
};
}
if (componentInputType === ComponentInputType.JSONArray) {
return {
fieldType: FormFieldSchemaType.JSON,
};
}
if (componentInputType === ComponentInputType.Markdown) {
return {
fieldType: FormFieldSchemaType.Markdown,
};
}
if (componentInputType === ComponentInputType.Markdown) {
return {
fieldType: FormFieldSchemaType.Markdown,
};
}
if (componentInputType === ComponentInputType.JavaScript) {
return {
fieldType: FormFieldSchemaType.JavaScript,
};
}
if (componentInputType === ComponentInputType.JavaScript) {
return {
fieldType: FormFieldSchemaType.JavaScript,
};
}
if (componentInputType === ComponentInputType.Query) {
return {
fieldType: FormFieldSchemaType.JSON,
};
}
if (componentInputType === ComponentInputType.Query) {
return {
fieldType: FormFieldSchemaType.JSON,
};
}
if (componentInputType === ComponentInputType.Select) {
return {
fieldType: FormFieldSchemaType.JSON,
};
}
if (componentInputType === ComponentInputType.Select) {
return {
fieldType: FormFieldSchemaType.JSON,
};
}
if (componentInputType === ComponentInputType.StringDictionary) {
return {
fieldType: FormFieldSchemaType.JSON,
};
}
if (componentInputType === ComponentInputType.StringDictionary) {
return {
fieldType: FormFieldSchemaType.JSON,
};
}
if (componentInputType === ComponentInputType.LongText) {
return {
fieldType: FormFieldSchemaType.LongText,
};
}
if (componentInputType === ComponentInputType.LongText) {
return {
fieldType: FormFieldSchemaType.LongText,
};
}
// Second priority.
// Second priority.
if (
argValue &&
typeof argValue === Typeof.String &&
argValue.toString().includes('{{')
) {
return {
fieldType: FormFieldSchemaType.Text,
dropdownOptions: [],
};
}
if (componentInputType === ComponentInputType.Boolean) {
return {
fieldType: FormFieldSchemaType.Toggle,
dropdownOptions: [],
};
}
if (componentInputType === ComponentInputType.HTML) {
return {
fieldType: FormFieldSchemaType.HTML,
dropdownOptions: [],
};
}
if (componentInputType === ComponentInputType.CronTab) {
return {
fieldType: FormFieldSchemaType.Dropdown,
dropdownOptions: [
{
label: 'Every Minute',
value: '* * * * *',
},
{
label: 'Every 30 minutes',
value: '*/30 * * * *',
},
{
label: 'Every Hour',
value: '0 * * * *',
},
{
label: 'Every Day',
value: '0 0 * * *',
},
{
label: 'Every Week',
value: '0 0 * * 0',
},
{
label: 'Every Month',
value: '0 0 1 * *',
},
{
label: 'Every Three Months',
value: '0 0 1 */3 *',
},
{
label: 'Every Six Months',
value: '0 0 1 */6 *',
},
],
};
}
if (componentInputType === ComponentInputType.Operator) {
return {
fieldType: FormFieldSchemaType.Dropdown,
dropdownOptions: [
{
label: 'Equal To',
value: '==',
},
{
label: 'Not Equal To',
value: '!=',
},
{
label: 'Greater Than',
value: '>',
},
{
label: 'Less Than',
value: '<',
},
{
label: 'Greater Than or Equal',
value: '>=',
},
{
label: 'Less Than or Equal',
value: '<=',
},
],
};
}
if (componentInputType === ComponentInputType.Date) {
return {
fieldType: FormFieldSchemaType.Date,
};
}
if (componentInputType === ComponentInputType.DateTime) {
return {
fieldType: FormFieldSchemaType.DateTime,
};
}
if (componentInputType === ComponentInputType.Decimal) {
return {
fieldType: FormFieldSchemaType.Number,
};
}
if (componentInputType === ComponentInputType.Email) {
return {
fieldType: FormFieldSchemaType.Email,
};
}
if (componentInputType === ComponentInputType.Number) {
return {
fieldType: FormFieldSchemaType.Number,
};
}
if (componentInputType === ComponentInputType.Password) {
return {
fieldType: FormFieldSchemaType.Password,
};
}
if (componentInputType === ComponentInputType.URL) {
return {
fieldType: FormFieldSchemaType.URL,
};
}
if (
argValue &&
typeof argValue === Typeof.String &&
argValue.toString().includes('{{')
) {
return {
fieldType: FormFieldSchemaType.Text,
dropdownOptions: [],
};
}
if (componentInputType === ComponentInputType.Boolean) {
return {
fieldType: FormFieldSchemaType.Toggle,
dropdownOptions: [],
};
}
if (componentInputType === ComponentInputType.HTML) {
return {
fieldType: FormFieldSchemaType.HTML,
dropdownOptions: [],
};
}
if (componentInputType === ComponentInputType.CronTab) {
return {
fieldType: FormFieldSchemaType.Dropdown,
dropdownOptions: [
{
label: 'Every Minute',
value: '* * * * *',
},
{
label: 'Every 30 minutes',
value: '*/30 * * * *',
},
{
label: 'Every Hour',
value: '0 * * * *',
},
{
label: 'Every Day',
value: '0 0 * * *',
},
{
label: 'Every Week',
value: '0 0 * * 0',
},
{
label: 'Every Month',
value: '0 0 1 * *',
},
{
label: 'Every Three Months',
value: '0 0 1 */3 *',
},
{
label: 'Every Six Months',
value: '0 0 1 */6 *',
},
],
};
}
if (componentInputType === ComponentInputType.Operator) {
return {
fieldType: FormFieldSchemaType.Dropdown,
dropdownOptions: [
{
label: 'Equal To',
value: '==',
},
{
label: 'Not Equal To',
value: '!=',
},
{
label: 'Greater Than',
value: '>',
},
{
label: 'Less Than',
value: '<',
},
{
label: 'Greater Than or Equal',
value: '>=',
},
{
label: 'Less Than or Equal',
value: '<=',
},
],
};
}
if (componentInputType === ComponentInputType.Date) {
return {
fieldType: FormFieldSchemaType.Date,
};
}
if (componentInputType === ComponentInputType.DateTime) {
return {
fieldType: FormFieldSchemaType.DateTime,
};
}
if (componentInputType === ComponentInputType.Decimal) {
return {
fieldType: FormFieldSchemaType.Number,
};
}
if (componentInputType === ComponentInputType.Email) {
return {
fieldType: FormFieldSchemaType.Email,
};
}
if (componentInputType === ComponentInputType.Number) {
return {
fieldType: FormFieldSchemaType.Number,
};
}
if (componentInputType === ComponentInputType.Password) {
return {
fieldType: FormFieldSchemaType.Password,
};
}
if (componentInputType === ComponentInputType.URL) {
return {
fieldType: FormFieldSchemaType.URL,
};
}
return {
fieldType: FormFieldSchemaType.Text,
dropdownOptions: [],
};
};

View File

@@ -42,26 +42,27 @@ import RunModal from './RunModal';
type GetPlaceholderTriggerNodeFunction = () => Node;
export const getPlaceholderTriggerNode: GetPlaceholderTriggerNodeFunction = (): Node => {
return {
id: ObjectID.generate().toString(),
type: 'node',
position: { x: 100, y: 100 },
data: {
metadata: {
iconProp: IconProp.Bolt,
componentType: ComponentType.Trigger,
title: 'Trigger',
description: 'Please click here to add trigger',
export const getPlaceholderTriggerNode: GetPlaceholderTriggerNodeFunction =
(): Node => {
return {
id: ObjectID.generate().toString(),
type: 'node',
position: { x: 100, y: 100 },
data: {
metadata: {
iconProp: IconProp.Bolt,
componentType: ComponentType.Trigger,
title: 'Trigger',
description: 'Please click here to add trigger',
},
metadataId: '',
internalId: '',
nodeType: NodeType.PlaceholderNode,
id: '',
error: '',
},
metadataId: '',
internalId: '',
nodeType: NodeType.PlaceholderNode,
id: '',
error: '',
},
};
};
};
const nodeTypes: NodeTypes = {
node: WorkflowComponent,
@@ -340,7 +341,9 @@ const Workflow: FunctionComponent<ComponentProps> = (props: ComponentProps) => {
type AddToGraphFunction = (componentMetadata: ComponentMetadata) => void;
const addToGraph: AddToGraphFunction = (componentMetadata: ComponentMetadata) => {
const addToGraph: AddToGraphFunction = (
componentMetadata: ComponentMetadata
) => {
const metaDataId: string = componentMetadata.id;
let hasFoundExistingId: boolean = true;

View File

@@ -63,7 +63,7 @@ describe('BasicForm test', () => {
});
test('Should accept values and submit if valid', async () => {
const handleSubmit: jest.Mock<any, any> = jest.fn();
const handleSubmit: jest.Mock<any, any> = jest.fn();
const onSubmitSuccessful: jest.Mock<any, any> = jest.fn();
render(
<BasicForm

View File

@@ -35,7 +35,9 @@ const getComponentMetadata: GetComponentMetadataFunction = (
type GetComponentCategoryFunction = (name?: string) => ComponentCategory;
const getComponentCategory: GetComponentCategoryFunction = (name?: string): ComponentCategory => {
const getComponentCategory: GetComponentCategoryFunction = (
name?: string
): ComponentCategory => {
return {
name: name || faker.datatype.uuid(),
description: `Description for ${name}`,

View File

@@ -12,7 +12,6 @@ import Typeof from 'Common/Types/Typeof';
import { JSONValue } from 'Common/Types/JSON';
import logger from 'CommonServer/Utils/Logger';
const router: ExpressRouter = Express.getRouter();
router.get(