@bsol-oss/react-datatable5 13.0.1-beta.2 → 13.0.1-beta.3

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.js CHANGED
@@ -3714,7 +3714,7 @@ const TextWithCopy = ({ text, globalFilter, highlightedText, }) => {
3714
3714
  const displayText = highlightedText !== undefined
3715
3715
  ? highlightedText
3716
3716
  : highlightText$1(textValue, globalFilter);
3717
- return (jsxRuntime.jsxs(react.HStack, { gap: 2, alignItems: "center", children: [jsxRuntime.jsx(react.Text, { as: "span", children: displayText }), jsxRuntime.jsx(react.Clipboard.Root, { value: textValue, children: jsxRuntime.jsx(react.Clipboard.Trigger, { asChild: true, children: jsxRuntime.jsx(react.IconButton, { size: "xs", variant: "ghost", "aria-label": "Copy", fontSize: "1em", children: jsxRuntime.jsx(react.Clipboard.Indicator, { copied: jsxRuntime.jsx(lu.LuCheck, {}), children: jsxRuntime.jsx(lu.LuCopy, {}) }) }) }) })] }));
3717
+ return (jsxRuntime.jsxs(react.HStack, { gap: 2, alignItems: "center", children: [jsxRuntime.jsx(react.Text, { as: "span", children: displayText }), jsxRuntime.jsx(react.Clipboard.Root, { value: textValue, children: jsxRuntime.jsx(react.Clipboard.Trigger, { asChild: true, children: jsxRuntime.jsx(react.IconButton, { size: "2xs", variant: "ghost", "aria-label": "Copy", fontSize: "1em", children: jsxRuntime.jsx(react.Clipboard.Indicator, { copied: jsxRuntime.jsx(lu.LuCheck, {}), children: jsxRuntime.jsx(lu.LuCopy, {}) }) }) }) })] }));
3718
3718
  };
3719
3719
 
3720
3720
  // Helper function to highlight matching text
