Skip to content

Commit d643a93

Browse files
committed
Revert "revert(zapier): make View a text field again — view list isn't OAuth-accessible"
This reverts commit 3b8c0d8.
1 parent 3b8c0d8 commit d643a93

6 files changed

Lines changed: 53 additions & 4 deletions

File tree

packages/zapier/src/authentication.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const SCOPES = [
1515
'base|read',
1616
'table|read',
1717
'field|read',
18+
'view|read',
1819
'record|read',
1920
'record|create',
2021
'record|update',

packages/zapier/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { rawInstance } from './lib/client';
77
import bases from './triggers/bases';
88
import tables from './triggers/tables';
99
import fields from './triggers/fields';
10+
import views from './triggers/views';
1011
import newRecord from './triggers/new_record';
1112
import newOrUpdatedRecord from './triggers/new_or_updated_record';
1213

@@ -73,6 +74,7 @@ const App = {
7374
bases,
7475
tables,
7576
fields,
77+
views,
7678
new_record: newRecord,
7779
new_or_updated_record: newOrUpdatedRecord,
7880
},

packages/zapier/src/lib/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ export interface TeableTable {
3030
name: string;
3131
}
3232

33+
// A view as returned by GET /table/{tableId}/view.
34+
export interface TeableView {
35+
id: string;
36+
name: string;
37+
}
38+
3339
// An { id, name } row used to populate Zapier dynamic dropdowns.
3440
export interface DropdownItem {
3541
id: string;

packages/zapier/src/triggers/new_or_updated_record.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,17 @@ export default {
4646
required: true,
4747
dynamic: 'tables.id.name',
4848
search: 'tables.id',
49+
// Pass the chosen table down so the View dropdown (which depends on
50+
// tableId) re-fetches with it in scope.
51+
altersDynamicFields: true,
4952
},
5053
{
5154
key: 'viewId',
5255
label: 'View',
5356
type: 'string',
5457
required: false,
55-
helpText:
56-
'Optional. The `viw…` id of a view to limit records to (from the view URL). Leave blank for all records.',
58+
dynamic: 'views.id.name',
59+
helpText: 'Limit to records in a specific view. Leave blank for all records.',
5760
},
5861
],
5962
perform,

packages/zapier/src/triggers/new_record.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,17 @@ export default {
3636
required: true,
3737
dynamic: 'tables.id.name',
3838
search: 'tables.id',
39+
// Pass the chosen table down so the View dropdown (which depends on
40+
// tableId) re-fetches with it in scope.
41+
altersDynamicFields: true,
3942
},
4043
{
4144
key: 'viewId',
4245
label: 'View',
4346
type: 'string',
4447
required: false,
45-
helpText:
46-
'Optional. The `viw…` id of a view to limit records to (from the view URL). Leave blank for all records.',
48+
dynamic: 'views.id.name',
49+
helpText: 'Limit to records in a specific view. Leave blank for all records.',
4750
},
4851
],
4952
perform,
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import type { ZObject, Bundle } from 'zapier-platform-core';
2+
import { apiUrl } from '../lib/client';
3+
import type { TeableView, DropdownItem } from '../lib/types';
4+
5+
// Hidden trigger powering the "View" dropdown. Depends on a chosen tableId.
6+
const perform = async (z: ZObject, bundle: Bundle): Promise<DropdownItem[]> => {
7+
const { tableId } = bundle.inputData;
8+
z.console.log(`views dropdown: tableId=${tableId ?? '(none)'}`);
9+
if (!tableId) return [];
10+
const response = await z.request<TeableView[]>({
11+
url: apiUrl(bundle, `/table/${tableId}/view`),
12+
});
13+
const items = (response.data || []).map((view) => ({
14+
id: view.id,
15+
name: view.name,
16+
}));
17+
z.console.log(`views dropdown: ${items.length} view(s) for table ${tableId}`);
18+
return items;
19+
};
20+
21+
export default {
22+
key: 'views',
23+
noun: 'View',
24+
display: {
25+
label: 'List Views',
26+
description: 'Internal trigger used to populate the View dropdown.',
27+
hidden: true,
28+
},
29+
operation: {
30+
inputFields: [{ key: 'tableId', type: 'string', required: true }],
31+
perform,
32+
sample: { id: 'viwXXXXXXXXXXXX', name: 'Grid view' },
33+
},
34+
};

0 commit comments

Comments
 (0)