@redsift/table 9.3.2 → 9.3.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/index.d.ts CHANGED
@@ -85,16 +85,24 @@ type StyledDataGridProps = {
85
85
 
86
86
  declare const DataGrid: Comp<DataGridProps, HTMLDivElement>;
87
87
 
88
+ interface CompletionResponseItem {
89
+ columnField: string;
90
+ operatorValue: string;
91
+ value?: string;
92
+ }
88
93
  type CompletionResponse = {
89
94
  linkOperator: 'and' | 'or';
90
- items: [
91
- {
92
- columnField: string;
93
- operatorValue: string;
94
- value?: string;
95
- }
96
- ];
95
+ items: CompletionResponseItem[];
97
96
  };
97
+ interface LocaleText {
98
+ textLabel?: string;
99
+ textPlaceholder?: string;
100
+ buttonAriaLabel?: string;
101
+ buttonText?: string;
102
+ powerText?: string;
103
+ powerTooltipContent?: string;
104
+ errorText?: string;
105
+ }
98
106
  interface FilterConfig {
99
107
  columns: object[];
100
108
  typeOperators: object;
@@ -105,6 +113,11 @@ interface FilterConfig {
105
113
  interface GridToolbarFilterSemanticFieldProps extends ComponentProps<'form'> {
106
114
  nlpFilterConfig: FilterConfig;
107
115
  onFilterModelChange: (filterModel: GridFilterModel) => void;
116
+ dateFormat?: string;
117
+ defaultModel?: string;
118
+ defaultFilter?: CompletionResponse;
119
+ disablePower?: boolean;
120
+ localeText?: LocaleText;
108
121
  }
109
122
 
110
123
  declare const DEFAULT_OPERATORS: {
@@ -120,6 +133,7 @@ declare const GridToolbarFilterSemanticField: Comp<GridToolbarFilterSemanticFiel
120
133
 
121
134
  type GridToolbarColumnsProps = Omit<typeof GridToolbarColumnsButton, 'ref'>;
122
135
  type GridToolbarDensityProps = Omit<typeof GridToolbarDensitySelector, 'ref'>;
136
+ type GridToolbarFilterSemanticProps = Omit<GridToolbarFilterSemanticFieldProps, 'ref'>;
123
137
  interface ToolbarProps {
124
138
  /** Props to forward to the column button. */
125
139
  columnsButtonProps?: GridToolbarColumnsProps;
@@ -146,8 +160,8 @@ interface ToolbarProps {
146
160
  /** Whether the filter button is displayed or not. */
147
161
  hasFilterButton?: boolean;
148
162
  /** Configuration object for NLP filter. undefined if disabled. */
149
- nlpFilterConfig?: FilterConfig;
150
163
  onFilterModelChange?: (filterModel: GridFilterModel) => void;
164
+ semanticFilterProps?: GridToolbarFilterSemanticProps;
151
165
  }
152
166
 
153
167
  /**
package/index.js CHANGED
@@ -21462,7 +21462,7 @@ const StyledTooltipContent = styled$3.div`
21462
21462
 
21463
21463
  const COMPONENT_NAME$5 = 'TooltipContent';
21464
21464
  const CLASSNAME$5 = 'redsift-tooltip-content';
21465
- const DEFAULT_PROPS$3 = {};
21465
+ const DEFAULT_PROPS$4 = {};
21466
21466
 
21467
21467
  /**
21468
21468
  * The TooltipContent component.
@@ -21524,12 +21524,12 @@ const TooltipContent = /*#__PURE__*/forwardRef((props, ref) => {
21524
21524
  }, children)));
21525
21525
  });
21526
21526
  TooltipContent.className = CLASSNAME$5;
21527
- TooltipContent.defaultProps = DEFAULT_PROPS$3;
21527
+ TooltipContent.defaultProps = DEFAULT_PROPS$4;
21528
21528
  TooltipContent.displayName = COMPONENT_NAME$5;
21529
21529
 
21530
21530
  const COMPONENT_NAME$4 = 'TooltipTrigger';
21531
21531
  const CLASSNAME$4 = 'redsift-tooltip-trigger';
21532
- const DEFAULT_PROPS$2 = {};
21532
+ const DEFAULT_PROPS$3 = {};
21533
21533
 
21534
21534
  /**
21535
21535
  * The TooltipTrigger component.
@@ -21560,7 +21560,7 @@ const TooltipTrigger = /*#__PURE__*/forwardRef((props, ref) => {
21560
21560
  }, getReferenceProps(props)), children);
