@antelopejs/dms 0.21.4-next.992.ga290d49 → 0.21.4-next.993.g1ed3e62

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.
@@ -7,7 +7,12 @@ import { resolveResponseToast } from "../../utils/responseWarning";
7
7
  import { resolveConfirmText } from "../confirm/confirmDialogTexts";
8
8
  import { readBulkCount } from "../table-view/utils/bulkActions";
9
9
  import { type DownloadFetch, saveDownload } from "../../utils/fileDownload";
10
- import { downloadTargetFilename, targetUrl } from "./actionTargetUrl";
10
+ import { isJsonObject } from "../../utils/json";
11
+ import {
12
+ apiRedirectPath,
13
+ downloadTargetFilename,
14
+ targetUrl,
15
+ } from "./actionTargetUrl";
11
16
 
12
17
  const JOB_ID_TOKEN = /\{\{\s*job\.id\s*\}\}/g;
13
18
 
@@ -113,6 +118,14 @@ export function createActionRequests(
113
118
  ),
114
119
  );
115
120
  if (target.method !== "GET") config.refreshCallback?.();
121
+ const redirect =
122
+ target.redirect &&
123
+ apiRedirectPath(
124
+ target.redirect,
125
+ isJsonObject(response) ? response : undefined,
126
+ rowData,
127
+ );
128
+ if (redirect) await navigateDms(redirect);
116
129
  };
117
130
  const handleApiTarget = async (
118
131
  target: ActionTarget & { type: "api" },
@@ -1,8 +1,10 @@
1
1
  import {
2
+ hasUrlVariables,
2
3
  namesPageValue,
3
4
  resolveLinkVariables,
4
5
  resolveTextVariables,
5
6
  } from "../../utils/urlVariables";
7
+ import type { JsonObject } from "../../utils/json";
6
8
  import { currentPageUrlValues } from "../page/pageUrlValues";
7
9
  import { interpolateRowText } from "#dms-core/app/utils/url-interpolation";
8
10
 
@@ -23,3 +25,26 @@ export function downloadTargetFilename(
23
25
  const withRow = rowData ? interpolateRowText(filename, rowData) : filename;
24
26
  return resolveTextVariables(withRow, currentPageUrlValues());
25
27
  }
28
+
29
+ /**
30
+ * The page an `api` target's `redirect` names once its request answered
31
+ * `response`: its page and `{{response.X}}` tokens filled as a form's
32
+ * `redirectOnSuccess` is, then its row tokens. `undefined`, with a console
33
+ * warning, while a token is left, such as a field the response lacks.
34
+ */
35
+ export function apiRedirectPath(
36
+ redirect: string,
37
+ response: JsonObject | undefined,
38
+ rowData?: Data,
39
+ ): string | undefined {
40
+ const withResponse = resolveLinkVariables(redirect, {
41
+ ...currentPageUrlValues(),
42
+ response,
43
+ });
44
+ const path = rowData ? interpolateUrl(withResponse, rowData) : withResponse;
45
+ if (!hasUrlVariables(path)) return path;
46
+ console.warn(
47
+ `[dms] The redirect "${redirect}" names a value the response lacks: staying on the page.`,
48
+ );
49
+ return undefined;
50
+ }
@@ -88,6 +88,11 @@ export type ActionTarget =
88
88
  body?: Record<string, JsonValue>;
89
89
  /** Field of the JSON response copied to the clipboard on success. */
90
90
  copy?: string;
91
+ /**
92
+ * Dashboard path opened on success: the tokens of `url`, plus
93
+ * `{{response.<field>}}`.
94
+ */
95
+ redirect?: string;
91
96
  successMessage: string;
92
97
  }
93
98
  | {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antelopejs/dms",
3
- "version": "0.21.4-next.992.ga290d49",
3
+ "version": "0.21.4-next.993.g1ed3e62",
4
4
  "description": "AntelopeJS DMS. Plug in your PostgreSQL, MySQL, MariaDB, MongoDB or RethinkDB database and your coding agent builds a back office and analytics dashboard as typed TypeScript. Real-time updates on the data the DMS manages.",
5
5
  "keywords": [
6
6
  "antelopejs",
@@ -89,7 +89,7 @@
89
89
  "@antelopejs/interface-data-api": ">=0.8.0 <0.9.0",
90
90
  "@antelopejs/interface-database": ">=0.4.0 <0.5.0",
91
91
  "@antelopejs/interface-database-decorators": ">=0.5.2 <0.6.0",
92
- "@antelopejs/interface-dms": "0.14.7-next.992.ga290d49",
92
+ "@antelopejs/interface-dms": "0.14.7-next.993.g1ed3e62",
93
93
  "@antelopejs/interface-dms-builder": "0.6.2-next.987.gb437fd0",
94
94
  "@antelopejs/interface-email": ">=0.2.1 <0.3.0",
95
95
  "@antelopejs/interface-file-storage": ">=0.1.4 <0.2.0",
@@ -212,7 +212,7 @@
212
212
  "optional": true
213
213
  }
214
214
  },
215
- "gitHead": "a290d49093fb67770262ec7a2d2c8193a19fea84",
215
+ "gitHead": "1ed3e62b54315cf252ee2805470f0d1c5f3ef1ba",
216
216
  "scripts": {
217
217
  "build": "pnpm --filter @antelopejs/interface-dms --filter @antelopejs/interface-dms-builder build && rimraf dist && antelopejs-tsc && tsc-alias && tsc -p e2e/tsconfig.types.json",
218
218
  "dev": "ajs project run --inspect -w -p playground",