@antelopejs/dms 0.7.15 → 0.7.16
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 +18 -0
- package/dist/test/unit/interfaces/dms/page-layout-query.test.js +16 -0
- package/dist/test/unit/interfaces/dms/page-layout-query.test.js.map +1 -1
- package/dist/test/unit/interfaces/dms-base/layout-header-actions.test.js +66 -0
- package/dist/test/unit/interfaces/dms-base/layout-header-actions.test.js.map +1 -1
- package/frontend-vue/layers/dms-core/app/composables/period/presetResolvers.ts +19 -1
- package/frontend-vue/layers/dms-core/app/composables/period/usePeriod.ts +52 -28
- package/frontend-vue/layers/dms-core/i18n/locales/core-en-GB.json +1 -0
- package/frontend-vue/layers/dms-core/i18n/locales/core-fr-FR.json +1 -0
- package/frontend-vue/layers/dms-layout/app/build/components/layout/PageHeaderActionBar.vue +48 -4
- package/frontend-vue/layers/dms-layout/app/build/components/layout/PageHeaderActionsOutlet.vue +6 -2
- package/frontend-vue/layers/dms-layout/app/composables/layout/usePageHeaderActions.ts +32 -1
- package/frontend-vue/layers/dms-ui/app/build/components/period/PeriodRangeCalendar.vue +17 -1
- package/frontend-vue/layers/dms-ui/app/build/composables/period/periodDisplay.ts +49 -0
- package/frontend-vue/layers/dms-ui/app/build/composables/period/usePeriodLocation.ts +34 -11
- package/frontend-vue/layers/dms-ui/app/build/composables/table-view/useTableUrlTab.ts +47 -0
- package/frontend-vue/layers/dms-ui/app/components/period/PeriodSelector.vue +32 -6
- package/frontend-vue/layers/dms-ui/app/components/table-view/TableView.vue +14 -4
- package/frontend-vue/tests/header-action-page-query.test.ts +96 -1
- package/frontend-vue/tests/period-day-rollover.test.ts +80 -0
- package/frontend-vue/tests/period-max-days.test.ts +128 -0
- package/frontend-vue/tests/period-selector-url.test.ts +44 -8
- package/frontend-vue/tests/table-view-url-tab.test.ts +115 -0
- package/package.json +2 -2
- package/skills/dms-pages/REFERENCE.md +6 -1
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
/**
|
|
3
|
+
* `maxDays` caps the custom range a PeriodSelector lets the user pick: the
|
|
4
|
+
* calendar disables the days past it once a start day is picked, and a range
|
|
5
|
+
* from the date fields or a long preset is cut to it.
|
|
6
|
+
*/
|
|
7
|
+
import { CalendarDate } from "@internationalized/date";
|
|
8
|
+
import { readFileSync } from "node:fs";
|
|
9
|
+
import { resolve } from "node:path";
|
|
10
|
+
import { createApp, defineComponent, h, nextTick, type App } from "vue";
|
|
11
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
12
|
+
import PeriodRangeCalendar from "../layers/dms-ui/app/build/components/period/PeriodRangeCalendar.vue";
|
|
13
|
+
import {
|
|
14
|
+
calendarRangeDays,
|
|
15
|
+
isBeyondMaxDays,
|
|
16
|
+
limitCalendarRange,
|
|
17
|
+
} from "../layers/dms-ui/app/build/composables/period/periodDisplay";
|
|
18
|
+
|
|
19
|
+
const OCTOBER_FIRST = new CalendarDate(2026, 10, 1);
|
|
20
|
+
const OCTOBER_LAST = new CalendarDate(2026, 10, 31);
|
|
21
|
+
|
|
22
|
+
describe("limitCalendarRange", () => {
|
|
23
|
+
const october = { start: OCTOBER_FIRST, end: OCTOBER_LAST };
|
|
24
|
+
|
|
25
|
+
it("keeps a range within the limit", () => {
|
|
26
|
+
expect(limitCalendarRange(october, 31, "start")).toBe(october);
|
|
27
|
+
expect(limitCalendarRange(october, undefined, "start")).toBe(october);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("moves the end when the start is kept", () => {
|
|
31
|
+
const limited = limitCalendarRange(october, 7, "start");
|
|
32
|
+
expect(limited.start.toString()).toBe("2026-10-01");
|
|
33
|
+
expect(limited.end.toString()).toBe("2026-10-07");
|
|
34
|
+
expect(calendarRangeDays(limited)).toBe(7);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("moves the start when the end is kept", () => {
|
|
38
|
+
const limited = limitCalendarRange(october, 7, "end");
|
|
39
|
+
expect(limited.start.toString()).toBe("2026-10-25");
|
|
40
|
+
expect(limited.end.toString()).toBe("2026-10-31");
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
describe("isBeyondMaxDays", () => {
|
|
45
|
+
it("allows exactly maxDays days on either side of the picked day", () => {
|
|
46
|
+
const picked = new CalendarDate(2026, 10, 10);
|
|
47
|
+
expect(isBeyondMaxDays(picked.add({ days: 6 }), picked, 7)).toBe(false);
|
|
48
|
+
expect(isBeyondMaxDays(picked.add({ days: 7 }), picked, 7)).toBe(true);
|
|
49
|
+
expect(isBeyondMaxDays(picked.subtract({ days: 6 }), picked, 7)).toBe(
|
|
50
|
+
false,
|
|
51
|
+
);
|
|
52
|
+
expect(isBeyondMaxDays(picked.subtract({ days: 7 }), picked, 7)).toBe(true);
|
|
53
|
+
expect(isBeyondMaxDays(picked.add({ days: 400 }), picked, undefined)).toBe(
|
|
54
|
+
false,
|
|
55
|
+
);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
describe("the range calendar with maxDays", () => {
|
|
60
|
+
let app: App | undefined;
|
|
61
|
+
|
|
62
|
+
afterEach(() => {
|
|
63
|
+
app?.unmount();
|
|
64
|
+
app = undefined;
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
function mountCalendar(maxDays?: number): HTMLElement {
|
|
68
|
+
const host = document.createElement("div");
|
|
69
|
+
document.body.appendChild(host);
|
|
70
|
+
app = createApp(
|
|
71
|
+
defineComponent({
|
|
72
|
+
setup: () => () =>
|
|
73
|
+
h(PeriodRangeCalendar, {
|
|
74
|
+
modelValue: {
|
|
75
|
+
start: new CalendarDate(2026, 9, 1),
|
|
76
|
+
end: new CalendarDate(2026, 9, 2),
|
|
77
|
+
},
|
|
78
|
+
locale: "en-US",
|
|
79
|
+
numberOfMonths: 1,
|
|
80
|
+
maxDays,
|
|
81
|
+
}),
|
|
82
|
+
}),
|
|
83
|
+
);
|
|
84
|
+
app.config.globalProperties.$t = (_key: string, fallback: string) =>
|
|
85
|
+
fallback;
|
|
86
|
+
app.component(
|
|
87
|
+
"UButton",
|
|
88
|
+
defineComponent({ setup: () => () => h("button") }),
|
|
89
|
+
);
|
|
90
|
+
app.mount(host);
|
|
91
|
+
return host;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function day(host: HTMLElement, value: string): HTMLElement {
|
|
95
|
+
const cell = host.querySelector<HTMLElement>(`[data-value="${value}"]`);
|
|
96
|
+
if (!cell) throw new Error(`No day ${value}`);
|
|
97
|
+
return cell;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
it("disables the days past the limit once a start day is picked", async () => {
|
|
101
|
+
const host = mountCalendar(7);
|
|
102
|
+
expect(day(host, "2026-09-20").hasAttribute("data-disabled")).toBe(false);
|
|
103
|
+
day(host, "2026-09-10").click();
|
|
104
|
+
await nextTick();
|
|
105
|
+
expect(day(host, "2026-09-16").hasAttribute("data-disabled")).toBe(false);
|
|
106
|
+
expect(day(host, "2026-09-17").hasAttribute("data-disabled")).toBe(true);
|
|
107
|
+
expect(day(host, "2026-09-03").hasAttribute("data-disabled")).toBe(true);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("leaves every day enabled without a limit", async () => {
|
|
111
|
+
const host = mountCalendar();
|
|
112
|
+
day(host, "2026-09-10").click();
|
|
113
|
+
await nextTick();
|
|
114
|
+
expect(day(host, "2026-09-30").hasAttribute("data-disabled")).toBe(false);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it("hands maxDays to the calendar and cuts the date fields to it", () => {
|
|
119
|
+
const source = readFileSync(
|
|
120
|
+
resolve(
|
|
121
|
+
__dirname,
|
|
122
|
+
"../layers/dms-ui/app/components/period/PeriodSelector.vue",
|
|
123
|
+
),
|
|
124
|
+
"utf8",
|
|
125
|
+
);
|
|
126
|
+
expect(source).toContain(':max-days="maxDays"');
|
|
127
|
+
expect(source).toContain("limitCalendarRange(range, props.maxDays, anchor)");
|
|
128
|
+
});
|
|
@@ -25,12 +25,13 @@ const preferences = new Map<string, unknown>();
|
|
|
25
25
|
vi.stubGlobal("useDmsRoute", () => route);
|
|
26
26
|
// Inertia's client-side replace moves its page URL, which the DMS route
|
|
27
27
|
// follows: the route then holds the query the browser shows.
|
|
28
|
+
function followInertiaPage({ url }: { url: string }): void {
|
|
29
|
+
route.query = Object.fromEntries(
|
|
30
|
+
new URL(url, "http://dms.local").searchParams,
|
|
31
|
+
);
|
|
32
|
+
}
|
|
28
33
|
const { inertiaReplace } = vi.hoisted(() => ({
|
|
29
|
-
inertiaReplace: vi.fn(
|
|
30
|
-
route.query = Object.fromEntries(
|
|
31
|
-
new URL(url, "http://dms.local").searchParams,
|
|
32
|
-
);
|
|
33
|
-
}),
|
|
34
|
+
inertiaReplace: vi.fn(),
|
|
34
35
|
}));
|
|
35
36
|
vi.mock("@inertiajs/vue3", () => ({ router: { replace: inertiaReplace } }));
|
|
36
37
|
vi.stubGlobal("usePreferences", () => ({
|
|
@@ -116,13 +117,24 @@ function mount(...ids: string[]): void {
|
|
|
116
117
|
|
|
117
118
|
const search = () => new URLSearchParams(window.location.search);
|
|
118
119
|
|
|
120
|
+
/** A navigation from outside: the browser's URL moves, then the route. */
|
|
121
|
+
function navigate(query: Record<string, string>): void {
|
|
122
|
+
window.history.replaceState(
|
|
123
|
+
null,
|
|
124
|
+
"",
|
|
125
|
+
`${PAGE_PATH}?${new URLSearchParams(query)}`,
|
|
126
|
+
);
|
|
127
|
+
route.query = query;
|
|
128
|
+
}
|
|
129
|
+
|
|
119
130
|
const remember = (query: Record<string, string>) =>
|
|
120
131
|
preferences.set(PERIOD_PREFERENCE_KEY, { [`${PAGE_ID}#page`]: query });
|
|
121
132
|
|
|
122
133
|
beforeEach(() => {
|
|
123
134
|
route.query = {};
|
|
124
135
|
preferences.clear();
|
|
125
|
-
inertiaReplace.
|
|
136
|
+
inertiaReplace.mockReset();
|
|
137
|
+
inertiaReplace.mockImplementation(followInertiaPage);
|
|
126
138
|
window.history.replaceState(null, "", PAGE_PATH);
|
|
127
139
|
});
|
|
128
140
|
|
|
@@ -272,10 +284,34 @@ describe("a change of period", () => {
|
|
|
272
284
|
});
|
|
273
285
|
});
|
|
274
286
|
|
|
287
|
+
describe("the route while Inertia catches up", () => {
|
|
288
|
+
it("holds the new period at once", async () => {
|
|
289
|
+
inertiaReplace.mockImplementation(() => {});
|
|
290
|
+
mount("page");
|
|
291
|
+
handles.page!.setPreset("last-7-days");
|
|
292
|
+
await nextTick();
|
|
293
|
+
expect(route.query["page.period"]).toBe("last-7-days");
|
|
294
|
+
expect(search().get("page.period")).toBe("last-7-days");
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
it("does not move the period back when it reports the old URL late", async () => {
|
|
298
|
+
inertiaReplace.mockImplementation(() => {});
|
|
299
|
+
mount("page");
|
|
300
|
+
await nextTick();
|
|
301
|
+
const before = { ...route.query };
|
|
302
|
+
handles.page!.setPreset("last-7-days");
|
|
303
|
+
await nextTick();
|
|
304
|
+
route.query = before;
|
|
305
|
+
await nextTick();
|
|
306
|
+
expect(handles.page!.preset.value).toBe("last-7-days");
|
|
307
|
+
expect(search().get("page.period")).toBe("last-7-days");
|
|
308
|
+
});
|
|
309
|
+
});
|
|
310
|
+
|
|
275
311
|
describe("a route changed from outside", () => {
|
|
276
312
|
it("moves the period of the selector it names", async () => {
|
|
277
313
|
mount("sales", "traffic");
|
|
278
|
-
|
|
314
|
+
navigate({ "sales.period": "last-30-days" });
|
|
279
315
|
await nextTick();
|
|
280
316
|
expect(handles.sales!.preset.value).toBe("last-30-days");
|
|
281
317
|
expect(handles.traffic!.preset.value).toBe("this-month");
|
|
@@ -285,7 +321,7 @@ describe("a route changed from outside", () => {
|
|
|
285
321
|
mount("page");
|
|
286
322
|
handles.page!.setPreset("last-7-days");
|
|
287
323
|
await nextTick();
|
|
288
|
-
|
|
324
|
+
navigate({ "page.period": "last-decade" });
|
|
289
325
|
await nextTick();
|
|
290
326
|
expect(handles.page!.preset.value).toBe("last-7-days");
|
|
291
327
|
});
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
/**
|
|
3
|
+
* A table view opens the tab its URL names (`?<tableId>.tab=`, or `?tab=` on
|
|
4
|
+
* a page with a single table view), on arrival and afterwards: a link or a
|
|
5
|
+
* `router.replace` naming another tab switches to it in place, without
|
|
6
|
+
* remounting the page.
|
|
7
|
+
*/
|
|
8
|
+
import { readFileSync } from "node:fs";
|
|
9
|
+
import { resolve } from "node:path";
|
|
10
|
+
import { createApp, defineComponent, h, nextTick, reactive, ref } from "vue";
|
|
11
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
12
|
+
import {
|
|
13
|
+
readTableUrlTab,
|
|
14
|
+
useTableUrlTab,
|
|
15
|
+
} from "../layers/dms-ui/app/build/composables/table-view/useTableUrlTab";
|
|
16
|
+
import type { TableUrlScope } from "../layers/dms-ui/app/build/composables/table-view/utils/views";
|
|
17
|
+
|
|
18
|
+
const OPENABLE_TABS = new Set(["all", "active", "archived"]);
|
|
19
|
+
const mounted: Array<{ unmount: () => void }> = [];
|
|
20
|
+
|
|
21
|
+
function mountTable(scope: TableUrlScope, query: Record<string, string>) {
|
|
22
|
+
const route = reactive({ query });
|
|
23
|
+
const activeTabId = ref(readTableUrlTab(route.query, scope) ?? "all");
|
|
24
|
+
const app = createApp(
|
|
25
|
+
defineComponent({
|
|
26
|
+
setup() {
|
|
27
|
+
useTableUrlTab({
|
|
28
|
+
route,
|
|
29
|
+
urlScope: scope,
|
|
30
|
+
activeTabId,
|
|
31
|
+
isOpenable: (tabId) => OPENABLE_TABS.has(tabId),
|
|
32
|
+
});
|
|
33
|
+
return () => h("div");
|
|
34
|
+
},
|
|
35
|
+
}),
|
|
36
|
+
);
|
|
37
|
+
app.mount(document.createElement("div"));
|
|
38
|
+
mounted.push(app);
|
|
39
|
+
return { route, activeTabId };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
afterEach(() => {
|
|
43
|
+
mounted.splice(0).forEach((app) => app.unmount());
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
describe("the tab a URL names", () => {
|
|
47
|
+
it("opens on arrival", () => {
|
|
48
|
+
const { activeTabId } = mountTable(
|
|
49
|
+
{ tableId: "runs" },
|
|
50
|
+
{ "runs.tab": "active" },
|
|
51
|
+
);
|
|
52
|
+
expect(activeTabId.value).toBe("active");
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("switches the tab when the prefixed key changes after mount", async () => {
|
|
56
|
+
const { route, activeTabId } = mountTable({ tableId: "runs" }, {});
|
|
57
|
+
route.query = { "runs.tab": "archived" };
|
|
58
|
+
await nextTick();
|
|
59
|
+
expect(activeTabId.value).toBe("archived");
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("follows the short key on a page with a single table view", async () => {
|
|
63
|
+
const { route, activeTabId } = mountTable(
|
|
64
|
+
{ tableId: "runs", isSoleTableView: true },
|
|
65
|
+
{ tab: "active" },
|
|
66
|
+
);
|
|
67
|
+
expect(activeTabId.value).toBe("active");
|
|
68
|
+
route.query = { tab: "archived" };
|
|
69
|
+
await nextTick();
|
|
70
|
+
expect(activeTabId.value).toBe("archived");
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("ignores the short key on a page with several table views", async () => {
|
|
74
|
+
const { route, activeTabId } = mountTable({ tableId: "runs" }, {});
|
|
75
|
+
route.query = { tab: "archived" };
|
|
76
|
+
await nextTick();
|
|
77
|
+
expect(activeTabId.value).toBe("all");
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("keeps the open tab when the key is dropped or unknown", async () => {
|
|
81
|
+
const { route, activeTabId } = mountTable(
|
|
82
|
+
{ tableId: "runs" },
|
|
83
|
+
{ "runs.tab": "active" },
|
|
84
|
+
);
|
|
85
|
+
route.query = {};
|
|
86
|
+
await nextTick();
|
|
87
|
+
expect(activeTabId.value).toBe("active");
|
|
88
|
+
route.query = { "runs.tab": "missing" };
|
|
89
|
+
await nextTick();
|
|
90
|
+
expect(activeTabId.value).toBe("active");
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("lets the user change tabs while the URL stays put", async () => {
|
|
94
|
+
const { route, activeTabId } = mountTable(
|
|
95
|
+
{ tableId: "runs" },
|
|
96
|
+
{ "runs.tab": "active" },
|
|
97
|
+
);
|
|
98
|
+
activeTabId.value = "archived";
|
|
99
|
+
route.query = { "runs.tab": "active", other: "1" };
|
|
100
|
+
await nextTick();
|
|
101
|
+
expect(activeTabId.value).toBe("archived");
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it("wires the URL tab into the table view", () => {
|
|
106
|
+
const source = readFileSync(
|
|
107
|
+
resolve(
|
|
108
|
+
__dirname,
|
|
109
|
+
"../layers/dms-ui/app/components/table-view/TableView.vue",
|
|
110
|
+
),
|
|
111
|
+
"utf8",
|
|
112
|
+
);
|
|
113
|
+
expect(source).toContain("readTableUrlTab(route.query, urlScope)");
|
|
114
|
+
expect(source).toContain("useTableUrlTab({");
|
|
115
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antelopejs/dms",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.16",
|
|
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.
|
|
40
|
+
"@antelopejs/interface-dms": ">=0.5.11 <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",
|
|
@@ -39,7 +39,12 @@ A page's `headerActions` follow its URL: a target URL takes `{{params.X}}` / `{{
|
|
|
39
39
|
(`?workspace={{query.workspace}}`, a pair the page has no value for is dropped), and an
|
|
40
40
|
`availability` reads `context.query`, asked again when the query changes — no need to build
|
|
41
41
|
the header in Vue with `usePageHeaderActions` to carry the scope —
|
|
42
|
-
`docs/07.interfaces/3.base/6.layout.md#buttons-that-follow-the-page-url`.
|
|
42
|
+
`docs/07.interfaces/3.base/6.layout.md#buttons-that-follow-the-page-url`. An `availability`
|
|
43
|
+
answering `{ hidden: true }` leaves the button out for that query (`{ reason }` only
|
|
44
|
+
disables it): no Vue header to hide "Add key" on a read-only workspace. `order` on a
|
|
45
|
+
header button and `usePageHeaderActions(render, { order })` interleave served buttons with a
|
|
46
|
+
component's client-side ones (default `0`, served first on a tie: `order: -1` puts a Vue
|
|
47
|
+
"Export" before a served "Add key") — `docs/07.interfaces/3.base/6.layout.md#ordering-the-header`.
|
|
43
48
|
|
|
44
49
|
A button or row action (`customButtons`, `rowActions.custom`, a page's `headerActions`)
|
|
45
50
|
points at an `ActionTarget`. A `drawer` target opens from the bottom; give it
|