@krak-stack/registry 0.1.48 → 0.1.50

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,23 @@
1
1
  # @krak-stack/registry
2
2
 
3
+ ## 0.1.50
4
+
5
+ ### Patch Changes
6
+
7
+ - Render configured empty groups and their actions in DataTable table and gallery views even when no resource rows exist. Preserve loading, error, and normal empty states when no groups are available.
8
+ - Persist Group by selections alongside column and view preferences, including explicitly cleared grouping. Keep existing saved preferences compatible and use the initial grouping when no grouping preference has been saved.
9
+
10
+ ## 0.1.49
11
+
12
+ ### Patch Changes
13
+
14
+ - e026d8d: Fix silent form submission failures in `SubmitError`, including typed HTTP errors such as `Forbidden` whose messages are empty.
15
+ - Display a non-empty server or domain error message first, when available.
16
+ - Otherwise, display an English or French message for recognized HTTP errors, then a generic failure message if no useful message or recognized status is available.
17
+ - Use localized HTTP status messages instead of raw HTTP-client diagnostics for recognized statuses.
18
+ - Support the provider locale and explicit `locale` and `messages` overrides.
19
+ - Continue displaying schema validation errors beside their fields rather than in the submission error display.
20
+
3
21
  ## 0.1.48
4
22
 
5
23
  ### Patch Changes
@@ -979,6 +979,7 @@ import { jsx as jsx14, jsxs as jsxs8, Fragment } from "react/jsx-runtime";
979
979
  var DataTablePersistedUiStateSchema = Schema.Struct({
980
980
  columnVisibility: Schema.Record(Schema.String, Schema.Boolean),
981
981
  columnSizing: Schema.Record(Schema.String, Schema.Number),
982
+ grouping: Schema.optionalKey(Schema.Array(Schema.String)),
982
983
  view: Schema.Literals(["table", "gallery"])
983
984
  }).annotate({ identifier: "DataTablePersistedUiState" });
984
985
  var dataTableStorageRuntime = Atom.runtime(BrowserKeyValueStore.layerLocalStorage);
@@ -1071,11 +1072,11 @@ var DEFAULT_UI_STATE = {
1071
1072
  var persistedUiFromState = (state) => ({
1072
1073
  columnVisibility: state.columnVisibility,
1073
1074
  columnSizing: state.columnSizing,
1075
+ grouping: state.grouping,
1074
1076
  view: state.view
1075
1077
  });
1076
1078
  var transientUiFromState = (state) => ({
1077
1079
  rowSelection: state.rowSelection,
1078
- grouping: state.grouping,
1079
1080
  collapsedGroups: state.collapsedGroups
1080
1081
  });
1081
1082
  var clampWidth = (column, width) => Math.min(column.maxWidth ?? DEFAULT_MAX_WIDTH, Math.max(column.minWidth ?? DEFAULT_MIN_WIDTH, width));
@@ -2355,11 +2356,11 @@ var GroupActions = ({
2355
2356
  });
2356
2357
  };
