Skip to content

Commit

Permalink
feat(google-sheet): add new spreadsheets trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
ridvanakca authored and barinali committed Apr 6, 2023
1 parent 41dd404 commit 9deed54
Show file tree
Hide file tree
Showing 17 changed files with 121 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down
3 changes: 3 additions & 0 deletions packages/backend/src/apps/google-sheets/dynamic-data/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import listDrives from './list-drives';

export default [listDrives];
Original file line number Diff line number Diff line change
@@ -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;
},
};
Original file line number Diff line number Diff line change
@@ -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,
});
3 changes: 3 additions & 0 deletions packages/backend/src/apps/google-sheets/triggers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import newSpreadsheets from './new-spreadsheets';

export default [newSpreadsheets];
Original file line number Diff line number Diff line change
@@ -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($);
},
});
Original file line number Diff line number Diff line change
@@ -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;
4 changes: 2 additions & 2 deletions packages/web/src/components/ControlledAutocomplete/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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>
Expand Down

0 comments on commit 9deed54

Please sign in to comment.