Skip to content

Commit 435908d

Browse files
committed
[OG-4]: Get case fields based on uuid for update case (#1282)
## TL;DR Fetches the case fields based on the case UUID that is selected or input. Works with pasted case UUID and variables. ## Why make this change? Ensures that the fields are valid for the selected case. * Previous implementation fetched the fields based on the last case that was created in OG, but OG can have multiple case types. * Reduces errors for user than if they were to manually type in the field ## Tests - [ ] Correct fields are fetched for different case UUIDs - [ ] Update case fetches correct fields with case uuid variable - [ ] Update case fetches correct fields with case uuid variable from for each
1 parent a768739 commit 435908d

File tree

3 files changed

+96
-32
lines changed

3 files changed

+96
-32
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const action: IRawAction = {
2323
label: 'Case type',
2424
key: 'caseType',
2525
type: 'dropdown' as const,
26-
description: 'Enter the type of the case you want to create',
26+
description: 'Select the type of the case you want to create',
2727
required: true,
2828
variables: false,
2929
showOptionValue: false,

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,19 @@ const action: IRawAction = {
2020
label: 'Case UUID',
2121
key: 'caseUuid',
2222
type: 'string' as const,
23-
description: 'Enter the case uuid you want to update',
23+
description: 'Select the case uuid you want to update.',
2424
required: true,
2525
variables: true,
26+
// we intentionally disable typing for case uuid as it is used in
27+
// to get dynamic data for case fields
28+
// it can still be pasted via mouse click
2629
singleVariableSelection: true,
2730
},
28-
// TODO: see if it is possible to get all possible statuses from the API
2931
{
3032
label: 'Case status',
3133
key: 'caseStatus',
3234
type: 'dropdown' as const,
33-
description: 'Enter the status you want to update the case to.',
35+
description: 'Select the status you want to update the case to.',
3436
required: false,
3537
variables: false,
3638
showOptionValue: false,
@@ -65,6 +67,10 @@ const action: IRawAction = {
6567
name: 'key',
6668
value: 'getCaseFields',
6769
},
70+
{
71+
name: 'parameters.caseUuid',
72+
value: '{parameters.caseUuid}',
73+
},
6874
],
6975
},
7076
customStyle: { flex: 2 },

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

Lines changed: 86 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,54 +5,112 @@ import {
55
} from '@plumber/types'
66

77
import HttpError from '@/errors/http'
8+
import { VARIABLE_REGEX } from '@/helpers/check-step-parameters'
9+
import { computeForEachParameters } from '@/helpers/compute-for-each-parameters'
10+
import computeParameters from '@/helpers/compute-parameters'
11+
import { getTestExecutionSteps } from '@/helpers/get-test-execution-steps'
812

9-
import { fetchCaseFields } from '../common/fetch-case-fields'
10-
import { GatherSGError } from '../common/types'
11-
12-
/**
13-
* Subset of result
14-
*/
15-
interface GatherSGCase {
16-
uuid: string
17-
createdAt: string
18-
updatedAt: string
19-
status: {
20-
uuid: string
21-
name: string
22-
color: string
23-
isFinal: boolean
13+
import { fetchCaseFields, GatherSGCaseField } from '../common/fetch-case-fields'
14+
import { GatherSGCase, GatherSGError } from '../common/types'
15+
16+
const getCaseUuidFromVariable = async (
17+
$: IGlobalVariable,
18+
variable: string,
19+
) => {
20+
const testExecutionSteps = await getTestExecutionSteps($.flow.id)
21+
22+
if (/items.columns/.test(variable)) {
23+
// if variable from for each, then we compute slightly differently
24+
const stepIdAndKeyPath = variable.replace(/{{step.|}}/g, '') as string
25+
const [stepId, ...keyPaths] = stepIdAndKeyPath.split('.')
26+
27+
const executionStep = testExecutionSteps.find((executionStep) => {
28+
return executionStep.stepId === stepId
29+
})
30+
31+
if (!executionStep) {
32+
return ''
33+
}
34+
35+
return computeForEachParameters({
36+
data: executionStep?.dataOut,
37+
keyPath: keyPaths.join('.'),
38+
executionSteps: testExecutionSteps,
39+
executionStep,
40+
stepId,
41+
forEachContext: {
42+
executionStepMetadata: testExecutionSteps[0].metadata,
43+
forEachStepPosition: 0,
44+
isForEachStep: true,
45+
stepPositions: {
46+
[stepId]: 0,
47+
},
48+
},
49+
})
50+
} else {
51+
const { caseUuid } = computeParameters(
52+
{ caseUuid: variable },
53+
testExecutionSteps,
54+
)
55+
return caseUuid
56+
}
57+
}
58+
59+
const processCaseFields = (caseFields: GatherSGCaseField[]) => {
60+
return {
61+
data: caseFields.map((field) => {
62+
return {
63+
name: field.name,
64+
value: field.name,
65+
}
66+
}),
2467
}
25-
caseRef: string
26-
fields: Record<string, string | string[] | null | number>
27-
tags: string[]
2868
}
2969

3070
const dynamicData: IDynamicData = {
3171
key: 'getCaseFields',
3272
name: 'Get Case Fields',
3373
async run($: IGlobalVariable): Promise<DynamicDataOutput> {
3474
try {
35-
const { caseType: caseTypeUuid } = $.step.parameters
75+
const { caseType: caseTypeUuid, caseUuid } = $.step.parameters
3676

3777
if (caseTypeUuid) {
78+
// Fetch case fields using the determined case type UUID
3879
const { filteredFields } = await fetchCaseFields({
3980
$,
4081
caseTypeUuid: caseTypeUuid as string,
4182
})
4283

84+
return processCaseFields(filteredFields)
85+
} else if (caseUuid) {
86+
if (
87+
typeof caseUuid === 'string' &&
88+
caseUuid.match(`^${VARIABLE_REGEX.source}$`)
89+
) {
90+
// if the case uuid is a variable, we need to compute the value
91+
const computedCaseUuid = await getCaseUuidFromVariable($, caseUuid)
92+
93+
// use the case uuid to fetch the case data to derive the case type uuid
94+
const { data: caseData } = await $.http.get<{ data: GatherSGCase }>(
95+
`/cases/:caseUuid`,
96+
{
97+
urlPathParams: { caseUuid: computedCaseUuid as string },
98+
},
99+
)
100+
101+
const { filteredFields } = await fetchCaseFields({
102+
$,
103+
caseTypeUuid: caseData.data.type.uuid,
104+
})
105+
return processCaseFields(filteredFields)
106+
}
107+
43108
return {
44-
data: filteredFields.map((field) => {
45-
return {
46-
name: field.name,
47-
value: field.name,
48-
}
49-
}),
109+
data: [],
50110
}
51111
}
52112

53-
// TODO (kevinkim-ogp): this needs to be updated to use the caseUuid to fetch the fields
54-
// of that specific case using /cases/{caseUuid}
55-
// need to figure out how to do this with both string and computed parameters if the UUID is a variable
113+
// BACKWARD COMPATIBILITY: this gets the case fields from the latest case in gathersg
56114
const { data: searchResult } = await $.http.post<{
57115
traceId: string
58116
total: number

0 commit comments

Comments
 (0)