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.
package/dist/index.esm.js CHANGED
@@ -20,7 +20,7 @@ import remarkGfm from 'remark-gfm';
20
20
  import DOMPurify from 'dompurify';
21
21
  import { useNavigate, useLocation } from 'react-router-dom-v5-compat';
22
22
  import { setSelectedFilters, setFilterConfiguration, getFilterUserConfiguration } from 'core/actions/filterAction';
23
- import { setThinkingContext, setChatbotContext, setStepFormStreamData, setMinimizedStreamData, setPersistedFormValues, clearPersistedFormValues, setCurrentAgentChatId, setHierarchyKeyValue, setChatbotFilterOptions, setSavedFilterSets } from 'core/actions/smartBotActions';
23
+ import { setThinkingContext, setChatbotContext, setStepFormStreamData, setMinimizedStreamData, setPersistedFormValues, setCurrentAgentChatId, clearPersistedFormValues, setHierarchyKeyValue, setChatbotFilterOptions, setSavedFilterSets } from 'core/actions/smartBotActions';
24
24
  import RefreshIcon from '@mui/icons-material/Refresh';
25
25
  import styled from 'styled-components';
26
26
  import { CircularProgress, Typography, Grid } from '@mui/material';
@@ -30,8 +30,8 @@ import isArray$2 from 'lodash/isArray';
30
30
  import isEmpty$2 from 'lodash/isEmpty';
31
31
  import { stopAgentFlow } from 'core/commonComponents/smartBot/services/chatbot-services';
32
32
  import { updateQuestionTiming } from 'core/commonComponents/smartBot/services/conversation-service';
33
- import AgGridComponent from 'core/Utils/agGrid';
34
- import agGridColumnFormatter from 'core/Utils/agGrid/column-formatter';
33
+ import AgGridComponent from 'core/Utils/agGridV36';
34
+ import agGridColumnFormatter from 'core/Utils/agGridV36/columnFormatter';
35
35
  import CoreChart from 'core/Utils/core-charts';
36
36
  import makeStyles$1 from '@mui/styles/makeStyles';
37
37
  import ChevronRightIcon$1 from '@mui/icons-material/ChevronRight';