21561
21561
  });
21562
21562
  TooltipTrigger.className = CLASSNAME$4;
21563
- TooltipTrigger.defaultProps = DEFAULT_PROPS$2;
21563
+ TooltipTrigger.defaultProps = DEFAULT_PROPS$3;
21564
21564
  TooltipTrigger.displayName = COMPONENT_NAME$4;
21565
21565
 
21566
21566
  function useTooltip(_ref) {
@@ -21626,7 +21626,7 @@ function useTooltip(_ref) {
21626
21626
 
21627
21627
  const COMPONENT_NAME$3 = 'Tooltip';
21628
21628
  const CLASSNAME$3 = 'redsift-tooltip';
21629
- const DEFAULT_PROPS$1 = {
21629
+ const DEFAULT_PROPS$2 = {
21630
21630
  delay: 500,
21631
21631
  placement: TooltipPlacement.top
21632
21632
  };
@@ -21658,7 +21658,7 @@ const BaseTooltip = props => {
21658
21658
  }, trigger, content);
21659
21659
  };
21660
21660
  BaseTooltip.className = CLASSNAME$3;
21661
- BaseTooltip.defaultProps = DEFAULT_PROPS$1;
21661
+ BaseTooltip.defaultProps = DEFAULT_PROPS$2;
21662
21662
  BaseTooltip.displayName = COMPONENT_NAME$3;
21663
21663
  const Tooltip = Object.assign(BaseTooltip, {
21664
21664
  Trigger: TooltipTrigger,
@@ -21689,13 +21689,26 @@ const StyledGridToolbarFilterSemanticField = styled$3.form`
21689
21689
  }
21690
21690
  `;
21691
21691
 
21692
- const _excluded$e = ["className", "nlpFilterConfig", "onFilterModelChange"];
21692
+ const _excluded$e = ["className", "nlpFilterConfig", "onFilterModelChange", "dateFormat", "defaultModel", "defaultFilter", "disablePower", "localeText"];
21693
21693
  const COMPONENT_NAME$2 = 'GridToolbarFilterSemanticField';
21694
21694
  const CLASSNAME$2 = 'redsift-datagrid-toolbar-nlp-filter-field';
21695
- const DATE_FORMAT = 'yyyy-mm-dd';
21696
- const DEFAULT_GPT_MODEL = 'gpt-4-0613';
21697
- const DEFAULT_FILTER = {
21698
- items: []
21695
+ const DEFAULT_PROPS$1 = {
21696
+ dateFormat: 'yyyy-mm-dd',
21697
+ defaultModel: 'gpt-4-0613',
21698
+ defaultFilter: {
21699
+ items: [],
21700
+ linkOperator: 'and'
21701
+ },
21702
+ disablePower: false,
21703
+ localeText: {
21704
+ textLabel: 'Semantic filtering',
21705
+ textPlaceholder: 'Describe here how you would like to filter this datagrid.',
21706
+ buttonAriaLabel: 'Submit',
21707
+ buttonText: 'Run',
21708
+ powerText: 'Power mode',
21709
+ powerTooltipContent: 'The Power mode can get better results but is slower.',
21710
+ errorText: 'Unable to find a valid filter, please try again with a more specific prompt.'
21711
+ }
21699
21712
  };
21700
21713
  const DEFAULT_OPERATORS = {
21701
21714
  string: ['contains', 'equals', 'startsWith', 'endsWith', 'isEmpty', 'isNotEmpty', 'isAnyOf'],
@@ -21703,7 +21716,7 @@ const DEFAULT_OPERATORS = {
21703
21716
  boolean: ['is'],
21704
21717
  date: ['is', 'not', 'after', 'onOrAfter', 'before', 'onOrBefore', 'isEmpty', 'isNotEmpty']
21705
21718
  };
21706
- const getRole = config => {
21719
+ const getRole = (config, dateFormat) => {
21707
21720
  const today = new Date().toDateString();
21708
21721
  const columns = `[${config.columns.map(_ref => {
21709
21722
  let {
@@ -21733,7 +21746,7 @@ The AI assistant extracts information from the user input and generates a JSON o
21733
21746
  - this can be skipped if the "operatorValue" is either "isEmpty" or "isNotEmpty"
21734
21747
  - a list of multiple values if the "operatorValue" ends with "AnyOf"
21735
21748
  - otherwise, it's a single value represented as a string: "true" instead of true, "false" instead of false, "0.6" instead of 0.6.
21736
- For "date" data type, use ${DATE_FORMAT}. If relative date is input, convert to the actual date given today is ${today}.
21749
+ For "date" data type, use ${dateFormat}. If relative date is input, convert to the actual date given today is ${today}.
21737
21750
  - "operatorValue": the comparison operator, accepted values depend on the data type of the column
21738
21751
  ${operators}
21739
21752
 
@@ -21750,9 +21763,9 @@ Return just the JSON object without any extra text, explanation or note.
21750
21763
  If the user input can't be parsed, return a JSON object to indicate the error and the reason {"code":"error", "reason":"explain why it was failed to parse"}.
21751
21764
  `;
21752
21765
  };
21753
- async function getOpenAICompletion(config, prompt, model) {
21766
+ async function getOpenAICompletion(config, prompt, model, dateFormat) {
21754
21767
  const text = 'Parse the text delimited by triple backticks: ```' + prompt.trim() + '``` and make sure the output is a valid JSON object';
21755
- const role = getRole(config);
21768
+ const role = getRole(config, dateFormat);
21756
21769
  const completion = await getCompletion(text, role, config.openaiApiKey, model);
21757
21770
  const response = JSON.parse(completion);
21758
21771
  if ('code' in response) {
@@ -21769,11 +21782,25 @@ const GridToolbarFilterSemanticField = /*#__PURE__*/forwardRef((props, ref) => {
21769
21782
  const {
21770
21783
  className,
21771
21784
  nlpFilterConfig,
21772
- onFilterModelChange
21785
+ onFilterModelChange,
21786
+ dateFormat = DEFAULT_PROPS$1.dateFormat,
21787
+ defaultModel = DEFAULT_PROPS$1.defaultModel,
21788
+ defaultFilter = DEFAULT_PROPS$1.defaultFilter,
21789
+ disablePower = DEFAULT_PROPS$1.disablePower,
21790
+ localeText
21773
21791
  } = props,
21774
21792
  forwardedProps = _objectWithoutProperties(props, _excluded$e);
21793
+ const {
21794
+ textLabel,
21795
+ textPlaceholder,
21796
+ buttonAriaLabel,
21797
+ buttonText,
21798
+ powerText,
21799
+ powerTooltipContent,
21800
+ errorText
21801
+ } = _objectSpread2(_objectSpread2({}, DEFAULT_PROPS$1.localeText), localeText);
21775
21802
  const [prompt, setPrompt] = useState('');
21776
- const modelRef = useRef(DEFAULT_GPT_MODEL);
21803
+ const modelRef = useRef(defaultModel);
21777
21804
  const showErrorRef = useRef(false);
21778
21805
  const [isLoading, setIsLoading] = useState(false);
21779
21806
  const handlePromptSubmit = async event => {
@@ -21784,7 +21811,7 @@ const GridToolbarFilterSemanticField = /*#__PURE__*/forwardRef((props, ref) => {
21784
21811
  // Use the cache if it's available and it's not the default filter.
21785
21812
  // We still want to rerun default filter because it might be due to request fail.
21786
21813
  const response = sessionStorage.getItem(prompt);
21787
- if (response && response !== JSON.stringify(DEFAULT_FILTER)) {
21814
+ if (response && response !== JSON.stringify(defaultFilter)) {
21788
21815
  filter = JSON.parse(response);
21789
21816
  } else {
21790
21817
  setIsLoading(true);
@@ -21793,12 +21820,12 @@ const GridToolbarFilterSemanticField = /*#__PURE__*/forwardRef((props, ref) => {
21793
21820
  if (nlpFilterConfig.completionFunc !== undefined) {
21794
21821
  filter = await nlpFilterConfig.completionFunc(nlpFilterConfig, prompt, modelRef.current);
21795
21822
  } else {
21796
- filter = await getOpenAICompletion(nlpFilterConfig, prompt, modelRef.current);
21823
+ filter = await getOpenAICompletion(nlpFilterConfig, prompt, modelRef.current, dateFormat);
21797
21824
  }
21798
21825
  sessionStorage.setItem(prompt, JSON.stringify(filter));
21799
21826
  } catch (error) {
21800
21827
  showErrorRef.current = true;
21801
- filter = DEFAULT_FILTER;
21828
+ filter = defaultFilter;
21802
21829
  }
21803
21830
 
21804
21831
  // MUI requires different id
@@ -21821,25 +21848,26 @@ const GridToolbarFilterSemanticField = /*#__PURE__*/forwardRef((props, ref) => {
21821
21848
  width: "100%"
21822
21849
  }, /*#__PURE__*/React__default.createElement(TextField$2, {
21823
21850
  width: "100%",
21824
- label: "Semantic filtering",
21825
- placeholder: "Describe here how you would like to filter this datagrid.",
21851
+ label: textLabel,
21852
+ placeholder: textPlaceholder,
21826
21853
  onChange: value => setPrompt(value),
21827
21854
  value: prompt
21828
21855
  }), /*#__PURE__*/React__default.createElement(Button, {
21829
21856
  variant: "primary",
21830
- "aria-label": "Submit",
21857
+ "aira-label": buttonAriaLabel,
21831
21858
  type: "submit",
21832
21859
  isLoading: isLoading
21833
- }, "Run")), /*#__PURE__*/React__default.createElement(Tooltip, null, /*#__PURE__*/React__default.createElement(Tooltip.Trigger, null, /*#__PURE__*/React__default.createElement(Switch, {
21860
+ }, buttonText)), !disablePower && /*#__PURE__*/React__default.createElement(Tooltip, null, /*#__PURE__*/React__default.createElement(Tooltip.Trigger, null, /*#__PURE__*/React__default.createElement(Switch, {
21834
21861
  width: "175px",
21835
21862
  isSelected: modelRef.current === 'gpt-4-0613',
21836
21863
  onChange: value => modelRef.current = value ? 'gpt-4-0613' : 'gpt-3.5-turbo-0613'
21837
- }, "Power mode")), /*#__PURE__*/React__default.createElement(Tooltip.Content, null, "The Power mode can get better results but is slower."))), showErrorRef.current && /*#__PURE__*/React__default.createElement(Text, {
21864
+ }, powerText)), /*#__PURE__*/React__default.createElement(Tooltip.Content, null, powerTooltipContent))), showErrorRef.current && /*#__PURE__*/React__default.createElement(Text, {
21838
21865
  color: "error",
21839
21866
  marginLeft: "8px"
21840
- }, "Unable to find a valid filter, please try again with a more specific prompt."));
21867
+ }, errorText));
21841
21868
  });
21842
21869
  GridToolbarFilterSemanticField.className = CLASSNAME$2;
21870
+ GridToolbarFilterSemanticField.defaultProps = DEFAULT_PROPS$1;
21843
21871
  GridToolbarFilterSemanticField.displayName = COMPONENT_NAME$2;
21844
21872
 
21845
21873
  /**
@@ -21863,9 +21891,12 @@ const Toolbar$2 = props => {
21863
21891
  hasDensityButton = true,
21864
21892
  densityButtonProps,
21865
21893
  densityButtonRef,
21866
- nlpFilterConfig = undefined,
21867
- onFilterModelChange
21894
+ onFilterModelChange,
21895
+ semanticFilterProps = undefined
21868
21896
  } = props;
21897
+ if (semanticFilterProps && onFilterModelChange) {
21898
+ semanticFilterProps.onFilterModelChange = onFilterModelChange;
21899
+ }
21869
21900
  return /*#__PURE__*/React__default.createElement(GridToolbarWrapper, null, /*#__PURE__*/React__default.createElement(GridToolbarContainer, null, /*#__PURE__*/React__default.createElement(Flexbox, {
21870
21901
  gap: "0"
21871
21902
  }, hasFilterButton ? /*#__PURE__*/React__default.createElement(GridToolbarFilterButton, _extends$2({}, filterButtonProps, {
@@ -21896,10 +21927,7 @@ const Toolbar$2 = props => {
21896
21927
  className: filterButtonProps !== null && filterButtonProps !== void 0 && filterButtonProps.className ? `${filterButtonProps === null || filterButtonProps === void 0 ? void 0 : filterButtonProps.className} redsift-condensed` : 'redsift-condensed'
21897
21928
  })) : null), /*#__PURE__*/React__default.createElement(Flexbox, {
21898
21929
  flexGrow: 3
21899
- }, nlpFilterConfig && onFilterModelChange ? /*#__PURE__*/React__default.createElement(GridToolbarFilterSemanticField, {
21900
- nlpFilterConfig: nlpFilterConfig,
21901
- onFilterModelChange: onFilterModelChange
21902
- }) : null)));
21930
+ }, semanticFilterProps ? /*#__PURE__*/React__default.createElement(GridToolbarFilterSemanticField, semanticFilterProps) : null)));
21903
21931
  };
21904
21932
 
21905
21933
  const _excluded$d = ["displayName"];