Merge branch 'main' into issue-553

This commit is contained in:
Ömer Faruk Aydın
2022-10-16 13:23:07 +02:00
committed by GitHub
37 changed files with 616 additions and 431 deletions

View File

@@ -4,7 +4,7 @@
"license": "AGPL-3.0",
"description": "The open source Zapier alternative. Build workflow automation without spending time and money.",
"scripts": {
"dev": "ts-node-dev src/server.ts",
"dev": "ts-node-dev --exit-child src/server.ts",
"worker": "nodemon --watch 'src/**/*.ts' --exec 'ts-node' src/worker.ts",
"build": "tsc && yarn copy-statics",
"build:watch": "nodemon --watch 'src/**/*.ts' --watch 'bin/**/*.ts' --exec yarn build --ext ts",
@@ -134,4 +134,4 @@
"publishConfig": {
"access": "public"
}
}
}

View File

@@ -1,4 +1,5 @@
import { DateTime } from 'luxon';
import { IJSONObject } from '@automatisch/types';
export default function getDateTimeObjectRepresentation(dateTime: DateTime) {
const defaults = dateTime.toObject();
@@ -10,5 +11,5 @@ export default function getDateTimeObjectRepresentation(dateTime: DateTime) {
pretty_time: dateTime.toLocaleString(DateTime.TIME_WITH_SECONDS),
pretty_day_of_week: dateTime.toFormat('cccc'),
day_of_week: dateTime.weekday,
};
} as IJSONObject;
}

View File

@@ -6,5 +6,4 @@ export default {
authDocUrl: "https://automatisch.io/docs/connections/scheduler",
primaryColor: "0059F7",
supportsConnections: false,
requiresAuthentication: false,
};

View File

@@ -1,10 +1,11 @@
import { DateTime } from 'luxon';
import { IGlobalVariable, IJSONValue } from '@automatisch/types';
import defineTrigger from '../../../../helpers/define-trigger';
import cronTimes from '../../common/cron-times';
import getNextCronDateTime from '../../common/get-next-cron-date-time';
import getDateTimeObjectRepresentation from '../../common/get-date-time-object';
export default {
export default defineTrigger({
name: 'Every day',
key: 'everyDay',
description: 'Triggers every day.',
@@ -154,23 +155,22 @@ export default {
return cronTimes.everyDayExcludingWeekendsAt(parameters.hour as number);
},
async run($: IGlobalVariable, startDateTime: Date) {
const dateTime = DateTime.fromJSDate(startDateTime);
const dateTimeObjectRepresentation = getDateTimeObjectRepresentation(
dateTime
) as IJSONValue;
return { data: [dateTimeObjectRepresentation] };
},
async testRun($: IGlobalVariable) {
async run($) {
const nextCronDateTime = getNextCronDateTime(
this.getInterval($.step.parameters)
);
const dateTime = DateTime.now();
const dateTimeObjectRepresentation = getDateTimeObjectRepresentation(
nextCronDateTime
) as IJSONValue;
$.execution.testRun ? nextCronDateTime : dateTime
);
return { data: [dateTimeObjectRepresentation] };
const dataItem = {
raw: dateTimeObjectRepresentation,
meta: {
internalId: dateTime.toMillis().toString(),
},
};
return { data: [dataItem] };
},
};
});

View File

@@ -1,10 +1,11 @@
import { DateTime } from 'luxon';
import { IGlobalVariable, IJSONValue } from '@automatisch/types';
import { IGlobalVariable } from '@automatisch/types';
import defineTrigger from '../../../../helpers/define-trigger';
import cronTimes from '../../common/cron-times';
import getNextCronDateTime from '../../common/get-next-cron-date-time';
import getDateTimeObjectRepresentation from '../../common/get-date-time-object';
export default {
export default defineTrigger({
name: 'Every hour',
key: 'everyHour',
description: 'Triggers every hour.',
@@ -48,23 +49,22 @@ export default {
return cronTimes.everyHourExcludingWeekends;
},
async run($: IGlobalVariable, startDateTime: Date) {
const dateTime = DateTime.fromJSDate(startDateTime);
const dateTimeObjectRepresentation = getDateTimeObjectRepresentation(
dateTime
) as IJSONValue;
return { data: [dateTimeObjectRepresentation] };
},
async testRun($: IGlobalVariable) {
async run($) {
const nextCronDateTime = getNextCronDateTime(
this.getInterval($.step.parameters)
);
const dateTime = DateTime.now();
const dateTimeObjectRepresentation = getDateTimeObjectRepresentation(
nextCronDateTime
) as IJSONValue;
$.execution.testRun ? nextCronDateTime : dateTime
);
return { data: [dateTimeObjectRepresentation] };
const dataItem = {
raw: dateTimeObjectRepresentation,
meta: {
internalId: dateTime.toMillis().toString(),
},
};
return { data: [dataItem] };
},
};
});