@@ -5626,10 +5626,10 @@ const defaultRenderDisplay = (item) => {
5626
5626
  const useIdPickerData = ({ column, schema, prefix, isMultiple, }) => {
5627
5627
  const { watch, getValues, formState: { errors }, setValue, } = reactHookForm.useFormContext();
5628
5628
  const { idMap, setIdMap, idPickerLabels, insideDialog } = useSchemaContext();
5629
- const { renderDisplay, loadInitialValues: schemaLoadInitialValues, foreign_key, variant, } = schema;
5629
+ const { renderDisplay, loadInitialValues, foreign_key, variant } = schema;
5630
5630
  // loadInitialValues must be provided in schema for id-picker fields
5631
5631
  // It's used to load the record of the id so the display is human-readable
5632
- if (variant === 'id-picker' && !schemaLoadInitialValues) {
5632
+ if (variant === 'id-picker' && !loadInitialValues) {
5633
5633
  throw new Error(`loadInitialValues is required in schema for IdPicker field '${column}'. Please provide loadInitialValues function in the schema to load records for human-readable display.`);
5634
5634
  }
5635
5635
  const { table, column: column_ref, customQueryFn, } = foreign_key;
@@ -5676,19 +5676,26 @@ const useIdPickerData = ({ column, schema, prefix, isMultiple, }) => {
5676
5676
  const missingIdsKey = React.useMemo(() => {
5677
5677
  return JSON.stringify([...missingIds].sort());
5678
5678
  }, [missingIds]);
5679
+ // Include idMap state in query key to force refetch when idMap is reset (e.g., on remount from another page)
5680
+ // This ensures the query runs even if React Query has cached data for the same missing IDs
5681
+ const idMapStateKey = React.useMemo(() => {
5682
+ // Create a key based on whether the required IDs are in idMap
5683
+ const hasRequiredIds = currentValue.every((id) => idMap[id]);
5684
+ return hasRequiredIds ? 'complete' : 'incomplete';
5685
+ }, [currentValue, idMap]);
5679
5686
  // Query to fetch initial values that are missing from idMap
5680
5687
  // This query runs automatically when missingIds.length > 0 and updates idMap
5681
5688
  const initialValuesQuery = reactQuery.useQuery({
5682
- queryKey: [`idpicker-initial`, column, missingIdsKey],
5689
+ queryKey: [`idpicker-initial`, column, missingIdsKey, idMapStateKey],
5683
5690
  queryFn: async () => {
5684
5691
  if (missingIds.length === 0) {
5685
5692
  return { data: [], count: 0 };
5686
5693
  }
5687
5694
  // Use schema's loadInitialValues (required for id-picker)
5688
- if (!schemaLoadInitialValues) {
5695
+ if (!loadInitialValues) {
5689
5696
  throw new Error(`loadInitialValues is required in schema for IdPicker field '${column}'.`);
5690
5697
  }
5691
- const result = await schemaLoadInitialValues({
5698
+ const result = await loadInitialValues({
5692
5699
  ids: missingIds,
5693
5700
  foreign_key: foreign_key,
5694
5701
  setIdMap,
@@ -5696,7 +5703,9 @@ const useIdPickerData = ({ column, schema, prefix, isMultiple, }) => {
5696
5703
  return result.data;
5697
5704
  },
5698
5705
  enabled: missingIds.length > 0, // Only fetch if there are missing IDs
5699
- staleTime: 300000,
5706
+ staleTime: 0, // Always consider data stale to refetch on remount
5707
+ refetchOnMount: true, // Always refetch when component remounts (e.g., from another page)
5708
+ refetchOnWindowFocus: false, // Don't refetch on window focus
5700
5709
  });
5701
5710
  const { isLoading: isLoadingInitialValues, isFetching: isFetchingInitialValues, } = initialValuesQuery;
5702
5711
  // Query for search results (async loading)
@@ -5841,7 +5850,7 @@ const useIdPickerData = ({ column, schema, prefix, isMultiple, }) => {
5841
5850
  idPickerLabels,
5842
5851
  insideDialog: insideDialog ?? false,
5843
5852
  renderDisplay,
5844
- loadInitialValues: schemaLoadInitialValues, // Required for id-picker, checked above
5853
+ loadInitialValues: loadInitialValues, // Required for id-picker, checked above
5845
5854
  column_ref,
5846
5855
  errors,
5847
5856
  setValue,
package/dist/index.mjs CHANGED
@@ -3694,7 +3694,7 @@ const TextWithCopy = ({ text, globalFilter, highlightedText, }) => {
3694
3694
  const displayText = highlightedText !== undefined
3695
3695
  ? highlightedText
3696
3696
  : highlightText$1(textValue, globalFilter);
3697
- return (jsxs(HStack, { gap: 2, alignItems: "center", children: [jsx(Text, { as: "span", children: displayText }), jsx(Clipboard.Root, { value: textValue, children: jsx(Clipboard.Trigger, { asChild: true, children: jsx(IconButton, { size: "xs", variant: "ghost", "aria-label": "Copy", fontSize: "1em", children: jsx(Clipboard.Indicator, { copied: jsx(LuCheck, {}), children: jsx(LuCopy, {}) }) }) }) })] }));
3697
+ return (jsxs(HStack, { gap: 2, alignItems: "center", children: [jsx(Text, { as: "span", children: displayText }), jsx(Clipboard.Root, { value: textValue, children: jsx(Clipboard.Trigger, { asChild: true, children: jsx(IconButton, { size: "2xs", variant: "ghost", "aria-label": "Copy", fontSize: "1em", children: jsx(Clipboard.Indicator, { copied: jsx(LuCheck, {}), children: jsx(LuCopy, {}) }) }) }) })] }));
3698
3698
  };
3699
3699
 
3700
3700
  // Helper function to highlight matching text
@@ -5606,10 +5606,10 @@ const defaultRenderDisplay = (item) => {
5606
5606
  const useIdPickerData = ({ column, schema, prefix, isMultiple, }) => {
5607
5607
  const { watch, getValues, formState: { errors }, setValue, } = useFormContext();
5608
5608
  const { idMap, setIdMap, idPickerLabels, insideDialog } = useSchemaContext();
5609
- const { renderDisplay, loadInitialValues: schemaLoadInitialValues, foreign_key, variant, } = schema;
5609
+ const { renderDisplay, loadInitialValues, foreign_key, variant } = schema;
5610
5610
  // loadInitialValues must be provided in schema for id-picker fields
5611
5611
  // It's used to load the record of the id so the display is human-readable
5612
- if (variant === 'id-picker' && !schemaLoadInitialValues) {
5612
+ if (variant === 'id-picker' && !loadInitialValues) {
5613
5613
  throw new Error(`loadInitialValues is required in schema for IdPicker field '${column}'. Please provide loadInitialValues function in the schema to load records for human-readable display.`);
5614
5614
  }
5615
5615
  const { table, column: column_ref, customQueryFn, } = foreign_key;
@@ -5656,19 +5656,26 @@ const useIdPickerData = ({ column, schema, prefix, isMultiple, }) => {
5656
5656
  const missingIdsKey = useMemo(() => {
5657
5657
  return JSON.stringify([...missingIds].sort());
5658
5658
  }, [missingIds]);
5659
+ // Include idMap state in query key to force refetch when idMap is reset (e.g., on remount from another page)
5660
+ // This ensures the query runs even if React Query has cached data for the same missing IDs
5661
+ const idMapStateKey = useMemo(() => {
5662
+ // Create a key based on whether the required IDs are in idMap
5663
+ const hasRequiredIds = currentValue.every((id) => idMap[id]);
5664
+ return hasRequiredIds ? 'complete' : 'incomplete';
5665
+ }, [currentValue, idMap]);
5659
5666
  // Query to fetch initial values that are missing from idMap
5660
5667
  // This query runs automatically when missingIds.length > 0 and updates idMap
5661
5668
  const initialValuesQuery = useQuery({
5662
- queryKey: [`idpicker-initial`, column, missingIdsKey],
5669
+ queryKey: [`idpicker-initial`, column, missingIdsKey, idMapStateKey],
5663
5670
  queryFn: async () => {
5664
5671
  if (missingIds.length === 0) {
5665
5672
  return { data: [], count: 0 };
5666
5673
  }
5667
5674
  // Use schema's loadInitialValues (required for id-picker)
5668
- if (!schemaLoadInitialValues) {
5675
+ if (!loadInitialValues) {
5669
5676
  throw new Error(`loadInitialValues is required in schema for IdPicker field '${column}'.`);
5670
5677
  }
5671
- const result = await schemaLoadInitialValues({
5678
+ const result = await loadInitialValues({
5672
5679
  ids: missingIds,
5673
5680
  foreign_key: foreign_key,
5674
5681
  setIdMap,
@@ -5676,7 +5683,9 @@ const useIdPickerData = ({ column, schema, prefix, isMultiple, }) => {
5676
5683
  return result.data;
5677
5684
  },
5678
5685
  enabled: missingIds.length > 0, // Only fetch if there are missing IDs
5679
- staleTime: 300000,
5686
+ staleTime: 0, // Always consider data stale to refetch on remount
5687
+ refetchOnMount: true, // Always refetch when component remounts (e.g., from another page)
5688
+ refetchOnWindowFocus: false, // Don't refetch on window focus
5680
5689
  });
5681
5690
  const { isLoading: isLoadingInitialValues, isFetching: isFetchingInitialValues, } = initialValuesQuery;
5682
5691
  // Query for search results (async loading)
@@ -5821,7 +5830,7 @@ const useIdPickerData = ({ column, schema, prefix, isMultiple, }) => {
5821
5830
  idPickerLabels,
5822
5831
  insideDialog: insideDialog ?? false,
5823
5832
  renderDisplay,
5824
- loadInitialValues: schemaLoadInitialValues, // Required for id-picker, checked above
5833
+ loadInitialValues: loadInitialValues, // Required for id-picker, checked above
5825
5834
  column_ref,
5826
5835
  errors,
5827
5836
  setValue,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bsol-oss/react-datatable5",
3
- "version": "13.0.1-beta.2",
3
+ "version": "13.0.1-beta.3",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",