@redsift/table 9.2.4 → 9.3.0-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 +14 -4
- package/index.js +166 -183
- package/index.js.map +1 -1
- package/package.json +4 -4
package/index.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { GRID_DETAIL_PANEL_TOGGLE_COL_DEF, getGridNumericOperators as getGridNumericOperators$1, GridFilterInputMultipleValue, getGridStringOperators as getGridStringOperators$1, GridToolbarContainer, GridToolbarFilterButton, GridToolbarColumnsButton, GridToolbarDensitySelector, GridToolbarExport,
|
|
2
|
-
export * from '@mui/x-data-grid-pro';
|
|
1
|
+
import { GRID_DETAIL_PANEL_TOGGLE_COL_DEF, getGridNumericOperators as getGridNumericOperators$1, GridFilterInputMultipleValue, getGridStringOperators as getGridStringOperators$1, GridToolbarContainer, GridToolbarFilterButton, GridToolbarColumnsButton, GridToolbarDensitySelector, GridToolbarExport, gridVisibleSortedRowIdsSelector, useGridApiRef, DataGridPro, gridPaginatedVisibleSortedGridRowEntriesSelector, gridPaginatedVisibleSortedGridRowIdsSelector, gridFilteredSortedRowEntriesSelector, gridFilteredSortedRowIdsSelector } from '@mui/x-data-grid-pro';
|
|
3
2
|
export { getGridBooleanOperators, getGridDateOperators, getGridSingleSelectOperators } from '@mui/x-data-grid-pro';
|
|
4
3
|
import * as React from 'react';
|
|
5
4
|
import React__default, { Children, isValidElement, cloneElement, useLayoutEffect, useEffect, useRef, forwardRef, useState, useCallback, createElement } from 'react';
|
|
6
|
-
import { Icon, baseContainer, useId as useId$2, partitionComponents, isComponent, Flexbox, TextField as TextField$2, Button, Switch, CtasColorPalette, NotificationsColorPalette, IconButton as IconButton$2, Checkbox,
|
|
5
|
+
import { Icon, baseContainer, useId as useId$2, partitionComponents, isComponent, Flexbox, TextField as TextField$2, Button, Switch, Text, CtasColorPalette, NotificationsColorPalette, IconButton as IconButton$2, Checkbox, LinkButton, Shield } from '@redsift/design-system';
|
|
7
6
|
import { mdiSync, mdiFilterVariant, mdiViewColumn, mdiChevronUp, mdiChevronDown, mdiViewHeadline, mdiViewSequential, mdiViewStream, mdiChevronRight, mdiTrayArrowDown } from '@redsift/icons';
|
|
8
7
|
import emStyled from '@emotion/styled';
|
|
9
8
|
import { Global, ThemeContext, keyframes } from '@emotion/react';
|
|
@@ -17467,7 +17466,7 @@ const isBetweenOperator = {
|
|
|
17467
17466
|
label: 'is between',
|
|
17468
17467
|
value: 'isBetween',
|
|
17469
17468
|
getApplyFilterFn: filterItem => {
|
|
17470
|
-
if (!filterItem.
|
|
17469
|
+
if (!filterItem.columnField || !filterItem.value || !filterItem.operatorValue) {
|
|
17471
17470
|
return null;
|
|
17472
17471
|
}
|
|
17473
17472
|
if (!Array.isArray(filterItem.value) || filterItem.value.length !== 2) {
|
|
@@ -17480,7 +17479,7 @@ const isBetweenOperator = {
|
|
|
17480
17479
|
return null;
|
|
17481
17480
|
}
|
|
17482
17481
|
return params => {
|
|
17483
|
-
return params.value !== null &&
|
|
17482
|
+
return params.value !== null && filterItem.value[0] <= params.value && params.value <= filterItem.value[1];
|
|
17484
17483
|
};
|
|
17485
17484
|
},
|
|
17486
17485
|
InputComponent: InputNumberInterval
|
|
@@ -17493,7 +17492,7 @@ const containsAnyOfOperator = {
|
|
|
17493
17492
|
label: 'contains any of',
|
|
17494
17493
|
value: 'containsAnyOf',
|
|
17495
17494
|
getApplyFilterFn: filterItem => {
|
|
17496
|
-
if (!filterItem.
|
|
17495
|
+
if (!filterItem.columnField || !filterItem.value || !filterItem.operatorValue) {
|
|
17497
17496
|
return null;
|
|
17498
17497
|
}
|
|
17499
17498
|
return params => {
|
|
@@ -17516,7 +17515,7 @@ const containsAnyOfCIOperator = {
|
|
|
17516
17515
|
label: 'contains any of (case insensitive)',
|
|
17517
17516
|
value: 'containsAnyOf',
|
|
17518
17517
|
getApplyFilterFn: filterItem => {
|
|
17519
|
-
if (!filterItem.
|
|
17518
|
+
if (!filterItem.columnField || !filterItem.value || !filterItem.operatorValue) {
|
|
17520
17519
|
return null;
|
|
17521
17520
|
}
|
|
17522
17521
|
return params => {
|
|
@@ -17543,7 +17542,7 @@ const endsWithAnyOfOperator = {
|
|
|
17543
17542
|
label: 'ends with any of',
|
|
17544
17543
|
value: 'endsWithAnyOf',
|
|
17545
17544
|
getApplyFilterFn: filterItem => {
|
|
17546
|
-
if (!filterItem.
|
|
17545
|
+
if (!filterItem.columnField || !filterItem.value || !filterItem.operatorValue) {
|
|
17547
17546
|
return null;
|
|
17548
17547
|
}
|
|
17549
17548
|
return params => {
|
|
@@ -17570,7 +17569,7 @@ const isAnyOfOperator = {
|
|
|
17570
17569
|
label: 'is any of',
|
|
17571
17570
|
value: 'isAnyOf',
|
|
17572
17571
|
getApplyFilterFn: filterItem => {
|
|
17573
|
-
if (!filterItem.
|
|
17572
|
+
if (!filterItem.columnField || !filterItem.value || !filterItem.operatorValue) {
|
|
17574
17573
|
return null;
|
|
17575
17574
|
}
|
|
17576
17575
|
return params => {
|
|
@@ -17594,7 +17593,7 @@ const isNotAnyOfOperator = {
|
|
|
17594
17593
|
label: 'is not any of',
|
|
17595
17594
|
value: 'isNotAnyOf',
|
|
17596
17595
|
getApplyFilterFn: filterItem => {
|
|
17597
|
-
if (!filterItem.
|
|
17596
|
+
if (!filterItem.columnField || !filterItem.value || !filterItem.operatorValue) {
|
|
17598
17597
|
return null;
|
|
17599
17598
|
}
|
|
17600
17599
|
return params => {
|
|
@@ -17618,7 +17617,7 @@ const startsWithAnyOfOperator = {
|
|
|
17618
17617
|
label: 'starts with any of',
|
|
17619
17618
|
value: 'startsWithAnyOf',
|
|
17620
17619
|
getApplyFilterFn: filterItem => {
|
|
17621
|
-
if (!filterItem.
|
|
17620
|
+
if (!filterItem.columnField || !filterItem.value || !filterItem.operatorValue) {
|
|
17622
17621
|
return null;
|
|
17623
17622
|
}
|
|
17624
17623
|
return params => {
|
|
@@ -21661,12 +21660,7 @@ const StyledGridToolbarFilterSemanticField = styled$3.form`
|
|
|
21661
21660
|
const API_URL = 'https://api.openai.com/v1/chat/completions';
|
|
21662
21661
|
async function getCompletion(text, role, openai_api_key) {
|
|
21663
21662
|
let model = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'gpt-3.5-turbo-0613';
|
|
21664
|
-
let verbose = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
|
|
21665
|
-
/**
|
|
21666
|
-
* Returns the text responded by GPT.
|
|
21667
|
-
*/
|
|
21668
21663
|
try {
|
|
21669
|
-
const t0 = new Date();
|
|
21670
21664
|
const messages = [{
|
|
21671
21665
|
role: 'system',
|
|
21672
21666
|
content: role
|
|
@@ -21674,15 +21668,8 @@ async function getCompletion(text, role, openai_api_key) {
|
|
|
21674
21668
|
role: 'user',
|
|
21675
21669
|
content: text
|
|
21676
21670
|
}];
|
|
21677
|
-
|
|
21678
|
-
|
|
21679
|
-
console.log('prompt:', text);
|
|
21680
|
-
console.log('model:', model);
|
|
21681
|
-
console.log('characters count (4 chars ~ 1 token)');
|
|
21682
|
-
console.log(`- system=${role.length}`);
|
|
21683
|
-
console.log(`- user=${text.length}`);
|
|
21684
|
-
}
|
|
21685
|
-
const response = await fetch(API_URL, {
|
|
21671
|
+
const url = API_URL;
|
|
21672
|
+
const response = await fetch(url, {
|
|
21686
21673
|
method: 'POST',
|
|
21687
21674
|
headers: {
|
|
21688
21675
|
'Content-Type': 'application/json',
|
|
@@ -21695,15 +21682,6 @@ async function getCompletion(text, role, openai_api_key) {
|
|
|
21695
21682
|
})
|
|
21696
21683
|
});
|
|
21697
21684
|
const data = await response.json();
|
|
21698
|
-
if (verbose) {
|
|
21699
|
-
const t1 = new Date();
|
|
21700
|
-
const t = (role.length + text.length + data.choices[0].message.content.length) / 4;
|
|
21701
|
-
console.log(`- response=${data.choices[0].message.content.length}`);
|
|
21702
|
-
console.log(`total is about ${t.toFixed(0)} tokens and took ${// @ts-ignore
|
|
21703
|
-
((t1 - t0) / 1000).toFixed(0)} seconds to complete`);
|
|
21704
|
-
console.log('response:');
|
|
21705
|
-
console.log(data.choices[0].message.content);
|
|
21706
|
-
}
|
|
21707
21685
|
return data.choices[0].message.content;
|
|
21708
21686
|
} catch (error) {
|
|
21709
21687
|
return '';
|
|
@@ -21714,77 +21692,66 @@ const _excluded$e = ["className", "nlpFilterConfig", "onFilterModelChange"];
|
|
|
21714
21692
|
const COMPONENT_NAME$2 = 'GridToolbarFilterSemanticField';
|
|
21715
21693
|
const CLASSNAME$2 = 'redsift-datagrid-toolbar-nlp-filter-field';
|
|
21716
21694
|
const DATE_FORMAT = 'yyyy-mm-dd';
|
|
21695
|
+
const DEFAULT_GPT_MODEL = 'gpt-4-0613';
|
|
21717
21696
|
const DEFAULT_FILTER = {
|
|
21718
21697
|
items: []
|
|
21719
21698
|
};
|
|
21720
|
-
const
|
|
21699
|
+
const getRole = config => {
|
|
21700
|
+
const today = new Date().toDateString();
|
|
21701
|
+
const columns = `[${config.columns.map(_ref => {
|
|
21702
|
+
let {
|
|
21703
|
+
field
|
|
21704
|
+
} = _ref;
|
|
21705
|
+
return `"${field}"`;
|
|
21706
|
+
}).join(', ')}]`;
|
|
21707
|
+
const operators = Object.entries(config.typeOperators).map(_ref2 => {
|
|
21708
|
+
let [k, values] = _ref2;
|
|
21709
|
+
return values.length === 1 ? ` - For "${k}" data type, operator must only be "${values[0]}"` : ` - For "${k}" data type, operator must be one of [${values.map(v => `"${v}"`).join(', ')}]`;
|
|
21710
|
+
}).join('\n');
|
|
21711
|
+
const column_description = config.columns.map(_ref3 => {
|
|
21712
|
+
let {
|
|
21713
|
+
field,
|
|
21714
|
+
type,
|
|
21715
|
+
description
|
|
21716
|
+
} = _ref3;
|
|
21717
|
+
return `- "${field}": "${type}" data type; ${description ? description.trim() : ''}`;
|
|
21718
|
+
}).join('\n');
|
|
21719
|
+
return `The AI assistant parses user input to generate a JSON object that will be used as a row filter for a data table MUI Data Grid.
|
|
21721
21720
|
The filter supports mulitple conditions using only two logical operator "and", "or". It only allows "and" between all conditions or "or" between all conditions. It can't mix the two types.
|
|
21722
21721
|
The AI assistant extracts information from the user input and generates a JSON object with exactly the two keys "linkOperator" and "items":
|
|
21723
21722
|
- "linkOperator": the logical operator, only "and" or "or" are allowed. If there is only one condition in the "items", use "and".
|
|
21724
21723
|
- "items": a list of conditions, each is an object with exactly the three keys "columnField", "operatorValue" and "value":
|
|
21725
|
-
- "columnField": the column name, must be one of {
|
|
21726
|
-
- "value":
|
|
21724
|
+
- "columnField": the column name, must be one of ${columns}
|
|
21725
|
+
- "value":
|
|
21727
21726
|
- this can be skipped if the "operatorValue" is either "isEmpty" or "isNotEmpty"
|
|
21728
21727
|
- a list of multiple values if the "operatorValue" ends with "AnyOf"
|
|
21729
|
-
- otherwise, it's a single value represented as a string: "true" instead of true, "false" instead of false, "0.6" instead of 0.6.
|
|
21730
|
-
For "date" data type, use ${DATE_FORMAT}. If relative date is input, convert to the actual date given today is {
|
|
21728
|
+
- otherwise, it's a single value represented as a string: "true" instead of true, "false" instead of false, "0.6" instead of 0.6.
|
|
21729
|
+
For "date" data type, use ${DATE_FORMAT}. If relative date is input, convert to the actual date given today is ${today}.
|
|
21731
21730
|
- "operatorValue": the comparison operator, accepted values depend on the data type of the column
|
|
21732
|
-
{
|
|
21731
|
+
${operators}
|
|
21733
21732
|
|
|
21734
21733
|
Below is the datatype in square bracket, constraints on the data range if any, followed by the description of each column used in the data table:
|
|
21735
|
-
{
|
|
21734
|
+
${column_description}
|
|
21736
21735
|
|
|
21737
21736
|
Notes:
|
|
21738
21737
|
- For "boolean" data type, use "is" operator with value "false" instead of "isEmpty".
|
|
21739
|
-
{
|
|
21738
|
+
${config.notes.trim()}
|
|
21740
21739
|
|
|
21741
21740
|
Pay close attention to the the data type, description and supported operators above to make a valid selection of fields.
|
|
21742
21741
|
Think step by step and check carefully if the chosen operator is supported by the chosen data type.
|
|
21743
21742
|
Return just the JSON object without any extra text, explanation or note.
|
|
21744
|
-
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"}
|
|
21745
|
-
|
|
21746
|
-
|
|
21747
|
-
|
|
21748
|
-
|
|
21749
|
-
|
|
21750
|
-
|
|
21751
|
-
const
|
|
21752
|
-
|
|
21753
|
-
|
|
21754
|
-
|
|
21755
|
-
|
|
21756
|
-
}).join(', ') + ']';
|
|
21757
|
-
role = role.replace('{{columns}}', columnText);
|
|
21758
|
-
|
|
21759
|
-
// Type operators
|
|
21760
|
-
const opreatorText = Object.entries(config.typeOperators).map(_ref2 => {
|
|
21761
|
-
let [k, values] = _ref2;
|
|
21762
|
-
if (values.length == 1) {
|
|
21763
|
-
return ` - For "${k}" data type, operator must only be "${values[0]}"`;
|
|
21764
|
-
} else {
|
|
21765
|
-
const types = '[' + values.map(v => `"${v}"`).join(', ') + ']';
|
|
21766
|
-
return ` - For "${k}" data type, operator must be one of ${types}`;
|
|
21767
|
-
}
|
|
21768
|
-
}).join('\n');
|
|
21769
|
-
role = role.replace('{{type operators}}', opreatorText);
|
|
21770
|
-
|
|
21771
|
-
// Column description
|
|
21772
|
-
// const descriptionText = config.columns.map(({field, type, description}) => `- "${field}": "${type}" data type; operators must be one of [${config.typeOperators[type].map(v => '"' + v + '"').join(', ')}]; ${description.trim()}`).join('\n');
|
|
21773
|
-
const descriptionText = config.columns.map(_ref3 => {
|
|
21774
|
-
let {
|
|
21775
|
-
field,
|
|
21776
|
-
type,
|
|
21777
|
-
description
|
|
21778
|
-
} = _ref3;
|
|
21779
|
-
return `- "${field}": "${type}" data type; ${description ? description.trim() : ''}`;
|
|
21780
|
-
}).join('\n');
|
|
21781
|
-
role = role.replace('{{column description}}', descriptionText);
|
|
21782
|
-
|
|
21783
|
-
// Notes
|
|
21784
|
-
role = role.replace('{{notes}}', config.notes.trim());
|
|
21785
|
-
|
|
21786
|
-
// console.log(role);
|
|
21787
|
-
return role;
|
|
21743
|
+
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"}.
|
|
21744
|
+
`;
|
|
21745
|
+
};
|
|
21746
|
+
async function getOpenAICompletion(config, prompt, model) {
|
|
21747
|
+
const text = 'Parse the text delimited by triple backticks: ```' + prompt.trim() + '``` and make sure the output is a valid JSON object';
|
|
21748
|
+
const role = getRole(config);
|
|
21749
|
+
const completion = await getCompletion(text, role, config.openaiApiKey, model);
|
|
21750
|
+
const response = JSON.parse(completion);
|
|
21751
|
+
if ('code' in response) {
|
|
21752
|
+
throw new Error(response.reason);
|
|
21753
|
+
}
|
|
21754
|
+
return response;
|
|
21788
21755
|
}
|
|
21789
21756
|
|
|
21790
21757
|
/**
|
|
@@ -21799,7 +21766,8 @@ const GridToolbarFilterSemanticField = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
21799
21766
|
} = props,
|
|
21800
21767
|
forwardedProps = _objectWithoutProperties(props, _excluded$e);
|
|
21801
21768
|
const [prompt, setPrompt] = useState('');
|
|
21802
|
-
const
|
|
21769
|
+
const modelRef = useRef(DEFAULT_GPT_MODEL);
|
|
21770
|
+
const showErrorRef = useRef(false);
|
|
21803
21771
|
const [isLoading, setIsLoading] = useState(false);
|
|
21804
21772
|
const handlePromptSubmit = async event => {
|
|
21805
21773
|
event.preventDefault();
|
|
@@ -21811,36 +21779,33 @@ const GridToolbarFilterSemanticField = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
21811
21779
|
const response = sessionStorage.getItem(prompt);
|
|
21812
21780
|
if (response && response !== JSON.stringify(DEFAULT_FILTER)) {
|
|
21813
21781
|
filter = JSON.parse(response);
|
|
21814
|
-
console.log('filter from cache:', filter);
|
|
21815
21782
|
} else {
|
|
21816
21783
|
setIsLoading(true);
|
|
21817
|
-
|
|
21818
|
-
const text = 'Parse the text delimited by triple backticks: ```' + prompt.trim() + '``` and make sure the output is a valid JSON object';
|
|
21819
|
-
const output_str = await getCompletion(text, role, nlpFilterConfig.openaiApiKey, model);
|
|
21784
|
+
showErrorRef.current = false;
|
|
21820
21785
|
try {
|
|
21821
|
-
|
|
21822
|
-
|
|
21823
|
-
console.log('GPT does not understand input', filter.reason);
|
|
21824
|
-
filter = DEFAULT_FILTER;
|
|
21786
|
+
if (nlpFilterConfig.completionFunc !== undefined) {
|
|
21787
|
+
filter = await nlpFilterConfig.completionFunc(nlpFilterConfig, prompt, modelRef.current);
|
|
21825
21788
|
} else {
|
|
21826
|
-
|
|
21789
|
+
filter = await getOpenAICompletion(nlpFilterConfig, prompt, modelRef.current);
|
|
21827
21790
|
}
|
|
21791
|
+
sessionStorage.setItem(prompt, JSON.stringify(filter));
|
|
21828
21792
|
} catch (error) {
|
|
21829
|
-
|
|
21793
|
+
showErrorRef.current = true;
|
|
21830
21794
|
filter = DEFAULT_FILTER;
|
|
21831
21795
|
}
|
|
21832
21796
|
|
|
21833
21797
|
// MUI requires different id
|
|
21834
|
-
filter.items.forEach((d, i) =>
|
|
21835
|
-
d.id = i;
|
|
21836
|
-
});
|
|
21837
|
-
console.log('filter:', filter);
|
|
21798
|
+
filter.items.forEach((d, i) => d.id = i);
|
|
21838
21799
|
}
|
|
21839
21800
|
onFilterModelChange(filter);
|
|
21840
21801
|
setIsLoading(false);
|
|
21841
21802
|
}
|
|
21842
21803
|
};
|
|
21843
|
-
return /*#__PURE__*/React__default.createElement(
|
|
21804
|
+
return /*#__PURE__*/React__default.createElement(Flexbox, {
|
|
21805
|
+
flexDirection: "column",
|
|
21806
|
+
gap: "0",
|
|
21807
|
+
width: "100%"
|
|
21808
|
+
}, /*#__PURE__*/React__default.createElement(StyledGridToolbarFilterSemanticField, _extends$2({}, forwardedProps, {
|
|
21844
21809
|
className: classNames(GridToolbarFilterSemanticField.className, className),
|
|
21845
21810
|
ref: fieldRef,
|
|
21846
21811
|
onSubmit: handlePromptSubmit
|
|
@@ -21858,13 +21823,14 @@ const GridToolbarFilterSemanticField = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
21858
21823
|
"aria-label": "Submit",
|
|
21859
21824
|
type: "submit",
|
|
21860
21825
|
isLoading: isLoading
|
|
21861
|
-
}, "Run")), /*#__PURE__*/React__default.createElement(Tooltip, null, /*#__PURE__*/React__default.createElement(Tooltip.Trigger, null, /*#__PURE__*/React__default.createElement(Switch
|
|
21862
|
-
// style={{"display":"none"}} // Hide it for the demo
|
|
21863
|
-
, {
|
|
21826
|
+
}, "Run")), /*#__PURE__*/React__default.createElement(Tooltip, null, /*#__PURE__*/React__default.createElement(Tooltip.Trigger, null, /*#__PURE__*/React__default.createElement(Switch, {
|
|
21864
21827
|
width: "175px",
|
|
21865
|
-
isSelected:
|
|
21866
|
-
onChange: value =>
|
|
21867
|
-
}, "Power mode")), /*#__PURE__*/React__default.createElement(Tooltip.Content, null, "The Power mode can get better results but is slower.")))
|
|
21828
|
+
isSelected: modelRef.current === 'gpt-4-0613',
|
|
21829
|
+
onChange: value => modelRef.current = value ? 'gpt-4-0613' : 'gpt-3.5-turbo-0613'
|
|
21830
|
+
}, "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, {
|
|
21831
|
+
color: "error",
|
|
21832
|
+
marginLeft: "8px"
|
|
21833
|
+
}, "Unable to find a valid filter, please try again with a more specific prompt."));
|
|
21868
21834
|
});
|
|
21869
21835
|
GridToolbarFilterSemanticField.className = CLASSNAME$2;
|
|
21870
21836
|
GridToolbarFilterSemanticField.displayName = COMPONENT_NAME$2;
|
|
@@ -21912,7 +21878,7 @@ const Toolbar$2 = props => {
|
|
|
21912
21878
|
let {
|
|
21913
21879
|
apiRef
|
|
21914
21880
|
} = _ref;
|
|
21915
|
-
return
|
|
21881
|
+
return gridVisibleSortedRowIdsSelector(apiRef);
|
|
21916
21882
|
}
|
|
21917
21883
|
},
|
|
21918
21884
|
printOptions: {
|
|
@@ -24367,7 +24333,7 @@ process.env.NODE_ENV !== "production" ? TablePagination.propTypes /* remove-prop
|
|
|
24367
24333
|
} : void 0;
|
|
24368
24334
|
var TablePagination$1 = TablePagination;
|
|
24369
24335
|
|
|
24370
|
-
const _excluded$1 = ["apiRef", "autoHeight", "className", "
|
|
24336
|
+
const _excluded$1 = ["apiRef", "autoHeight", "className", "components", "componentsProps", "filterModel", "height", "hideToolbar", "initialState", "isRowSelectable", "license", "onFilterModelChange", "onPageChange", "onPageSizeChange", "onSelectionModelChange", "page", "pageSize", "pagination", "paginationPlacement", "paginationProps", "rows", "rowsPerPageOptions", "sx"];
|
|
24371
24337
|
const COMPONENT_NAME$1 = 'DataGrid';
|
|
24372
24338
|
const CLASSNAME$1 = 'redsift-datagrid';
|
|
24373
24339
|
const DEFAULT_PROPS = {
|
|
@@ -24396,9 +24362,11 @@ const ControlledPagination = _ref3 => {
|
|
|
24396
24362
|
displayPagination = false,
|
|
24397
24363
|
selectionStatus,
|
|
24398
24364
|
apiRef,
|
|
24399
|
-
|
|
24400
|
-
|
|
24401
|
-
|
|
24365
|
+
page,
|
|
24366
|
+
onPageChange,
|
|
24367
|
+
pageSize,
|
|
24368
|
+
onPageSizeChange,
|
|
24369
|
+
rowsPerPageOptions,
|
|
24402
24370
|
isRowSelectable,
|
|
24403
24371
|
paginationProps
|
|
24404
24372
|
} = _ref3;
|
|
@@ -24428,28 +24396,24 @@ const ControlledPagination = _ref3 => {
|
|
|
24428
24396
|
}, `${selectionStatus.numberOfSelectedRows} row${selectionStatus.numberOfSelectedRows > 1 ? 's' : ''} selected`) : /*#__PURE__*/React__default.createElement(Text, null)) : null, displayPagination ? /*#__PURE__*/React__default.createElement(TablePagination$1, _extends$2({
|
|
24429
24397
|
component: "div",
|
|
24430
24398
|
count: numberOfFilteredRowsInTable,
|
|
24431
|
-
page:
|
|
24432
|
-
onPageChange: (event,
|
|
24433
|
-
|
|
24434
|
-
|
|
24435
|
-
|
|
24436
|
-
|
|
24437
|
-
|
|
24438
|
-
page: paginationModel.page,
|
|
24439
|
-
pageSize: parseInt(event.target.value, 10)
|
|
24440
|
-
}),
|
|
24441
|
-
rowsPerPageOptions: displayRowsPerPage ? pageSizeOptions : []
|
|
24399
|
+
page: page,
|
|
24400
|
+
onPageChange: (event, newPage) => onPageChange(newPage),
|
|
24401
|
+
rowsPerPage: pageSize,
|
|
24402
|
+
onRowsPerPageChange: event => {
|
|
24403
|
+
onPageSizeChange(parseInt(event.target.value, 10));
|
|
24404
|
+
},
|
|
24405
|
+
rowsPerPageOptions: displayRowsPerPage ? rowsPerPageOptions : []
|
|
24442
24406
|
}, paginationProps)) : null);
|
|
24443
24407
|
};
|
|
24444
24408
|
const DataGrid = /*#__PURE__*/forwardRef((props, ref) => {
|
|
24445
|
-
var
|
|
24409
|
+
var _initialState$paginat, _initialState$paginat2;
|
|
24446
24410
|
const datagridRef = ref || useRef();
|
|
24447
24411
|
const {
|
|
24448
24412
|
apiRef: propsApiRef,
|
|
24449
24413
|
autoHeight,
|
|
24450
24414
|
className,
|
|
24451
|
-
|
|
24452
|
-
|
|
24415
|
+
components,
|
|
24416
|
+
componentsProps,
|
|
24453
24417
|
filterModel: propsFilterModel,
|
|
24454
24418
|
height: propsHeight,
|
|
24455
24419
|
hideToolbar,
|
|
@@ -24457,20 +24421,22 @@ const DataGrid = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
24457
24421
|
isRowSelectable,
|
|
24458
24422
|
license,
|
|
24459
24423
|
onFilterModelChange: propsOnFilterModelChange,
|
|
24460
|
-
|
|
24461
|
-
|
|
24462
|
-
|
|
24424
|
+
onPageChange: propsOnPageChange,
|
|
24425
|
+
onPageSizeChange: propsOnPageSizeChange,
|
|
24426
|
+
onSelectionModelChange,
|
|
24427
|
+
page: propsPage,
|
|
24428
|
+
pageSize: propsPageSize,
|
|
24463
24429
|
pagination,
|
|
24464
24430
|
paginationPlacement,
|
|
24465
24431
|
paginationProps,
|
|
24466
24432
|
rows,
|
|
24467
|
-
|
|
24433
|
+
rowsPerPageOptions,
|
|
24468
24434
|
sx
|
|
24469
24435
|
} = props,
|
|
24470
24436
|
forwardedProps = _objectWithoutProperties(props, _excluded$1);
|
|
24471
24437
|
const _apiRef = useGridApiRef();
|
|
24472
24438
|
const apiRef = propsApiRef !== null && propsApiRef !== void 0 ? propsApiRef : _apiRef;
|
|
24473
|
-
const RenderedToolbar =
|
|
24439
|
+
const RenderedToolbar = components !== null && components !== void 0 && components.Toolbar ? components.Toolbar : Toolbar$2;
|
|
24474
24440
|
LicenseInfo.setLicenseKey(license);
|
|
24475
24441
|
const height = propsHeight !== null && propsHeight !== void 0 ? propsHeight : autoHeight ? undefined : '500px';
|
|
24476
24442
|
const selectionStatus = useRef({
|
|
@@ -24488,22 +24454,33 @@ const DataGrid = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
24488
24454
|
setFilterModel(model);
|
|
24489
24455
|
}
|
|
24490
24456
|
};
|
|
24491
|
-
const [
|
|
24492
|
-
|
|
24493
|
-
|
|
24494
|
-
|
|
24495
|
-
|
|
24496
|
-
if (propsOnPaginationModelChange) {
|
|
24497
|
-
propsOnPaginationModelChange(model, undefined);
|
|
24457
|
+
const [page, setPage] = React__default.useState((initialState === null || initialState === void 0 ? void 0 : (_initialState$paginat = initialState.pagination) === null || _initialState$paginat === void 0 ? void 0 : _initialState$paginat.page) || propsPage || 0);
|
|
24458
|
+
const [pageSize, setPageSize] = React__default.useState((initialState === null || initialState === void 0 ? void 0 : (_initialState$paginat2 = initialState.pagination) === null || _initialState$paginat2 === void 0 ? void 0 : _initialState$paginat2.pageSize) || propsPageSize || (rowsPerPageOptions === null || rowsPerPageOptions === void 0 ? void 0 : rowsPerPageOptions[0]) || 100);
|
|
24459
|
+
const onPageChange = page => {
|
|
24460
|
+
if (propsOnPageChange) {
|
|
24461
|
+
propsOnPageChange(page, undefined);
|
|
24498
24462
|
} else {
|
|
24499
|
-
|
|
24463
|
+
setPage(page);
|
|
24500
24464
|
}
|
|
24501
24465
|
};
|
|
24502
24466
|
useEffect(() => {
|
|
24503
|
-
if (
|
|
24504
|
-
|
|
24467
|
+
if (propsPage || propsPage === 0) {
|
|
24468
|
+
setPage(propsPage);
|
|
24469
|
+
}
|
|
24470
|
+
}, [propsPage]);
|
|
24471
|
+
const onPageSizeChange = pageSize => {
|
|
24472
|
+
onPageChange(0);
|
|
24473
|
+
if (propsOnPageSizeChange) {
|
|
24474
|
+
propsOnPageSizeChange(pageSize, undefined);
|
|
24475
|
+
} else {
|
|
24476
|
+
setPageSize(pageSize);
|
|
24505
24477
|
}
|
|
24506
|
-
}
|
|
24478
|
+
};
|
|
24479
|
+
useEffect(() => {
|
|
24480
|
+
if (propsPageSize) {
|
|
24481
|
+
setPageSize(propsPageSize);
|
|
24482
|
+
}
|
|
24483
|
+
}, [propsPageSize]);
|
|
24507
24484
|
if (!Array.isArray(rows)) {
|
|
24508
24485
|
return null;
|
|
24509
24486
|
}
|
|
@@ -24515,46 +24492,46 @@ const DataGrid = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
24515
24492
|
apiRef: apiRef,
|
|
24516
24493
|
autoHeight: autoHeight,
|
|
24517
24494
|
checkboxSelectionVisibleOnly: Boolean(pagination),
|
|
24518
|
-
|
|
24519
|
-
|
|
24520
|
-
|
|
24521
|
-
//
|
|
24522
|
-
|
|
24523
|
-
|
|
24495
|
+
components: _objectSpread2(_objectSpread2({
|
|
24496
|
+
BaseButton,
|
|
24497
|
+
BaseCheckbox,
|
|
24498
|
+
// BaseTextField,
|
|
24499
|
+
BasePopper,
|
|
24500
|
+
ColumnFilteredIcon: props => /*#__PURE__*/React__default.createElement(BaseIcon, _extends$2({}, props, {
|
|
24524
24501
|
displayName: "ColumnFilteredIcon"
|
|
24525
24502
|
})),
|
|
24526
|
-
|
|
24503
|
+
ColumnSelectorIcon: props => /*#__PURE__*/React__default.createElement(BaseIcon, _extends$2({}, props, {
|
|
24527
24504
|
displayName: "ColumnSelectorIcon"
|
|
24528
24505
|
})),
|
|
24529
|
-
|
|
24506
|
+
ColumnSortedAscendingIcon: props => /*#__PURE__*/React__default.createElement(BaseIcon, _extends$2({}, props, {
|
|
24530
24507
|
displayName: "ColumnSortedAscendingIcon"
|
|
24531
24508
|
})),
|
|
24532
|
-
|
|
24509
|
+
ColumnSortedDescendingIcon: props => /*#__PURE__*/React__default.createElement(BaseIcon, _extends$2({}, props, {
|
|
24533
24510
|
displayName: "ColumnSortedDescendingIcon"
|
|
24534
24511
|
})),
|
|
24535
|
-
|
|
24512
|
+
DensityCompactIcon: props => /*#__PURE__*/React__default.createElement(BaseIcon, _extends$2({}, props, {
|
|
24536
24513
|
displayName: "DensityCompactIcon"
|
|
24537
24514
|
})),
|
|
24538
|
-
|
|
24515
|
+
DensityStandardIcon: props => /*#__PURE__*/React__default.createElement(BaseIcon, _extends$2({}, props, {
|
|
24539
24516
|
displayName: "DensityStandardIcon"
|
|
24540
24517
|
})),
|
|
24541
|
-
|
|
24518
|
+
DensityComfortableIcon: props => /*#__PURE__*/React__default.createElement(BaseIcon, _extends$2({}, props, {
|
|
24542
24519
|
displayName: "DensityComfortableIcon"
|
|
24543
24520
|
})),
|
|
24544
|
-
|
|
24521
|
+
DetailPanelCollapseIcon: props => /*#__PURE__*/React__default.createElement(BaseIcon, _extends$2({}, props, {
|
|
24545
24522
|
displayName: "DetailPanelCollapseIcon"
|
|
24546
24523
|
})),
|
|
24547
|
-
|
|
24524
|
+
DetailPanelExpandIcon: props => /*#__PURE__*/React__default.createElement(BaseIcon, _extends$2({}, props, {
|
|
24548
24525
|
displayName: "DetailPanelExpandIcon"
|
|
24549
24526
|
})),
|
|
24550
|
-
|
|
24527
|
+
ExportIcon: props => /*#__PURE__*/React__default.createElement(BaseIcon, _extends$2({}, props, {
|
|
24551
24528
|
displayName: "ExportIcon"
|
|
24552
24529
|
})),
|
|
24553
|
-
|
|
24530
|
+
OpenFilterButtonIcon: props => /*#__PURE__*/React__default.createElement(BaseIcon, _extends$2({
|
|
24554
24531
|
displayName: "OpenFilterButtonIcon"
|
|
24555
24532
|
}, props))
|
|
24556
|
-
},
|
|
24557
|
-
|
|
24533
|
+
}, components), {}, {
|
|
24534
|
+
Toolbar: props => {
|
|
24558
24535
|
return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, !hideToolbar ? /*#__PURE__*/React__default.createElement(RenderedToolbar, _extends$2({}, props, {
|
|
24559
24536
|
filterModel: filterModel,
|
|
24560
24537
|
onFilterModelChange: onFilterModelChange
|
|
@@ -24565,27 +24542,31 @@ const DataGrid = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
24565
24542
|
selectionStatus: selectionStatus.current,
|
|
24566
24543
|
apiRef: apiRef,
|
|
24567
24544
|
isRowSelectable: isRowSelectable,
|
|
24568
|
-
|
|
24569
|
-
|
|
24570
|
-
|
|
24545
|
+
page: page,
|
|
24546
|
+
onPageChange: onPageChange,
|
|
24547
|
+
pageSize: pageSize,
|
|
24548
|
+
onPageSizeChange: onPageSizeChange,
|
|
24549
|
+
rowsPerPageOptions: rowsPerPageOptions,
|
|
24571
24550
|
paginationProps: paginationProps
|
|
24572
24551
|
}) : null);
|
|
24573
24552
|
},
|
|
24574
|
-
|
|
24553
|
+
Pagination: props => pagination ? /*#__PURE__*/React__default.createElement(ControlledPagination, _extends$2({}, props, {
|
|
24575
24554
|
displaySelection: false,
|
|
24576
24555
|
displayRowsPerPage: ['bottom', 'both'].includes(paginationPlacement),
|
|
24577
24556
|
displayPagination: ['bottom', 'both'].includes(paginationPlacement),
|
|
24578
24557
|
selectionStatus: selectionStatus.current,
|
|
24579
24558
|
apiRef: apiRef,
|
|
24580
24559
|
isRowSelectable: isRowSelectable,
|
|
24581
|
-
|
|
24582
|
-
|
|
24583
|
-
|
|
24560
|
+
page: page,
|
|
24561
|
+
onPageChange: onPageChange,
|
|
24562
|
+
pageSize: pageSize,
|
|
24563
|
+
onPageSizeChange: onPageSizeChange,
|
|
24564
|
+
rowsPerPageOptions: rowsPerPageOptions,
|
|
24584
24565
|
paginationProps: paginationProps
|
|
24585
24566
|
})) : null
|
|
24586
24567
|
}),
|
|
24587
|
-
|
|
24588
|
-
toolbar: _objectSpread2({},
|
|
24568
|
+
componentsProps: _objectSpread2(_objectSpread2({}, componentsProps), {}, {
|
|
24569
|
+
toolbar: _objectSpread2({}, componentsProps === null || componentsProps === void 0 ? void 0 : componentsProps.toolbar)
|
|
24589
24570
|
}),
|
|
24590
24571
|
filterModel: filterModel,
|
|
24591
24572
|
initialState: initialState,
|
|
@@ -24593,38 +24574,40 @@ const DataGrid = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
24593
24574
|
onFilterModelChange: onFilterModelChange,
|
|
24594
24575
|
pagination: pagination,
|
|
24595
24576
|
rows: rows,
|
|
24596
|
-
|
|
24597
|
-
|
|
24598
|
-
|
|
24599
|
-
|
|
24577
|
+
rowsPerPageOptions: rowsPerPageOptions,
|
|
24578
|
+
page: page,
|
|
24579
|
+
onPageChange: onPageChange,
|
|
24580
|
+
pageSize: pageSize,
|
|
24581
|
+
onPageSizeChange: onPageSizeChange,
|
|
24582
|
+
onSelectionModelChange: (newSelectionModel, details) => {
|
|
24600
24583
|
if (pagination) {
|
|
24601
|
-
const selectableRowsInPage = props.isRowSelectable && typeof props.isRowSelectable === 'function' ? gridPaginatedVisibleSortedGridRowEntriesSelector(apiRef).filter(
|
|
24584
|
+
const selectableRowsInPage = props.isRowSelectable && typeof props.isRowSelectable === 'function' ? gridPaginatedVisibleSortedGridRowEntriesSelector(apiRef).filter(_ref4 => {
|
|
24602
24585
|
var _props$isRowSelectabl;
|
|
24603
24586
|
let {
|
|
24604
24587
|
model
|
|
24605
|
-
} =
|
|
24588
|
+
} = _ref4;
|
|
24606
24589
|
return (_props$isRowSelectabl = props.isRowSelectable) === null || _props$isRowSelectabl === void 0 ? void 0 : _props$isRowSelectabl.call(props, {
|
|
24607
24590
|
row: model
|
|
24608
24591
|
});
|
|
24609
|
-
}).map(
|
|
24592
|
+
}).map(_ref5 => {
|
|
24610
24593
|
let {
|
|
24611
24594
|
id
|
|
24612
|
-
} =
|
|
24595
|
+
} = _ref5;
|
|
24613
24596
|
return id;
|
|
24614
24597
|
}) : gridPaginatedVisibleSortedGridRowIdsSelector(apiRef);
|
|
24615
24598
|
const numberOfSelectableRowsInPage = selectableRowsInPage.length;
|
|
24616
|
-
const selectableRowsInTable = props.isRowSelectable && typeof props.isRowSelectable === 'function' ? gridFilteredSortedRowEntriesSelector(apiRef).filter(
|
|
24599
|
+
const selectableRowsInTable = props.isRowSelectable && typeof props.isRowSelectable === 'function' ? gridFilteredSortedRowEntriesSelector(apiRef).filter(_ref6 => {
|
|
24617
24600
|
var _props$isRowSelectabl2;
|
|
24618
24601
|
let {
|
|
24619
24602
|
model
|
|
24620
|
-
} =
|
|
24603
|
+
} = _ref6;
|
|
24621
24604
|
return (_props$isRowSelectabl2 = props.isRowSelectable) === null || _props$isRowSelectabl2 === void 0 ? void 0 : _props$isRowSelectabl2.call(props, {
|
|
24622
24605
|
row: model
|
|
24623
24606
|
});
|
|
24624
|
-
}).map(
|
|
24607
|
+
}).map(_ref7 => {
|
|
24625
24608
|
let {
|
|
24626
24609
|
id
|
|
24627
|
-
} =
|
|
24610
|
+
} = _ref7;
|
|
24628
24611
|
return id;
|
|
24629
24612
|
}) : gridFilteredSortedRowIdsSelector(apiRef);
|
|
24630
24613
|
const numberOfSelectableRowsInTable = selectableRowsInTable.length;
|
|
@@ -24656,7 +24639,7 @@ const DataGrid = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
24656
24639
|
};
|
|
24657
24640
|
}
|
|
24658
24641
|
}
|
|
24659
|
-
|
|
24642
|
+
onSelectionModelChange === null || onSelectionModelChange === void 0 ? void 0 : onSelectionModelChange(newSelectionModel, details);
|
|
24660
24643
|
},
|
|
24661
24644
|
sx: _objectSpread2(_objectSpread2({}, sx), {}, {
|
|
24662
24645
|
'.MuiDataGrid-columnHeaders': {
|