impact-chatbot 2.3.98 → 2.3.99

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.
@@ -36,6 +36,7 @@ declare const useCrossFilterCascading: ({ filters, fetchOptionsFn, initialSelect
36
36
  loadingMap: {};
37
37
  selectionsMap: {};
38
38
  onFilterChange: (paramName: any, selectedValues: any) => void;
39
+ setSelectionSilent: (paramName: any, values: any) => void;
39
40
  resetAll: () => void;
40
41
  resetFilter: (paramName: any) => void;
41
42
  fetchOptions: (paramName: any) => void;
package/dist/index.cjs.js CHANGED
@@ -33,8 +33,8 @@ var isArray$1 = require('lodash/isArray');
33
33
  var isEmpty$1 = require('lodash/isEmpty');
34
34
  var chatbotServices = require('core/commonComponents/smartBot/services/chatbot-services');
35
35
  var conversationService = require('core/commonComponents/smartBot/services/conversation-service');
36
- var AgGridComponent = require('core/Utils/agGrid');
37
- var agGridColumnFormatter = require('core/Utils/agGrid/column-formatter');
36
+ var AgGridComponent = require('core/Utils/agGridV36');
37
+ var agGridColumnFormatter = require('core/Utils/agGridV36/columnFormatter');
38
38
  var CoreChart = require('core/Utils/core-charts');
39
39
  var makeStyles = require('@mui/styles/makeStyles');
40
40
  var ChevronRightIcon$1 = require('@mui/icons-material/ChevronRight');
@@ -6903,6 +6903,19 @@ const useCrossFilterCascading = ({ filters = [], fetchOptionsFn, initialSelectio
6903
6903
  */
6904
6904
  const onFilterChange = React.useCallback((paramName, selectedValues) => {
6905
6905
  const values = Array.isArray(selectedValues) ? selectedValues : [selectedValues];
6906
+ // Eagerly update the ref so that any code running synchronously after
6907
+ // this call (e.g. fetchUpstreamOptions) sees the latest selections
6908
+ // without waiting for the React state-updater to be flushed.
6909
+ // Also clear downstream selections when the filter is emptied, so the
6910
+ // ref doesn't carry stale downstream values into the next API call.
6911
+ const eagerUpdate = { ...selectionsRef.current, [paramName]: values };
6912
+ if (values.length === 0) {
6913
+ const downstreamFilters = getDownstreamFilters(paramName);
6914
+ downstreamFilters.forEach((f) => {
6915
+ eagerUpdate[getParamName(f)] = [];
6916
+ });
6917
+ }
6918
+ selectionsRef.current = eagerUpdate;
6906
6919
  // Update selections
6907
6920
  setSelectionsMap((prev) => {
6908
6921
  const updated = { ...prev, [paramName]: values };
@@ -6942,6 +6955,18 @@ const useCrossFilterCascading = ({ filters = [], fetchOptionsFn, initialSelectio
6942
6955
  }
6943
6956
  }
6944
6957
  }, [getDownstreamFilters, getParamName, fetchOptionsForFilter, onSelectionChange]);
6958
+ /**
6959
+ * Update a filter's selection without triggering downstream cascade clears.
6960
+ * Used by saved-filter hydration to clear stale selectionsMap entries for
6961
+ * fields the saved filter doesn't cover, without wiping downstream options.
6962
+ */
6963
+ const setSelectionSilent = React.useCallback((paramName, values) => {
6964
+ setSelectionsMap((prev) => {
6965
+ const updated = { ...prev, [paramName]: values };
6966
+ selectionsRef.current = updated;
6967
+ return updated;
6968
+ });
6969
+ }, []);
6945
6970
  /**
6946
6971
  * Reset all filters — clears selections and re-fetches initial options
6947
6972
  */
@@ -7097,6 +7122,7 @@ const useCrossFilterCascading = ({ filters = [], fetchOptionsFn, initialSelectio
7097
7122
  loadingMap,
7098
7123
  selectionsMap,
7099
7124
  onFilterChange,
7125
+ setSelectionSilent,
7100
7126
  resetAll,
7101
7127
  resetFilter,
7102
7128
  fetchOptions,
@@ -7429,6 +7455,7 @@ const SelectContent = ({ bodyText, isFormDisabled = false, messageIndex }) => {
7429
7455
  const latestContext = chatbotContextRef.current;
7430
7456
  const updatedContext = {
7431
7457
  ...latestContext,
7458
+ __fromSavedFilter: false,
7432
7459
  [bodyText?.paramName]: {
7433
7460
  ...latestContext?.[bodyText?.paramName],
7434
7461
  [bodyText?.paramName]: value,
@@ -7455,6 +7482,13 @@ const SelectContent = ({ bodyText, isFormDisabled = false, messageIndex }) => {
7455
7482
  const persisted = persistedFormValues?.[formKey];
7456
7483
  if (!persisted || (Array.isArray(persisted) && persisted.length === 0)) {
7457
7484
  setCurrentSelectedOptions([]);
7485
+ setIsAllSelected(false);
7486
+ selectAllCountRef.current = 0;
7487
+ }
7488
+ else if (chatbotContextRef.current?.__fromSavedFilter) {
7489
+ setCurrentSelectedOptions(persisted);
7490
+ setIsAllSelected(false);
7491
+ selectAllCountRef.current = 0;
7458
7492
  }
7459
7493
  }, [persistedFormValues, formKey]);
7460
7494
  // When cross-filter context provides new options for this filter, update local state
@@ -7545,6 +7579,7 @@ const SelectContent = ({ bodyText, isFormDisabled = false, messageIndex }) => {
7545
7579
  const ctx1 = chatbotContextRef.current;
7546
7580
  dispatch(smartBotActions.setChatbotContext({
7547
7581
  ...ctx1,
7582
+ __fromSavedFilter: false,
7548
7583
  [bodyText?.paramName]: {
7549
7584
  ...ctx1?.[bodyText?.paramName],
7550
7585
  [bodyText?.paramName]: [],
@@ -7555,6 +7590,9 @@ const SelectContent = ({ bodyText, isFormDisabled = false, messageIndex }) => {
7555
7590
  // Notify cross-filter context to clear downstream filters
7556
7591
  if (isCascading) {
7557
7592
  crossFilterCtx.onFilterChange(paramName, []);
7593
+ // Re-fetch upstream options so they are no longer narrowed
7594
+ // by this filter's previous selection
7595
+ crossFilterCtx.fetchUpstreamOptions(paramName);
7558
7596
  }
7559
7597
  }, handleChange: (selected) => onChange(selected), isCloseWhenClickOutside: true, setIsOpen: (open) => {
7560
7598
  setIsOpen(open);
@@ -7587,6 +7625,11 @@ const SelectContent = ({ bodyText, isFormDisabled = false, messageIndex }) => {
7587
7625
  }
7588
7626
  crossFilterCtx.fetchUpstreamOptions(paramName);
7589
7627
  }
7628
+ else {
7629
+ // Selection was cleared — re-fetch upstream options so they are
7630
+ // no longer narrowed by this filter's previous selection
7631
+ crossFilterCtx.fetchUpstreamOptions(paramName);
7632
+ }
7590
7633
  }
7591
7634
  }
7592
7635
  }, isOpen: isOpen, selectedOptions: currentSelectedOptions, setSelectedOptions: setCurrentSelectedOptions, initialOptions: initialOptions, isMulti: isMulti, isSelectAll: isAllSelected, setIsSelectAll: setIsAllSelected, toggleSelectAll: true, isLoading: isCascading ? crossFilterCtx.loadingMap[paramName] : false, emptyMessage: isCascading && crossFilterCtx.loadingMap[paramName] ? "Loading values..." : "No options available", isWithSearch: isMulti ? true : false, onSearch: handleSearch, onMenuScrollToBottom: () => {
@@ -7628,6 +7671,7 @@ const SelectContent = ({ bodyText, isFormDisabled = false, messageIndex }) => {
7628
7671
  const ctx2 = chatbotContextRef.current;
7629
7672
  dispatch(smartBotActions.setChatbotContext({
7630
7673
  ...ctx2,
7674
+ __fromSavedFilter: false,
7631
7675
  [bodyText?.paramName]: {
7632
7676
  ...ctx2?.[bodyText?.paramName],
7633
7677
  [bodyText?.paramName]: valuesToDispatch,
@@ -7650,6 +7694,7 @@ const SelectContent = ({ bodyText, isFormDisabled = false, messageIndex }) => {
7650
7694
  const ctx3 = chatbotContextRef.current;
7651
7695
  dispatch(smartBotActions.setChatbotContext({
7652
7696
  ...ctx3,
7697
+ __fromSavedFilter: false,
7653
7698
  [bodyText?.paramName]: {
7654
7699
  ...ctx3?.[bodyText?.paramName],
7655
7700
  [bodyText?.paramName]: [],
@@ -7938,6 +7983,55 @@ const ImageContent = ({ bodyText }) => {
7938
7983
 
7939
7984
  // Key used to persist timeout state in sessionStorage (survives component remounts from tab switches)
7940
7985
  const STEP_FORM_TIMEOUT_KEY = "__stepFormTimedOut";
7986
+ /**
7987
+ * Renderless bridge component that lives inside CrossFilterProvider.
7988
+ * Watches for saved filter selection changes and programmatically triggers
7989
+ * the cross-filter cascading system so downstream fields get their options.
7990
+ */
7991
+ const SavedFilterCascadeBridge = ({ chatbotContext, crossFilterConfigs }) => {
7992
+ const crossFilterCtx = useCrossFilterContext();
7993
+ const prevSelectionRef = React.useRef(null);
7994
+ React.useEffect(() => {
7995
+ if (!crossFilterCtx?.isEnabled)
7996
+ return;
7997
+ const isFromSaved = chatbotContext?.__fromSavedFilter === true;
7998
+ if (!isFromSaved) {
7999
+ prevSelectionRef.current = null;
8000
+ return;
8001
+ }
8002
+ // Derive a stable key from the saved filter selection to detect switches
8003
+ const currentSelection = chatbotContext?.__savedFilterSelection;
8004
+ const selectionKey = Array.isArray(currentSelection)
8005
+ ? currentSelection[0]?.value
8006
+ : currentSelection?.value;
8007
+ // Skip if this is the same saved filter we already processed
8008
+ if (selectionKey === prevSelectionRef.current)
8009
+ return;
8010
+ prevSelectionRef.current = selectionKey;
8011
+ // Set cascading selections for fields the saved filter covers.
8012
+ // For unmatched fields, silently clear selectionsMap without triggering
8013
+ // downstream cascade wipes (which would blank option lists).
8014
+ let lastMatchingParam = null;
8015
+ crossFilterConfigs.forEach((cfg) => {
8016
+ const ctx = chatbotContext[cfg.paramName];
8017
+ if (ctx && ctx.updated && Array.isArray(ctx[cfg.paramName]) && ctx[cfg.paramName].length > 0) {
8018
+ crossFilterCtx.onFilterChange(cfg.paramName, ctx[cfg.paramName]);
8019
+ lastMatchingParam = cfg.paramName;
8020
+ }
8021
+ else {
8022
+ // Clear stale selectionsMap entry without cascade
8023
+ crossFilterCtx.setSelectionSilent(cfg.paramName, []);
8024
+ }
8025
+ });
8026
+ // Fetch downstream options for the lowest matched filter
8027
+ if (lastMatchingParam) {
8028
+ setTimeout(() => {
8029
+ crossFilterCtx.fetchDownstreamOptions(lastMatchingParam);
8030
+ }, 100);
8031
+ }
8032
+ }, [chatbotContext?.__fromSavedFilter, chatbotContext?.__savedFilterSelection]);
8033
+ return null;
8034
+ };
7941
8035
  /**
7942
8036
  * Renders form widget data inline within a step.
7943
8037
  * Reuses the same rendering logic as CombinedContent but designed
@@ -8014,13 +8108,14 @@ const StepFormContent = ({ formData, messageIndex = 0, isFormDisabled = false, s
8014
8108
  setFilterSetCurrentOptions(opts);
8015
8109
  return opts;
8016
8110
  }, [savedFilterSets]);
8017
- const isFilterSelected = Array.isArray(selectedFilterSet) ? selectedFilterSet.length > 0 : !!selectedFilterSet && Object.keys(selectedFilterSet).length > 0;
8111
+ Array.isArray(selectedFilterSet) ? selectedFilterSet.length > 0 : !!selectedFilterSet && Object.keys(selectedFilterSet).length > 0;
8018
8112
  const onFilterSetChange = React.useCallback((selected) => {
8019
8113
  try {
8020
8114
  const selectedValue = Array.isArray(selected) ? selected[0]?.value : selected?.value;
8021
8115
  if (!selectedValue) {
8022
- dispatch(smartBotActions.setChatbotContext({}));
8023
- dispatch(smartBotActions.clearPersistedFormValues());
8116
+ // Only remove saved filter flags; keep dropdown values and persisted state intact
8117
+ const { __fromSavedFilter, __savedFilterSelection, ...rest } = chatbotContext || {};
8118
+ dispatch(smartBotActions.setChatbotContext(rest));
8024
8119
  return;
8025
8120
  }
8026
8121
  const fullFilterObj = (savedFilterSets || []).find((f) => (f.fuc_code || f.name || f.label) === selectedValue);
@@ -8049,15 +8144,51 @@ const StepFormContent = ({ formData, messageIndex = 0, isFormDisabled = false, s
8049
8144
  };
8050
8145
  }
8051
8146
  });
8052
- newContext.__fromSavedFilter = true;
8053
- newContext.__savedFilterSelection = selected;
8054
- dispatch(smartBotActions.setChatbotContext(newContext));
8147
+ // Merge into existing context to preserve non-select field values (dates, inputs, sliders).
8148
+ // Clear all select fields first, then overlay saved filter values.
8149
+ const mergedContext = { ...(chatbotContext || {}) };
8150
+ (formData || []).forEach((item) => {
8151
+ const pName = item?.data?.param_name;
8152
+ if (!pName || item?.type !== "select")
8153
+ return;
8154
+ mergedContext[pName] = { [pName]: [], updated: false };
8155
+ });
8156
+ Object.keys(newContext).forEach((key) => {
8157
+ mergedContext[key] = newContext[key];
8158
+ });
8159
+ mergedContext.__fromSavedFilter = true;
8160
+ mergedContext.__savedFilterSelection = selected;
8161
+ dispatch(smartBotActions.setChatbotContext(mergedContext));
8162
+ // Build persisted values for ALL form select fields.
8163
+ // Matching fields get the saved filter values; unmatched fields get [] (cleared).
8164
+ const formPersisted = {};
8165
+ (formData || []).forEach((item) => {
8166
+ const pName = item?.data?.param_name;
8167
+ if (!pName || item?.type !== "select")
8168
+ return;
8169
+ const key = `${messageIndex}_${pName}`;
8170
+ const selectAllKey = `${key}__selectAllCount`;
8171
+ if (newContext[pName] && newContext[pName][pName]) {
8172
+ const values = newContext[pName][pName];
8173
+ formPersisted[key] = values.map((v) => ({
8174
+ label: v,
8175
+ value: v,
8176
+ }));
8177
+ }
8178
+ else {
8179
+ // Clear fields not covered by the saved filter
8180
+ formPersisted[key] = [];
8181
+ }
8182
+ // Always reset select-all count when a saved filter is applied
8183
+ formPersisted[selectAllKey] = 0;
8184
+ });
8185
+ dispatch(smartBotActions.setPersistedFormValues(formPersisted));
8055
8186
  }
8056
8187
  catch (error) {
8057
8188
  console.error("[StepFormContent] onFilterSetChange error:", error);
8058
8189
  }
8059
- }, [savedFilterSets, dispatch]);
8060
- const isFormFieldUsed = React.useMemo(() => {
8190
+ }, [savedFilterSets, dispatch, formData, messageIndex, chatbotContext]);
8191
+ React.useMemo(() => {
8061
8192
  if (!persistedFormValues)
8062
8193
  return false;
8063
8194
  const prefix = `${messageIndex}_`;
@@ -8068,8 +8199,8 @@ const StepFormContent = ({ formData, messageIndex = 0, isFormDisabled = false, s
8068
8199
  return val && (Array.isArray(val) ? val.length > 0 : !!val);
8069
8200
  });
8070
8201
  }, [persistedFormValues, messageIndex]);
8071
- const formFieldsDisabled = isFormDisabled || isFilterSelected || isFormSubmitted || isTimedOut;
8072
- const savedFilterDisabled = isFormDisabled || isFormFieldUsed || isFormSubmitted || isTimedOut;
8202
+ const formFieldsDisabled = isFormDisabled || isFormSubmitted || isTimedOut;
8203
+ const savedFilterDisabled = isFormDisabled || isFormSubmitted || isTimedOut;
8073
8204
  const requiredFieldsFilled = React.useMemo(() => {
8074
8205
  if (!formData || !Array.isArray(formData))
8075
8206
  return false;
@@ -8309,9 +8440,7 @@ const StepFormContent = ({ formData, messageIndex = 0, isFormDisabled = false, s
8309
8440
  });
8310
8441
  if (formFields.length === 0 && buttonItems.length === 0)
8311
8442
  return null;
8312
- return (jsxRuntime.jsxs("div", { className: "step-form-content", children: [showSavedFilters && filterSetOptions.length > 0 && (jsxRuntime.jsx("div", { style: { width: "100%", marginTop: "10px" }, children: jsxRuntime.jsx(impactUiV3.Select, { currentOptions: filterSetCurrentOptions, setCurrentOptions: setFilterSetCurrentOptions, label: "Saved Filter Sets", labelOrientation: "top", isRequired: false, isDisabled: savedFilterDisabled, handleChange: (selected) => onFilterSetChange(selected), isCloseWhenClickOutside: true, setIsOpen: setIsFilterSetOpen, isOpen: isFilterSetOpen, selectedOptions: selectedFilterSet, setSelectedOptions: setSelectedFilterSet, initialOptions: filterSetOptions, isMulti: false, isClearable: true }) })), showSavedFilters && filterSetOptions.length > 0 && (jsxRuntime.jsx("hr", { style: { border: "none", borderTop: "1px solid #E0E0E0", margin: "12px 0" } })), jsxRuntime.jsx("div", { style: {
8313
- ...(isFilterSelected && !isFormDisabled ? { pointerEvents: "none", opacity: 0.5 } : {}),
8314
- }, children: crossFilterConfigs.length >= 1 ? (jsxRuntime.jsx(CrossFilterProvider, { filters: crossFilterConfigs, fetchOptionsFn: (filterConfig, existingSelections, allFilters) => fetchCrossFilterOptions(filterConfig, existingSelections, allFilters, preSelectedFilters), initialSelections: crossFilterInitialSelections, fetchOnMount: false, children: formFields })) : (formFields) }), buttonItems] }));
8443
+ return (jsxRuntime.jsxs("div", { className: "step-form-content", children: [showSavedFilters && filterSetOptions.length > 0 && (jsxRuntime.jsx("div", { style: { width: "100%", marginTop: "10px" }, children: jsxRuntime.jsx(impactUiV3.Select, { currentOptions: filterSetCurrentOptions, setCurrentOptions: setFilterSetCurrentOptions, label: "Saved Filter Sets", labelOrientation: "top", isRequired: false, isDisabled: savedFilterDisabled, handleChange: (selected) => onFilterSetChange(selected), isCloseWhenClickOutside: true, setIsOpen: setIsFilterSetOpen, isOpen: isFilterSetOpen, selectedOptions: selectedFilterSet, setSelectedOptions: setSelectedFilterSet, initialOptions: filterSetOptions, isMulti: false, isClearable: true }) })), showSavedFilters && filterSetOptions.length > 0 && (jsxRuntime.jsx("hr", { style: { border: "none", borderTop: "1px solid #E0E0E0", margin: "12px 0" } })), jsxRuntime.jsx("div", { children: crossFilterConfigs.length >= 1 ? (jsxRuntime.jsxs(CrossFilterProvider, { filters: crossFilterConfigs, fetchOptionsFn: (filterConfig, existingSelections, allFilters) => fetchCrossFilterOptions(filterConfig, existingSelections, allFilters, preSelectedFilters), initialSelections: crossFilterInitialSelections, fetchOnMount: false, children: [jsxRuntime.jsx(SavedFilterCascadeBridge, { chatbotContext: chatbotContext, crossFilterConfigs: crossFilterConfigs }), formFields] })) : (formFields) }), buttonItems] }));
8315
8444
  };
8316
8445
  /** Reset the timeout flag (call when a new conversation/message starts) */
8317
8446
  const resetStepFormTimeoutFlag = () => {