@canva/cli 0.0.1-beta.30 → 0.0.1-beta.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli.js +313 -276
- package/package.json +1 -1
- package/templates/data_connector/package.json +1 -1
- package/templates/data_connector/src/api/data_sources/designs.tsx +60 -17
- package/templates/data_connector/src/api/data_sources/templates.tsx +66 -24
- package/templates/data_connector/src/api/fetch_data_table.ts +12 -8
- package/templates/data_connector/src/app.tsx +3 -7
- package/templates/data_connector/src/components/inputs/messages.tsx +19 -0
- package/templates/data_connector/src/components/inputs/search_filter.tsx +108 -0
- package/templates/data_connector/src/context/app_context.tsx +10 -10
- package/templates/data_connector/src/entrypoint.tsx +5 -8
- package/templates/data_connector/src/index.tsx +10 -10
- package/templates/data_connector/src/utils/data_params.ts +9 -9
- package/templates/data_connector/src/utils/data_table.ts +17 -2
- package/templates/data_connector/src/utils/fetch_result.ts +6 -6
- package/templates/data_connector/src/utils/tests/data_table.test.ts +6 -6
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RenderSelectionUiRequest } from "@canva/intents/data";
|
|
2
2
|
|
|
3
|
-
export const isLaunchedWithError = (
|
|
4
|
-
return
|
|
3
|
+
export const isLaunchedWithError = (request: RenderSelectionUiRequest) => {
|
|
4
|
+
return request.invocationContext.reason === "app_error";
|
|
5
5
|
};
|
|
6
6
|
|
|
7
|
-
export const isOutdatedSource = (
|
|
8
|
-
return
|
|
7
|
+
export const isOutdatedSource = (request: RenderSelectionUiRequest) => {
|
|
8
|
+
return request.invocationContext.reason === "outdated_source_ref";
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
-
export const isDataRefEmpty = (
|
|
11
|
+
export const isDataRefEmpty = (request: RenderSelectionUiRequest) => {
|
|
12
12
|
return (
|
|
13
|
-
!
|
|
14
|
-
(!isLaunchedWithError(
|
|
15
|
-
!
|
|
13
|
+
!request?.invocationContext ||
|
|
14
|
+
(!isLaunchedWithError(request) &&
|
|
15
|
+
!request.invocationContext.dataSourceRef?.source)
|
|
16
16
|
);
|
|
17
17
|
};
|
|
@@ -5,6 +5,7 @@ import type {
|
|
|
5
5
|
DateDataTableCell,
|
|
6
6
|
NumberDataTableCell,
|
|
7
7
|
StringDataTableCell,
|
|
8
|
+
ColumnConfig,
|
|
8
9
|
} from "@canva/intents/data";
|
|
9
10
|
import type { APIResponseItem } from "src/api";
|
|
10
11
|
|
|
@@ -20,9 +21,9 @@ export function toDataTable<T extends APIResponseItem>(
|
|
|
20
21
|
rowLimit: number,
|
|
21
22
|
): DataTable {
|
|
22
23
|
const items = apiData.slice(0, rowLimit);
|
|
23
|
-
const headerRow = columns.map((column) => stringCell(column.label));
|
|
24
24
|
const dataTable: DataTable = {
|
|
25
|
-
|
|
25
|
+
columnConfigs: columnConfig(columns),
|
|
26
|
+
rows: [],
|
|
26
27
|
};
|
|
27
28
|
items.forEach((item) => {
|
|
28
29
|
const cells = columns.map((column) => {
|
|
@@ -37,6 +38,20 @@ export function toDataTable<T extends APIResponseItem>(
|
|
|
37
38
|
return dataTable;
|
|
38
39
|
}
|
|
39
40
|
|
|
41
|
+
/**
|
|
42
|
+
* Converts an array of DataTableColumn to ColumnConfig.
|
|
43
|
+
* @param columns Array of DataTableColumn
|
|
44
|
+
* @returns Array of ColumnConfig
|
|
45
|
+
*/
|
|
46
|
+
function columnConfig<T extends APIResponseItem>(
|
|
47
|
+
columns: DataTableColumn<T>[],
|
|
48
|
+
): ColumnConfig[] {
|
|
49
|
+
return columns.map((column) => ({
|
|
50
|
+
name: column.label,
|
|
51
|
+
type: column.toCell({} as unknown).type, // Use an empty object to infer the type
|
|
52
|
+
}));
|
|
53
|
+
}
|
|
54
|
+
|
|
40
55
|
/**
|
|
41
56
|
* Creates a string cell for the data table.
|
|
42
57
|
* @param value String containing up to 10,000 characters
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
DataTable,
|
|
3
3
|
DataTableMetadata,
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
GetDataTableError,
|
|
5
|
+
GetDataTableCompleted,
|
|
6
6
|
} from "@canva/intents/data";
|
|
7
7
|
|
|
8
8
|
export const completeDataTable = (
|
|
9
9
|
dataTable: DataTable,
|
|
10
10
|
metadata?: DataTableMetadata,
|
|
11
|
-
):
|
|
11
|
+
): GetDataTableCompleted => {
|
|
12
12
|
return {
|
|
13
13
|
status: "completed",
|
|
14
14
|
dataTable,
|
|
@@ -16,20 +16,20 @@ export const completeDataTable = (
|
|
|
16
16
|
};
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
export const appError = (message?: string):
|
|
19
|
+
export const appError = (message?: string): GetDataTableError => {
|
|
20
20
|
return {
|
|
21
21
|
status: "app_error",
|
|
22
22
|
message,
|
|
23
23
|
};
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
-
export const outdatedSourceRef = ():
|
|
26
|
+
export const outdatedSourceRef = (): GetDataTableError => {
|
|
27
27
|
return {
|
|
28
28
|
status: "outdated_source_ref",
|
|
29
29
|
};
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
-
export const remoteRequestFailed = ():
|
|
32
|
+
export const remoteRequestFailed = (): GetDataTableError => {
|
|
33
33
|
return {
|
|
34
34
|
status: "remote_request_failed",
|
|
35
35
|
};
|
|
@@ -68,11 +68,11 @@ describe("data table utils", () => {
|
|
|
68
68
|
},
|
|
69
69
|
];
|
|
70
70
|
|
|
71
|
-
test("toDataTable creates correct structure
|
|
71
|
+
test("toDataTable creates correct structure", () => {
|
|
72
72
|
const result = toDataTable(testItems, columns, 10);
|
|
73
73
|
|
|
74
|
-
expect(result.rows.length).toBe(
|
|
75
|
-
expect(result.
|
|
74
|
+
expect(result.rows.length).toBe(testItems.length);
|
|
75
|
+
expect(result.columnConfigs?.map((cell) => cell.name)).toEqual([
|
|
76
76
|
"ID",
|
|
77
77
|
"Name",
|
|
78
78
|
"Count",
|
|
@@ -85,15 +85,15 @@ describe("data table utils", () => {
|
|
|
85
85
|
test("toDataTable respects row limit", () => {
|
|
86
86
|
const result = toDataTable(testItems, columns, 1);
|
|
87
87
|
|
|
88
|
-
expect(result.rows.length).toBe(
|
|
88
|
+
expect(result.rows.length).toBe(1);
|
|
89
89
|
});
|
|
90
90
|
|
|
91
91
|
test("toDataTable handles function-based getValue", () => {
|
|
92
92
|
const result = toDataTable(testItems, columns, 10);
|
|
93
93
|
|
|
94
94
|
// Check the custom column values
|
|
95
|
-
expect(result.rows[
|
|
96
|
-
expect(result.rows[
|
|
95
|
+
expect(result.rows[0].cells[5].value).toBe("Test Item 1 (42)");
|
|
96
|
+
expect(result.rows[1].cells[5].value).toBe("Test Item 2 (0)");
|
|
97
97
|
});
|
|
98
98
|
|
|
99
99
|
test("cell formatter functions create correct cell structures", () => {
|