feat(google-sheets): add new spreadsheets trigger
This commit is contained in:
Before Width: | Height: | Size: 9.0 KiB After Width: | Height: | Size: 9.0 KiB |
@@ -11,7 +11,7 @@ export default {
|
||||
type: 'string' as const,
|
||||
required: true,
|
||||
readOnly: true,
|
||||
value: '{WEB_APP_URL}/app/google-sheet/connections/add',
|
||||
value: '{WEB_APP_URL}/app/google-sheets/connections/add',
|
||||
placeholder: null,
|
||||
description:
|
||||
'When asked to input a redirect URL in Google Cloud, enter the URL above.',
|
@@ -0,0 +1,3 @@
|
||||
import listDrives from './list-drives';
|
||||
|
||||
export default [listDrives];
|
@@ -0,0 +1,38 @@
|
||||
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
|
||||
|
||||
export default {
|
||||
name: 'List drives',
|
||||
key: 'listDrives',
|
||||
|
||||
async run($: IGlobalVariable) {
|
||||
const drives: {
|
||||
data: IJSONObject[];
|
||||
} = {
|
||||
data: [{ value: null, name: 'My Google Drive' }],
|
||||
};
|
||||
|
||||
const params = {
|
||||
pageSize: 100,
|
||||
pageToken: undefined as unknown as string,
|
||||
};
|
||||
|
||||
do {
|
||||
const { data } = await $.http.get(
|
||||
`https://www.googleapis.com/drive/v3/drives`,
|
||||
{ params }
|
||||
);
|
||||
params.pageToken = data.nextPageToken;
|
||||
|
||||
if (data.drives) {
|
||||
for (const drive of data.drives) {
|
||||
drives.data.push({
|
||||
value: drive.id,
|
||||
name: drive.name,
|
||||
});
|
||||
}
|
||||
}
|
||||
} while (params.pageToken);
|
||||
|
||||
return drives;
|
||||
},
|
||||
};
|
@@ -1,16 +1,20 @@
|
||||
import defineApp from '../../helpers/define-app';
|
||||
import addAuthHeader from './common/add-auth-header';
|
||||
import auth from './auth';
|
||||
import triggers from './triggers';
|
||||
import dynamicData from './dynamic-data';
|
||||
|
||||
export default defineApp({
|
||||
name: 'Google Sheet',
|
||||
key: 'google-sheet',
|
||||
name: 'Google Sheets',
|
||||
key: 'google-sheets',
|
||||
baseUrl: 'https://docs.google.com/spreadsheets',
|
||||
apiBaseUrl: 'https://sheets.googleapis.com',
|
||||
iconUrl: '{BASE_URL}/apps/google-sheet/assets/favicon.svg',
|
||||
authDocUrl: 'https://automatisch.io/docs/apps/google-sheet/connection',
|
||||
iconUrl: '{BASE_URL}/apps/google-sheets/assets/favicon.svg',
|
||||
authDocUrl: 'https://automatisch.io/docs/apps/google-sheets/connection',
|
||||
primaryColor: '0F9D58',
|
||||
supportsConnections: true,
|
||||
beforeRequest: [addAuthHeader],
|
||||
auth,
|
||||
triggers,
|
||||
dynamicData,
|
||||
});
|
@@ -0,0 +1,3 @@
|
||||
import newSpreadsheets from './new-spreadsheets';
|
||||
|
||||
export default [newSpreadsheets];
|
@@ -0,0 +1,33 @@
|
||||
import defineTrigger from '../../../../helpers/define-trigger';
|
||||
import newSpreadsheets from './new-spreadsheets'
|
||||
|
||||
export default defineTrigger({
|
||||
name: 'New Spreadsheets',
|
||||
key: 'newSpreadsheets',
|
||||
pollInterval: 15,
|
||||
description: 'Triggers when you create a new spreadsheet.',
|
||||
arguments: [
|
||||
{
|
||||
label: 'Drive',
|
||||
key: 'driveId',
|
||||
type: 'dropdown' as const,
|
||||
required: false,
|
||||
description: 'The Google Drive where your spreadsheet resides. If nothing is selected, then your personal Google Drive will be used.',
|
||||
variables: false,
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
arguments: [
|
||||
{
|
||||
name: 'key',
|
||||
value: 'listDrives',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
async run($) {
|
||||
await newSpreadsheets($);
|
||||
},
|
||||
});
|
@@ -0,0 +1,33 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
|
||||
const newSpreadsheets = async ($: IGlobalVariable) => {
|
||||
const params = {
|
||||
pageToken: undefined as unknown as string,
|
||||
orderBy: 'createdTime desc',
|
||||
q: `mimeType='application/vnd.google-apps.spreadsheet'`,
|
||||
fields: '*',
|
||||
pageSize: 1000,
|
||||
driveId: $.step.parameters.driveId,
|
||||
};
|
||||
|
||||
do {
|
||||
const { data } = await $.http.get(
|
||||
'https://www.googleapis.com/drive/v3/files',
|
||||
{ params }
|
||||
);
|
||||
params.pageToken = data.nextPageToken;
|
||||
|
||||
if (data.files?.length) {
|
||||
for (const file of data.files) {
|
||||
$.pushTriggerItem({
|
||||
raw: file,
|
||||
meta: {
|
||||
internalId: file.id,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
} while (params.pageToken);
|
||||
};
|
||||
|
||||
export default newSpreadsheets;
|
@@ -69,7 +69,7 @@ function ControlledAutocomplete(
|
||||
},
|
||||
fieldState,
|
||||
}) => (
|
||||
<div style={{ width:'100%' }}>
|
||||
<div style={{ width: '100%' }}>
|
||||
{/* encapsulated with an element such as div to vertical spacing delegated from parent */}
|
||||
<Autocomplete
|
||||
{...autocompleteProps}
|
||||
@@ -102,7 +102,7 @@ function ControlledAutocomplete(
|
||||
renderOption={(optionProps, option) => (
|
||||
<li
|
||||
{...optionProps}
|
||||
key={option.value.toString()}
|
||||
key={option.value?.toString()}
|
||||
style={{ flexDirection: 'column', alignItems: 'start' }}
|
||||
>
|
||||
<Typography>{option.label}</Typography>
|
||||
|
Reference in New Issue
Block a user