Skip to content

Commit cd73274

Browse files
committed
donotmerge: for each user testing
1 parent b86f6ba commit cd73274

File tree

35 files changed

+770
-112
lines changed

35 files changed

+770
-112
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import loopItems from './loop-items'
2+
3+
export default [loopItems]
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { IDataOutMetadata, IExecutionStep } from '@plumber/types'
2+
3+
async function getDataOutMetadata(
4+
executionStep: IExecutionStep,
5+
): Promise<IDataOutMetadata> {
6+
const { dataOut: rawDataOut } = executionStep
7+
if (!rawDataOut) {
8+
return null
9+
}
10+
11+
let inputList = rawDataOut.inputList
12+
if (rawDataOut.inputType === 'array') {
13+
inputList = JSON.parse(rawDataOut.inputList as string)
14+
}
15+
16+
return {
17+
iterations: {
18+
label: 'Number of items',
19+
},
20+
inputList: {
21+
label: 'Input list',
22+
type: 'hidden',
23+
},
24+
inputType: {
25+
label: 'Input type',
26+
type: 'hidden',
27+
},
28+
arrayValue: {
29+
label: 'Array value',
30+
displayedValue: Array.isArray(inputList)
31+
? JSON.stringify(inputList[0])
32+
: undefined,
33+
},
34+
}
35+
}
36+
37+
export default getDataOutMetadata
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { IRawAction } from '@plumber/types'
2+
3+
import StepError from '@/errors/step'
4+
5+
import getDataOutMetadata from './get-data-out-metadata'
6+
7+
const action: IRawAction = {
8+
name: 'Loops',
9+
key: 'forEach',
10+
description: 'Loops through items',
11+
groupsLaterSteps: true,
12+
arguments: [
13+
{
14+
label: 'Loop items',
15+
description:
16+
'Supported lists include find multiple rows actions and FormSG checkboxes',
17+
key: 'forEachInputList',
18+
type: 'string' as const,
19+
required: true,
20+
variables: true,
21+
variableTypes: ['array'],
22+
},
23+
],
24+
25+
getDataOutMetadata,
26+
27+
async run($) {
28+
const { forEachInputList } = $.step.parameters as {
29+
forEachInputList: string
30+
}
31+
32+
try {
33+
const isJsonString =
34+
forEachInputList.includes('[') || forEachInputList.includes('{')
35+
const inputList = isJsonString
36+
? JSON.parse(forEachInputList)
37+
: forEachInputList.split(',').map((item) => item.trim())
38+
39+
$.setActionItem({
40+
raw: {
41+
iterations: inputList.length,
42+
},
43+
})
44+
45+
return {
46+
nextStep: {
47+
command: 'start-loop',
48+
stepId: $.step.id,
49+
},
50+
}
51+
} catch (err) {
52+
console.error(err)
53+
throw new StepError(
54+
'Invalid input list',
55+
'Select a valid input list',
56+
$.step.position,
57+
$.app.name,
58+
)
59+
}
60+
},
61+
}
62+
63+
export default action
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { IApp } from '@plumber/types'
2+
3+
import actions from './actions'
4+
5+
const app: IApp = {
6+
name: 'Loops',
7+
description: 'Loop through items',
8+
key: 'for-each',
9+
iconUrl: '{BASE_URL}/apps/for-each/assets/favicon.svg',
10+
authDocUrl: '',
11+
baseUrl: '',
12+
apiBaseUrl: '',
13+
primaryColor: '',
14+
actions,
15+
category: 'logic',
16+
}
17+
18+
export default app

