@antelopejs/dms 0.7.17 → 0.7.19

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/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Changelog
2
2
 
3
+ ## v0.7.19
4
+
5
+ [compare changes](https://github.com/AntelopeJS/dms/compare/v0.7.18...v0.7.19)
6
+
7
+ ## v0.7.18
8
+
9
+ [compare changes](https://github.com/AntelopeJS/dms/compare/v0.7.17...v0.7.18)
10
+
11
+ ### 🚀 Enhancements
12
+
13
+ - **layout:** Let a header button's label read the page's query ([#247](https://github.com/AntelopeJS/dms/pull/247))
14
+
15
+ ### ❤️ Contributors
16
+
17
+ - Antony Rizzitelli <rizzitelli.antony@pm.me>
18
+
3
19
  ## v0.7.17
4
20
 
5
21
  [compare changes](https://github.com/AntelopeJS/dms/compare/v0.7.16...v0.7.17)
@@ -117,13 +117,20 @@ const defaultVariant = (
117
117
  const orderOf = (action: LayoutHeaderAction): number =>
118
118
  action.order ?? DEFAULT_PAGE_HEADER_ACTIONS_ORDER;
119
119
 
120
+ // A served label's translation reads the page query as its parameters:
121
+ // `"Download {locale}.json"` names the language of `?locale=`.
122
+ function labelParams(): Record<string, unknown> {
123
+ const { routeParams, routeQuery } = pageUrlValues.value;
124
+ return { ...routeParams, ...routeQuery };
125
+ }
126
+
120
127
  function baseButton(action: LayoutHeaderAction): ButtonProps {
121
128
  const color = action.color ?? "neutral";
122
129
  return {
123
130
  color,
124
131
  variant: action.variant ?? defaultVariant(color),
125
132
  icon: action.icon,
126
- label: action.label ? processI18n(action.label) : undefined,
133
+ label: action.label ? processI18n(action.label, labelParams()) : undefined,
127
134
  disabled: action.disabled,
128
135
  };
129
136
  }
@@ -73,7 +73,10 @@ beforeEach(() => {
73
73
  vi.stubGlobal("useAuthFetch", () => ({ $authFetch: authFetch }));
74
74
  vi.stubGlobal("computed", computed);
75
75
  vi.stubGlobal("useTranslation", () => ({
76
- processI18n: (value: string) => value,
76
+ processI18n: (value: string, params?: Record<string, unknown>) =>
77
+ value.replace(/\{(\w+)\}/g, (_, name: string) =>
78
+ String(params?.[name] ?? `{${name}}`),
79
+ ),
77
80
  }));
78
81
  vi.stubGlobal("useI18n", () => ({ t: (key: string) => key }));
79
82
  vi.stubGlobal("useDmsRoute", () => route);
@@ -270,6 +273,24 @@ describe("a header button's target URL", () => {
270
273
  });
271
274
  });
272
275
 
276
+ describe("a header button's label", () => {
277
+ it("reads the page's query and params as its parameters, and follows them", async () => {
278
+ route.query = { workspace: "web", file: "fr" };
279
+ await mountBar([
280
+ {
281
+ id: "download",
282
+ label: "Download {file}.json for {locale}",
283
+ target: { type: "page", url: "/x" },
284
+ },
285
+ ]);
286
+ expect(labels()).toEqual(["Download fr.json for de"]);
287
+
288
+ route.query = { workspace: "web", file: "it" };
289
+ await nextTick();
290
+ expect(labels()).toEqual(["Download it.json for de"]);
291
+ });
292
+ });
293
+
273
294
  describe("a header button's availability", () => {
274
295
  const download = (disabled: boolean) => ({
275
296
  id: "download",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antelopejs/dms",
3
- "version": "0.7.17",
3
+ "version": "0.7.19",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/AntelopeJS/dms.git"
@@ -37,7 +37,7 @@
37
37
  "@antelopejs/interface-data-api": ">=0.2.0 <1.0.0",
38
38
  "@antelopejs/interface-database": ">=0.1.8 <1.0.0",
39
39
  "@antelopejs/interface-database-decorators": ">=0.1.7 <1.0.0",
40
- "@antelopejs/interface-dms": ">=0.5.11 <0.6.0",
40
+ "@antelopejs/interface-dms": ">=0.5.12 <0.6.0",
41
41
  "@antelopejs/interface-email": ">=0.0.5 <1.0.0",
42
42
  "@antelopejs/interface-file-storage": ">=0.1.3 <1.0.0",
43
43
  "archiver": "^7.0.1",
@@ -36,7 +36,8 @@ gets `navigation` (J / K, `index` / `total` in the order shown) —
36
36
  `docs/04.components/06.tables/8.row-drawers.md`.
37
37
 
38
38
  A page's `headerActions` follow its URL: a target URL takes `{{params.X}}` / `{{query.X}}`
39
- (`?workspace={{query.workspace}}`, a pair the page has no value for is dropped), and an
39
+ (`?workspace={{query.workspace}}`, a pair the page has no value for is dropped), a label's
40
+ translation takes the page's route and query parameters (`"Download {locale}.json"`), and an
40
41
  `availability` reads `context.query`, asked again when the query changes — no need to build
41
42
  the header in Vue with `usePageHeaderActions` to carry the scope —
42
43
  `docs/07.interfaces/3.base/6.layout.md#buttons-that-follow-the-page-url`. An `availability`