2357
2358
  var GroupedTable = ({
2358
- tableAtom
2359
+ tableAtom,
2360
+ sections
2359
2361
  }) => {
2360
2362
  const [store, setStore] = useTableAtom(tableAtom);
2361
2363
  const model = deriveModel(store);
2362
- const sections = groupDataTableRows(model.sortedRows, getActiveGrouping(store));
2363
2364
  const extra = (store.config.features.selection ? 1 : 0) + (hasRowActionMenu(store) ? 1 : 0) + (canDragRows(store) ? 1 : 0);
2364
2365
  const renderSections = (items) => items.flatMap((section) => {
2365
2366
  const collapsed = !!store.state.collapsedGroups[section.key];
@@ -2597,12 +2598,15 @@ var DataTableBody = ({
2597
2598
  }) => {
2598
2599
  const [store] = useTableAtom(tableAtom);
2599
2600
  const model = deriveModel(store);
2600
- const grouped = getActiveGrouping(store).length > 0;
2601
+ const fields = getActiveGrouping(store);
2602
+ const grouped = fields.length > 0;
2601
2603
  const rows = grouped ? model.sortedRows : model.pageRows;
2604
+ const sections = groupDataTableRows(rows, fields);
2602
2605
  const colSpan = model.visibleColumns.length + (store.config.features.selection ? 1 : 0) + (hasRowActionMenu(store) ? 1 : 0) + (canDragRows(store) ? 1 : 0);
2603
- if (grouped && rows.length && !store.config.status.error) {
2606
+ if (sections.length && (rows.length || !store.config.status.loading) && !store.config.status.error) {
2604
2607
  return /* @__PURE__ */ jsx14(GroupedTable, {
2605
- tableAtom
2608
+ tableAtom,
2609
+ sections
2606
2610
  });
2607
2611
  }
2608
2612
  return /* @__PURE__ */ jsx14(TableBody, {
@@ -2706,6 +2710,7 @@ var DataTableGallery = ({
2706
2710
  const model = deriveModel(store);
2707
2711
  const fields = getActiveGrouping(store);
2708
2712
  const rows = fields.length ? model.sortedRows : model.pageRows;
2713
+ const sections = groupDataTableRows(rows, fields);
2709
2714
  if (store.config.status.error) {
2710
2715
  return /* @__PURE__ */ jsx14("div", {
2711
2716
  className: "text-destructive rounded-lg border border-dashed p-10 text-center",
@@ -2720,7 +2725,7 @@ var DataTableGallery = ({
2720
2725
  })
2721
2726
  });
2722
2727
  }
2723
- if (!rows.length) {
2728
+ if (!rows.length && !sections.length) {
2724
2729
  return /* @__PURE__ */ jsx14("div", {
2725
2730
  className: "text-muted-foreground rounded-lg border border-dashed p-10 text-center",
2726
2731
  children: store.config.status.empty ?? store.config.labels.empty
@@ -2799,7 +2804,7 @@ var DataTableGallery = ({
2799
2804
  });
2800
2805
  return /* @__PURE__ */ jsx14("div", {
2801
2806
  className: "space-y-4",
2802
- children: renderSections(groupDataTableRows(rows, fields))
2807
+ children: renderSections(sections)
2803
2808
  });
2804
2809
  };
2805
2810
  var DataTablePagination = ({
@@ -2845,15 +2850,17 @@ var HydratedDataTable = ({
2845
2850
  setPersistedUiState,
2846
2851
  ...props
2847
2852
  }) => {
2848
- const [transientUiAtom] = useState(() => {
2853
+ const [initialGrouping] = useState(() => {
2849
2854
  const grouping = props.features?.grouping;
2850
- return Atom.make({
2851
- ...transientUiFromState(DEFAULT_UI_STATE),
2852
- grouping: grouping && grouping.initial ? grouping.initial : []
2853
- });
2855
+ return grouping && grouping.initial ? grouping.initial : [];
2854
2856
  });
2857
+ const [transientUiAtom] = useState(() => Atom.make(transientUiFromState(DEFAULT_UI_STATE)));
2855
2858
  const [transientUiState, setTransientUiState] = useAtom(transientUiAtom);
2856
- const uiState = useMemo(() => ({ ...persistedUiState, ...transientUiState }), [persistedUiState, transientUiState]);
2859
+ const uiState = useMemo(() => ({
2860
+ ...persistedUiState,
2861
+ ...transientUiState,
2862
+ grouping: persistedUiState.grouping ?? initialGrouping
2863
+ }), [persistedUiState, transientUiState, initialGrouping]);
2857
2864
  const setUiState = useCallback((state) => {
2858
2865
  setPersistedUiState(persistedUiFromState(state));
2859
2866
  setTransientUiState(transientUiFromState(state));
@@ -2946,7 +2953,10 @@ var DataTable = (props) => {
2946
2953
  runtime: dataTableStorageRuntime,
2947
2954
  key: `data-table:${pathname}:${columnIds}:${viewCapability}:ui`,
2948
2955
  schema: DataTablePersistedUiStateSchema,
2949
- defaultValue: () => persistedUiFromState(DEFAULT_UI_STATE)
2956
+ defaultValue: () => ({
2957
+ ...persistedUiFromState(DEFAULT_UI_STATE),
2958
+ grouping: props.features?.grouping ? props.features.grouping.initial ?? [] : []
2959
+ })
2950
2960
  });
2951
2961
  });
2952
2962
  const [persistedUiResult, setPersistedUiState] = useAtom(persistedUiAtom);
@@ -18,6 +18,14 @@ export type EffectFormMessages = {
18
18
  nameRequired: string;
19
19
  revert: string;
20
20
  submit: string;
21
+ submitBadRequest: string;
22
+ submitUnauthorized: string;
23
+ submitForbidden: string;
24
+ submitNotFound: string;
25
+ submitConflict: string;
26
+ submitRateLimited: string;
27
+ submitUnavailable: string;
28
+ submitFailed: string;
21
29
  suggestedImageSize: (width: string, height: string) => string;
22
30
  value: string;
23
31
  };
@@ -44,8 +52,10 @@ export declare const FieldWrapper: ({ children, description, editingLocale, lege
44
52
  export declare const ErrorMessage: ({ text }: {
45
53
  text: string;
46
54
  }) => JSX.Element;
47
- export declare const SubmitError: <A, E>({ result, }: {
55
+ export declare const SubmitError: <A, E>({ result, locale, messages, }: {
48
56
  result: AsyncResult.AsyncResult<A, E>;
57
+ locale?: string;
58
+ messages?: EffectFormMessageTranslations;
49
59
  }) => JSX.Element | null;
50
60
  export type SubmitForm<A, E> = {
51
61
  isDirty: Atom.Atom<boolean>;
@@ -2,6 +2,7 @@
2
2
  import { useAtomSet, useAtomValue } from "@effect/atom-react";
3
3
  import { Block } from "@tanstack/react-router";
4
4
  import { Cause, Option, Schema as Schema2 } from "effect";
5
+ import { HttpClientError } from "effect/http";
5
6
  import { AsyncResult } from "effect/reactivity";
6
7
  import { Languages, Loader2, Plus, Trash } from "lucide-react";
7
8
 
@@ -1288,6 +1289,14 @@ var messages3 = {
1288
1289
  nameRequired: "Name is required",
1289
1290
  revert: "Revert to default",
1290
1291
  submit: "Submit",
1292
+ submitBadRequest: "The submitted information is invalid.",
1293
+ submitUnauthorized: "Please sign in to submit this form.",
1294
+ submitForbidden: "You do not have permission to submit this form.",
1295
+ submitNotFound: "The requested resource could not be found.",
1296
+ submitConflict: "Your changes conflict with the current state. Please refresh and try again.",
1297
+ submitRateLimited: "Too many requests. Please try again later.",
1298
+ submitUnavailable: "The service is temporarily unavailable. Please try again later.",
1299
+ submitFailed: "Your changes could not be saved. Please try again.",
1291
1300
  suggestedImageSize: (width, height) => `Suggested image size: ${width} x ${height}`,
1292
1301
  value: "Value"
1293
1302
  },
@@ -1305,6 +1314,14 @@ var messages3 = {
1305
1314
  nameRequired: "Le nom est obligatoire",
1306
1315
  revert: "Revenir aux paramètres par défaut",
1307
1316
  submit: "Soumettre",
1317
+ submitBadRequest: "Les informations soumises sont invalides.",
1318
+ submitUnauthorized: "Veuillez vous connecter pour soumettre ce formulaire.",
1319
+ submitForbidden: "Vous n’avez pas la permission de soumettre ce formulaire.",
1320
+ submitNotFound: "La ressource demandée est introuvable.",
1321
+ submitConflict: "Vos modifications sont en conflit avec l’état actuel. Veuillez actualiser la page et réessayer.",
1322
+ submitRateLimited: "Trop de requêtes. Veuillez réessayer plus tard.",
1323
+ submitUnavailable: "Le service est temporairement indisponible. Veuillez réessayer plus tard.",
1324
+ submitFailed: "Vos modifications n’ont pas pu être enregistrées. Veuillez réessayer.",
1308
1325
  suggestedImageSize: (width, height) => `Taille de l'image suggérée : ${width} x ${height}`,
1309
1326
  value: "Valeur"
1310
1327
  }
@@ -1315,9 +1332,46 @@ var effectFormMessages = (locale = "en", translations) => ({
1315
1332
  ...translations?.[locale]
1316
1333
  });
1317
1334
  var useEffectFormMessages = (locale, translations) => effectFormMessages(useKrakstackLocale3(locale), translations);
1318
- var getCauseErrorMessage = (cause) => {
1335
+ var SubmitErrorDetails = Schema2.Struct({
1336
+ _tag: Schema2.optional(Schema2.String),
1337
+ status: Schema2.optional(Schema2.Number),
1338
+ statusCode: Schema2.optional(Schema2.Number)
1339
+ }).annotate({ identifier: "SubmitErrorDetails" });
1340
+ var submitErrorStatuses = new Map([
1341
+ ["BadRequest", 400],
1342
+ ["Unauthorized", 401],
1343
+ ["Forbidden", 403],
1344
+ ["NotFound", 404],
1345
+ ["Conflict", 409],
1346
+ ["TooManyRequests", 429],
1347
+ ["InternalServerError", 500],
1348
+ ["NotImplemented", 501],
1349
+ ["ServiceUnavailable", 503]
1350
+ ]);
1351
+ var getCauseErrorMessage = (cause, labels) => {
1319
1352
  const error = Cause.squash(cause);
1320
- return error instanceof Error ? error.message : String(error);
1353
+ const isHttpClientError = HttpClientError.isHttpClientError(error);
1354
+ if (!isHttpClientError && error instanceof Error && error.message.trim()) {
1355
+ return error.message.trim();
1356
+ }
1357
+ const details = Option.getOrUndefined(Schema2.decodeUnknownOption(SubmitErrorDetails)(error));
1358
+ const status = isHttpClientError ? error.response?.status : details?.status ?? details?.statusCode ?? submitErrorStatuses.get(details?._tag ?? "");
1359
+ const statusMessage = new Map([
1360
+ [400, labels.submitBadRequest],
1361
+ [401, labels.submitUnauthorized],
1362
+ [403, labels.submitForbidden],
1363
+ [404, labels.submitNotFound],
1364
+ [409, labels.submitConflict],
1365
+ [429, labels.submitRateLimited],
1366
+ [500, labels.submitFailed],
1367
+ [501, labels.submitFailed],
1368
+ [503, labels.submitUnavailable]
1369
+ ]).get(status ?? 0);
1370
+ if (statusMessage)
1371
+ return statusMessage;
1372
+ if (error instanceof Error)
1373
+ return error.message.trim() || labels.submitFailed;
1374
+ return Option.getOrElse(Schema2.decodeUnknownOption(Schema2.String)(error), () => "").trim() || labels.submitFailed;
1321
1375
  };
1322
1376
  var FieldWrapper = ({
1323
1377
  children,
@@ -1355,9 +1409,12 @@ var ErrorMessage = ({ text }) => /* @__PURE__ */ jsx13("em", {
1355
1409
  children: text
1356
1410
  });
1357
1411
  var SubmitError = ({
1358
- result
1412
+ result,
1413
+ locale,
1414
+ messages
1359
1415
  }) => {
1360
- const message = AsyncResult.isFailure(result) ? Schema2.isSchemaError(Cause.squash(result.cause)) ? undefined : getCauseErrorMessage(result.cause) : undefined;
1416
+ const labels = useEffectFormMessages(locale, messages);
1417
+ const message = AsyncResult.isFailure(result) ? Schema2.isSchemaError(Cause.squash(result.cause)) ? undefined : getCauseErrorMessage(result.cause, labels) : undefined;
1361
1418
  return message ? /* @__PURE__ */ jsx13(ErrorMessage, {
1362
1419
  text: message
1363
1420
  }) : null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@krak-stack/registry",
3
- "version": "0.1.48",
3
+ "version": "0.1.50",
4
4
  "description": "Tree-shakable KrakStack components and Effect services.",
5
5
  "license": "MIT",
6
6
  "repository": {