packages/backend/src/apps/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { IApp } from '@plumber/types'
33
import calculatorApp from './calculator'
44
import customApiApp from './custom-api'
55
import delayApp from './delay'
6+
import forEachApp from './for-each'
67
import formatterApp from './formatter'
78
import formsgApp from './formsg'
89
import lettersgApp from './lettersg'
@@ -23,6 +24,7 @@ const apps: Record<string, IApp> = {
2324
[calculatorApp.key]: calculatorApp,
2425
[customApiApp.key]: customApiApp,
2526
[delayApp.key]: delayApp,
27+
[forEachApp.key]: forEachApp,
2628
[formatterApp.key]: formatterApp,
2729
[formsgApp.key]: formsgApp,
2830
[lettersgApp.key]: lettersgApp,

packages/backend/src/apps/m365-excel/__tests__/actions/get-table-rows-metadata.test.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe('getTableRows getDataOutMetadata', () => {
2222

2323
expect(result).toEqual({
2424
rowsFound: {
25-
label: 'No. of rows found',
25+
label: 'Number of rows found',
2626
},
2727
})
2828
})
@@ -58,20 +58,25 @@ describe('getTableRows getDataOutMetadata', () => {
5858

5959
expect(result).toEqual({
6060
rows: {
61-
label: 'Data rows',
62-
displayedValue: '2 rows',
61+
displayedValue: 'Preview 2 row(s)',
62+
label: 'List of row(s) found',
63+
type: 'array',
6364
},
6465
rowsFound: {
65-
label: 'No. of rows found',
66+
label: 'Number of rows found',
6667
},
6768
columns: [
6869
{
6970
label: 'Column1',
70-
displayedValue: '',
71+
displayedValue: ' ',
72+
order: 1,
73+
value: 'Column1',
7174
},
7275
{
7376
label: 'Column2',
74-
displayedValue: '',
77+
displayedValue: ' ',
78+
order: 2,
79+
value: 'Column2',
7580
},
7681
],
7782
})
@@ -90,11 +95,12 @@ describe('getTableRows getDataOutMetadata', () => {
9095

9196
expect(result).toEqual({
9297
rowsFound: {
93-
label: 'No. of rows found',
98+
label: 'Number of rows found',
9499
},
95100
rows: {
96-
label: 'Data rows',
97-
displayedValue: '1 rows',
101+
displayedValue: 'Preview 1 row(s)',
102+
label: 'List of row(s) found',
103+
type: 'array',
98104
},
99105
columns: [],
100106
})

packages/backend/src/apps/tiles/actions/find-multiple-rows/get-data-out-metadata.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ async function getDataOutMetadata(
2929
rows: {
3030
label: 'List of row(s) found',
3131
displayedValue: `Preview ${dataOut.rowsFound} row(s)`,
32+
type: 'array',
33+
},
34+
rowId: {
35+
label: 'Row ID',
36+
value: 'rowId',
37+
displayedValue: ' ',
3238
},
3339
}
3440

@@ -39,7 +45,8 @@ async function getDataOutMetadata(
3945
label: name,
4046
order: columnOrder[id] ?? null,
4147
// leave as blank to not display column id in the frontend
42-
displayedValue: '',
48+
displayedValue: ' ',
49+
value: id,
4350
}
4451
})
4552
}

packages/backend/src/apps/tiles/actions/find-multiple-rows/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,7 @@ const action: IRawAction = {
194194
$.setActionItem({
195195
raw: {
196196
rowsFound: 0,
197-
rows: JSON.stringify([]),
198-
columns: {},
197+
rows: [],
199198
} satisfies FindMultipleRowsOutput,
200199
})
201200
return
@@ -219,6 +218,7 @@ const action: IRawAction = {
219218
rowsFound: slicedRows.length,
220219
rows: JSON.stringify(slicedRows),
221220
columns: columnsToReturn,
221+
rowId: 'rowId',
222222
} satisfies FindMultipleRowsOutput,
223223
})
224224
},
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Knex } from 'knex'
2+
3+
export async function up(knex: Knex): Promise<void> {
4+
return knex.schema.table('execution_steps', (table) => {
5+
table.string('key').nullable()
6+
})
7+
}
8+
9+
export async function down(knex: Knex): Promise<void> {
10+
return knex.schema.table('execution_steps', (table) => {
11+
table.dropColumn('key')
12+
})
13+
}

0 commit comments

Comments
 (0)