Skip to content

Commit f3583f6

Browse files
committed
fix: dynamic data and default field type
1 parent e1f2866 commit f3583f6

File tree

6 files changed

+44
-47
lines changed

6 files changed

+44
-47
lines changed

packages/backend/src/apps/gathersg/actions/update-case/index.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ const action: IRawAction = {
2424
'You can only select a step variable here to make reference to.',
2525
required: true,
2626
variables: true,
27-
singleVariableSelection: true,
2827
},
2928
// TODO: see if it is possible to get all possible statuses from the API
3029
{
@@ -34,16 +33,12 @@ const action: IRawAction = {
3433
description: 'Enter the status you want to update the case to.',
3534
required: false,
3635
variables: true,
37-
hiddenIf: {
38-
fieldKey: 'caseUuid',
39-
op: 'is_empty',
40-
},
4136
},
4237
{
4338
label: 'Case fields',
4439
key: 'caseFields',
4540
type: 'multirow-multicol' as const,
46-
required: true,
41+
required: false,
4742
description:
4843
'Specify values for each field you want to update in your case. Note that fields that require an array of objects as a value are not supported yet.',
4944

@@ -64,10 +59,6 @@ const action: IRawAction = {
6459
name: 'key',
6560
value: 'getCaseFields',
6661
},
67-
{
68-
name: 'parameters.caseUuid',
69-
value: '{parameters.caseUuid}',
70-
},
7162
],
7263
},
7364
customStyle: { flex: 2 },
@@ -78,6 +69,8 @@ const action: IRawAction = {
7869
type: 'dropdown' as const,
7970
showOptionValue: false,
8071
required: true,
72+
value: 'string',
73+
variables: false,
8174
options: [
8275
{
8376
label: 'String',
@@ -108,10 +101,6 @@ const action: IRawAction = {
108101
customStyle: { flex: 3, minWidth: 0, maxWidth: '60%' },
109102
},
110103
],
111-
hiddenIf: {
112-
fieldKey: 'caseUuid',
113-
op: 'is_empty',
114-
},
115104
},
116105
],
117106

packages/backend/src/apps/gathersg/actions/update-case/schema.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ export const requestSchema = z
2020
.array(
2121
z.object({
2222
field: z.string().trim().min(1, 'Field empty'),
23-
fieldType: fieldTypeEnum,
23+
// we add nullish here because defaultValue or value doesnt work properly in dropdown
24+
fieldType: fieldTypeEnum.nullish(),
2425
value: z.string().trim().nullish(),
2526
}),
2627
)

packages/backend/src/apps/gathersg/dynamic-data/get-case-fields.ts

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,49 +5,53 @@ import {
55
} from '@plumber/types'
66

77
import HttpError from '@/errors/http'
8-
import computeParameters from '@/helpers/compute-parameters'
9-
import ExecutionStep from '@/models/execution-step'
108

119
import { GatherSGError } from '../common/types'
1210

11+
/**
12+
* Subset of result
13+
*/
14+
interface GatherSGCase {
15+
uuid: string
16+
createdAt: string
17+
updatedAt: string
18+
status: {
19+
uuid: string
20+
name: string
21+
color: string
22+
isFinal: boolean
23+
}
24+
caseRef: string
25+
fields: Record<string, string | string[] | null | number>
26+
tags: string[]
27+
}
28+
1329
const dynamicData: IDynamicData = {
1430
key: 'getCaseFields',
1531
name: 'Get Case Fields',
1632
async run($: IGlobalVariable): Promise<DynamicDataOutput> {
1733
try {
18-
// This action only allows a step variable which we have to attempt to compute the parameter value, thinking if there is a better way to do this
19-
// TODO: see if we can refresh the case fields from the API instead of using the cached data because right now, the user has to manually refresh the case fields to get the latest data
20-
const { caseUuid } = $.step.parameters
21-
if (!caseUuid) {
22-
return {
23-
data: [],
24-
}
25-
}
26-
27-
const priorExecutionSteps = await ExecutionStep.query().where({
28-
execution_id: $.flow.testExecutionId,
29-
status: 'success',
30-
})
31-
32-
const computedParameters = computeParameters(
33-
$.step.parameters,
34-
priorExecutionSteps,
35-
)
36-
const computedCaseUuid = computedParameters.caseUuid as string
37-
38-
const { data: responseData } = await $.http.get(`/cases/:caseUuid`, {
39-
urlPathParams: {
40-
caseUuid: computedCaseUuid,
41-
},
34+
const { data: searchResult } = await $.http.post<{
35+
traceId: string
36+
total: number
37+
data: GatherSGCase[]
38+
}>('/cases/search', {
39+
page: 1,
40+
size: 1,
41+
sort: 'createdAt',
42+
order: 'desc',
4243
})
4344

44-
if (!responseData?.data) {
45+
/**
46+
* No cases found
47+
*/
48+
if (searchResult.data.length === 0) {
4549
return {
4650
data: [],
4751
}
4852
}
4953

50-
const caseFields: object = responseData.data.fields
54+
const caseFields: object = searchResult.data[0].fields
5155
const updatedCaseFields: { name: string; value: string }[] = []
5256
for (const [field, value] of Object.entries(caseFields)) {
5357
// Right now, we cannot support adding of array of objects as a value so just going to exclude to not cause errors unnecessarily
@@ -87,7 +91,7 @@ const dynamicData: IDynamicData = {
8791

8892
return {
8993
data: [],
90-
error: error?.message || 'Unknown error',
94+
error: error?.message || error?.code || 'Unknown error',
9195
}
9296
}
9397
},

packages/backend/src/helpers/global-variable.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ const globalVariable = async (
7272
userId: flow?.userId,
7373
hasFileProcessingActions:
7474
(await flow?.containsFileProcessingActions()) ?? false,
75-
testExecutionId: flow?.testExecutionId,
7675
},
7776
step: {
7877
id: step?.id,

packages/frontend/src/components/MultiRow/index.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,12 @@ function MultiRow(props: MultiRowProps): JSX.Element {
106106
{actualRows.map((row, index) => {
107107
const namePrefix = `${name}.${index}`
108108
return (
109-
<Flex key={row.id} flexDir="column" gap={4} mb={4}>
109+
<Flex
110+
key={`${row.id}-${index}`}
111+
flexDir="column"
112+
gap={4}
113+
mb={4}
114+
>
110115
{type === 'multirow-multicol' ? (
111116
<>
112117
<MultiCol

packages/types/index.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,6 @@ export type IGlobalVariable = {
859859
userId: string
860860
remoteWebhookId?: string
861861
setRemoteWebhookId?: (remoteWebhookId: string) => Promise<void>
862-
testExecutionId: string
863862
}
864863
step?: {
865864
id: string

0 commit comments

Comments
 (0)