Skip to content

Commit 87981c9

Browse files
committed
2385 - SF
1 parent d02c8ed commit 87981c9

File tree

13 files changed

+234
-134
lines changed

13 files changed

+234
-134
lines changed

docs/content/docs/reference/components/coda.mdx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Version: 1
3939
## Actions
4040

4141

42-
### List docs
42+
### List Docs
4343
Name: listDocs
4444

4545
`Returns a list of docs accessible by the user, and which they have opened at least once.`
@@ -55,7 +55,7 @@ Name: listDocs
5555
#### Example JSON Structure
5656
```json
5757
{
58-
"label" : "List docs",
58+
"label" : "List Docs",
5959
"name" : "listDocs",
6060
"parameters" : {
6161
"isOwner" : false,
@@ -133,7 +133,7 @@ Type: OBJECT
133133
```
134134

135135

136-
### Copy doc
136+
### Copy Doc
137137
Name: copyDoc
138138

139139
`Copies an existing doc.`
@@ -148,7 +148,7 @@ Name: copyDoc
148148
#### Example JSON Structure
149149
```json
150150
{
151-
"label" : "Copy doc",
151+
"label" : "Copy Doc",
152152
"name" : "copyDoc",
153153
"parameters" : {
154154
"title" : "",
@@ -231,7 +231,7 @@ Type: OBJECT
231231
```
232232

233233

234-
### Update row
234+
### Update Row
235235
Name: updateRow
236236

237237
`Updates the specified row in the table.`
@@ -248,7 +248,7 @@ Name: updateRow
248248
#### Example JSON Structure
249249
```json
250250
{
251-
"label" : "Update row",
251+
"label" : "Update Row",
252252
"name" : "updateRow",
253253
"parameters" : {
254254
"docId" : "",
@@ -291,7 +291,7 @@ Type: OBJECT
291291
```
292292

293293

294-
### Insert row
294+
### Insert Row
295295
Name: insertRow
296296

