@canva/cli 0.0.1-beta.9 → 1.0.0

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.
Files changed (149) hide show
  1. package/README.md +131 -31
  2. package/cli.js +841 -437
  3. package/lib/cjs/index.cjs +11 -0
  4. package/lib/esm/index.mjs +11 -0
  5. package/package.json +19 -4
  6. package/templates/base/backend/routers/auth.ts +4 -4
  7. package/templates/base/backend/routers/oauth.ts +3 -3
  8. package/templates/base/eslint.config.mjs +2 -25
  9. package/templates/base/package.json +26 -23
  10. package/templates/base/scripts/ssl/ssl.ts +1 -1
  11. package/templates/base/scripts/start/app_runner.ts +42 -5
  12. package/templates/base/scripts/start/context.ts +12 -6
  13. package/templates/base/scripts/start/start.ts +12 -1
  14. package/templates/base/scripts/start/tests/start.tests.ts +61 -0
  15. package/templates/base/utils/backend/base_backend/create.ts +3 -3
  16. package/templates/base/utils/backend/bearer_middleware/bearer_middleware.ts +2 -2
  17. package/templates/base/utils/backend/jwt_middleware/jwt_middleware.ts +4 -4
  18. package/templates/base/utils/backend/jwt_middleware/tests/jwt_middleware.tests.ts +1 -1
  19. package/templates/base/utils/use_add_element.ts +1 -1
  20. package/templates/base/utils/use_feature_support.ts +1 -1
  21. package/templates/{gen_ai/webpack.config.cjs → base/webpack.config.ts} +50 -68
  22. package/templates/common/.env.template +3 -3
  23. package/templates/common/README.md +16 -17
  24. package/templates/common/jest.config.mjs +1 -1
  25. package/templates/common/jest.setup.ts +1 -0
  26. package/templates/common/utils/backend/base_backend/create.ts +3 -3
  27. package/templates/common/utils/backend/jwt_middleware/jwt_middleware.ts +4 -4
  28. package/templates/common/utils/backend/jwt_middleware/tests/jwt_middleware.tests.ts +1 -1
  29. package/templates/common/utils/tests/table_wrapper.tests.ts +1 -1
  30. package/templates/common/utils/use_add_element.ts +1 -1
  31. package/templates/common/utils/use_feature_support.ts +1 -1
  32. package/templates/dam/backend/routers/dam.ts +24 -20
  33. package/templates/dam/backend/server.ts +1 -1
  34. package/templates/dam/canva-app.json +16 -0
  35. package/templates/dam/eslint.config.mjs +2 -28
  36. package/templates/dam/package.json +38 -41
  37. package/templates/dam/scripts/ssl/ssl.ts +1 -1
  38. package/templates/dam/scripts/start/app_runner.ts +42 -5
  39. package/templates/dam/scripts/start/context.ts +12 -6
  40. package/templates/dam/scripts/start/start.ts +12 -1
  41. package/templates/dam/scripts/start/tests/start.tests.ts +61 -0
  42. package/templates/dam/src/app.tsx +24 -3
  43. package/templates/dam/src/config.ts +212 -87
  44. package/templates/dam/src/index.tsx +1 -1
  45. package/templates/dam/utils/backend/base_backend/create.ts +3 -3
  46. package/templates/dam/utils/backend/jwt_middleware/jwt_middleware.ts +4 -4
  47. package/templates/dam/utils/backend/jwt_middleware/tests/jwt_middleware.tests.ts +1 -1
  48. package/templates/{base/webpack.config.cjs → dam/webpack.config.ts} +50 -68
  49. package/templates/data_connector/README.md +84 -0
  50. package/templates/data_connector/canva-app.json +21 -0
  51. package/templates/data_connector/declarations/declarations.d.ts +29 -0
  52. package/templates/data_connector/eslint.config.mjs +14 -0
  53. package/templates/data_connector/package.json +91 -0
  54. package/templates/data_connector/scripts/ssl/ssl.ts +131 -0
  55. package/templates/data_connector/scripts/start/app_runner.ts +201 -0
  56. package/templates/data_connector/scripts/start/context.ts +171 -0
  57. package/templates/data_connector/scripts/start/start.ts +46 -0
  58. package/templates/data_connector/scripts/start/tests/start.tests.ts +61 -0
  59. package/templates/data_connector/src/api/connect_client.ts +6 -0
  60. package/templates/data_connector/src/api/data_source.ts +96 -0
  61. package/templates/data_connector/src/api/data_sources/designs.tsx +296 -0
  62. package/templates/data_connector/src/api/data_sources/index.ts +4 -0
  63. package/templates/data_connector/src/api/data_sources/templates.tsx +329 -0
  64. package/templates/data_connector/src/api/fetch_data_table.ts +55 -0
  65. package/templates/data_connector/src/api/index.ts +4 -0
  66. package/templates/data_connector/src/api/oauth.ts +8 -0
  67. package/templates/data_connector/src/api/tests/data_source.test.tsx +99 -0
  68. package/templates/data_connector/src/app.tsx +20 -0
  69. package/templates/data_connector/src/components/app_error.tsx +15 -0
  70. package/templates/data_connector/src/components/footer.tsx +26 -0
  71. package/templates/data_connector/src/components/header.tsx +40 -0
  72. package/templates/data_connector/src/components/index.ts +3 -0
  73. package/templates/data_connector/src/components/inputs/messages.tsx +99 -0
  74. package/templates/data_connector/src/components/inputs/search_filter.tsx +108 -0
  75. package/templates/data_connector/src/components/inputs/select_field.tsx +26 -0
  76. package/templates/data_connector/src/context/app_context.tsx +124 -0
  77. package/templates/data_connector/src/context/index.ts +2 -0
  78. package/templates/data_connector/src/context/use_app_context.ts +17 -0
  79. package/templates/data_connector/src/entrypoint.tsx +70 -0
  80. package/templates/data_connector/src/home.tsx +21 -0
  81. package/templates/data_connector/src/index.tsx +68 -0
  82. package/templates/data_connector/src/pages/data_source_config.tsx +9 -0
  83. package/templates/data_connector/src/pages/error.tsx +37 -0
  84. package/templates/data_connector/src/pages/index.ts +4 -0
  85. package/templates/data_connector/src/pages/login.tsx +145 -0
  86. package/templates/data_connector/src/pages/select_source.tsx +24 -0
  87. package/templates/data_connector/src/routes/index.ts +2 -0
  88. package/templates/data_connector/src/routes/protected_route.tsx +25 -0
  89. package/templates/data_connector/src/routes/routes.tsx +46 -0
  90. package/templates/data_connector/src/utils/data_params.ts +17 -0
  91. package/templates/data_connector/src/utils/data_table.ts +115 -0
  92. package/templates/data_connector/src/utils/fetch_result.ts +36 -0
  93. package/templates/data_connector/src/utils/index.ts +2 -0
  94. package/templates/data_connector/src/utils/tests/data_table.test.ts +133 -0
  95. package/templates/data_connector/styles/components.css +38 -0
  96. package/templates/data_connector/tsconfig.json +54 -0
  97. package/templates/{dam/webpack.config.cjs → data_connector/webpack.config.ts} +50 -68
  98. package/templates/gen_ai/backend/routers/image.ts +8 -8
  99. package/templates/gen_ai/backend/server.ts +1 -1
  100. package/templates/gen_ai/canva-app.json +20 -0
  101. package/templates/gen_ai/eslint.config.mjs +2 -25
  102. package/templates/gen_ai/package.json +42 -43
  103. package/templates/gen_ai/scripts/ssl/ssl.ts +1 -1
  104. package/templates/gen_ai/scripts/start/app_runner.ts +42 -5
  105. package/templates/gen_ai/scripts/start/context.ts +12 -6
  106. package/templates/gen_ai/scripts/start/start.ts +12 -1
  107. package/templates/gen_ai/scripts/start/tests/start.tests.ts +61 -0
  108. package/templates/gen_ai/src/app.tsx +3 -3
  109. package/templates/gen_ai/src/components/footer.tsx +4 -4
  110. package/templates/gen_ai/src/components/image_grid.tsx +1 -1
  111. package/templates/gen_ai/src/components/loading_results.tsx +8 -8
  112. package/templates/gen_ai/src/components/prompt_input.tsx +3 -3
  113. package/templates/gen_ai/src/components/remaining_credits.tsx +1 -1
  114. package/templates/gen_ai/src/components/report_box.tsx +1 -1
  115. package/templates/gen_ai/src/components/tests/remaining_credit.tests.tsx +2 -2
  116. package/templates/gen_ai/src/home.tsx +2 -2
  117. package/templates/gen_ai/src/pages/error.tsx +2 -2
  118. package/templates/gen_ai/src/pages/results.tsx +1 -1
  119. package/templates/gen_ai/utils/backend/base_backend/create.ts +3 -3
  120. package/templates/gen_ai/utils/backend/bearer_middleware/bearer_middleware.ts +2 -2
  121. package/templates/{hello_world/webpack.config.cjs → gen_ai/webpack.config.ts} +50 -68
  122. package/templates/hello_world/canva-app.json +16 -0
  123. package/templates/hello_world/eslint.config.mjs +2 -25
  124. package/templates/hello_world/package.json +35 -38
  125. package/templates/hello_world/scripts/copy_env.ts +10 -0
  126. package/templates/hello_world/scripts/ssl/ssl.ts +1 -1
  127. package/templates/hello_world/scripts/start/app_runner.ts +42 -5
  128. package/templates/hello_world/scripts/start/context.ts +12 -6
  129. package/templates/hello_world/scripts/start/start.ts +12 -1
  130. package/templates/hello_world/scripts/start/tests/start.tests.ts +61 -0
  131. package/templates/hello_world/src/app.tsx +1 -1
  132. package/templates/hello_world/src/index.tsx +1 -1
  133. package/templates/hello_world/src/tests/__snapshots__/app.tests.tsx.snap +5 -5
  134. package/templates/hello_world/src/tests/app.tests.tsx +3 -3
  135. package/templates/hello_world/utils/use_add_element.ts +1 -1
  136. package/templates/hello_world/utils/use_feature_support.ts +1 -1
  137. package/templates/hello_world/webpack.config.ts +254 -0
  138. package/templates/optional/.cursor/mcp.json +8 -0
  139. package/templates/optional/.vscode/mcp.json +9 -0
  140. package/templates/optional/AGENTS.md +76 -0
  141. package/templates/optional/CLAUDE.md +76 -0
  142. package/templates/common/conf/eslint-general.mjs +0 -303
  143. package/templates/common/conf/eslint-i18n.mjs +0 -41
  144. package/templates/common/conf/eslint-local-i18n-rules/index.mjs +0 -181
  145. /package/templates/base/scripts/{copy-env.ts → copy_env.ts} +0 -0
  146. /package/templates/dam/scripts/{copy-env.ts → copy_env.ts} +0 -0
  147. /package/templates/{gen_ai/scripts/copy-env.ts → data_connector/scripts/copy_env.ts} +0 -0
  148. /package/templates/{hello_world/scripts/copy-env.ts → gen_ai/scripts/copy_env.ts} +0 -0
  149. /package/templates/{common → optional}/.vscode/extensions.json +0 -0
