@middag-io/react 0.50.1 → 0.51.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@middag-io/react",
3
- "version": "0.50.1",
3
+ "version": "0.51.1",
4
4
  "type": "module",
5
5
  "description": "MIDDAG shared React UI library for Moodle, WordPress and other Inertia hosts",
6
6
  "license": "Apache-2.0",
@@ -23,6 +23,28 @@ import { renderLabel } from "@/i18n/render-label";
23
23
  import { useTranslation } from "@/i18n/useTranslation";
24
24
  import { resolveActionTarget } from "@/lib/actions/resolve-action-target";
25
25
 
26
+ /** Query keys the server-mode table writes on every request. */
27
+ const TABLE_OWNED_PARAMS = new Set(["page", "per_page", "sort", "direction", "search"]);
28
+ const TABLE_FILTER_PARAM_PREFIX = "filter[";
29
+
30
+ function isTableOwnedParam(key: string): boolean {
31
+ return TABLE_OWNED_PARAMS.has(key) || key.startsWith(TABLE_FILTER_PARAM_PREFIX);
32
+ }
33
+
34
+ /**
35
+ * The page's query string without the params the table owns, as `?...` or "".
36
+ * The table sends its full state on each request, so whatever it leaves out
37
+ * (a cleared sort, a removed filter) has to be absent from the request too.
38
+ */
39
+ function pageQueryWithoutTableParams(search: string): string {
40
+ const kept = new URLSearchParams();
41
+ new URLSearchParams(search).forEach((value, key) => {
42
+ if (!isTableOwnedParam(key)) kept.append(key, value);
43
+ });
44
+ const query = kept.toString();
45
+ return query ? `?${query}` : "";
46
+ }
47
+
26
48
  export function DenseTableBlock({ block }: BlockProps<DenseTableBlockData>): ReactElement {
27
49
  const { t } = useTranslation();
28
50
  const { data, key, meta } = block;
@@ -137,9 +159,11 @@ export function DenseTableBlock({ block }: BlockProps<DenseTableBlockData>): Rea
137
159
  // Inertia builds the request URL from the href plus these params, with
138
160
  // the params winning on matching keys. Keep the page's own query string
139
161
  // in the href so params the table does not govern (tabs, collection,
140
- // groups, ...) survive a sort/search/filter/page change; the table's
141
- // values still override any stale copy of them in the current URL.
142
- const href = window.location.pathname + window.location.search;
162
+ // groups, ...) survive a sort/search/filter/page change. Strip the keys
163
+ // the table owns from it first: the params above carry their current
164
+ // values, and a value the user just cleared (a removed sort) must not
165
+ // come back from a stale copy in the URL.
166
+ const href = window.location.pathname + pageQueryWithoutTableParams(window.location.search);
143
167
  router.get(href, queryParams as Record<string, string>, {
144
168
  preserveState: true,
145
169
  preserveScroll: true,
@@ -6,20 +6,3 @@
6
6
  */
7
7
 
8
8
  export type { FlashMessages, SharedAuth, SharedProps, SharedTheme } from "@/contracts/generated";
9
-
10
- /** One tab of the host admin tab bar. */
11
- export interface AdminTabItem {
12
- key: string;
13
- label: string;
14
- href: string;
15
- }
16
-
17
- /**
18
- * The 'admin_tabs' prop some hosts add next to the shared props. It is wire with
19
- * no php-ui value object: each host builds it, and the shared props carry it
20
- * through their open index signature.
21
- */
22
- export interface AdminTabsProps {
23
- active: string;
24
- items: AdminTabItem[];
25
- }