@@ -83,66 +83,40 @@ const dynamicData: IDynamicData = {
8383
8484 return processCaseFields ( filteredFields )
8585 } else if ( caseUuid ) {
86+ // account that case uuid can be pasted in the frontend
87+ // and may not always be a variable
88+ let computedCaseUuid = caseUuid as string
89+
8690 if (
8791 typeof caseUuid === 'string' &&
8892 caseUuid . match ( `^${ VARIABLE_REGEX . source } $` )
8993 ) {
9094 // 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 ( {
95+ computedCaseUuid = ( await getCaseUuidFromVariable (
10296 $ ,
103- caseTypeUuid : caseData . data . type . uuid ,
104- } )
105- return processCaseFields ( filteredFields )
97+ caseUuid ,
98+ ) ) as string
10699 }
107100
108- return {
109- data : [ ] ,
110- }
111- }
112-
113- // BACKWARD COMPATIBILITY: this gets the case fields from the latest case in gathersg
114- const { data : searchResult } = await $ . http . post < {
115- traceId : string
116- total : number
117- data : GatherSGCase [ ]
118- } > ( '/cases/search' , {
119- page : 1 ,
120- size : 1 ,
121- sort : 'createdAt' ,
122- order : 'desc' ,
123- } )
124-
125- /**
126- * No cases found
127- */
128- if ( searchResult . data . length === 0 ) {
129- return {
130- data : [ ] ,
131- }
132- }
101+ // use the case uuid to fetch the case data to derive the case type uuid
102+ const { data : caseData } = await $ . http . get < { data : GatherSGCase } > (
103+ `/cases/:caseUuid` ,
104+ {
105+ urlPathParams : { caseUuid : computedCaseUuid } ,
106+ } ,
107+ )
133108
134- const caseFields : object = searchResult . data [ 0 ] . fields
135- const updatedCaseFields : { name : string ; value : string } [ ] = [ ]
136- for ( const [ field , value ] of Object . entries ( caseFields ) ) {
137- // Right now, we cannot support adding of array of objects as a value so just going to exclude to not cause errors unnecessarily
138- if ( Array . isArray ( value ) ) {
139- continue
140- }
141- updatedCaseFields . push ( { name : field , value : field } )
109+ const { filteredFields } = await fetchCaseFields ( {
110+ $,
111+ caseTypeUuid : caseData . data . type . uuid ,
112+ } )
113+ return processCaseFields ( filteredFields )
142114 }
143115
116+ // fallback to return empty array
117+ // user can still manually input the case field
144118 return {
145- data : updatedCaseFields ,
119+ data : [ ] ,
146120 }
147121 } catch ( error ) {
148122 if ( error instanceof HttpError ) {
0 commit comments