@bsol-oss/react-datatable5 12.0.0-beta.70 → 12.0.0-beta.72

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.
@@ -1,8 +1,9 @@
1
- import { AxiosRequestConfig } from "axios";
2
- import { JSONSchema7 } from "json-schema";
3
- import { Dispatch, ReactNode, SetStateAction } from "react";
4
- import { FieldValues } from "react-hook-form";
5
- import { UseTranslationResponse } from "react-i18next";
1
+ import { AxiosRequestConfig } from 'axios';
2
+ import { JSONSchema7 } from 'json-schema';
3
+ import { Dispatch, ReactNode, SetStateAction } from 'react';
4
+ import { FieldValues } from 'react-hook-form';
5
+ import { UseTranslationResponse } from 'react-i18next';
6
+ import { DateTimePickerLabels, IdPickerLabels } from './components/types/CustomJSONSchema7';
6
7
  export interface SchemaFormContext<TData extends FieldValues> {
7
8
  schema: JSONSchema7;
8
9
  serverUrl: string;
@@ -30,11 +31,14 @@ export interface SchemaFormContext<TData extends FieldValues> {
30
31
  setError: Dispatch<SetStateAction<unknown>>;
31
32
  getUpdatedData: () => TData | Promise<TData>;
32
33
  customErrorRenderer?: (error: unknown) => ReactNode;
34
+ customSuccessRenderer?: (resetHandler: () => void | Promise<void>) => ReactNode;
33
35
  timezone?: string;
34
36
  displayConfig: {
35
37
  showSubmitButton?: boolean;
36
38
  showResetButton?: boolean;
37
39
  showTitle?: boolean;
38
40
  };
41
+ dateTimePickerLabels?: DateTimePickerLabels;
42
+ idPickerLabels?: IdPickerLabels;
39
43
  }
40
44
  export declare const SchemaFormContext: import("react").Context<SchemaFormContext<unknown>>;
@@ -1 +1,2 @@
1
- export declare const FormBody: <TData extends object>() => import("react/jsx-runtime").JSX.Element;
1
+ /// <reference types="react" />
2
+ export declare const FormBody: <TData extends object>() => string | number | bigint | boolean | Iterable<import("react").ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<import("react").ReactNode> | null | undefined> | import("react/jsx-runtime").JSX.Element | null | undefined;
@@ -1,10 +1,10 @@
1
- import { ForeignKeyProps } from "@/components/Form/components/fields/StringInputField";
2
- import { AxiosRequestConfig } from "axios";
3
- import { JSONSchema7 } from "json-schema";
4
- import { Dispatch, ReactNode, SetStateAction } from "react";
5
- import { FieldValues, SubmitHandler, UseFormReturn } from "react-hook-form";
6
- import { UseTranslationResponse } from "react-i18next";
7
- import { CustomJSONSchema7 } from "../types/CustomJSONSchema7";
1
+ import { ForeignKeyProps } from '@/components/Form/components/fields/StringInputField';
2
+ import { AxiosRequestConfig } from 'axios';
3
+ import { JSONSchema7 } from 'json-schema';
4
+ import { Dispatch, ReactNode, SetStateAction } from 'react';
5
+ import { FieldValues, SubmitHandler, UseFormReturn } from 'react-hook-form';
6
+ import { UseTranslationResponse } from 'react-i18next';
7
+ import { CustomJSONSchema7, DateTimePickerLabels, IdPickerLabels } from '../types/CustomJSONSchema7';
8
8
  export interface FormRootProps<TData extends FieldValues> {
9
9
  schema: CustomJSONSchema7;
10
10
  serverUrl: string;
@@ -22,11 +22,14 @@ export interface FormRootProps<TData extends FieldValues> {
22
22
  requestOptions?: AxiosRequestConfig;
23
23
  getUpdatedData?: () => TData | Promise<TData> | void;
24
24
  customErrorRenderer?: (error: unknown) => ReactNode;
25
+ customSuccessRenderer?: (resetHandler: () => void | Promise<void>) => ReactNode;
25
26
  displayConfig?: {
26
27
  showSubmitButton?: boolean;
27
28
  showResetButton?: boolean;
28
29
  showTitle?: boolean;
29
30
  };
31
+ dateTimePickerLabels?: DateTimePickerLabels;
32
+ idPickerLabels?: IdPickerLabels;
30
33
  }
31
34
  export interface CustomJSONSchema7Definition extends JSONSchema7 {
32
35
  variant: string;
@@ -43,4 +46,4 @@ export declare const idPickerSanityCheck: (column: string, foreign_key?: {
43
46
  column?: string | undefined;
44
47
  display_column?: string | undefined;
45
48
  } | undefined) => void;
46
- export declare const FormRoot: <TData extends FieldValues>({ schema, idMap, setIdMap, form, serverUrl, translate, children, order, ignore, include, onSubmit, rowNumber, requestOptions, getUpdatedData, customErrorRenderer, displayConfig, }: FormRootProps<TData>) => import("react/jsx-runtime").JSX.Element;
49
+ export declare const FormRoot: <TData extends FieldValues>({ schema, idMap, setIdMap, form, serverUrl, translate, children, order, ignore, include, onSubmit, rowNumber, requestOptions, getUpdatedData, customErrorRenderer, customSuccessRenderer, displayConfig, dateTimePickerLabels, idPickerLabels, }: FormRootProps<TData>) => import("react/jsx-runtime").JSX.Element;
@@ -1,4 +1,4 @@
1
- import { CustomJSONSchema7 } from "../types/CustomJSONSchema7";
1
+ import { CustomJSONSchema7 } from '../types/CustomJSONSchema7';
2
2
  export interface IdPickerProps {
3
3
  column: string;
4
4
  schema: CustomJSONSchema7;
@@ -1,7 +1,23 @@
1
- import { JSONSchema7 } from "json-schema";
2
- import { ReactNode } from "react";
3
- import { ForeignKeyProps } from "../fields/StringInputField";
4
- import { UseFormReturn } from "react-hook-form";
1
+ import { JSONSchema7 } from 'json-schema';
2
+ import { ReactNode } from 'react';
3
+ import { ForeignKeyProps } from '../fields/StringInputField';
4
+ import { UseFormReturn } from 'react-hook-form';
5
+ export interface DateTimePickerLabels {
6
+ monthNamesShort?: string[];
7
+ weekdayNamesShort?: string[];
8
+ backButtonLabel?: string;
9
+ forwardButtonLabel?: string;
10
+ }
11
+ export interface IdPickerLabels {
12
+ undefined?: string;
13
+ addMore?: string;
14
+ typeToSearch?: string;
15
+ total?: string;
16
+ showing?: string;
17
+ perPage?: string;
18
+ emptySearchResult?: string;
19
+ initialResults?: string;
20
+ }
5
21
  export interface CustomJSONSchema7 extends JSONSchema7 {
6
22
  gridColumn?: string;
7
23
  gridRow?: string;
@@ -3,10 +3,11 @@ import { FieldValues } from "react-hook-form";
3
3
  export interface UseFormProps {
4
4
  preLoadedValues?: FieldValues | undefined;
5
5
  keyPrefix?: string;
6
+ namespace?: string;
6
7
  }
7
- export declare const useForm: ({ preLoadedValues, keyPrefix }: UseFormProps) => {
8
+ export declare const useForm: ({ preLoadedValues, keyPrefix, namespace }: UseFormProps) => {
8
9
  form: import("react-hook-form").UseFormReturn<FieldValues, any, undefined>;
9
10
  idMap: Record<string, object>;
10
11
  setIdMap: import("react").Dispatch<import("react").SetStateAction<Record<string, object>>>;
11
- translate: import("react-i18next").UseTranslationResponse<"", string>;
12
+ translate: import("react-i18next").UseTranslationResponse<string, string>;
12
13
  };
@@ -0,0 +1,219 @@
1
+ /**
2
+ * Type definitions for error message configuration
3
+ */
4
+ /**
5
+ * Common validation error types that can be customized
6
+ */
7
+ export type ValidationErrorType = "minLength" | "maxLength" | "pattern" | "minimum" | "maximum" | "multipleOf" | "format" | "type" | "enum";
8
+ /**
9
+ * Configuration for field-specific validation errors
10
+ */
11
+ export type FieldErrorConfig = Partial<Record<ValidationErrorType, string>>;
12
+ /**
13
+ * Configuration for building error messages
14
+ */
15
+ export interface ErrorMessageConfig {
16
+ /**
17
+ * Required field error messages
18
+ * Maps field names to their required error messages
19
+ * Supports both plain strings and i18n translation keys
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * required: {
24
+ * username: "Username is required", // plain string
25
+ * email: "user.email.field_required" // i18n key
26
+ * }
27
+ * ```
28
+ */
29
+ required?: Record<string, string>;
30
+ /**
31
+ * Field-specific validation error messages
32
+ * Maps field names to their validation error configurations
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * properties: {
37
+ * username: {
38
+ * minLength: "Username must be at least 3 characters",
39
+ * pattern: "Username can only contain letters and numbers"
40
+ * },
41
+ * age: {
42
+ * minimum: "Age must be at least 18",
43
+ * maximum: "Age cannot exceed 120"
44
+ * }
45
+ * }
46
+ * ```
47
+ */
48
+ properties?: Record<string, FieldErrorConfig>;
49
+ /**
50
+ * Global fallback error messages for validation types
51
+ * These are used when no field-specific message is provided
52
+ *
53
+ * @example
54
+ * ```typescript
55
+ * {
56
+ * minLength: "This field is too short",
57
+ * minimum: "Value is too small"
58
+ * }
59
+ * ```
60
+ */
61
+ [key: string]: any;
62
+ }
63
+ /**
64
+ * Result of buildErrorMessages that follows ajv-errors format
65
+ */
66
+ export interface ErrorMessageResult {
67
+ required?: Record<string, string>;
68
+ properties?: Record<string, FieldErrorConfig>;
69
+ [key: string]: any;
70
+ }
71
+ /**
72
+ * Schema-level error message builder
73
+ *
74
+ * Builds a complete errorMessage object compatible with ajv-errors plugin.
75
+ * Supports both i18n translation keys and plain string messages.
76
+ *
77
+ * @param config - Error message configuration
78
+ * @returns Complete errorMessage object for JSON Schema
79
+ *
80
+ * @example
81
+ * ```typescript
82
+ * // Simple required field errors
83
+ * const errorMessage = buildErrorMessages({
84
+ * required: {
85
+ * username: "Username is required",
86
+ * email: "user.email.field_required" // i18n key
87
+ * }
88
+ * });
89
+ *
90
+ * // With validation rules
91
+ * const errorMessage = buildErrorMessages({
92
+ * required: {
93
+ * password: "Password is required"
94
+ * },
95
+ * properties: {
96
+ * password: {
97
+ * minLength: "Password must be at least 8 characters",
98
+ * pattern: "Password must contain letters and numbers"
99
+ * },
100
+ * age: {
101
+ * minimum: "Must be 18 or older",
102
+ * maximum: "Must be under 120"
103
+ * }
104
+ * }
105
+ * });
106
+ *
107
+ * // With global fallbacks
108
+ * const errorMessage = buildErrorMessages({
109
+ * required: {
110
+ * email: "Email is required"
111
+ * },
112
+ * minLength: "This field is too short", // applies to all fields
113
+ * minimum: "Value is too small"
114
+ * });
115
+ * ```
116
+ */
117
+ export declare const buildErrorMessages: (config: ErrorMessageConfig) => ErrorMessageResult;
118
+ /**
119
+ * Helper function to build required field errors
120
+ *
121
+ * Simplifies creating required field error messages, especially useful
122
+ * for generating i18n translation keys following a pattern.
123
+ *
124
+ * @param fields - Array of required field names
125
+ * @param messageOrGenerator - Either a string template or function to generate messages
126
+ * @returns Required field error configuration
127
+ *
128
+ * @example
129
+ * ```typescript
130
+ * // Plain string messages
131
+ * const required = buildRequiredErrors(
132
+ * ["username", "email", "password"],
133
+ * (field) => `${field} is required`
134
+ * );
135
+ * // Result: { username: "username is required", email: "email is required", ... }
136
+ *
137
+ * // i18n translation keys
138
+ * const required = buildRequiredErrors(
139
+ * ["username", "email"],
140
+ * (field) => `user.${field}.field_required`
141
+ * );
142
+ * // Result: { username: "user.username.field_required", email: "user.email.field_required" }
143
+ *
144
+ * // Same message for all fields
145
+ * const required = buildRequiredErrors(
146
+ * ["username", "email"],
147
+ * "This field is required"
148
+ * );
149
+ * // Result: { username: "This field is required", email: "This field is required" }
150
+ *
151
+ * // With keyPrefix for i18n
152
+ * const required = buildRequiredErrors(
153
+ * ["username", "email"],
154
+ * (field) => `${field}.field_required`,
155
+ * "user"
156
+ * );
157
+ * // Result: { username: "user.username.field_required", email: "user.email.field_required" }
158
+ * ```
159
+ */
160
+ export declare const buildRequiredErrors: (fields: string[], messageOrGenerator: string | ((field: string) => string), keyPrefix?: string) => Record<string, string>;
161
+ /**
162
+ * Helper function to build field-specific validation errors
163
+ *
164
+ * Creates property-specific error messages for multiple fields at once.
165
+ *
166
+ * @param config - Maps field names to their validation error configurations
167
+ * @returns Properties error configuration
168
+ *
169
+ * @example
170
+ * ```typescript
171
+ * const properties = buildFieldErrors({
172
+ * username: {
173
+ * minLength: "Username must be at least 3 characters",
174
+ * pattern: "Username can only contain letters and numbers"
175
+ * },
176
+ * age: {
177
+ * minimum: "Must be 18 or older",
178
+ * maximum: "Must be under 120"
179
+ * },
180
+ * email: {
181
+ * format: "Please enter a valid email address"
182
+ * }
183
+ * });
184
+ * ```
185
+ */
186
+ export declare const buildFieldErrors: (config: Record<string, FieldErrorConfig>) => Record<string, FieldErrorConfig>;
187
+ /**
188
+ * Helper function to create a complete error message configuration in one call
189
+ *
190
+ * Convenient wrapper that combines required and validation errors.
191
+ *
192
+ * @param required - Required field error messages
193
+ * @param properties - Field-specific validation error messages
194
+ * @param globalFallbacks - Global fallback error messages
195
+ * @returns Complete error message configuration
196
+ *
197
+ * @example
198
+ * ```typescript
199
+ * const errorMessage = createErrorMessage(
200
+ * {
201
+ * username: "Username is required",
202
+ * email: "Email is required"
203
+ * },
204
+ * {
205
+ * username: {
206
+ * minLength: "Username must be at least 3 characters"
207
+ * },
208
+ * email: {
209
+ * format: "Please enter a valid email"
210
+ * }
211
+ * },
212
+ * {
213
+ * minLength: "This field is too short",
214
+ * format: "Invalid format"
215
+ * }
216
+ * );
217
+ * ```
218
+ */
219
+ export declare const createErrorMessage: (required?: Record<string, string>, properties?: Record<string, FieldErrorConfig>, globalFallbacks?: Partial<Record<ValidationErrorType, string>>) => ErrorMessageResult;
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Custom hook to simplify i18n translation for form fields.
3
+ * Automatically handles colLabel construction and removeIndex logic.
4
+ *
5
+ * @param column - The column name
6
+ * @param prefix - The prefix for the field (usually empty string or parent path)
7
+ * @returns Object with translation helper functions
8
+ *
9
+ * @example
10
+ * ```tsx
11
+ * const formI18n = useFormI18n(column, prefix);
12
+ *
13
+ * // Get field label
14
+ * <Field label={formI18n.label()} />
15
+ *
16
+ * // Get error message
17
+ * <Text>{formI18n.required()}</Text>
18
+ *
19
+ * // Get custom translation key
20
+ * <Text>{formI18n.t('add_more')}</Text>
21
+ *
22
+ * // Access the raw colLabel
23
+ * const colLabel = formI18n.colLabel;
24
+ * ```
25
+ */
26
+ export declare const useFormI18n: (column: string, prefix?: string) => {
27
+ /**
28
+ * The constructed column label (prefix + column)
29
+ */
30
+ colLabel: string;
31
+ /**
32
+ * Get the field label translation
33
+ * Equivalent to: translate.t(removeIndex(`${colLabel}.field_label`))
34
+ */
35
+ label: (options?: any) => string;
36
+ /**
37
+ * Get the required error message translation
38
+ * Equivalent to: translate.t(removeIndex(`${colLabel}.field_required`))
39
+ */
40
+ required: (options?: any) => string;
41
+ /**
42
+ * Get a translation for any custom key relative to the field
43
+ * Equivalent to: translate.t(removeIndex(`${colLabel}.${key}`))
44
+ *
45
+ * @param key - The translation key suffix (e.g., 'add_more', 'total', etc.)
46
+ * @param options - Optional translation options (e.g., defaultValue, interpolation variables)
47
+ */
48
+ t: (key: string, options?: any) => string;
49
+ /**
50
+ * Access to the original translate object for edge cases
51
+ */
52
+ translate: import("react-i18next").UseTranslationResponse<any, any>;
53
+ };
@@ -115,7 +115,9 @@ export * from "./components/Form/components/core/DefaultForm";
115
115
  export * from "./components/Form/components/core/FormRoot";
116
116
  export * from "./components/Form/components/core/FormTitle";
117
117
  export * from "./components/Form/components/core/FormBody";
118
+ export * from "./components/Form/components/types/CustomJSONSchema7";
118
119
  export * from "./components/Form/useForm";
120
+ export * from "./components/Form/utils/buildErrorMessages";
119
121
  export * from "./components/DatePicker/DatePicker";
120
122
  export * from "./components/DatePicker/getMultiDates";
121
123
  export * from "./components/DatePicker/getRangeDates";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bsol-oss/react-datatable5",
3
- "version": "12.0.0-beta.70",
3
+ "version": "12.0.0-beta.72",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -32,7 +32,8 @@
32
32
  "preview": "vite preview",
33
33
  "storybook": "storybook dev -p 6006",
34
34
  "build-storybook": "storybook build",
35
- "format": "prettier --ignore-unknown '**/*'"
35
+ "format": "prettier --ignore-unknown '**/*'",
36
+ "prepare": "husky"
36
37
  },
37
38
  "peerDependencies": {
38
39
  "@atlaskit/pragmatic-drag-and-drop": "^1.4.0",
@@ -81,10 +82,17 @@
81
82
  "eslint-plugin-react-hooks": "^4.6.0",
82
83
  "eslint-plugin-react-refresh": "^0.4.6",
83
84
  "eslint-plugin-storybook": "^0.8.0",
85
+ "husky": "^9.1.7",
86
+ "lint-staged": "^16.2.5",
84
87
  "prettier": "3.2.5",
85
88
  "rollup-plugin-dts": "^6.1.0",
86
89
  "storybook": "^8.4.7",
87
90
  "typescript": "^5.2.2",
88
91
  "vite": "^5.2.0"
92
+ },
93
+ "lint-staged": {
94
+ "*.{ts,js,json,md,tsx}": [
95
+ "prettier --config ./.prettierrc --write"
96
+ ]
89
97
  }
90
98
  }