@bsol-oss/react-datatable5 12.0.0-beta.26 → 12.0.0-beta.28
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/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -30,6 +30,7 @@ var reactI18next = require('react-i18next');
|
|
|
30
30
|
var axios = require('axios');
|
|
31
31
|
var reactHookForm = require('react-hook-form');
|
|
32
32
|
var dayjs = require('dayjs');
|
|
33
|
+
var utc = require('dayjs/plugin/utc');
|
|
33
34
|
var ti = require('react-icons/ti');
|
|
34
35
|
|
|
35
36
|
function _interopNamespaceDefault(e) {
|
|
@@ -3790,37 +3791,46 @@ const PopoverRoot = react.Popover.Root;
|
|
|
3790
3791
|
const PopoverBody = react.Popover.Body;
|
|
3791
3792
|
const PopoverTrigger = react.Popover.Trigger;
|
|
3792
3793
|
|
|
3794
|
+
dayjs.extend(utc);
|
|
3793
3795
|
const DatePicker = ({ column, schema, prefix }) => {
|
|
3794
3796
|
const { watch, formState: { errors }, setValue, } = reactHookForm.useFormContext();
|
|
3795
3797
|
const { translate } = useSchemaContext();
|
|
3796
|
-
const { required, gridColumn, gridRow, dateFormat = "YYYY-MM-DD[T]HH:mm:ss[Z]", } = schema;
|
|
3798
|
+
const { required, gridColumn, gridRow, displayDateFormat = "YYYY-MM-DD", dateFormat = "YYYY-MM-DD[T]HH:mm:ss[Z]", } = schema;
|
|
3797
3799
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
3798
3800
|
const colLabel = `${prefix}${column}`;
|
|
3799
3801
|
const [open, setOpen] = React.useState(false);
|
|
3800
3802
|
const selectedDate = watch(colLabel);
|
|
3801
|
-
const
|
|
3803
|
+
const displayDate = dayjs.utc(selectedDate).format(displayDateFormat);
|
|
3802
3804
|
React.useEffect(() => {
|
|
3803
|
-
|
|
3804
|
-
|
|
3805
|
-
|
|
3806
|
-
|
|
3807
|
-
|
|
3808
|
-
|
|
3809
|
-
|
|
3810
|
-
|
|
3811
|
-
|
|
3812
|
-
|
|
3813
|
-
|
|
3814
|
-
|
|
3815
|
-
|
|
3816
|
-
|
|
3805
|
+
try {
|
|
3806
|
+
if (selectedDate) {
|
|
3807
|
+
// Parse the selectedDate as UTC or in a specific timezone to avoid +8 hour shift
|
|
3808
|
+
// For example, parse as UTC:
|
|
3809
|
+
const parsedDate = dayjs.utc(selectedDate);
|
|
3810
|
+
// Or if you want to parse in local timezone without shifting:
|
|
3811
|
+
// const parsedDate = dayjs.tz(selectedDate, dayjs.tz.guess());
|
|
3812
|
+
if (!parsedDate.isValid())
|
|
3813
|
+
return;
|
|
3814
|
+
console.log(selectedDate, parsedDate, parsedDate.format(dateFormat), "dkosfp");
|
|
3815
|
+
// Format according to dateFormat from schema
|
|
3816
|
+
const formatted = parsedDate.format(dateFormat);
|
|
3817
|
+
// Update the form value only if different to avoid loops
|
|
3818
|
+
if (formatted !== selectedDate) {
|
|
3819
|
+
setValue(colLabel, formatted, {
|
|
3820
|
+
shouldValidate: true,
|
|
3821
|
+
shouldDirty: true,
|
|
3822
|
+
});
|
|
3823
|
+
}
|
|
3817
3824
|
}
|
|
3818
3825
|
}
|
|
3826
|
+
catch (e) {
|
|
3827
|
+
console.error(e);
|
|
3828
|
+
}
|
|
3819
3829
|
}, [selectedDate, dateFormat, colLabel, setValue]);
|
|
3820
3830
|
return (jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.field_label`))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
3821
3831
|
gridRow, children: [jsxRuntime.jsxs(PopoverRoot, { open: open, onOpenChange: (e) => setOpen(e.open), closeOnInteractOutside: true, children: [jsxRuntime.jsx(PopoverTrigger, { asChild: true, children: jsxRuntime.jsxs(Button, { size: "sm", variant: "outline", onClick: () => {
|
|
3822
3832
|
setOpen(true);
|
|
3823
|
-
}, justifyContent: "start", children: [jsxRuntime.jsx(md.MdDateRange, {}), selectedDate !== undefined ? `${
|
|
3833
|
+
}, justifyContent: "start", children: [jsxRuntime.jsx(md.MdDateRange, {}), selectedDate !== undefined ? `${displayDate}` : ""] }) }), jsxRuntime.jsx(PopoverContent, { children: jsxRuntime.jsxs(PopoverBody, { children: [jsxRuntime.jsx(PopoverTitle, {}), jsxRuntime.jsx(DatePicker$1
|
|
3824
3834
|
// @ts-expect-error TODO: find appropriate types
|
|
3825
3835
|
, {
|
|
3826
3836
|
// @ts-expect-error TODO: find appropriate types
|
|
@@ -4861,12 +4871,13 @@ const CustomViewer = ({ column, schema, prefix }) => {
|
|
|
4861
4871
|
const DateViewer = ({ column, schema, prefix }) => {
|
|
4862
4872
|
const { watch, formState: { errors }, } = reactHookForm.useFormContext();
|
|
4863
4873
|
const { translate } = useSchemaContext();
|
|
4864
|
-
const { required, gridColumn, gridRow } = schema;
|
|
4874
|
+
const { required, gridColumn, gridRow, displayDateFormat = "YYYY-MM-DD", } = schema;
|
|
4865
4875
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4866
4876
|
const colLabel = `${prefix}${column}`;
|
|
4867
4877
|
const selectedDate = watch(colLabel);
|
|
4878
|
+
const displayDate = dayjs.utc(selectedDate).format(displayDateFormat);
|
|
4868
4879
|
return (jsxRuntime.jsxs(Field, { label: `${translate.t(removeIndex(`${column}.field_label`))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
4869
|
-
gridRow, children: [jsxRuntime.jsxs(react.Text, { children: [" ", selectedDate !== undefined ?
|
|
4880
|
+
gridRow, children: [jsxRuntime.jsxs(react.Text, { children: [" ", selectedDate !== undefined ? displayDate : ""] }), errors[`${column}`] && (jsxRuntime.jsx(react.Text, { color: "red.400", children: translate.t(`${column}.field_required`) }))] }));
|
|
4870
4881
|
};
|
|
4871
4882
|
|
|
4872
4883
|
const EnumViewer = ({ column, isMultiple = false, schema, prefix, }) => {
|
package/dist/index.mjs
CHANGED
|
@@ -29,6 +29,7 @@ import { useTranslation } from 'react-i18next';
|
|
|
29
29
|
import axios from 'axios';
|
|
30
30
|
import { FormProvider, useFormContext, useForm as useForm$1 } from 'react-hook-form';
|
|
31
31
|
import dayjs from 'dayjs';
|
|
32
|
+
import utc from 'dayjs/plugin/utc';
|
|
32
33
|
import { TiDeleteOutline } from 'react-icons/ti';
|
|
33
34
|
|
|
34
35
|
const DataTableContext = createContext({
|
|
@@ -3770,37 +3771,46 @@ const PopoverRoot = Popover.Root;
|
|
|
3770
3771
|
const PopoverBody = Popover.Body;
|
|
3771
3772
|
const PopoverTrigger = Popover.Trigger;
|
|
3772
3773
|
|
|
3774
|
+
dayjs.extend(utc);
|
|
3773
3775
|
const DatePicker = ({ column, schema, prefix }) => {
|
|
3774
3776
|
const { watch, formState: { errors }, setValue, } = useFormContext();
|
|
3775
3777
|
const { translate } = useSchemaContext();
|
|
3776
|
-
const { required, gridColumn, gridRow, dateFormat = "YYYY-MM-DD[T]HH:mm:ss[Z]", } = schema;
|
|
3778
|
+
const { required, gridColumn, gridRow, displayDateFormat = "YYYY-MM-DD", dateFormat = "YYYY-MM-DD[T]HH:mm:ss[Z]", } = schema;
|
|
3777
3779
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
3778
3780
|
const colLabel = `${prefix}${column}`;
|
|
3779
3781
|
const [open, setOpen] = useState(false);
|
|
3780
3782
|
const selectedDate = watch(colLabel);
|
|
3781
|
-
const
|
|
3783
|
+
const displayDate = dayjs.utc(selectedDate).format(displayDateFormat);
|
|
3782
3784
|
useEffect(() => {
|
|
3783
|
-
|
|
3784
|
-
|
|
3785
|
-
|
|
3786
|
-
|
|
3787
|
-
|
|
3788
|
-
|
|
3789
|
-
|
|
3790
|
-
|
|
3791
|
-
|
|
3792
|
-
|
|
3793
|
-
|
|
3794
|
-
|
|
3795
|
-
|
|
3796
|
-
|
|
3785
|
+
try {
|
|
3786
|
+
if (selectedDate) {
|
|
3787
|
+
// Parse the selectedDate as UTC or in a specific timezone to avoid +8 hour shift
|
|
3788
|
+
// For example, parse as UTC:
|
|
3789
|
+
const parsedDate = dayjs.utc(selectedDate);
|
|
3790
|
+
// Or if you want to parse in local timezone without shifting:
|
|
3791
|
+
// const parsedDate = dayjs.tz(selectedDate, dayjs.tz.guess());
|
|
3792
|
+
if (!parsedDate.isValid())
|
|
3793
|
+
return;
|
|
3794
|
+
console.log(selectedDate, parsedDate, parsedDate.format(dateFormat), "dkosfp");
|
|
3795
|
+
// Format according to dateFormat from schema
|
|
3796
|
+
const formatted = parsedDate.format(dateFormat);
|
|
3797
|
+
// Update the form value only if different to avoid loops
|
|
3798
|
+
if (formatted !== selectedDate) {
|
|
3799
|
+
setValue(colLabel, formatted, {
|
|
3800
|
+
shouldValidate: true,
|
|
3801
|
+
shouldDirty: true,
|
|
3802
|
+
});
|
|
3803
|
+
}
|
|
3797
3804
|
}
|
|
3798
3805
|
}
|
|
3806
|
+
catch (e) {
|
|
3807
|
+
console.error(e);
|
|
3808
|
+
}
|
|
3799
3809
|
}, [selectedDate, dateFormat, colLabel, setValue]);
|
|
3800
3810
|
return (jsxs(Field, { label: `${translate.t(removeIndex(`${colLabel}.field_label`))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
3801
3811
|
gridRow, children: [jsxs(PopoverRoot, { open: open, onOpenChange: (e) => setOpen(e.open), closeOnInteractOutside: true, children: [jsx(PopoverTrigger, { asChild: true, children: jsxs(Button, { size: "sm", variant: "outline", onClick: () => {
|
|
3802
3812
|
setOpen(true);
|
|
3803
|
-
}, justifyContent: "start", children: [jsx(MdDateRange, {}), selectedDate !== undefined ? `${
|
|
3813
|
+
}, justifyContent: "start", children: [jsx(MdDateRange, {}), selectedDate !== undefined ? `${displayDate}` : ""] }) }), jsx(PopoverContent, { children: jsxs(PopoverBody, { children: [jsx(PopoverTitle, {}), jsx(DatePicker$1
|
|
3804
3814
|
// @ts-expect-error TODO: find appropriate types
|
|
3805
3815
|
, {
|
|
3806
3816
|
// @ts-expect-error TODO: find appropriate types
|
|
@@ -4841,12 +4851,13 @@ const CustomViewer = ({ column, schema, prefix }) => {
|
|
|
4841
4851
|
const DateViewer = ({ column, schema, prefix }) => {
|
|
4842
4852
|
const { watch, formState: { errors }, } = useFormContext();
|
|
4843
4853
|
const { translate } = useSchemaContext();
|
|
4844
|
-
const { required, gridColumn, gridRow } = schema;
|
|
4854
|
+
const { required, gridColumn, gridRow, displayDateFormat = "YYYY-MM-DD", } = schema;
|
|
4845
4855
|
const isRequired = required?.some((columnId) => columnId === column);
|
|
4846
4856
|
const colLabel = `${prefix}${column}`;
|
|
4847
4857
|
const selectedDate = watch(colLabel);
|
|
4858
|
+
const displayDate = dayjs.utc(selectedDate).format(displayDateFormat);
|
|
4848
4859
|
return (jsxs(Field, { label: `${translate.t(removeIndex(`${column}.field_label`))}`, required: isRequired, alignItems: "stretch", gridColumn,
|
|
4849
|
-
gridRow, children: [jsxs(Text, { children: [" ", selectedDate !== undefined ?
|
|
4860
|
+
gridRow, children: [jsxs(Text, { children: [" ", selectedDate !== undefined ? displayDate : ""] }), errors[`${column}`] && (jsx(Text, { color: "red.400", children: translate.t(`${column}.field_required`) }))] }));
|
|
4850
4861
|
};
|
|
4851
4862
|
|
|
4852
4863
|
const EnumViewer = ({ column, isMultiple = false, schema, prefix, }) => {
|