297297
`Inserts row into a table.`
@@ -307,7 +307,7 @@ Name: insertRow
307307
#### Example JSON Structure
308308
```json
309309
{
310-
"label" : "Insert row",
310+
"label" : "Insert Row",
311311
"name" : "insertRow",
312312
"parameters" : {
313313
"docId" : "",

server/libs/modules/components/coda/openapi.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ servers:
99
paths:
1010
/docs:
1111
get:
12-
summary: "List docs"
12+
summary: "List Docs"
1313
description: "Returns a list of docs accessible by the user, and which they have opened at least once."
1414
operationId: "listDocs"
1515
x-ai-agent-tool: true
@@ -44,7 +44,7 @@ paths:
4444
schema:
4545
$ref: '#/components/schemas/DocList'
4646
post:
47-
summary: "Copy doc"
47+
summary: "Copy Doc"
4848
description: "Copies an existing doc."
4949
operationId: "copyDoc"
5050
x-ai-agent-tool: true
@@ -76,7 +76,7 @@ paths:
7676

7777
/docs/{docId}/tables/{tableId}/rows/{rowId}:
7878
put:
79-
summary: "Update row"
79+
summary: "Update Row"
8080
description: "Updates the specified row in the table."
8181
operationId: "updateRow"
8282
x-ai-agent-tool: true

server/libs/modules/components/coda/src/main/java/com/bytechef/component/coda/CodaComponentHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import java.util.List;
2929

3030
/**
31-
* This class will not be overwritten on the subsequent calls of the generator.
31+
* @author Marija Horvat
3232
*/
3333
@AutoService(OpenApiComponentHandler.class)
3434
public class CodaComponentHandler extends AbstractCodaComponentHandler {

server/libs/modules/components/coda/src/main/java/com/bytechef/component/coda/action/CodaCopyDocAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*/
3838
public class CodaCopyDocAction {
3939
public static final ComponentDsl.ModifiableActionDefinition ACTION_DEFINITION = action("copyDoc")
40-
.title("Copy doc")
40+
.title("Copy Doc")
4141
.description("Copies an existing doc.")
4242
.metadata(
4343
Map.of(

server/libs/modules/components/coda/src/main/java/com/bytechef/component/coda/action/CodaInsertRowAction.java

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616

1717
package com.bytechef.component.coda.action;
1818

19-
import static com.bytechef.component.coda.util.CodaPropertiesUtils.convertPropertyToCodaRowValue;
19+
import static com.bytechef.component.coda.constant.CodaConstants.DOC_ID;
20+
import static com.bytechef.component.coda.constant.CodaConstants.ROW_VALUES;
21+
import static com.bytechef.component.coda.constant.CodaConstants.TABLE_ID;
2022
import static com.bytechef.component.definition.ComponentDsl.action;
2123
import static com.bytechef.component.definition.ComponentDsl.array;
2224
import static com.bytechef.component.definition.ComponentDsl.dynamicProperties;
@@ -32,20 +34,16 @@
3234
import com.bytechef.component.definition.Context.Http.Body;
3335
import com.bytechef.component.definition.OptionsDataSource.ActionOptionsFunction;
3436
import com.bytechef.component.definition.Parameters;
35-
import com.bytechef.component.definition.TypeReference;
37+
import java.util.List;
3638
import java.util.Map;
3739

3840
/**
3941
* @author Marija Horvat
4042
*/
4143
public class CodaInsertRowAction {
4244

43-
public static final String DOC_ID = "docId";
44-
public static final String ROW_VALUES = "rowValues";
45-
public static final String TABLE_ID = "tableId";
46-
4745
public static final ModifiableActionDefinition ACTION_DEFINITION = action("insertRow")
48-
.title("Insert row")
46+
.title("Insert Row")
4947
.description("Inserts row into a table.")
5048
.properties(
5149
string(DOC_ID)
@@ -79,17 +77,24 @@ public class CodaInsertRowAction {
7977
private CodaInsertRowAction() {
8078
}
8179

82-
public static Map<String, Object> perform(
83-
Parameters inputParameters, Parameters connectionParameters, Context context) {
84-
80+
public static Object perform(Parameters inputParameters, Parameters connectionParameters, Context context) {
8581
Map<String, Object> codaRowValues = convertPropertyToCodaRowValue(inputParameters.getMap(ROW_VALUES));
8682

87-
return context
88-
.http(http -> http.post("/docs/" + inputParameters.getRequiredString(DOC_ID)
89-
+ "/tables/" + inputParameters.getRequiredString(TABLE_ID) + "/rows"))
83+
return context.http(
84+
http -> http.post("/docs/%s/tables/%s/rows".formatted(
85+
inputParameters.getRequiredString(DOC_ID), inputParameters.getRequiredString(TABLE_ID))))
9086
.body(Body.of(codaRowValues))
9187
.configuration(Http.responseType(Http.ResponseType.JSON))
9288
.execute()
93-
.getBody(new TypeReference<>() {});
89+
.getBody();
90+
}
91+
92+
private static Map<String, Object> convertPropertyToCodaRowValue(Map<String, ?> rowValuesInput) {
93+
List<Map<String, Object>> cells = rowValuesInput.entrySet()
94+
.stream()
95+
.map(entry -> Map.of("column", entry.getKey(), "value", entry.getValue()))
96+
.toList();
97+
98+
return Map.of("rows", List.of(Map.of("cells", cells)));
9499
}
95100
}

server/libs/modules/components/coda/src/main/java/com/bytechef/component/coda/action/CodaListDocsAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
*/
3636
public class CodaListDocsAction {
3737
public static final ComponentDsl.ModifiableActionDefinition ACTION_DEFINITION = action("listDocs")
38-
.title("List docs")
38+
.title("List Docs")
3939
.description("Returns a list of docs accessible by the user, and which they have opened at least once.")
4040
.metadata(
4141
Map.of(

server/libs/modules/components/coda/src/main/java/com/bytechef/component/coda/action/CodaUpdateRowAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*/
3838
public class CodaUpdateRowAction {
3939
public static final ComponentDsl.ModifiableActionDefinition ACTION_DEFINITION = action("updateRow")
40-
.title("Update row")
40+
.title("Update Row")
4141
.description("Updates the specified row in the table.")
4242
.metadata(
4343
Map.of(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright 2025 ByteChef
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.bytechef.component.coda.constant;
18+
19+
/**
20+
* @author Monika Kušter
21+
*/
22+
public class CodaConstants {
23+
24+
public static final String DOC_ID = "docId";
25+
public static final String ROW_VALUES = "rowValues";
26+
public static final String TABLE_ID = "tableId";
27+
28+
private CodaConstants() {
29+
}
30+
}

server/libs/modules/components/coda/src/main/java/com/bytechef/component/coda/util/CodaPropertiesUtils.java

Lines changed: 35 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package com.bytechef.component.coda.util;
1818

19+
import static com.bytechef.component.coda.constant.CodaConstants.DOC_ID;
20+
import static com.bytechef.component.coda.constant.CodaConstants.TABLE_ID;
1921
import static com.bytechef.component.definition.ComponentDsl.bool;
2022
import static com.bytechef.component.definition.ComponentDsl.date;
2123
import static com.bytechef.component.definition.ComponentDsl.dateTime;
@@ -27,12 +29,12 @@
2729

2830
import com.bytechef.component.definition.ActionContext;
2931
import com.bytechef.component.definition.ComponentDsl.ModifiableValueProperty;
30-
import com.bytechef.component.definition.Context;
32+
import com.bytechef.component.definition.Context.Http;
3133
import com.bytechef.component.definition.Parameters;
32-
import com.bytechef.component.definition.Property;
34+
import com.bytechef.component.definition.Property.ControlType;
35+
import com.bytechef.component.definition.Property.ValueProperty;
3336
import com.bytechef.component.definition.TypeReference;
3437
import java.util.ArrayList;
35-
import java.util.HashMap;
3638
import java.util.List;
3739
import java.util.Map;
3840
import java.util.Objects;
@@ -45,14 +47,14 @@ public class CodaPropertiesUtils {
4547
private CodaPropertiesUtils() {
4648
}
4749

48-
public static List<Property.ValueProperty<?>> createPropertiesForRowValues(
50+
public static List<ValueProperty<?>> createPropertiesForRowValues(
4951
Parameters inputParameters, Parameters connectionParameters, Map<String, String> lookupDependsOnPaths,
50-
ActionContext context) {
52+
ActionContext actionContext) {
5153

52-
Map<String, Object> body = context
53-
.http(http -> http.get("/docs/" + inputParameters.getRequiredString("docId") + "/tables/"
54-
+ inputParameters.getRequiredString("tableId") + "/columns"))
55-
.configuration(responseType(Context.Http.ResponseType.JSON))
54+
Map<String, Object> body = actionContext
55+
.http(http -> http.get("/docs/%s/tables/%s/columns".formatted(
56+
inputParameters.getRequiredString(DOC_ID), inputParameters.getRequiredString(TABLE_ID))))
57+
.configuration(responseType(Http.ResponseType.JSON))
5658
.execute()
5759
.getBody(new TypeReference<>() {});
5860

@@ -78,52 +80,43 @@ public static List<Property.ValueProperty<?>> createPropertiesForRowValues(
7880

7981
if (type != null) {
8082
return switch (type) {
81-
case "duration", "slider", "scale" -> integer(name).label(name)
83+
case "duration", "slider", "scale" -> integer(name)
84+
.label(name)
8285
.required(false);
83-
case "lookup", "select" -> string(name).label(name)
86+
case "lookup", "select", "text", "canvas" -> string(name)
87+
.label(name)
8488
.required(false);
85-
case "link", "image" -> string(name).label(name)
89+
case "link", "image" -> string(name)
90+
.label(name)
8691
.required(false)
87-
.controlType(Property.ControlType.URL);
88-
case "checkbox" -> bool(name).label(name)
92+
.controlType(ControlType.URL);
93+
case "checkbox" -> bool(name)
94+
.label(name)
8995
.required(false);
90-
case "email" -> string(name).label(name)
96+
case "email" -> string(name)
97+
.label(name)
9198
.required(false)
92-
.controlType(Property.ControlType.EMAIL);
93-
case "text", "canvas" -> string(name).label(name)
94-
.required(false)
95-
.controlType(Property.ControlType.TEXT);
96-
case "number", "percent", "currency" -> number(name).label(name)
99+
.controlType(ControlType.EMAIL);
100+
case "number", "percent", "currency" -> number(name)
101+
.label(name)
97102
.required(false);
98-
case "date" -> date(name).label(name)
103+
case "date" -> date(name)
104+
.label(name)
99105
.required(false);
100-
case "dateTime" -> dateTime(name).label(name)
106+
case "dateTime" -> dateTime(name)
107+
.label(name)
101108
.required(false);
102-
case "time" -> time(name).label(name)
109+
case "time" -> time(name)
110+
.label(name)
103111
.required(false);
104-
case "person" -> string(name).label(name)
112+
case "person" -> string(name)
113+
.label(name)
105114
.description("Use email address to insert person.")
106115
.required(false);
107-
default -> throw new IllegalArgumentException(
108-
"Unknown Coda field type='%s'".formatted(type));
116+
default -> null;
109117
};
110118
}
111-
return null;
112-
}
113-
114-
public static Map<String, Object> convertPropertyToCodaRowValue(
115-
Map<String, ?> rowValuesInput) {
116-
117-
Map<String, Object> rowValues = new HashMap<>();
118-
for (Map.Entry<String, ?> entry : rowValuesInput.entrySet()) {
119-
rowValues.put(entry.getKey(), entry.getValue());
120-
}
121119

122-
List<Map<String, Object>> cells = rowValues.entrySet()
123-
.stream()
124-
.map(entry -> Map.of("column", entry.getKey(), "value", entry.getValue()))
125-
.toList();
126-
127-
return Map.of("rows", List.of(Map.of("cells", cells)));
120+
return null;
128121
}
129122
}

0 commit comments

Comments
 (0)