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