View File

@@ -1,10 +1,11 @@
import { DateTime } from 'luxon';
import { IGlobalVariable, IJSONValue } from '@automatisch/types';
import { IGlobalVariable } from '@automatisch/types';
import defineTrigger from '../../../../helpers/define-trigger';
import cronTimes from '../../common/cron-times';
import getNextCronDateTime from '../../common/get-next-cron-date-time';
import getDateTimeObjectRepresentation from '../../common/get-date-time-object';
export default {
export default defineTrigger({
name: 'Every month',
key: 'everyMonth',
description: 'Triggers every month.',
@@ -22,127 +23,127 @@ export default {
variables: false,
options: [
{
label: 1,
label: '1',
value: 1,
},
{
label: 2,
label: '2',
value: 2,
},
{
label: 3,
label: '3',
value: 3,
},
{
label: 4,
label: '4',
value: 4,
},
{
label: 5,
label: '5',
value: 5,
},
{
label: 6,
label: '6',
value: 6,
},
{
label: 7,
label: '7',
value: 7,
},
{
label: 8,
label: '8',
value: 8,
},
{
label: 9,
label: '9',
value: 9,
},
{
label: 10,
label: '10',
value: 10,
},
{
label: 11,
label: '11',
value: 11,
},
{
label: 12,
label: '12',
value: 12,
},
{
label: 13,
label: '13',
value: 13,
},
{
label: 14,
label: '14',
value: 14,
},
{
label: 15,
label: '15',
value: 15,
},
{
label: 16,
label: '16',
value: 16,
},
{
label: 17,
label: '17',
value: 17,
},
{
label: 18,
label: '18',
value: 18,
},
{
label: 19,
label: '19',
value: 19,
},
{
label: 20,
label: '20',
value: 20,
},
{
label: 21,
label: '21',
value: 21,
},
{
label: 22,
label: '22',
value: 22,
},
{
label: 23,
label: '23',
value: 23,
},
{
label: 24,
label: '24',
value: 24,
},
{
label: 25,
label: '25',
value: 25,
},
{
label: 26,
label: '26',
value: 26,
},
{
label: 27,
label: '27',
value: 27,
},
{
label: 28,
label: '28',
value: 28,
},
{
label: 29,
label: '29',
value: 29,
},
{
label: 30,
label: '30',
value: 30,
},
{
label: 31,
label: '31',
value: 31,
},
],
@@ -270,23 +271,22 @@ export default {
return interval;
},
async run($: IGlobalVariable, startDateTime: Date) {
const dateTime = DateTime.fromJSDate(startDateTime);
const dateTimeObjectRepresentation = getDateTimeObjectRepresentation(
dateTime
) as IJSONValue;
return { data: [dateTimeObjectRepresentation] };
},
async testRun($: IGlobalVariable) {
async run($) {
const nextCronDateTime = getNextCronDateTime(
this.getInterval($.step.parameters)
);
const dateTime = DateTime.now();
const dateTimeObjectRepresentation = getDateTimeObjectRepresentation(
nextCronDateTime
) as IJSONValue;
$.execution.testRun ? nextCronDateTime : dateTime
);
return { data: [dateTimeObjectRepresentation] };
const dataItem = {
raw: dateTimeObjectRepresentation,
meta: {
internalId: dateTime.toMillis().toString(),
},
};
return { data: [dataItem] };
},
};
});

View File

@@ -1,10 +1,11 @@
import { DateTime } from 'luxon';
import { IGlobalVariable, IJSONValue } from '@automatisch/types';
import defineTrigger from '../../../../helpers/define-trigger';
import cronTimes from '../../common/cron-times';
import getNextCronDateTime from '../../common/get-next-cron-date-time';
import getDateTimeObjectRepresentation from '../../common/get-date-time-object';
export default {
export default defineTrigger({
name: 'Every week',
key: 'everyWeek',
description: 'Triggers every week.',
@@ -174,23 +175,22 @@ export default {
return interval;
},
async run($: IGlobalVariable, startDateTime: Date) {
const dateTime = DateTime.fromJSDate(startDateTime);
const dateTimeObjectRepresentation = getDateTimeObjectRepresentation(
dateTime
) as IJSONValue;
return { data: [dateTimeObjectRepresentation] };
},
async testRun($: IGlobalVariable) {
async run($) {
const nextCronDateTime = getNextCronDateTime(
this.getInterval($.step.parameters)
);
const dateTime = DateTime.now();
const dateTimeObjectRepresentation = getDateTimeObjectRepresentation(
nextCronDateTime
) as IJSONValue;
$.execution.testRun ? nextCronDateTime : dateTime
);
return { data: [dateTimeObjectRepresentation] };
const dataItem = {
raw: dateTimeObjectRepresentation,
meta: {
internalId: dateTime.toMillis().toString(),
},
};
return { data: [dataItem] };
},
};
});

View File

@@ -28,7 +28,7 @@ const findMessage = async ($: IGlobalVariable, options: FindMessageOptions) => {
const message: IActionOutput = {
data: {
raw: data?.data?.messages.matches[0],
raw: data?.messages.matches[0],
},
error: response?.integrationError || (!data.ok && data),
};

View File

@@ -1,7 +1,7 @@
import { IGlobalVariable } from '@automatisch/types';
import defineAction from '../../../../helpers/define-action';
import findMessage from './find-message';
export default {
export default defineAction({
name: 'Find message',
key: 'findMessage',
description: 'Find a Slack message using the Slack Search feature.',
@@ -71,7 +71,7 @@ export default {
},
],
async run($: IGlobalVariable) {
async run($) {
const parameters = $.step.parameters;
const query = parameters.query as string;
const sortBy = parameters.sortBy as string;
@@ -87,4 +87,4 @@ export default {
return messages;
},
};
});

View File

@@ -1,7 +1,7 @@
import { IGlobalVariable } from '@automatisch/types';
import defineAction from '../../../../helpers/define-action';
import postMessage from './post-message';
export default {
export default defineAction({
name: 'Send a message to channel',
key: 'sendMessageToChannel',
description: 'Send a message to a specific channel you specify.',
@@ -48,7 +48,7 @@ export default {
},
],
async run($: IGlobalVariable) {
async run($) {
const channelId = $.step.parameters.channel as string;
const text = $.step.parameters.message as string;
@@ -56,4 +56,4 @@ export default {
return message;
},
};
});

View File

@@ -12,8 +12,6 @@ import getUserByUsername from './get-user-by-username';
type IGetUserTweetsOptions = {
currentUser: boolean;
userId?: string;
lastInternalId?: string;
};
const getUserTweets = async (
@@ -39,7 +37,7 @@ const getUserTweets = async (
do {
const params: IJSONObject = {
since_id: options.lastInternalId,
since_id: $.execution.testRun ? null : $.flow.lastInternalId,
pagination_token: response?.data?.meta?.next_token,
};
@@ -63,15 +61,13 @@ const getUserTweets = async (
response.data.data.forEach((tweet: IJSONObject) => {
tweets.data.push({
raw: tweet,
meta: { internalId: tweet.id as string },
meta: {
internalId: tweet.id as string,
},
});
});
}
} while (response.data.meta.next_token && options.lastInternalId);
tweets.data.sort((tweet, nextTweet) => {
return (tweet.raw.id as number) - (nextTweet.raw.id as number);
});
} while (response.data.meta.next_token && !$.execution.testRun);
return tweets;
};

View File

@@ -1,7 +1,7 @@
import { IGlobalVariable } from '@automatisch/types';
import defineTrigger from '../../../../helpers/define-trigger';
import getUserTweets from '../../common/get-user-tweets';
export default {
export default defineTrigger({
name: 'My Tweets',
key: 'myTweets',
pollInterval: 15,
@@ -17,14 +17,9 @@ export default {
},
],
async run($: IGlobalVariable) {
async run($) {
return await getUserTweets($, {
currentUser: true,
lastInternalId: $.flow.lastInternalId,
});
},
async testRun($: IGlobalVariable) {
return await getUserTweets($, { currentUser: true });
},
};
});

View File

@@ -1,7 +1,7 @@
import { IGlobalVariable } from '@automatisch/types';
import defineTrigger from '../../../../helpers/define-trigger';
import myFollowers from './my-followers';
export default {
export default defineTrigger({
name: 'New follower of me',
key: 'myFollowers',
pollInterval: 15,
@@ -17,11 +17,7 @@ export default {
},
],
async run($: IGlobalVariable) {
async run($) {
return await myFollowers($, $.flow.lastInternalId);
},
async testRun($: IGlobalVariable) {
return await myFollowers($);
},
};
});

View File

@@ -1,7 +1,7 @@
import { IGlobalVariable } from '@automatisch/types';
import defineTrigger from '../../../../helpers/define-trigger';
import searchTweets from './search-tweets';
export default {
export default defineTrigger({
name: 'Search Tweets',
key: 'searchTweets',
pollInterval: 15,
@@ -30,15 +30,7 @@ export default {
},
],
async run($: IGlobalVariable) {
return await searchTweets($, {
searchTerm: $.step.parameters.searchTerm as string,
});
async run($) {
return await searchTweets($);
},
async testRun($: IGlobalVariable) {
return await searchTweets($, {
searchTerm: $.step.parameters.searchTerm as string,
});
},
};
});

View File

@@ -7,15 +7,9 @@ import qs from 'qs';
import generateRequest from '../../common/generate-request';
import { omitBy, isEmpty } from 'lodash';
type ISearchTweetsOptions = {
searchTerm: string;
lastInternalId?: string;
};
const searchTweets = async ($: IGlobalVariable) => {
const searchTerm = $.step.parameters.searchTerm as string;
const searchTweets = async (
$: IGlobalVariable,
options: ISearchTweetsOptions
) => {
let response;
const tweets: ITriggerOutput = {
@@ -24,7 +18,7 @@ const searchTweets = async (
do {
const params: IJSONObject = {
query: options.searchTerm,
query: searchTerm,
since_id: $.execution.testRun ? null : $.flow.lastInternalId,
pagination_token: response?.data?.meta?.next_token,
};

View File

@@ -1,7 +1,7 @@
import { IGlobalVariable } from '@automatisch/types';
import defineTrigger from '../../../../helpers/define-trigger';
import getUserTweets from '../../common/get-user-tweets';
export default {
export default defineTrigger({
name: 'User Tweets',
key: 'userTweets',
pollInterval: 15,
@@ -29,18 +29,9 @@ export default {
},
],
async run($: IGlobalVariable) {
async run($) {
return await getUserTweets($, {
currentUser: false,
userId: $.step.parameters.username as string,
lastInternalId: $.flow.lastInternalId,
});
},
async testRun($: IGlobalVariable) {
return await getUserTweets($, {
currentUser: false,
userId: $.step.parameters.username as string,
});
},
};
});

View File

@@ -4,6 +4,7 @@ import { IApp } from '@automatisch/types';
type Params = {
name: string;
onlyWithTriggers: boolean;
onlyWithActions: boolean;
};
const getApps = async (_parent: unknown, params: Params) => {
@@ -13,6 +14,10 @@ const getApps = async (_parent: unknown, params: Params) => {
return apps.filter((app: IApp) => app.triggers?.length);
}
if (params.onlyWithActions) {
return apps.filter((app: IApp) => app.actions?.length);
}
return apps;
};

View File

@@ -1,5 +1,5 @@
type Query {
getApps(name: String, onlyWithTriggers: Boolean): [App]
getApps(name: String, onlyWithTriggers: Boolean, onlyWithActions: Boolean): [App]
getApp(key: AvailableAppsEnumType!): App
getConnectedApps(name: String): [App]
testConnection(id: String!): Connection

View File

@@ -9,10 +9,14 @@ const appInfoConverter = (rawAppData: IApp) => {
if (rawAppData.auth?.fields) {
rawAppData.auth.fields = rawAppData.auth.fields.map((field) => {
return {
...field,
value: field.value?.replace('{WEB_APP_URL}', appConfig.webAppUrl),
};
if (typeof field.value === 'string') {
return {
...field,
value: field.value.replace('{WEB_APP_URL}', appConfig.webAppUrl),
};
}
return field
});
}

View File

@@ -0,0 +1,5 @@
import { IAction } from '@automatisch/types';
export default function defineAction(actionDefinition: IAction): IAction {
return actionDefinition;
}

View File

@@ -0,0 +1,5 @@
import { ITrigger } from '@automatisch/types';
export default function defineTrigger(triggerDefinition: ITrigger): ITrigger {
return triggerDefinition;
}

View File

@@ -16,17 +16,13 @@ async function getFileContent<C>(
path: string,
stripFuncs: boolean
): Promise<C> {
try {
const fileContent = await getDefaultExport(path);
const fileContent = await getDefaultExport(path);
if (stripFuncs) {
return stripFunctions(fileContent);
}
return fileContent;
} catch (err) {
return null;
if (stripFuncs) {
return stripFunctions(fileContent);
}
return fileContent;
}
async function getChildrenContentInDirectory<C>(
@@ -55,10 +51,12 @@ async function getChildrenContentInDirectory<C>(
const getApp = async (appKey: string, stripFuncs = true) => {
const appData: IApp = await getDefaultExport(`../apps/${appKey}`);
appData.auth = await getFileContent<IAuth>(
`../apps/${appKey}/auth`,
stripFuncs
);
if (appData.supportsConnections) {
appData.auth = await getFileContent<IAuth>(
`../apps/${appKey}/auth`,
stripFuncs
);
}
appData.triggers = await getChildrenContentInDirectory<ITrigger>(
`${appKey}/triggers`,
stripFuncs

View File

@@ -48,7 +48,7 @@ export const processAction = async (options: ProcessActionOptions) => {
status: actionOutput.error ? 'failure' : 'success',
dataIn: computedParameters,
dataOut: actionOutput.error ? null : actionOutput.data.raw,
errorDetails: actionOutput.error,
errorDetails: actionOutput.error ? actionOutput.error : null,
});
return { flowId, stepId, executionId, executionStep };

View File

@@ -10,7 +10,7 @@
"serve": "vitepress serve pages"
},
"devDependencies": {
"vitepress": "^1.0.0-alpha.4",
"vitepress": "^1.0.0-alpha.21",
"vue": "^3.2.37"
},
"contributors": [

View File

@@ -8,6 +8,7 @@ export default defineConfig({
title: 'Automatisch Docs',
description:
'Build workflow automation without spending time and money. No code is required.',
cleanUrls: 'with-subfolders',
themeConfig: {
siteTitle: 'Automatisch',
nav: [
@@ -93,7 +94,35 @@ export default defineConfig({
text: 'Edit this page on GitHub',
},
footer: {
copyright: 'Copyright © 2021 Automatisch. All rights reserved.',
copyright: 'Copyright © 2022 Automatisch. All rights reserved.',
},
},
async transformHead(ctx) {
if (ctx.pageData.relativePath === '') return; // Skip 404 page.
const isHomepage = ctx.pageData.relativePath === 'index.md';
let canonicalUrl = 'https://automatisch.io/docs';
if (!isHomepage) {
canonicalUrl =
`${canonicalUrl}/` + ctx.pageData.relativePath.replace('.md', '');
}
// Added for logging purposes to check if there is something
// wrong with the canonical URL in the deployment pipeline.
console.log('');
console.log('File path : ', ctx.pageData.relativePath);
console.log('Canonical URL: ', canonicalUrl);
return [
[
'link',
{
rel: 'canonical',
href: canonicalUrl,
},
],
];
},
});

View File

@@ -90,45 +90,45 @@ export interface IFieldDropdown {
label: string;
type: 'dropdown';
required: boolean;
readOnly: boolean;
value: string;
placeholder: string | null;
description: string;
docUrl: string;
clickToCopy: boolean;
readOnly?: boolean;
value?: string | boolean;
placeholder?: string | null;
description?: string;
docUrl?: string;
clickToCopy?: boolean;
variables?: boolean;
dependsOn?: string[];
options?: IFieldDropdownOption[];
source?: IFieldDropdownSource;
}
export interface IFieldDropdownSource {
type: string;
name: string;
variables: boolean;
dependsOn: string[];
options: IFieldDropdownOption[];
source: {
type: string;
arguments: {
name: string;
arguments: {
name: string;
value: string;
}[];
};
value: string;
}[];
}
export interface IFieldDropdownOption {
label: string;
value: boolean | string;
value: boolean | string | number;
}
export interface IFieldText {
key: string;
label: string;
type: 'string';
required: boolean;
readOnly: boolean;
value: string;
placeholder: string | null;
description: string;
docUrl: string;
clickToCopy: boolean;
name: string;
variables: boolean;
dependsOn: string[];
required?: boolean;
readOnly?: boolean;
value?: string;
placeholder?: string | null;
description?: string;
docUrl?: string;
clickToCopy?: boolean;
variables?: boolean;
dependsOn?: string[];
}
export type IField = IFieldDropdown | IFieldText;
@@ -202,13 +202,12 @@ export interface ITriggerDataItem {
export interface ITrigger {
name: string;
key: string;
pollInterval: number;
pollInterval?: number;
description: string;
dedupeStrategy: 'greatest' | 'unique' | 'last';
dedupeStrategy?: 'greatest' | 'unique' | 'last';
substeps: ISubstep[];
getInterval(parameters: IGlobalVariable['step']['parameters']): string;
getInterval?(parameters: IGlobalVariable['step']['parameters']): string;
run($: IGlobalVariable): Promise<ITriggerOutput>;
testRun($: IGlobalVariable): Promise<ITriggerOutput>;
}
export interface IActionOutput {
@@ -239,7 +238,7 @@ export interface IAuthentication {
export interface ISubstep {
key: string;
name: string;
arguments: IField[];
arguments?: IField[];
}
export type IHttpClientParams = {
@@ -271,7 +270,7 @@ export type IGlobalVariable = {
execution?: {
id: string;
testRun: boolean;
}
};
process?: (triggerDataItem: ITriggerDataItem) => Promise<void>;
};

View File

@@ -19,7 +19,7 @@ const generateDocsLink = (link: string) => (str: string) => (
);
type AddAppConnectionProps = {
onClose: () => void;
onClose: (response: Record<string, unknown>) => void;
application: IApp;
connectionId?: string;
};
@@ -76,7 +76,7 @@ export default function AddAppConnection(props: AddAppConnectionProps): React.Re
stepIndex++;
if (stepIndex === steps.length) {
onClose();
onClose(response);
}
}

View File

@@ -49,9 +49,10 @@ function ChooseAppAndEventSubstep(
const editorContext = React.useContext(EditorContext);
const isTrigger = step.type === 'trigger';
const isAction = step.type === 'action';
const { data } = useQuery(GET_APPS, {
variables: { onlyWithTriggers: isTrigger },
variables: { onlyWithTriggers: isTrigger, onlyWithActions: isAction },
});
const apps: IApp[] = data?.getApps;
const app = apps?.find((currentApp: IApp) => currentApp.key === step.appKey);

View File

@@ -6,13 +6,16 @@ import Collapse from '@mui/material/Collapse';
import ListItem from '@mui/material/ListItem';
import Autocomplete from '@mui/material/Autocomplete';
import type { IApp, IConnection, IStep, ISubstep } from '@automatisch/types';
import useFormatMessage from 'hooks/useFormatMessage';
import { EditorContext } from 'contexts/Editor';
import FlowSubstepTitle from 'components/FlowSubstepTitle';
import type { IApp, IConnection, IStep, ISubstep } from '@automatisch/types';
import AddAppConnection from 'components/AddAppConnection';
import { GET_APP_CONNECTIONS } from 'graphql/queries/get-app-connections';
import { TEST_CONNECTION } from 'graphql/queries/test-connection';
type ChooseConnectionSubstepProps = {
application: IApp;
substep: ISubstep,
expanded?: boolean;
onExpand: () => void;
@@ -22,6 +25,8 @@ type ChooseConnectionSubstepProps = {
step: IStep;
};
const ADD_CONNECTION_VALUE = 'ADD_CONNECTION';
const optionGenerator = (connection: IConnection): { label: string; value: string; } => ({
label: connection?.formattedData?.screenName as string ?? 'Unnamed',
value: connection?.id as string,
@@ -38,13 +43,16 @@ function ChooseConnectionSubstep(props: ChooseConnectionSubstepProps): React.Rea
step,
onSubmit,
onChange,
application,
} = props;
const {
connection,
appKey,
} = step;
const formatMessage = useFormatMessage();
const editorContext = React.useContext(EditorContext);
const { data, loading } = useQuery(GET_APP_CONNECTIONS, { variables: { key: appKey }});
const [showAddConnectionDialog, setShowAddConnectionDialog] = React.useState(false);
const { data, loading, refetch } = useQuery(GET_APP_CONNECTIONS, { variables: { key: appKey }});
// TODO: show detailed error when connection test/verification fails
const [
testConnection,
@@ -72,10 +80,41 @@ function ChooseConnectionSubstep(props: ChooseConnectionSubstepProps): React.Rea
// intentionally no dependencies for initial test
}, []);
const connectionOptions = React.useMemo(() => (data?.getApp as IApp)?.connections?.map((connection) => optionGenerator(connection)) || [], [data]);
const connectionOptions = React.useMemo(() => {
const appWithConnections = data?.getApp as IApp;
const options = appWithConnections
?.connections
?.map((connection) => optionGenerator(connection)) || [];
options.push({
label: formatMessage('chooseConnectionSubstep.addNewConnection'),
value: ADD_CONNECTION_VALUE
})
return options;
}, [data, formatMessage]);
const { name } = substep;
const handleAddConnectionClose = React.useCallback(async (response) => {
setShowAddConnectionDialog(false);
const connectionId = response?.createConnection.id;
if (connectionId) {
await refetch();
onChange({
step: {
...step,
connection: {
id: connectionId,
},
},
});
}
}, [onChange, refetch, step]);
const handleChange = React.useCallback((event: React.SyntheticEvent, selectedOption: unknown) => {
if (typeof selectedOption === 'object') {
// TODO: try to simplify type casting below.
@@ -83,6 +122,11 @@ function ChooseConnectionSubstep(props: ChooseConnectionSubstepProps): React.Rea
const option: { value: string } = typedSelectedOption;
const connectionId = option?.value as string;
if (connectionId === ADD_CONNECTION_VALUE) {
setShowAddConnectionDialog(true);
return;
}
if (connectionId !== step.connection?.id) {
onChange({
step: {
@@ -122,7 +166,12 @@ function ChooseConnectionSubstep(props: ChooseConnectionSubstepProps): React.Rea
disableClearable
disabled={editorContext.readOnly}
options={connectionOptions}
renderInput={(params) => <TextField {...params} label="Choose connection" />}
renderInput={(params) => (
<TextField
{...params}
label={formatMessage('chooseConnectionSubstep.chooseConnection')}
/>
)}
value={getOption(connectionOptions, connection?.id)}
onChange={handleChange}
loading={loading}
@@ -136,10 +185,15 @@ function ChooseConnectionSubstep(props: ChooseConnectionSubstepProps): React.Rea
sx={{ mt: 2 }}
disabled={testResultLoading || !connection?.verified || editorContext.readOnly}data-test="flow-substep-continue-button"
>
Continue
{formatMessage('chooseConnectionSubstep.continue')}
</Button>
</ListItem>
</Collapse>
{application && showAddConnectionDialog && <AddAppConnection
onClose={handleAddConnectionClose}
application={application}
/>}
</React.Fragment>
);
}

View File

@@ -31,8 +31,9 @@ export default function ExecutionStep(props: ExecutionStepProps): React.ReactEle
const [activeTabIndex, setActiveTabIndex] = React.useState(0);
const step: IStep = executionStep.step;
const isTrigger = step.type === 'trigger';
const isAction = step.type === 'action';
const formatMessage = useFormatMessage();
const { data } = useQuery(GET_APPS, { variables: { onlyWithTriggers: isTrigger }});
const { data } = useQuery(GET_APPS, { variables: { onlyWithTriggers: isTrigger, onlyWithActions: isAction }});
const apps: IApp[] = data?.getApps;
const app = apps?.find((currentApp: IApp) => currentApp.key === step.appKey);

View File

@@ -69,7 +69,7 @@ function generateValidationSchema(substeps: ISubstep[]) {
}
// if the field depends on another field, add the dependsOn required validation
if (dependsOn?.length > 0) {
if (Array.isArray(dependsOn) && dependsOn.length > 0) {
for (const dependsOnKey of dependsOn) {
const missingDependencyValueMessage = `We're having trouble loading '${key}' data as required field '${dependsOnKey}' is missing.`;
@@ -108,10 +108,11 @@ export default function FlowStep(
null
);
const isTrigger = step.type === 'trigger';
const isAction = step.type === 'action';
const formatMessage = useFormatMessage();
const [currentSubstep, setCurrentSubstep] = React.useState<number | null>(0);
const { data } = useQuery(GET_APPS, {
variables: { onlyWithTriggers: isTrigger },
variables: { onlyWithTriggers: isTrigger, onlyWithActions: isAction },
});
const [
getStepWithTestExecutions,
@@ -250,7 +251,7 @@ export default function FlowStep(
index: number
) => (
<React.Fragment key={`${substep?.name}-${index}`}>
{substep.key === 'chooseConnection' && (
{substep.key === 'chooseConnection' && app && (
<ChooseConnectionSubstep
expanded={currentSubstep === index + 1}
substep={substep}
@@ -258,6 +259,7 @@ export default function FlowStep(
onCollapse={() => toggleSubstep(index + 1)}
onSubmit={expandNextStep}
onChange={handleChange}
application={app}
step={step}
/>
)}

View File

@@ -22,7 +22,7 @@ type RawOption = {
};
const optionGenerator = (options: RawOption[]): IFieldDropdownOption[] => options?.map(({ name, value }) => ({ label: name as string, value: value }));
const getOption = (options: IFieldDropdownOption[], value: string) => options?.find(option => option.value === value);
const getOption = (options: IFieldDropdownOption[], value?: string | boolean) => options?.find(option => option.value === value);
export default function InputCreator(props: InputCreatorProps): React.ReactElement {
const {

View File

@@ -1,8 +1,8 @@
import { gql } from '@apollo/client';
export const GET_APPS = gql`
query GetApps($name: String, $onlyWithTriggers: Boolean) {
getApps(name: $name, onlyWithTriggers: $onlyWithTriggers) {
query GetApps($name: String, $onlyWithTriggers: Boolean, $onlyWithActions: Boolean) {
getApps(name: $name, onlyWithTriggers: $onlyWithTriggers, onlyWithActions: $onlyWithActions) {
name
key
iconUrl

View File

@@ -4,13 +4,13 @@ import { useFormContext } from 'react-hook-form';
import set from 'lodash/set';
import type { UseFormReturn } from 'react-hook-form';
import isEqual from 'lodash/isEqual';
import type { IField, IFieldDropdown, IJSONObject } from '@automatisch/types';
import type { IField, IFieldDropdownSource, IJSONObject } from '@automatisch/types';
import { GET_DATA } from 'graphql/queries/get-data';
const variableRegExp = /({.*?})/g;
function computeArguments(args: IFieldDropdown["source"]["arguments"], getValues: UseFormReturn["getValues"]): IJSONObject {
function computeArguments(args: IFieldDropdownSource["arguments"], getValues: UseFormReturn["getValues"]): IJSONObject {
const initialValue = {};
return args.reduce(
(result, { name, value }) => {

View File

@@ -57,6 +57,9 @@
"flowEditor.pollIntervalValue": "Every {minutes} minutes",
"flowEditor.triggerEvent": "Trigger event",
"flowEditor.actionEvent": "Action event",
"chooseConnectionSubstep.continue": "Continue",
"chooseConnectionSubstep.addNewConnection": "Add new connection",
"chooseConnectionSubstep.chooseConnection": "Choose connection",
"flow.createdAt": "created {datetime}",
"flow.updatedAt": "updated {datetime}",
"flow.view": "View",