@@ -0,0 +1,61 @@
1
+ /* eslint-disable no-console */
2
+
3
+ import type { ChildProcess } from "child_process";
4
+ import { spawn } from "child_process";
5
+ import * as treeKill from "tree-kill";
6
+
7
+ describe("start script", () => {
8
+ let serverProcess: ChildProcess;
9
+
10
+ afterEach(() => {
11
+ if (serverProcess?.pid && !serverProcess.exitCode) {
12
+ treeKill(serverProcess.pid);
13
+ }
14
+ });
15
+
16
+ it("should execute 'npm run start' and start a dev server", async () => {
17
+ const testServerPort = 8089;
18
+ serverProcess = await spawn(
19
+ `npm run start -- -p ${testServerPort} --no-preview`,
20
+ {
21
+ shell: true,
22
+ },
23
+ );
24
+
25
+ if (!serverProcess.pid) {
26
+ throw new Error("Unable to start server");
27
+ }
28
+
29
+ // wait for the server to start and collect output until it reports the running URL
30
+ let output = "";
31
+ await new Promise<void>((resolve, reject) => {
32
+ serverProcess.stdout?.on("data", (data) => {
33
+ output += data.toString();
34
+ if (output.includes("Development URL")) {
35
+ resolve();
36
+ }
37
+ });
38
+
39
+ serverProcess.stderr?.on("data", (data) => {
40
+ console.error("Server process error: ", data.toString());
41
+ reject();
42
+ });
43
+
44
+ // timeout and fail test if the server hasn't correctly started in 10 seconds
45
+ setTimeout(() => {
46
+ if (serverProcess?.pid && !serverProcess.exitCode) {
47
+ treeKill(serverProcess.pid);
48
+ }
49
+ reject(new Error("Test timed out"));
50
+ }, 10000);
51
+ });
52
+
53
+ // check that the server is running and accessible
54
+ const expectedServerURL = `http://localhost:${testServerPort}`;
55
+ expect(output).toContain(expectedServerURL);
56
+ expect(serverProcess.exitCode).toBeNull();
57
+
58
+ // clean up
59
+ treeKill(serverProcess.pid);
60
+ }, 15000); // 15 seconds timeout to allow for the server to start
61
+ });
@@ -0,0 +1,6 @@
1
+ import type { APIResponseItem } from "./data_source";
2
+
3
+ export interface CanvaItemResponse<T extends APIResponseItem> {
4
+ continuation: string;
5
+ items: T[];
6
+ }
@@ -0,0 +1,96 @@
1
+ import type { DataTable } from "@canva/intents/data";
2
+ import { type DataTableColumn, toDataTable } from "src/utils";
3
+
4
+ /**
5
+ * This file defines types and classes related to data source configuration, fetching and outputting as a data table.
6
+ * When data is loaded, the app will save the data source config so that it can be queried again later to refresh the data.
7
+ * Strongly typed data sources are simple to reload and validate.
8
+ */
9
+
10
+ /**
11
+ * The data source configuration represents all parameters that are needed to represent the data source so that it can be queried again later.
12
+ * This includes the schema, any filters that are applied to the data source, and any other parameters that are needed to fetch the data.
13
+ */
14
+ export interface DataSourceConfig {
15
+ // a unique identifier for the data source that is used to associated the saved data source config with the data source handler
16
+ schema: string;
17
+ }
18
+
19
+ /**
20
+ * the API response item is a generic type that represents the data returned from the API
21
+ */
22
+ export interface APIResponseItem {
23
+ id: string;
24
+ }
25
+
26
+ export class DataAPIError extends Error {
27
+ constructor(message: string) {
28
+ super(message);
29
+ this.name = "APIError";
30
+ }
31
+ }
32
+
33
+ /**
34
+ * The data source handler class defines a particular data source and how to fetch data from it.
35
+ * In this template, the two data sources are brand templates and designs. Each data source has its own handler.
36
+ * The handler defines the schema for the data source configuration (what filters are applied to get the requested data), the columns to display, and how to fetch data from the API.
37
+ * It also defines the UI for how this source is represented on the data source selection page and how to render the data source configuration page where any filters can be set.
38
+ */
39
+ export class DataSourceHandler<
40
+ T extends DataSourceConfig,
41
+ R extends APIResponseItem,
42
+ > {
43
+ schema: string;
44
+ constructor(
45
+ // the configuration for this data source. The default values will be overridden by the user setting filters, or on app launch if the previous state is restored
46
+ public sourceConfig: T,
47
+ // the columns to display in the data table output. In this template they are fixed, but they could be dynamic based on the data source and configuration
48
+ public columns: DataTableColumn<R>[],
49
+ // the fetch logic for turning the data source configuration into an array of data items to turn into a data table
50
+ public fetchData: (
51
+ source: T,
52
+ authToken: string,
53
+ rowLimit: number,
54
+ signal: AbortSignal | undefined,
55
+ ) => Promise<R[]>,
56
+ // the UI for the data source selection page. This is where the user chooses which data source to use.
57
+ public selectionPage: () => JSX.Element,
58
+ // the UI for the data source configuration page. This is where the user sets any filters or other parameters for the data source.
59
+ public configPage: (sourceConfig: T) => JSX.Element,
60
+ ) {
61
+ this.schema = sourceConfig.schema;
62
+ }
63
+
64
+ /**
65
+ * A type guard / type predicate to check if the data source configuration matches the schema of this data source handler.
66
+ * @param source the data source configuration to match against
67
+ * @returns
68
+ */
69
+ matchSource(source: DataSourceConfig): source is T {
70
+ return source.schema === this.schema;
71
+ }
72
+
73
+ /**
74
+ * The buildTable function is called to fetch data from the API and return it as a data table.
75
+ * @param source the data source configuration
76
+ * @param authToken the auth token to use for the API request
77
+ * @param rowLimit the maximum number of rows to return
78
+ * @param signal an optional abort signal to cancel the request
79
+ * @returns a data table with the data from the API
80
+ */
81
+ async fetchAndBuildTable(
82
+ source: T,
83
+ authToken: string,
84
+ rowLimit: number,
85
+ signal: AbortSignal | undefined,
86
+ ): Promise<DataTable> {
87
+ let apiData: R[];
88
+ try {
89
+ apiData = await this.fetchData(source, authToken || "", rowLimit, signal);
90
+ } catch {
91
+ throw new DataAPIError("Failed to fetch data from API");
92
+ }
93
+ // the toDataTable utility takes the API data and the configured columns and turns it into a data table
94
+ return toDataTable(apiData, this.columns, rowLimit);
95
+ }
96
+ }
@@ -0,0 +1,296 @@
1
+ /* eslint-disable formatjs/no-literal-string-in-object */
2
+
3
+ import type { SelectOption } from "@canva/app-ui-kit";
4
+ import { Button, DatabaseIcon, HorizontalCard, Rows } from "@canva/app-ui-kit";
5
+ import { useEffect, useState } from "react";
6
+ import { useIntl } from "react-intl";
7
+ import { useNavigate } from "react-router-dom";
8
+ import { Header } from "src/components";
9
+ import {
10
+ ownershipFilter,
11
+ sortOrderField,
12
+ } from "src/components/inputs/messages";
13
+ import { SearchFilter } from "src/components/inputs/search_filter";
14
+ import { SelectField } from "src/components/inputs/select_field";
15
+ import { useAppContext } from "src/context";
16
+ import { Paths } from "src/routes";
17
+ import { dateCell, numberCell, stringCell } from "src/utils";
18
+ import type { CanvaItemResponse } from "../connect_client";
19
+ import { DataAPIError, DataSourceHandler } from "../data_source";
20
+ import type { APIResponseItem, DataSourceConfig } from "../data_source";
21
+
22
+ export interface DesignsDataSource extends DataSourceConfig {
23
+ query: string;
24
+ ownership: "any" | "owned" | "shared";
25
+ sort_by:
26
+ | "relevance"
27
+ | "modified_descending"
28
+ | "modified_ascending"
29
+ | "title_descending"
30
+ | "title_ascending";
31
+ }
32
+
33
+ export interface CanvaDesign extends APIResponseItem {
34
+ title: string;
35
+ created_at: number;
36
+ updated_at: number;
37
+ page_count: number;
38
+ }
39
+
40
+ export const designsSource = new DataSourceHandler<
41
+ DesignsDataSource,
42
+ CanvaDesign
43
+ >(
44
+ {
45
+ schema: "designs/v1",
46
+ query: "",
47
+ ownership: "any",
48
+ sort_by: "relevance",
49
+ },
50
+ [
51
+ {
52
+ label: "ID",
53
+ getValue: (design: CanvaDesign) => `ID ${design.id}`,
54
+ toCell: stringCell,
55
+ },
56
+ {
57
+ label: "Title",
58
+ getValue: "title",
59
+ toCell: stringCell,
60
+ },
61
+ {
62
+ label: "Created At",
63
+ getValue: "created_at",
64
+ toCell: dateCell,
65
+ },
66
+ {
67
+ label: "Updated At",
68
+ getValue: "updated_at",
69
+ toCell: dateCell,
70
+ },
71
+ {
72
+ label: "Page Count",
73
+ getValue: "page_count",
74
+ toCell: numberCell,
75
+ },
76
+ ],
77
+ (
78
+ source: DesignsDataSource,
79
+ authToken: string,
80
+ rowLimit: number,
81
+ signal: AbortSignal | undefined,
82
+ ) =>
83
+ getDesigns(
84
+ authToken,
85
+ rowLimit,
86
+ signal,
87
+ source.query,
88
+ source.ownership,
89
+ source.sort_by,
90
+ ),
91
+ DesignSelection,
92
+ DesignsSourceConfig,
93
+ );
94
+
95
+ export async function getDesigns(
96
+ authToken: string,
97
+ rowLimit: number,
98
+ signal: AbortSignal | undefined,
99
+ query: string,
100
+ ownership: string,
101
+ sort_by: string,
102
+ continuation?: string,
103
+ allItems: CanvaDesign[] = [],
104
+ ): Promise<CanvaDesign[]> {
105
+ const baseUrl = `https://api.canva.com/rest/v1/designs`;
106
+ const params = new URLSearchParams();
107
+ if (continuation) {
108
+ params.set("continuation", continuation);
109
+ } else {
110
+ if (query) {
111
+ params.set("query", query);
112
+ }
113
+ params.set("ownership", ownership);
114
+ params.set("sort_by", sort_by);
115
+ }
116
+ const url = `${baseUrl}?${params.toString()}`;
117
+
118
+ return fetch(url, {
119
+ headers: {
120
+ Authorization: `Bearer ${authToken}`,
121
+ },
122
+ signal,
123
+ })
124
+ .then((response) => {
125
+ if (!response.ok) {
126
+ throw new DataAPIError(
127
+ `Canva Connect response was not ok: ${response.statusText || response.status}`,
128
+ );
129
+ }
130
+ return response.json();
131
+ })
132
+ .then((data: CanvaItemResponse<CanvaDesign>) => {
133
+ const updatedItems = [...allItems, ...data.items];
134
+
135
+ if (data.continuation && updatedItems.length < rowLimit) {
136
+ return getDesigns(
137
+ authToken,
138
+ rowLimit,
139
+ signal,
140
+ query,
141
+ ownership,
142
+ sort_by,
143
+ data.continuation,
144
+ updatedItems,
145
+ );
146
+ }
147
+
148
+ return updatedItems;
149
+ });
150
+ }
151
+
152
+ function DesignSelection() {
153
+ const intl = useIntl();
154
+ const { setDataSourceHandler } = useAppContext();
155
+ const navigate = useNavigate();
156
+
157
+ const title = intl.formatMessage({
158
+ defaultMessage: "Designs",
159
+ description:
160
+ "Main heading on the designs button displayed when selecting the import type.",
161
+ });
162
+
163
+ const description = intl.formatMessage({
164
+ defaultMessage: "Query designs",
165
+ description:
166
+ "Subtext on the designs selection button displayed when selecting the import type.",
167
+ });
168
+
169
+ const handleClick = () => {
170
+ setDataSourceHandler(
171
+ designsSource as unknown as DataSourceHandler<
172
+ DataSourceConfig,
173
+ APIResponseItem
174
+ >,
175
+ );
176
+ navigate(Paths.DATA_SOURCE_CONFIG);
177
+ };
178
+
179
+ return (
180
+ <HorizontalCard
181
+ key="designs"
182
+ title={title}
183
+ thumbnail={{ icon: () => <DatabaseIcon /> }}
184
+ onClick={handleClick}
185
+ description={description}
186
+ ariaLabel={description}
187
+ />
188
+ );
189
+ }
190
+
191
+ function DesignsSourceConfig(sourceConfig: DesignsDataSource) {
192
+ const intl = useIntl();
193
+ const { loadDataSource } = useAppContext();
194
+ const [query, setQuery] = useState<string>(sourceConfig.query);
195
+ const [ownership, setOwnership] = useState<string>(sourceConfig.ownership);
196
+ const [sortOrder, setSortOrder] = useState<string>(sourceConfig.sort_by);
197
+ const [isLoading, setIsLoading] = useState(false);
198
+
199
+ const [filterCount, setFilterCount] = useState(0);
200
+ useEffect(() => {
201
+ // Update the filter count based on the selected filters
202
+ // consider a filter to be applied if not set to the default value
203
+ setFilterCount(
204
+ (ownership !== "any" ? 1 : 0) + (sortOrder !== "relevance" ? 1 : 0),
205
+ );
206
+ }, [ownership, sortOrder]);
207
+ const resetFilters = () => {
208
+ setOwnership("any");
209
+ setSortOrder("relevance");
210
+ };
211
+
212
+ const loadDesigns = async () => {
213
+ setIsLoading(true);
214
+ loadDataSource("Canva Designs", {
215
+ schema: "designs/v1",
216
+ query,
217
+ ownership,
218
+ sort_by: sortOrder,
219
+ } as DesignsDataSource).then(() => {
220
+ setIsLoading(false);
221
+ });
222
+ };
223
+
224
+ const ownershipOptions: SelectOption<string>[] = [
225
+ { value: "any", label: intl.formatMessage(ownershipFilter.any) },
226
+ { value: "owned", label: intl.formatMessage(ownershipFilter.owned) },
227
+ { value: "shared", label: intl.formatMessage(ownershipFilter.shared) },
228
+ ];
229
+
230
+ const sortOrderOptions: SelectOption<string>[] = [
231
+ { value: "relevance", label: intl.formatMessage(sortOrderField.relevance) },
232
+ {
233
+ value: "modified_descending",
234
+ label: intl.formatMessage(sortOrderField.modifiedDesc),
235
+ },
236
+ {
237
+ value: "modified_ascending",
238
+ label: intl.formatMessage(sortOrderField.modifiedAsc),
239
+ },
240
+ {
241
+ value: "title_descending",
242
+ label: intl.formatMessage(sortOrderField.titleDesc),
243
+ },
244
+ {
245
+ value: "title_ascending",
246
+ label: intl.formatMessage(sortOrderField.titleAsc),
247
+ },
248
+ ];
249
+
250
+ return (
251
+ <div>
252
+ <Rows spacing="2u">
253
+ <Header
254
+ title={intl.formatMessage({
255
+ defaultMessage: "Canva Designs",
256
+ description: "The header text for the designs data source",
257
+ })}
258
+ showBack={true}
259
+ />
260
+
261
+ <SearchFilter
262
+ value={query}
263
+ onChange={setQuery}
264
+ filterCount={filterCount}
265
+ resetFilters={resetFilters}
266
+ >
267
+ <SelectField
268
+ label={intl.formatMessage(ownershipFilter.label)}
269
+ options={ownershipOptions}
270
+ value={ownership}
271
+ onChange={setOwnership}
272
+ />
273
+ <SelectField
274
+ label={intl.formatMessage(sortOrderField.label)}
275
+ options={sortOrderOptions}
276
+ value={sortOrder}
277
+ onChange={setSortOrder}
278
+ />
279
+ </SearchFilter>
280
+
281
+ <Button
282
+ variant="primary"
283
+ loading={isLoading}
284
+ onClick={async () => {
285
+ loadDesigns();
286
+ }}
287
+ >
288
+ {intl.formatMessage({
289
+ defaultMessage: "Load Designs",
290
+ description: "Button for saving and applying the query filter",
291
+ })}
292
+ </Button>
293
+ </Rows>
294
+ </div>
295
+ );
296
+ }
@@ -0,0 +1,4 @@
1
+ import { designsSource } from "./designs";
2
+ import { brandTemplatesSource } from "./templates";
3
+
4
+ export const DATA_SOURCES = [designsSource, brandTemplatesSource];