@@ -6881,6 +6881,19 @@ const useCrossFilterCascading = ({ filters = [], fetchOptionsFn, initialSelectio
6881
6881
  */
6882
6882
  const onFilterChange = useCallback((paramName, selectedValues) => {
6883
6883
  const values = Array.isArray(selectedValues) ? selectedValues : [selectedValues];
6884
+ // Eagerly update the ref so that any code running synchronously after
6885
+ // this call (e.g. fetchUpstreamOptions) sees the latest selections
6886
+ // without waiting for the React state-updater to be flushed.
6887
+ // Also clear downstream selections when the filter is emptied, so the
6888
+ // ref doesn't carry stale downstream values into the next API call.
6889
+ const eagerUpdate = { ...selectionsRef.current, [paramName]: values };
6890
+ if (values.length === 0) {
6891
+ const downstreamFilters = getDownstreamFilters(paramName);
6892
+ downstreamFilters.forEach((f) => {
6893
+ eagerUpdate[getParamName(f)] = [];
6894
+ });
6895
+ }
6896
+ selectionsRef.current = eagerUpdate;
6884
6897
  // Update selections
6885
6898
  setSelectionsMap((prev) => {
6886
6899
  const updated = { ...prev, [paramName]: values };
@@ -6920,6 +6933,18 @@ const useCrossFilterCascading = ({ filters = [], fetchOptionsFn, initialSelectio
6920
6933
  }
6921
6934
  }
6922
6935
  }, [getDownstreamFilters, getParamName, fetchOptionsForFilter, onSelectionChange]);
6936
+ /**
6937
+ * Update a filter's selection without triggering downstream cascade clears.
6938
+ * Used by saved-filter hydration to clear stale selectionsMap entries for
6939
+ * fields the saved filter doesn't cover, without wiping downstream options.
6940
+ */
6941
+ const setSelectionSilent = useCallback((paramName, values) => {
6942
+ setSelectionsMap((prev) => {
6943
+ const updated = { ...prev, [paramName]: values };
6944
+ selectionsRef.current = updated;
6945
+ return updated;
6946
+ });
6947
+ }, []);
6923
6948
  /**
6924
6949
  * Reset all filters — clears selections and re-fetches initial options
6925
6950
  */
@@ -7075,6 +7100,7 @@ const useCrossFilterCascading = ({ filters = [], fetchOptionsFn, initialSelectio
7075
7100
  loadingMap,
7076
7101
  selectionsMap,
7077
7102
  onFilterChange,
7103
+ setSelectionSilent,
7078
7104
  resetAll,
7079
7105
  resetFilter,
7080
7106
  fetchOptions,
@@ -7407,6 +7433,7 @@ const SelectContent = ({ bodyText, isFormDisabled = false, messageIndex }) => {
7407
7433
  const latestContext = chatbotContextRef.current;
7408
7434
  const updatedContext = {
7409
7435
  ...latestContext,
7436
+ __fromSavedFilter: false,
7410
7437
  [bodyText?.paramName]: {
7411
7438
  ...latestContext?.[bodyText?.paramName],
7412
7439
  [bodyText?.paramName]: value,
@@ -7433,6 +7460,13 @@ const SelectContent = ({ bodyText, isFormDisabled = false, messageIndex }) => {
7433
7460
  const persisted = persistedFormValues?.[formKey];
7434
7461
  if (!persisted || (Array.isArray(persisted) && persisted.length === 0)) {
7435
7462
  setCurrentSelectedOptions([]);
7463
+ setIsAllSelected(false);
7464
+ selectAllCountRef.current = 0;
7465
+ }
7466
+ else if (chatbotContextRef.current?.__fromSavedFilter) {
7467
+ setCurrentSelectedOptions(persisted);
7468
+ setIsAllSelected(false);
7469
+ selectAllCountRef.current = 0;
7436
7470
  }
7437
7471
  }, [persistedFormValues, formKey]);
7438
7472
  // When cross-filter context provides new options for this filter, update local state
@@ -7523,6 +7557,7 @@ const SelectContent = ({ bodyText, isFormDisabled = false, messageIndex }) => {
7523
7557
  const ctx1 = chatbotContextRef.current;
7524
7558
  dispatch(setChatbotContext({
7525
7559
  ...ctx1,
7560
+ __fromSavedFilter: false,
7526
7561
  [bodyText?.paramName]: {
7527
7562
  ...ctx1?.[bodyText?.paramName],
7528
7563
  [bodyText?.paramName]: [],
@@ -7533,6 +7568,9 @@ const SelectContent = ({ bodyText, isFormDisabled = false, messageIndex }) => {
7533
7568
  // Notify cross-filter context to clear downstream filters
7534
7569
  if (isCascading) {
7535
7570
  crossFilterCtx.onFilterChange(paramName, []);
7571
+ // Re-fetch upstream options so they are no longer narrowed
7572
+ // by this filter's previous selection
7573
+ crossFilterCtx.fetchUpstreamOptions(paramName);
7536
7574
  }
7537
7575
  }, handleChange: (selected) => onChange(selected), isCloseWhenClickOutside: true, setIsOpen: (open) => {
7538
7576
  setIsOpen(open);
@@ -7565,6 +7603,11 @@ const SelectContent = ({ bodyText, isFormDisabled = false, messageIndex }) => {
7565
7603
  }
7566
7604
  crossFilterCtx.fetchUpstreamOptions(paramName);
7567
7605
  }
7606
+ else {
7607
+ // Selection was cleared — re-fetch upstream options so they are
7608
+ // no longer narrowed by this filter's previous selection
7609
+ crossFilterCtx.fetchUpstreamOptions(paramName);
7610
+ }
7568
7611
  }
7569
7612
  }
7570
7613
  }, 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: () => {
@@ -7606,6 +7649,7 @@ const SelectContent = ({ bodyText, isFormDisabled = false, messageIndex }) => {
7606
7649
  const ctx2 = chatbotContextRef.current;
7607
7650
  dispatch(setChatbotContext({
7608
7651
  ...ctx2,
7652
+ __fromSavedFilter: false,
7609
7653
  [bodyText?.paramName]: {
7610
7654
  ...ctx2?.[bodyText?.paramName],
7611
7655
  [bodyText?.paramName]: valuesToDispatch,
@@ -7628,6 +7672,7 @@ const SelectContent = ({ bodyText, isFormDisabled = false, messageIndex }) => {
7628
7672
  const ctx3 = chatbotContextRef.current;
7629
7673
  dispatch(setChatbotContext({
7630
7674
  ...ctx3,
7675
+ __fromSavedFilter: false,
7631
7676
  [bodyText?.paramName]: {
7632
7677
  ...ctx3?.[bodyText?.paramName],
7633
7678
  [bodyText?.paramName]: [],
@@ -7916,6 +7961,55 @@ const ImageContent = ({ bodyText }) => {
7916
7961
 
7917
7962
  // Key used to persist timeout state in sessionStorage (survives component remounts from tab switches)
7918
7963
  const STEP_FORM_TIMEOUT_KEY = "__stepFormTimedOut";
7964
+ /**
7965
+ * Renderless bridge component that lives inside CrossFilterProvider.
7966
+ * Watches for saved filter selection changes and programmatically triggers
7967
+ * the cross-filter cascading system so downstream fields get their options.
7968
+ */
7969
+ const SavedFilterCascadeBridge = ({ chatbotContext, crossFilterConfigs }) => {
7970
+ const crossFilterCtx = useCrossFilterContext();
7971
+ const prevSelectionRef = useRef(null);
7972
+ useEffect(() => {
7973
+ if (!crossFilterCtx?.isEnabled)
7974
+ return;
7975
+ const isFromSaved = chatbotContext?.__fromSavedFilter === true;
7976
+ if (!isFromSaved) {
7977
+ prevSelectionRef.current = null;
7978
+ return;
7979
+ }
7980
+ // Derive a stable key from the saved filter selection to detect switches
7981
+ const currentSelection = chatbotContext?.__savedFilterSelection;
7982
+ const selectionKey = Array.isArray(currentSelection)
7983
+ ? currentSelection[0]?.value
7984
+ : currentSelection?.value;
7985
+ // Skip if this is the same saved filter we already processed
7986
+ if (selectionKey === prevSelectionRef.current)
7987
+ return;
7988
+ prevSelectionRef.current = selectionKey;
7989
+ // Set cascading selections for fields the saved filter covers.
7990
+ // For unmatched fields, silently clear selectionsMap without triggering
7991
+ // downstream cascade wipes (which would blank option lists).
7992
+ let lastMatchingParam = null;
7993
+ crossFilterConfigs.forEach((cfg) => {
7994
+ const ctx = chatbotContext[cfg.paramName];
7995
+ if (ctx && ctx.updated && Array.isArray(ctx[cfg.paramName]) && ctx[cfg.paramName].length > 0) {
7996
+ crossFilterCtx.onFilterChange(cfg.paramName, ctx[cfg.paramName]);
7997
+ lastMatchingParam = cfg.paramName;
7998
+ }
7999
+ else {
8000
+ // Clear stale selectionsMap entry without cascade
8001
+ crossFilterCtx.setSelectionSilent(cfg.paramName, []);
8002
+ }
8003
+ });
8004
+ // Fetch downstream options for the lowest matched filter
8005
+ if (lastMatchingParam) {
8006
+ setTimeout(() => {
8007
+ crossFilterCtx.fetchDownstreamOptions(lastMatchingParam);
8008
+ }, 100);
8009
+ }
8010
+ }, [chatbotContext?.__fromSavedFilter, chatbotContext?.__savedFilterSelection]);
8011
+ return null;
8012
+ };
7919
8013
  /**
7920
8014
  * Renders form widget data inline within a step.
7921
8015
  * Reuses the same rendering logic as CombinedContent but designed
@@ -7992,13 +8086,14 @@ const StepFormContent = ({ formData, messageIndex = 0, isFormDisabled = false, s
7992
8086
  setFilterSetCurrentOptions(opts);
7993
8087
  return opts;
7994
8088
  }, [savedFilterSets]);
7995
- const isFilterSelected = Array.isArray(selectedFilterSet) ? selectedFilterSet.length > 0 : !!selectedFilterSet && Object.keys(selectedFilterSet).length > 0;
8089
+ Array.isArray(selectedFilterSet) ? selectedFilterSet.length > 0 : !!selectedFilterSet && Object.keys(selectedFilterSet).length > 0;
7996
8090
  const onFilterSetChange = useCallback((selected) => {
7997
8091
  try {
7998
8092
  const selectedValue = Array.isArray(selected) ? selected[0]?.value : selected?.value;
7999
8093
  if (!selectedValue) {
8000
- dispatch(setChatbotContext({}));
8001
- dispatch(clearPersistedFormValues());
8094
+ // Only remove saved filter flags; keep dropdown values and persisted state intact
8095
+ const { __fromSavedFilter, __savedFilterSelection, ...rest } = chatbotContext || {};
8096
+ dispatch(setChatbotContext(rest));
8002
8097
  return;
8003
8098
  }
8004
8099
  const fullFilterObj = (savedFilterSets || []).find((f) => (f.fuc_code || f.name || f.label) === selectedValue);
@@ -8027,15 +8122,51 @@ const StepFormContent = ({ formData, messageIndex = 0, isFormDisabled = false, s
8027
8122
  };
8028
8123
  }
8029
8124
  });
8030
- newContext.__fromSavedFilter = true;
8031
- newContext.__savedFilterSelection = selected;
8032
- dispatch(setChatbotContext(newContext));
8125
+ // Merge into existing context to preserve non-select field values (dates, inputs, sliders).
8126
+ // Clear all select fields first, then overlay saved filter values.
8127
+ const mergedContext = { ...(chatbotContext || {}) };
8128
+ (formData || []).forEach((item) => {
8129
+ const pName = item?.data?.param_name;
8130
+ if (!pName || item?.type !== "select")
8131
+ return;
8132
+ mergedContext[pName] = { [pName]: [], updated: false };
8133
+ });
8134
+ Object.keys(newContext).forEach((key) => {
8135
+ mergedContext[key] = newContext[key];
8136
+ });
8137
+ mergedContext.__fromSavedFilter = true;
8138
+ mergedContext.__savedFilterSelection = selected;
8139
+ dispatch(setChatbotContext(mergedContext));
8140
+ // Build persisted values for ALL form select fields.
8141
+ // Matching fields get the saved filter values; unmatched fields get [] (cleared).
8142
+ const formPersisted = {};
8143
+ (formData || []).forEach((item) => {
8144
+ const pName = item?.data?.param_name;
8145
+ if (!pName || item?.type !== "select")
8146
+ return;
8147
+ const key = `${messageIndex}_${pName}`;
8148
+ const selectAllKey = `${key}__selectAllCount`;
8149
+ if (newContext[pName] && newContext[pName][pName]) {
8150
+ const values = newContext[pName][pName];
8151
+ formPersisted[key] = values.map((v) => ({
8152
+ label: v,
8153
+ value: v,
8154
+ }));
8155
+ }
8156
+ else {
8157
+ // Clear fields not covered by the saved filter
8158
+ formPersisted[key] = [];
8159
+ }
8160
+ // Always reset select-all count when a saved filter is applied
8161
+ formPersisted[selectAllKey] = 0;
8162
+ });
8163
+ dispatch(setPersistedFormValues(formPersisted));
8033
8164
  }
8034
8165
  catch (error) {
8035
8166
  console.error("[StepFormContent] onFilterSetChange error:", error);
8036
8167
  }
8037
- }, [savedFilterSets, dispatch]);
8038
- const isFormFieldUsed = useMemo(() => {
8168
+ }, [savedFilterSets, dispatch, formData, messageIndex, chatbotContext]);
8169
+ useMemo(() => {
8039
8170
  if (!persistedFormValues)
8040
8171
  return false;
8041
8172
  const prefix = `${messageIndex}_`;
@@ -8046,8 +8177,8 @@ const StepFormContent = ({ formData, messageIndex = 0, isFormDisabled = false, s
8046
8177
  return val && (Array.isArray(val) ? val.length > 0 : !!val);
8047
8178
  });
8048
8179
  }, [persistedFormValues, messageIndex]);
8049
- const formFieldsDisabled = isFormDisabled || isFilterSelected || isFormSubmitted || isTimedOut;
8050
- const savedFilterDisabled = isFormDisabled || isFormFieldUsed || isFormSubmitted || isTimedOut;
8180
+ const formFieldsDisabled = isFormDisabled || isFormSubmitted || isTimedOut;
8181
+ const savedFilterDisabled = isFormDisabled || isFormSubmitted || isTimedOut;
8051
8182
  const requiredFieldsFilled = useMemo(() => {
8052
8183
  if (!formData || !Array.isArray(formData))
8053
8184
  return false;
@@ -8287,9 +8418,7 @@ const StepFormContent = ({ formData, messageIndex = 0, isFormDisabled = false, s
8287
8418
  });
8288
8419
  if (formFields.length === 0 && buttonItems.length === 0)
8289
8420
  return null;
8290
- return (jsxs("div", { className: "step-form-content", children: [showSavedFilters && filterSetOptions.length > 0 && (jsx("div", { style: { width: "100%", marginTop: "10px" }, children: jsx(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 && (jsx("hr", { style: { border: "none", borderTop: "1px solid #E0E0E0", margin: "12px 0" } })), jsx("div", { style: {
8291
- ...(isFilterSelected && !isFormDisabled ? { pointerEvents: "none", opacity: 0.5 } : {}),
8292
- }, children: crossFilterConfigs.length >= 1 ? (jsx(CrossFilterProvider, { filters: crossFilterConfigs, fetchOptionsFn: (filterConfig, existingSelections, allFilters) => fetchCrossFilterOptions(filterConfig, existingSelections, allFilters, preSelectedFilters), initialSelections: crossFilterInitialSelections, fetchOnMount: false, children: formFields })) : (formFields) }), buttonItems] }));
8421
+ return (jsxs("div", { className: "step-form-content", children: [showSavedFilters && filterSetOptions.length > 0 && (jsx("div", { style: { width: "100%", marginTop: "10px" }, children: jsx(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 && (jsx("hr", { style: { border: "none", borderTop: "1px solid #E0E0E0", margin: "12px 0" } })), jsx("div", { children: crossFilterConfigs.length >= 1 ? (jsxs(CrossFilterProvider, { filters: crossFilterConfigs, fetchOptionsFn: (filterConfig, existingSelections, allFilters) => fetchCrossFilterOptions(filterConfig, existingSelections, allFilters, preSelectedFilters), initialSelections: crossFilterInitialSelections, fetchOnMount: false, children: [jsx(SavedFilterCascadeBridge, { chatbotContext: chatbotContext, crossFilterConfigs: crossFilterConfigs }), formFields] })) : (formFields) }), buttonItems] }));
8293
8422
  };
8294
8423
  /** Reset the timeout flag (call when a new conversation/message starts) */
8295
8424
  const resetStepFormTimeoutFlag = () => {