Skip to content

Commit f0835fd

Browse files
fix: grpc resource issue around datatypes
1 parent e9738b5 commit f0835fd

File tree

3 files changed

+77
-5
lines changed

3 files changed

+77
-5
lines changed

core/test/generator_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ func TestGrpcServerGeneratorNoSql(t *testing.T) {
612612
Json: grpcServerConfigJSON,
613613
}
614614
defer func() {
615-
//_ = os.RemoveAll("/tmp/first-grpc-server-project-nosql")
615+
_ = os.RemoveAll("/tmp/first-grpc-server-project-nosql")
616616
}()
617617

618618
// retrieve project struct

ui/src/components/diagram-maker/node-properties/add-or-update-grpc-server-resource.tsx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export const AddOrUpdateGrpcServerResource = (props: AddOrUpdateGrpcServerResour
102102
errorMessage: ''
103103
},
104104
datatype: '',
105+
isComposite: false,
105106
mode: {
106107
index: 0,
107108
edit: false
@@ -169,14 +170,21 @@ export const AddOrUpdateGrpcServerResource = (props: AddOrUpdateGrpcServerResour
169170
if (field.mode.edit) {
170171
payload.fieldsCollection.splice(field.mode.index, 1);
171172
}
172-
payload.fieldsCollection.push({attribute: field.attribute.value, datatype: field.datatype});
173+
payload.fieldsCollection.push({
174+
attribute: field.attribute.value,
175+
datatype: field.datatype,
176+
isComposite: field.isComposite
177+
});
173178
setPayload({...payload});
174179
setField({
175180
attribute: {
176181
value: '',
177182
error: false,
178183
errorMessage: ''
179-
}, datatype: '', mode: {edit: false, index: 0}
184+
},
185+
datatype: '',
186+
isComposite: false,
187+
mode: {edit: false, index: 0}
180188
});
181189
}
182190
};
@@ -189,6 +197,7 @@ export const AddOrUpdateGrpcServerResource = (props: AddOrUpdateGrpcServerResour
189197
errorMessage: '',
190198
error: false
191199
},
200+
isComposite: payload.fieldsCollection[index].isComposite,
192201
datatype: payload.fieldsCollection[index].datatype,
193202
// set the index and mode as true
194203
mode: {edit: true, index}
@@ -321,7 +330,11 @@ export const AddOrUpdateGrpcServerResource = (props: AddOrUpdateGrpcServerResour
321330
const addOrUpdateGrpcResource = () => {
322331
const fields = {};
323332
for (const fld of payload.fieldsCollection) {
324-
fields[fld.attribute] = fld.datatype;
333+
if (fld.isComposite) {
334+
fields[fld.attribute] = {datatype: fld.datatype, isComposite: fld.isComposite};
335+
} else {
336+
fields[fld.attribute] = {datatype: fld.datatype};
337+
}
325338
}
326339
const resource: Resource = {fields: JSON.parse(JSON.stringify(fields)), name: payload.name.value};
327340
if (isNameValid()) {
@@ -337,6 +350,7 @@ export const AddOrUpdateGrpcServerResource = (props: AddOrUpdateGrpcServerResour
337350
fieldsCollection: []
338351
});
339352
setField({
353+
isComposite: false,
340354
datatype: '',
341355
attribute: {
342356
value: '',
@@ -453,6 +467,7 @@ export const AddOrUpdateGrpcServerResource = (props: AddOrUpdateGrpcServerResour
453467
<TableRow>
454468
<TableCell align="left">Attribute</TableCell>
455469
<TableCell align="center">Datatype</TableCell>
470+
<TableCell align="center">Is Composite</TableCell>
456471
<TableCell align="center">Actions</TableCell>
457472
</TableRow>
458473
</TableHead>
@@ -467,6 +482,7 @@ export const AddOrUpdateGrpcServerResource = (props: AddOrUpdateGrpcServerResour
467482
{fld.attribute}
468483
</TableCell>
469484
<TableCell align="center">{fld.datatype}</TableCell>
485+
<TableCell align="center">{fld.isComposite ? "Yes" : "No"}</TableCell>
470486
<TableCell align="left">
471487
<Stack direction="row-reverse" spacing={1}>
472488
<Button variant="text"

ui/src/components/diagram-maker/node-properties/new-node-properties.tsx

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ interface NodeTypesConfig {
7373
hasRestClients?: boolean;
7474
restConfig?: RestConfig;
7575
isGrpcServer?: boolean;
76+
isGrpcServerNoSQLDB?: boolean;
77+
isGrpcServerSQLDB?: boolean;
7678
hasGrpcClients?: boolean;
7779
grpcConfig?: GrpcConfig;
7880
isWsServer?: boolean;
@@ -176,6 +178,8 @@ export const NewNodeProperties = (props: NewNodePropertiesProps) => {
176178
hasRestClients: nodeTypesConfig.hasRestClients || false,
177179
restConfig: nodeTypesConfig.restConfig || getEmptyRestConfig(),
178180
isGrpcServer: nodeTypesConfig.isGrpcServer || false,
181+
isGrpcServerSQLDB: nodeTypesConfig.isGrpcServerSQLDB || false,
182+
isGrpcServerNoSQLDB: nodeTypesConfig.isGrpcServerNoSQLDB || false,
179183
hasGrpcClients: nodeTypesConfig.hasGrpcClients || false,
180184
grpcConfig: nodeTypesConfig.grpcConfig || getEmptyGrpcConfig(),
181185
isWsServer: nodeTypesConfig.isWsServer || false,
@@ -358,6 +362,8 @@ export const NewNodeProperties = (props: NewNodePropertiesProps) => {
358362
},
359363
language: '',
360364
isGrpcServer: false,
365+
isGrpcServerNoSQLDB: false,
366+
isGrpcServerSQLDB: false,
361367
isRestServer: false,
362368
isRestServerNoSQLDB: false,
363369
isRestServerSQLDB: false,
@@ -426,6 +432,26 @@ export const NewNodeProperties = (props: NewNodePropertiesProps) => {
426432
});
427433
};
428434

435+
const handleIsGrpcServerSQLDBChange = (event: ChangeEvent<HTMLInputElement>) => {
436+
const grpcConfig: GrpcConfig = payload.grpcConfig;
437+
grpcConfig.server.noSQLDB = '';
438+
setPayload({
439+
...payload,
440+
isGrpcServerSQLDB: event.target.checked,
441+
grpcConfig,
442+
});
443+
};
444+
445+
const handleIsGrpcServerNoSQLDBChange = (event: ChangeEvent<HTMLInputElement>) => {
446+
const grpcConfig: GrpcConfig = payload.grpcConfig;
447+
grpcConfig.server.sqlDB = '';
448+
setPayload({
449+
...payload,
450+
isGrpcServerNoSQLDB: event.target.checked,
451+
grpcConfig
452+
});
453+
};
454+
429455
const handleIsRestServerSQLDBChange = (event: ChangeEvent<HTMLInputElement>) => {
430456
const restConfig: RestConfig = payload.restConfig;
431457
restConfig.server.noSQLDB = '';
@@ -677,7 +703,7 @@ export const NewNodeProperties = (props: NewNodePropertiesProps) => {
677703
</TextField>;
678704
}
679705
}
680-
return ''
706+
return '';
681707
};
682708

683709
const getRestServerSQLDBContent = () => {
@@ -1067,7 +1093,9 @@ export const NewNodeProperties = (props: NewNodePropertiesProps) => {
10671093
{getGrpcTemplateContent()}
10681094
{getGrpcFrameworkContent()}
10691095
{getGrpcServerPortContent()}
1096+
{getGrpcServerSQLDBCheck()}
10701097
{getGrpcServerSQLDBContent()}
1098+
{getGrpcServerNoSQLDBCheck()}
10711099
{getGrpcServerNoSQLDBContent()}
10721100
{getGrpcServerResourcesContent()}
10731101
</React.Fragment>;
@@ -1170,6 +1198,34 @@ export const NewNodeProperties = (props: NewNodePropertiesProps) => {
11701198
return [];
11711199
};
11721200

1201+
const getGrpcServerSQLDBCheck = () => {
1202+
return <React.Fragment>
1203+
<FormControlLabel
1204+
label="SQL DB"
1205+
control={<Checkbox
1206+
id="isGrpcServerSQLDB"
1207+
disabled={payload.isGrpcServerNoSQLDB}
1208+
size="medium" checked={payload.isGrpcServerSQLDB}
1209+
onChange={handleIsGrpcServerSQLDBChange}
1210+
/>}
1211+
/>
1212+
</React.Fragment>;
1213+
};
1214+
1215+
const getGrpcServerNoSQLDBCheck = () => {
1216+
return <React.Fragment>
1217+
<FormControlLabel
1218+
label="NoSQL DB"
1219+
control={<Checkbox
1220+
id="isGrpcServerNoSQLDB"
1221+
disabled={payload.isGrpcServerSQLDB}
1222+
size="medium" checked={payload.isGrpcServerNoSQLDB}
1223+
onChange={handleIsGrpcServerNoSQLDBChange}
1224+
/>}
1225+
/>
1226+
</React.Fragment>;
1227+
};
1228+
11731229
const getRestServerSQLDBCheck = () => {
11741230
return <React.Fragment>
11751231
<FormControlLabel

0 commit comments

Comments
 (0)