@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.
@@ -1,17 +1,17 @@
1
- import type { RenderSelectionUiParams } from "@canva/intents/data";
1
+ import type { RenderSelectionUiRequest } from "@canva/intents/data";
2
2
 
3
- export const isLaunchedWithError = (dataParams: RenderSelectionUiParams) => {
4
- return dataParams.invocationContext.reason === "app_error";
3
+ export const isLaunchedWithError = (request: RenderSelectionUiRequest) => {
4
+ return request.invocationContext.reason === "app_error";
5
5
  };
6
6
 
7
- export const isOutdatedSource = (dataParams: RenderSelectionUiParams) => {
8
- return dataParams.invocationContext.reason === "outdated_source_ref";
7
+ export const isOutdatedSource = (request: RenderSelectionUiRequest) => {
8
+ return request.invocationContext.reason === "outdated_source_ref";
9
9
  };
10
10
 
11
- export const isDataRefEmpty = (dataParams: RenderSelectionUiParams) => {
11
+ export const isDataRefEmpty = (request: RenderSelectionUiRequest) => {
12
12
  return (
13
- !dataParams?.invocationContext ||
14
- (!isLaunchedWithError(dataParams) &&
15
- !dataParams.invocationContext.dataSourceRef?.source)
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
- rows: [{ cells: headerRow }],
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
- FetchDataTableError,
5
- FetchDataTableCompleted,
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
- ): FetchDataTableCompleted => {
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): FetchDataTableError => {
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 = (): FetchDataTableError => {
26
+ export const outdatedSourceRef = (): GetDataTableError => {
27
27
  return {
28
28
  status: "outdated_source_ref",
29
29
  };
30
30
  };
31
31
 
32
- export const remoteRequestFailed = (): FetchDataTableError => {
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 with header row", () => {
71
+ test("toDataTable creates correct structure", () => {
72
72
  const result = toDataTable(testItems, columns, 10);
73
73
 
74
- expect(result.rows.length).toBe(3); // header + 2 data rows
75
- expect(result.rows[0].cells.map((cell) => cell.value)).toEqual([
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(2); // header + 1 data row (limited)
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[1].cells[5].value).toBe("Test Item 1 (42)");
96
- expect(result.rows[2].cells[5].value).toBe("Test Item 2 (0)");
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", () => {