@mtes-mct/monitor-ui 5.9.2 → 6.0.0
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/CHANGELOG.md +7 -0
- package/fields/Search.d.ts +5 -4
- package/index.js +36 -170
- package/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [5.9.2](https://github.com/MTES-MCT/monitor-ui/compare/v5.9.1...v5.9.2) (2023-05-10)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **elements:** delete stop click event propagation in Button & IconButton ([b2d70ad](https://github.com/MTES-MCT/monitor-ui/commit/b2d70adf14ce7780b6ef45ff9bbba0d026ac77ef))
|
|
7
|
+
|
|
1
8
|
## [5.9.1](https://github.com/MTES-MCT/monitor-ui/compare/v5.9.0...v5.9.1) (2023-05-05)
|
|
2
9
|
|
|
3
10
|
|
package/fields/Search.d.ts
CHANGED
|
@@ -6,20 +6,21 @@ export type SearchProps<OptionValue extends OptionValueType = string> = Omit<Rsu
|
|
|
6
6
|
MenuItem?: React.ElementType | undefined;
|
|
7
7
|
/** Used to pass something else than `window.document` as a base container to attach global events listeners. */
|
|
8
8
|
baseContainer?: Document | HTMLDivElement | null | undefined;
|
|
9
|
-
defaultValue?: OptionValue | undefined;
|
|
10
9
|
error?: string | undefined;
|
|
11
10
|
isErrorMessageHidden?: boolean | undefined;
|
|
12
11
|
isLabelHidden?: boolean | undefined;
|
|
13
12
|
isLight?: boolean | undefined;
|
|
14
|
-
|
|
13
|
+
isSearchIconVisible?: boolean | undefined;
|
|
15
14
|
label: string;
|
|
16
15
|
name: string;
|
|
17
16
|
onChange?: ((nextValue: OptionValue | undefined) => Promisable<void>) | undefined;
|
|
18
17
|
onQuery?: ((nextQuery: string | undefined) => Promisable<void>) | undefined;
|
|
19
|
-
|
|
18
|
+
optionValueKey?: keyof OptionValue | undefined;
|
|
19
|
+
options?: Option<OptionValue>[];
|
|
20
20
|
queryMap?: ((record: Record<string, any>) => Option<OptionValue>) | undefined;
|
|
21
21
|
queryUrl?: string | undefined;
|
|
22
22
|
/** Duration in milliseconds */
|
|
23
23
|
throttleDuration?: number;
|
|
24
|
+
value?: OptionValue | undefined;
|
|
24
25
|
};
|
|
25
|
-
export declare function Search<OptionValue extends OptionValueType = string>({ baseContainer,
|
|
26
|
+
export declare function Search<OptionValue extends OptionValueType = string>({ baseContainer, error, isErrorMessageHidden, isLabelHidden, isLight, isSearchIconVisible, label, MenuItem, onChange, onQuery, options, optionValueKey, queryMap, queryUrl, throttleDuration, value, ...originalProps }: SearchProps<OptionValue>): JSX.Element;
|
package/index.js
CHANGED
|
@@ -1014,84 +1014,6 @@ _dispatchable(['fantasy-land/map', 'map'], _xmap, function map(fn, functor) {
|
|
|
1014
1014
|
|
|
1015
1015
|
var map$1 = map;
|
|
1016
1016
|
|
|
1017
|
-
/**
|
|
1018
|
-
* Determine if the passed argument is an integer.
|
|
1019
|
-
*
|
|
1020
|
-
* @private
|
|
1021
|
-
* @param {*} n
|
|
1022
|
-
* @category Type
|
|
1023
|
-
* @return {Boolean}
|
|
1024
|
-
*/
|
|
1025
|
-
var _isInteger = Number.isInteger || function _isInteger(n) {
|
|
1026
|
-
return n << 0 === n;
|
|
1027
|
-
};
|
|
1028
|
-
|
|
1029
|
-
/**
|
|
1030
|
-
* Returns the nth element of the given list or string. If n is negative the
|
|
1031
|
-
* element at index length + n is returned.
|
|
1032
|
-
*
|
|
1033
|
-
* @func
|
|
1034
|
-
* @memberOf R
|
|
1035
|
-
* @since v0.1.0
|
|
1036
|
-
* @category List
|
|
1037
|
-
* @sig Number -> [a] -> a | Undefined
|
|
1038
|
-
* @sig Number -> String -> String
|
|
1039
|
-
* @param {Number} offset
|
|
1040
|
-
* @param {*} list
|
|
1041
|
-
* @return {*}
|
|
1042
|
-
* @example
|
|
1043
|
-
*
|
|
1044
|
-
* const list = ['foo', 'bar', 'baz', 'quux'];
|
|
1045
|
-
* R.nth(1, list); //=> 'bar'
|
|
1046
|
-
* R.nth(-1, list); //=> 'quux'
|
|
1047
|
-
* R.nth(-99, list); //=> undefined
|
|
1048
|
-
*
|
|
1049
|
-
* R.nth(2, 'abc'); //=> 'c'
|
|
1050
|
-
* R.nth(3, 'abc'); //=> ''
|
|
1051
|
-
* @symb R.nth(-1, [a, b, c]) = c
|
|
1052
|
-
* @symb R.nth(0, [a, b, c]) = a
|
|
1053
|
-
* @symb R.nth(1, [a, b, c]) = b
|
|
1054
|
-
*/
|
|
1055
|
-
|
|
1056
|
-
var nth =
|
|
1057
|
-
/*#__PURE__*/
|
|
1058
|
-
_curry2(function nth(offset, list) {
|
|
1059
|
-
var idx = offset < 0 ? list.length + offset : offset;
|
|
1060
|
-
return _isString(list) ? list.charAt(idx) : list[idx];
|
|
1061
|
-
});
|
|
1062
|
-
|
|
1063
|
-
/**
|
|
1064
|
-
* Returns a function that when supplied an object returns the indicated
|
|
1065
|
-
* property of that object, if it exists.
|
|
1066
|
-
*
|
|
1067
|
-
* @func
|
|
1068
|
-
* @memberOf R
|
|
1069
|
-
* @since v0.1.0
|
|
1070
|
-
* @category Object
|
|
1071
|
-
* @typedefn Idx = String | Int | Symbol
|
|
1072
|
-
* @sig Idx -> {s: a} -> a | Undefined
|
|
1073
|
-
* @param {String|Number} p The property name or array index
|
|
1074
|
-
* @param {Object} obj The object to query
|
|
1075
|
-
* @return {*} The value at `obj.p`.
|
|
1076
|
-
* @see R.path, R.props, R.pluck, R.project, R.nth
|
|
1077
|
-
* @example
|
|
1078
|
-
*
|
|
1079
|
-
* R.prop('x', {x: 100}); //=> 100
|
|
1080
|
-
* R.prop('x', {}); //=> undefined
|
|
1081
|
-
* R.prop(0, [100]); //=> 100
|
|
1082
|
-
* R.compose(R.inc, R.prop('x'))({ x: 3 }) //=> 4
|
|
1083
|
-
*/
|
|
1084
|
-
|
|
1085
|
-
var prop =
|
|
1086
|
-
/*#__PURE__*/
|
|
1087
|
-
_curry2(function prop(p, obj) {
|
|
1088
|
-
if (obj == null) {
|
|
1089
|
-
return;
|
|
1090
|
-
}
|
|
1091
|
-
|
|
1092
|
-
return _isInteger(p) ? nth(p, obj) : obj[p];
|
|
1093
|
-
});
|
|
1094
|
-
|
|
1095
1017
|
/**
|
|
1096
1018
|
* Returns a single item by iterating through the list, successively calling
|
|
1097
1019
|
* the iterator function and passing it an accumulator value and the current
|
|
@@ -2123,40 +2045,6 @@ _curry2(function mergeDeepRight(lObj, rObj) {
|
|
|
2123
2045
|
|
|
2124
2046
|
var mergeDeepRight$1 = mergeDeepRight;
|
|
2125
2047
|
|
|
2126
|
-
/**
|
|
2127
|
-
* Returns `true` if the specified object property is equal, in
|
|
2128
|
-
* [`R.equals`](#equals) terms, to the given value; `false` otherwise.
|
|
2129
|
-
* You can test multiple properties with [`R.whereEq`](#whereEq).
|
|
2130
|
-
*
|
|
2131
|
-
* @func
|
|
2132
|
-
* @memberOf R
|
|
2133
|
-
* @since v0.1.0
|
|
2134
|
-
* @category Relation
|
|
2135
|
-
* @sig String -> a -> Object -> Boolean
|
|
2136
|
-
* @param {String} name
|
|
2137
|
-
* @param {*} val
|
|
2138
|
-
* @param {*} obj
|
|
2139
|
-
* @return {Boolean}
|
|
2140
|
-
* @see R.whereEq, R.propSatisfies, R.equals
|
|
2141
|
-
* @example
|
|
2142
|
-
*
|
|
2143
|
-
* const abby = {name: 'Abby', age: 7, hair: 'blond'};
|
|
2144
|
-
* const fred = {name: 'Fred', age: 12, hair: 'brown'};
|
|
2145
|
-
* const rusty = {name: 'Rusty', age: 10, hair: 'brown'};
|
|
2146
|
-
* const alois = {name: 'Alois', age: 15, disposition: 'surly'};
|
|
2147
|
-
* const kids = [abby, fred, rusty, alois];
|
|
2148
|
-
* const hasBrownHair = R.propEq('hair', 'brown');
|
|
2149
|
-
* R.filter(hasBrownHair, kids); //=> [fred, rusty]
|
|
2150
|
-
*/
|
|
2151
|
-
|
|
2152
|
-
var propEq =
|
|
2153
|
-
/*#__PURE__*/
|
|
2154
|
-
_curry3(function propEq(name, val, obj) {
|
|
2155
|
-
return equals$1(val, prop(name, obj));
|
|
2156
|
-
});
|
|
2157
|
-
|
|
2158
|
-
var propEq$1 = propEq;
|
|
2159
|
-
|
|
2160
2048
|
const UntypedStyledComponentsThemeProvider = ThemeProvider$1;
|
|
2161
2049
|
function ThemeProvider({ children, theme = {} }) {
|
|
2162
2050
|
const finalTheme = mergeDeepRight$1(THEME, theme);
|
|
@@ -21288,6 +21176,18 @@ function useKey(deps) {
|
|
|
21288
21176
|
return keyRef.current;
|
|
21289
21177
|
}
|
|
21290
21178
|
|
|
21179
|
+
function getRsuiteValueFromOptionValue(optionValue, optionValueKey) {
|
|
21180
|
+
return optionValue !== undefined ? String(optionValueKey ? optionValue[optionValueKey] : optionValue) : undefined;
|
|
21181
|
+
}
|
|
21182
|
+
|
|
21183
|
+
function getRsuiteDataFromOptions(options, optionValueKey) {
|
|
21184
|
+
return options.map(({ value, ...rest }) => ({
|
|
21185
|
+
...rest,
|
|
21186
|
+
optionValue: value,
|
|
21187
|
+
value: getRsuiteValueFromOptionValue(value, optionValueKey)
|
|
21188
|
+
}));
|
|
21189
|
+
}
|
|
21190
|
+
|
|
21291
21191
|
/**
|
|
21292
21192
|
* Trim and single-space a string
|
|
21293
21193
|
*/
|
|
@@ -21306,27 +21206,19 @@ function normalizeString(text) {
|
|
|
21306
21206
|
return cleanText.length > 0 ? cleanText : undefined;
|
|
21307
21207
|
}
|
|
21308
21208
|
|
|
21309
|
-
function Search({ baseContainer,
|
|
21209
|
+
function Search({ baseContainer, error, isErrorMessageHidden = false, isLabelHidden, isLight = false, isSearchIconVisible = true, label, MenuItem, onChange, onQuery, options = [], optionValueKey, queryMap, queryUrl, throttleDuration = 200, value, ...originalProps }) {
|
|
21310
21210
|
// eslint-disable-next-line no-null/no-null
|
|
21311
21211
|
const boxRef = useRef(null);
|
|
21312
21212
|
const queryRef = useRef(undefined);
|
|
21313
|
-
const
|
|
21314
|
-
const [
|
|
21315
|
-
const [autoGeneratedOptions, setAutoGeneratedOptions] = useState([]);
|
|
21316
|
-
const [controlledDefaultValue, setDefaultControlledValue] = useState(defaultValue);
|
|
21213
|
+
const data = useMemo(() => getRsuiteDataFromOptions(options, optionValueKey), [options, optionValueKey]);
|
|
21214
|
+
const [formattedOptions, setFormattedOptions] = useState(data);
|
|
21317
21215
|
const [isOpen, setIsOpen] = useState(false);
|
|
21318
21216
|
const { forceUpdate } = useForceUpdate();
|
|
21319
21217
|
const controlledError = useMemo(() => normalizeString(error), [error]);
|
|
21320
|
-
const controlledOptions = useMemo(() => options ?? autoGeneratedOptions, [autoGeneratedOptions, options]);
|
|
21321
|
-
const controlledValueAsLabel = useMemo(() => {
|
|
21322
|
-
if (originalProps.disabled) {
|
|
21323
|
-
return undefined;
|
|
21324
|
-
}
|
|
21325
|
-
const foundOption = controlledOptions.find(propEq$1('value', controlledDefaultValue));
|
|
21326
|
-
return foundOption ? foundOption.label : undefined;
|
|
21327
|
-
}, [controlledDefaultValue, controlledOptions, originalProps.disabled]);
|
|
21328
21218
|
const hasError = useMemo(() => Boolean(controlledError), [controlledError]);
|
|
21329
|
-
const key = useKey([
|
|
21219
|
+
const key = useKey([value, originalProps.disabled, originalProps.name]);
|
|
21220
|
+
const rsuiteValue = useMemo(() => getRsuiteValueFromOptionValue(value, optionValueKey), [value, optionValueKey]);
|
|
21221
|
+
const [inputValue, setInputValue] = useState(rsuiteValue);
|
|
21330
21222
|
const close = useCallback(() => {
|
|
21331
21223
|
setIsOpen(false);
|
|
21332
21224
|
}, []);
|
|
@@ -21339,61 +21231,51 @@ function Search({ baseContainer, defaultValue, error, isErrorMessageHidden = fal
|
|
|
21339
21231
|
const rawData = await ky$1.get(url).json();
|
|
21340
21232
|
return rawData.map(_queryMap);
|
|
21341
21233
|
}, throttleDuration);
|
|
21342
|
-
const handleChange = useCallback(async (nextQuery) => {
|
|
21234
|
+
const handleChange = useCallback(async (nextQuery, event) => {
|
|
21343
21235
|
if (!(typeof nextQuery === 'string')) {
|
|
21344
21236
|
return;
|
|
21345
21237
|
}
|
|
21346
|
-
setInputValue(nextQuery);
|
|
21347
21238
|
queryRef.current = normalizeString(nextQuery);
|
|
21239
|
+
if (event.type === 'change') {
|
|
21240
|
+
setInputValue(nextQuery);
|
|
21241
|
+
setIsOpen(Boolean(queryRef.current));
|
|
21242
|
+
}
|
|
21243
|
+
else {
|
|
21244
|
+
setIsOpen(false);
|
|
21245
|
+
}
|
|
21348
21246
|
if (queryUrl && queryMap && queryRef.current) {
|
|
21349
21247
|
const nextData = (await fetchQueryResponse(queryRef.current, queryUrl, queryMap)) || [];
|
|
21350
|
-
|
|
21248
|
+
setFormattedOptions(getRsuiteDataFromOptions(nextData, optionValueKey));
|
|
21351
21249
|
}
|
|
21352
|
-
setIsOpen(Boolean(queryRef.current));
|
|
21353
21250
|
if (onChange && !queryRef.current) {
|
|
21354
21251
|
onChange(undefined);
|
|
21355
21252
|
}
|
|
21356
21253
|
if (onQuery) {
|
|
21357
21254
|
onQuery(queryRef.current);
|
|
21358
21255
|
}
|
|
21359
|
-
}, [onChange, onQuery, queryMap, queryUrl, fetchQueryResponse]);
|
|
21360
|
-
const handleSelect = useCallback((
|
|
21256
|
+
}, [onChange, onQuery, queryMap, queryUrl, fetchQueryResponse, optionValueKey]);
|
|
21257
|
+
const handleSelect = useCallback((_, item) => {
|
|
21361
21258
|
if (onChange) {
|
|
21362
|
-
onChange(
|
|
21259
|
+
onChange(item.optionValue);
|
|
21363
21260
|
}
|
|
21364
|
-
|
|
21261
|
+
setInputValue(item.label);
|
|
21365
21262
|
}, [onChange]);
|
|
21366
|
-
const open = useCallback(() => {
|
|
21367
|
-
if (!queryRef.current) {
|
|
21368
|
-
return;
|
|
21369
|
-
}
|
|
21370
|
-
setIsOpen(true);
|
|
21371
|
-
}, []);
|
|
21372
|
-
useEffect(() => {
|
|
21373
|
-
if (defaultValue === prevDefaultValuePropRef.current) {
|
|
21374
|
-
return;
|
|
21375
|
-
}
|
|
21376
|
-
setDefaultControlledValue(defaultValue);
|
|
21377
|
-
}, [defaultValue]);
|
|
21378
21263
|
useFieldUndefineEffect(originalProps.disabled, onChange);
|
|
21379
21264
|
useClickOutsideEffect(boxRef, close, baseContainer);
|
|
21380
21265
|
useEffect(() => {
|
|
21381
21266
|
forceUpdate();
|
|
21382
21267
|
}, [forceUpdate]);
|
|
21383
|
-
return (jsxs(Field$2, { className: "Field-Search", children: [jsx(Label, { disabled: originalProps.disabled, hasError: hasError, htmlFor: originalProps.name, isHidden: isLabelHidden, children: label }), jsxs(Box$c, { ref: boxRef, isLight: isLight,
|
|
21268
|
+
return (jsxs(Field$2, { className: "Field-Search", children: [jsx(Label, { disabled: originalProps.disabled, hasError: hasError, htmlFor: originalProps.name, isHidden: isLabelHidden, children: label }), jsxs(Box$c, { ref: boxRef, isLight: isLight, children: [boxRef.current && (jsx(StyledAutoComplete, { "$isLight": isLight, container: boxRef.current, data: formattedOptions, id: originalProps.name, onChange: handleChange, onSelect: handleSelect, open: isOpen, renderMenuItem: (itemLabel, item) => MenuItem ? jsx(MenuItem, { item: item.value }) : itemLabel, value: inputValue, ...originalProps }, key)), inputValue && (jsxs(Fragment, { children: [jsx(StyledCloseButton, { accent: Accent.TERTIARY, color: THEME.color.slateGray, Icon: Close, isSearchIconVisible: isSearchIconVisible, onClick: clean, size: Size.SMALL }), isSearchIconVisible && jsx(Separator, { children: "|" })] })), isSearchIconVisible && jsx(StyledIconSearch, { color: THEME.color.slateGray, size: 20 })] }), !isErrorMessageHidden && hasError && jsx(FieldError, { children: controlledError })] }));
|
|
21384
21269
|
}
|
|
21385
21270
|
const StyledCloseButton = styled(IconButton) `
|
|
21386
21271
|
cursor: pointer;
|
|
21387
21272
|
height: 30px;
|
|
21388
|
-
margin: 5px ${p => (p.
|
|
21273
|
+
margin: 5px ${p => (p.isSearchIconVisible ? 0 : 5)}px 5px 5px;
|
|
21389
21274
|
padding: 8px;
|
|
21390
21275
|
width: 30px;
|
|
21391
21276
|
`;
|
|
21392
|
-
const
|
|
21393
|
-
border: unset;
|
|
21394
|
-
cursor: pointer;
|
|
21277
|
+
const StyledIconSearch = styled(Search$1) `
|
|
21395
21278
|
margin: 10px 10px 10px 8px;
|
|
21396
|
-
padding: 0px;
|
|
21397
21279
|
`;
|
|
21398
21280
|
const Separator = styled.div `
|
|
21399
21281
|
height: 40px;
|
|
@@ -21410,6 +21292,7 @@ const StyledAutoComplete = styled(AutoComplete) `
|
|
|
21410
21292
|
background-color: ${p => (p.$isLight ? p.theme.color.white : p.theme.color.gainsboro)};
|
|
21411
21293
|
border-width: 0 0 1px;
|
|
21412
21294
|
border-color: ${p => (p.$isLight ? p.theme.color.white : p.theme.color.gainsboro)};
|
|
21295
|
+
|
|
21413
21296
|
font-size: 13px;
|
|
21414
21297
|
width: 100%;
|
|
21415
21298
|
height: 40px;
|
|
@@ -22971,18 +22854,6 @@ const ChecboxesBox = styled.div `
|
|
|
22971
22854
|
`}
|
|
22972
22855
|
`;
|
|
22973
22856
|
|
|
22974
|
-
function getRsuiteValueFromOptionValue(optionValue, optionValueKey) {
|
|
22975
|
-
return optionValue !== undefined ? String(optionValueKey ? optionValue[optionValueKey] : optionValue) : undefined;
|
|
22976
|
-
}
|
|
22977
|
-
|
|
22978
|
-
function getRsuiteDataFromOptions(options, optionValueKey) {
|
|
22979
|
-
return options.map(({ value, ...rest }) => ({
|
|
22980
|
-
...rest,
|
|
22981
|
-
optionValue: value,
|
|
22982
|
-
value: getRsuiteValueFromOptionValue(value, optionValueKey)
|
|
22983
|
-
}));
|
|
22984
|
-
}
|
|
22985
|
-
|
|
22986
22857
|
function MultiSelect({ baseContainer, disabled = false, error, isErrorMessageHidden = false, isLabelHidden = false, isLight = false, isUndefinedWhenDisabled = false, label, onChange, options, optionValueKey, searchable = false, value, ...originalProps }) {
|
|
22987
22858
|
// eslint-disable-next-line no-null/no-null
|
|
22988
22859
|
const boxRef = useRef(null);
|
|
@@ -32390,13 +32261,8 @@ const StyledInput = styled(Input) `
|
|
|
32390
32261
|
function FormikSearch({ name, ...originalProps }) {
|
|
32391
32262
|
const [field, meta, helpers] = useField(name);
|
|
32392
32263
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
32393
|
-
const defaultValue = useMemo(() => field.value, []);
|
|
32394
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
32395
32264
|
const handleChange = useMemo(() => helpers.setValue, []);
|
|
32396
|
-
|
|
32397
|
-
return jsx(Search, { name: name, onChange: helpers.setValue, ...originalProps });
|
|
32398
|
-
}
|
|
32399
|
-
return (jsx(Search, { defaultValue: defaultValue, error: meta.error, name: name, onChange: handleChange, ...originalProps }));
|
|
32265
|
+
return jsx(Search, { error: meta.error, name: name, onChange: handleChange, value: field.value, ...originalProps });
|
|
32400
32266
|
}
|
|
32401
32267
|
|
|
32402
32268
|
function FormikCheckbox({ name, ...originalProps }) {
|