@centreon/ui 23.10.1-MON-20802-fe-implement-new-visualization.7 → 23.10.1-MON-20803-RS-add-basic-filter.4
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/package.json +1 -1
- package/src/Dashboard/Dashboard.styles.ts +1 -6
- package/src/Dashboard/Item.tsx +1 -4
- package/src/Dashboard/Layout.tsx +1 -1
- package/src/Graph/Gauge/Gauge.stories.tsx +0 -10
- package/src/Graph/Gauge/Gauge.tsx +1 -10
- package/src/Graph/Gauge/PieData.tsx +8 -8
- package/src/Graph/Gauge/ResponsiveGauge.tsx +23 -32
- package/src/Graph/Gauge/Thresholds.tsx +25 -2
- package/src/Graph/Gauge/models.ts +0 -1
- package/src/Graph/SingleBar/ResponsiveSingleBar.tsx +23 -41
- package/src/Graph/SingleBar/SingleBar.stories.tsx +0 -46
- package/src/Graph/SingleBar/ThresholdLine.tsx +12 -41
- package/src/Graph/SingleBar/Thresholds.tsx +1 -5
- package/src/Graph/SingleBar/models.ts +0 -4
- package/src/Graph/Text/Text.stories.tsx +0 -13
- package/src/Graph/Text/Text.tsx +12 -19
- package/src/Graph/common/timeSeries/index.test.ts +3 -106
- package/src/Graph/common/timeSeries/index.ts +4 -67
- package/src/Graph/common/timeSeries/models.ts +3 -6
- package/src/Graph/common/utils.ts +2 -4
- package/src/InputField/Select/Autocomplete/Multi/index.tsx +2 -4
- package/src/InputField/Select/Autocomplete/index.tsx +1 -4
- package/src/InputField/Text/index.tsx +7 -10
- package/src/Listing/Cell/DataCell.tsx +1 -1
- package/src/Listing/Cell/index.tsx +2 -2
- package/src/RichTextEditor/ContentEditable.tsx +1 -0
- package/src/RichTextEditor/RichTextEditor.cypress.spec.tsx +13 -5
- package/src/RichTextEditor/RichTextEditor.tsx +2 -5
- package/src/RichTextEditor/plugins/AutoLinkPlugin/index.tsx +1 -40
- package/src/RichTextEditor/plugins/FloatingLinkEditorPlugin.tsx +8 -33
- package/src/RichTextEditor/plugins/ToolbarPlugin/index.tsx +4 -10
- package/src/ThemeProvider/index.tsx +4 -6
- package/src/api/buildListingEndpoint/getSearchQueryParameterValue.ts +2 -4
- package/src/api/buildListingEndpoint/index.ts +1 -1
- package/src/api/useFetchQuery/index.ts +8 -10
- package/src/components/Modal/Modal.styles.ts +1 -3
- package/src/components/index.ts +0 -1
- package/src/index.ts +4 -1
- package/src/utils/index.ts +0 -1
- package/src/utils/useDebounce.ts +7 -2
- package/src/components/Inputs/Switch/Switch.stories.tsx +0 -22
- package/src/components/Inputs/Switch/Switch.styles.ts +0 -13
- package/src/components/Inputs/Switch/Switch.tsx +0 -18
- package/src/components/Inputs/index.ts +0 -1
- package/src/utils/centreonBaseURL.ts +0 -4
package/src/Graph/Text/Text.tsx
CHANGED
|
@@ -4,7 +4,7 @@ import { Typography, useTheme } from '@mui/material';
|
|
|
4
4
|
|
|
5
5
|
import { LineChartData, Thresholds } from '../common/models';
|
|
6
6
|
import {
|
|
7
|
-
|
|
7
|
+
formatMetricValue,
|
|
8
8
|
getMetricWithLatestData
|
|
9
9
|
} from '../common/timeSeries';
|
|
10
10
|
import { getColorFromDataAndTresholds } from '../common/utils';
|
|
@@ -12,9 +12,7 @@ import { getColorFromDataAndTresholds } from '../common/utils';
|
|
|
12
12
|
import { useTextStyles } from './Text.styles';
|
|
13
13
|
|
|
14
14
|
interface Props {
|
|
15
|
-
baseColor?: string;
|
|
16
15
|
data?: LineChartData;
|
|
17
|
-
displayAsRaw?: boolean;
|
|
18
16
|
labels: {
|
|
19
17
|
critical: string;
|
|
20
18
|
warning: string;
|
|
@@ -25,9 +23,7 @@ interface Props {
|
|
|
25
23
|
export const Text = ({
|
|
26
24
|
thresholds,
|
|
27
25
|
data,
|
|
28
|
-
|
|
29
|
-
labels,
|
|
30
|
-
baseColor
|
|
26
|
+
labels
|
|
31
27
|
}: Props): JSX.Element | null => {
|
|
32
28
|
const theme = useTheme();
|
|
33
29
|
const { classes } = useTextStyles();
|
|
@@ -41,21 +37,20 @@ export const Text = ({
|
|
|
41
37
|
const metricUnit = metric?.unit ?? '';
|
|
42
38
|
|
|
43
39
|
const color = getColorFromDataAndTresholds({
|
|
44
|
-
baseColor,
|
|
45
40
|
data: metricValue,
|
|
46
41
|
theme,
|
|
47
42
|
thresholds
|
|
48
43
|
});
|
|
49
44
|
|
|
50
45
|
const warningThresholdLabels = thresholds.warning.map(({ value }) =>
|
|
51
|
-
|
|
46
|
+
formatMetricValue({
|
|
52
47
|
unit: metricUnit,
|
|
53
48
|
value
|
|
54
49
|
})
|
|
55
50
|
);
|
|
56
51
|
|
|
57
52
|
const criticalThresholdLabels = thresholds.critical.map(({ value }) =>
|
|
58
|
-
|
|
53
|
+
formatMetricValue({
|
|
59
54
|
unit: metricUnit,
|
|
60
55
|
value
|
|
61
56
|
})
|
|
@@ -63,26 +58,24 @@ export const Text = ({
|
|
|
63
58
|
|
|
64
59
|
return (
|
|
65
60
|
<div className={classes.graphText}>
|
|
66
|
-
<Typography sx={{ color }} variant="
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
})}
|
|
73
|
-
</strong>
|
|
61
|
+
<Typography sx={{ color }} variant="h3">
|
|
62
|
+
{formatMetricValue({
|
|
63
|
+
unit: metricUnit,
|
|
64
|
+
value: metricValue
|
|
65
|
+
})}{' '}
|
|
66
|
+
{metricUnit}
|
|
74
67
|
</Typography>
|
|
75
68
|
{thresholds.enabled && (
|
|
76
69
|
<div className={classes.thresholds}>
|
|
77
70
|
<Typography sx={{ color: 'warning.main' }} variant="h5">
|
|
78
71
|
{labels.warning}
|
|
79
72
|
{': '}
|
|
80
|
-
{warningThresholdLabels.join(' - ')}
|
|
73
|
+
{warningThresholdLabels.join(' - ')} {metricUnit}
|
|
81
74
|
</Typography>
|
|
82
75
|
<Typography sx={{ color: 'error.main' }} variant="h5">
|
|
83
76
|
{labels.critical}
|
|
84
77
|
{': '}
|
|
85
|
-
{criticalThresholdLabels.join(' - ')}
|
|
78
|
+
{criticalThresholdLabels.join(' - ')} {metricUnit}
|
|
86
79
|
</Typography>
|
|
87
80
|
</div>
|
|
88
81
|
)}
|
|
@@ -335,10 +335,10 @@ describe('timeSeries', () => {
|
|
|
335
335
|
describe(timeSeries.formatMetricValue, () => {
|
|
336
336
|
const cases: Array<TestCase> = [
|
|
337
337
|
[218857269, '', 1000, '218.86m'],
|
|
338
|
-
[218857269, '', 1024, '208.
|
|
338
|
+
[218857269, '', 1024, '208.72M'],
|
|
339
339
|
[0.12232323445, '', 1000, '0.12'],
|
|
340
|
-
[1024, 'B', 1000, '
|
|
341
|
-
[1024, 'B', 1024, '
|
|
340
|
+
[1024, 'B', 1000, '1K'],
|
|
341
|
+
[1024, 'B', 1024, '1K'],
|
|
342
342
|
[null, 'B', 1024, null]
|
|
343
343
|
];
|
|
344
344
|
|
|
@@ -504,106 +504,3 @@ describe('timeSeries', () => {
|
|
|
504
504
|
});
|
|
505
505
|
});
|
|
506
506
|
});
|
|
507
|
-
|
|
508
|
-
describe('Format value with unit', () => {
|
|
509
|
-
const units = [
|
|
510
|
-
'B',
|
|
511
|
-
'bytes',
|
|
512
|
-
'bytespersecond',
|
|
513
|
-
'B/s',
|
|
514
|
-
'B/sec',
|
|
515
|
-
'o',
|
|
516
|
-
'octets',
|
|
517
|
-
'b/s',
|
|
518
|
-
'b',
|
|
519
|
-
'ms',
|
|
520
|
-
'%',
|
|
521
|
-
''
|
|
522
|
-
];
|
|
523
|
-
|
|
524
|
-
const getExpectedResult = (unit): string => {
|
|
525
|
-
if (unit === '') {
|
|
526
|
-
return '324.23m';
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
return `309.21 M${unit}`;
|
|
530
|
-
};
|
|
531
|
-
|
|
532
|
-
const humanReadableTestCases = units.map((unit) => {
|
|
533
|
-
if (unit === '%') {
|
|
534
|
-
return {
|
|
535
|
-
expectedResult: '45.56%',
|
|
536
|
-
unit,
|
|
537
|
-
value: 45.55678
|
|
538
|
-
};
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
if (unit === 'ms') {
|
|
542
|
-
return {
|
|
543
|
-
expectedResult: '34.23 seconds',
|
|
544
|
-
unit,
|
|
545
|
-
value: 34232
|
|
546
|
-
};
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
return {
|
|
550
|
-
expectedResult: getExpectedResult(unit),
|
|
551
|
-
unit,
|
|
552
|
-
value: 324234232.34233
|
|
553
|
-
};
|
|
554
|
-
});
|
|
555
|
-
|
|
556
|
-
const rawTestCases = units.map((unit) => {
|
|
557
|
-
if (unit === '%') {
|
|
558
|
-
return {
|
|
559
|
-
expectedResult: '45.55678%',
|
|
560
|
-
unit,
|
|
561
|
-
value: 45.55678
|
|
562
|
-
};
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
if (unit === 'ms') {
|
|
566
|
-
return {
|
|
567
|
-
expectedResult: '34232 ms',
|
|
568
|
-
unit,
|
|
569
|
-
value: 34232
|
|
570
|
-
};
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
return {
|
|
574
|
-
expectedResult:
|
|
575
|
-
unit === '' ? '324234232.34233 ' : `324234232.34233 ${unit}`,
|
|
576
|
-
unit,
|
|
577
|
-
value: 324234232.34233
|
|
578
|
-
};
|
|
579
|
-
});
|
|
580
|
-
|
|
581
|
-
describe('Format the value as human readable', () => {
|
|
582
|
-
it.each(humanReadableTestCases)(
|
|
583
|
-
'formats the value with $unit',
|
|
584
|
-
({ value, unit, expectedResult }) => {
|
|
585
|
-
expect(
|
|
586
|
-
timeSeries.formatMetricValueWithUnit({
|
|
587
|
-
unit,
|
|
588
|
-
value
|
|
589
|
-
})
|
|
590
|
-
).toEqual(expectedResult);
|
|
591
|
-
}
|
|
592
|
-
);
|
|
593
|
-
});
|
|
594
|
-
|
|
595
|
-
describe('Format the value as raw', () => {
|
|
596
|
-
it.each(rawTestCases)(
|
|
597
|
-
'formats the value with $unit',
|
|
598
|
-
({ value, unit, expectedResult }) => {
|
|
599
|
-
expect(
|
|
600
|
-
timeSeries.formatMetricValueWithUnit({
|
|
601
|
-
isRaw: true,
|
|
602
|
-
unit,
|
|
603
|
-
value
|
|
604
|
-
})
|
|
605
|
-
).toEqual(expectedResult);
|
|
606
|
-
}
|
|
607
|
-
);
|
|
608
|
-
});
|
|
609
|
-
});
|
|
@@ -28,10 +28,7 @@ import {
|
|
|
28
28
|
lt,
|
|
29
29
|
identity,
|
|
30
30
|
head,
|
|
31
|
-
last
|
|
32
|
-
cond,
|
|
33
|
-
always,
|
|
34
|
-
T
|
|
31
|
+
last
|
|
35
32
|
} from 'ramda';
|
|
36
33
|
|
|
37
34
|
import { margin } from '../../LineChart/common';
|
|
@@ -443,37 +440,6 @@ const getRightScale = ({
|
|
|
443
440
|
});
|
|
444
441
|
};
|
|
445
442
|
|
|
446
|
-
const formatTime = (value: number): string => {
|
|
447
|
-
if (value < 1000) {
|
|
448
|
-
return `${numeral(value).format('0.[00]a')} ms`;
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
const t = numeral(value / 1000).format('0.[00]a');
|
|
452
|
-
|
|
453
|
-
return `${t} seconds`;
|
|
454
|
-
};
|
|
455
|
-
|
|
456
|
-
const registerMsUnitToNumeral = (): null => {
|
|
457
|
-
try {
|
|
458
|
-
numeral.register('format', 'milliseconds', {
|
|
459
|
-
format: (value) => {
|
|
460
|
-
return formatTime(value);
|
|
461
|
-
},
|
|
462
|
-
regexps: {
|
|
463
|
-
format: /(ms)/,
|
|
464
|
-
unformat: /(ms)/
|
|
465
|
-
},
|
|
466
|
-
unformat: () => ''
|
|
467
|
-
});
|
|
468
|
-
|
|
469
|
-
return null;
|
|
470
|
-
} catch (_) {
|
|
471
|
-
return null;
|
|
472
|
-
}
|
|
473
|
-
};
|
|
474
|
-
|
|
475
|
-
registerMsUnitToNumeral();
|
|
476
|
-
|
|
477
443
|
const formatMetricValue = ({
|
|
478
444
|
value,
|
|
479
445
|
unit,
|
|
@@ -497,14 +463,11 @@ const formatMetricValue = ({
|
|
|
497
463
|
|
|
498
464
|
const base1024 = base2Units.includes(unit) || Number(base) === 1024;
|
|
499
465
|
|
|
500
|
-
const formatSuffix =
|
|
501
|
-
[equals('ms'), always(' ms')],
|
|
502
|
-
[T, always(base1024 ? ' ib' : 'a')]
|
|
503
|
-
])(unit);
|
|
466
|
+
const formatSuffix = base1024 ? ' ib' : 'a';
|
|
504
467
|
|
|
505
468
|
const formattedMetricValue = numeral(Math.abs(value))
|
|
506
469
|
.format(`0.[00]${formatSuffix}`)
|
|
507
|
-
.replace(/
|
|
470
|
+
.replace(/\s|i|B/g, '');
|
|
508
471
|
|
|
509
472
|
if (lt(value, 0)) {
|
|
510
473
|
return `-${formattedMetricValue}`;
|
|
@@ -513,31 +476,6 @@ const formatMetricValue = ({
|
|
|
513
476
|
return formattedMetricValue;
|
|
514
477
|
};
|
|
515
478
|
|
|
516
|
-
const formatMetricValueWithUnit = ({
|
|
517
|
-
value,
|
|
518
|
-
unit,
|
|
519
|
-
base = 1000,
|
|
520
|
-
isRaw = false
|
|
521
|
-
}: FormatMetricValueProps & { isRaw?: boolean }): string | null => {
|
|
522
|
-
if (isNil(value)) {
|
|
523
|
-
return null;
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
if (isRaw) {
|
|
527
|
-
const unitText = equals('%', unit) ? unit : ` ${unit}`;
|
|
528
|
-
|
|
529
|
-
return `${value}${unitText}`;
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
if (equals('%', unit)) {
|
|
533
|
-
return `${numeral(Math.abs(value)).format('0.[00]')}%`;
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
const formattedMetricValue = formatMetricValue({ base, unit, value });
|
|
537
|
-
|
|
538
|
-
return formattedMetricValue;
|
|
539
|
-
};
|
|
540
|
-
|
|
541
479
|
const getStackedYScale = ({
|
|
542
480
|
leftScale,
|
|
543
481
|
rightScale
|
|
@@ -619,6 +557,5 @@ export {
|
|
|
619
557
|
getStackedYScale,
|
|
620
558
|
getTimeValue,
|
|
621
559
|
bisectDate,
|
|
622
|
-
getMetricWithLatestData
|
|
623
|
-
formatMetricValueWithUnit
|
|
560
|
+
getMetricWithLatestData
|
|
624
561
|
};
|
|
@@ -14,17 +14,14 @@ interface DsData {
|
|
|
14
14
|
export interface Metric {
|
|
15
15
|
average_value: number | null;
|
|
16
16
|
crit: number | null;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
data: Array<number | null>;
|
|
20
|
-
ds_data?: DsData;
|
|
17
|
+
data: Array<number>;
|
|
18
|
+
ds_data: DsData;
|
|
21
19
|
legend: string;
|
|
22
20
|
maximum_value: number | null;
|
|
23
21
|
metric: string;
|
|
24
22
|
minimum_value: number | null;
|
|
25
23
|
unit: string;
|
|
26
|
-
|
|
27
|
-
warning_low_threshold: number | null;
|
|
24
|
+
warn: number | null;
|
|
28
25
|
}
|
|
29
26
|
|
|
30
27
|
type TimeSeries = { timeTick: string };
|
|
@@ -17,7 +17,6 @@ import { Theme } from '@mui/material';
|
|
|
17
17
|
import { Thresholds } from './models';
|
|
18
18
|
|
|
19
19
|
interface GetColorFromDataAndThresholdsProps {
|
|
20
|
-
baseColor?: string;
|
|
21
20
|
data: number;
|
|
22
21
|
theme: Theme;
|
|
23
22
|
thresholds: Thresholds;
|
|
@@ -26,11 +25,10 @@ interface GetColorFromDataAndThresholdsProps {
|
|
|
26
25
|
export const getColorFromDataAndTresholds = ({
|
|
27
26
|
data,
|
|
28
27
|
thresholds,
|
|
29
|
-
theme
|
|
30
|
-
baseColor
|
|
28
|
+
theme
|
|
31
29
|
}: GetColorFromDataAndThresholdsProps): string => {
|
|
32
30
|
if (!thresholds.enabled) {
|
|
33
|
-
return
|
|
31
|
+
return theme.palette.success.main;
|
|
34
32
|
}
|
|
35
33
|
|
|
36
34
|
const criticalValues = pluck('value', thresholds.critical).sort();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { includes, map, prop, reject } from 'ramda';
|
|
2
2
|
import { makeStyles } from 'tss-react/mui';
|
|
3
3
|
|
|
4
|
-
import { Chip
|
|
4
|
+
import { Chip } from '@mui/material';
|
|
5
5
|
import { UseAutocompleteProps } from '@mui/material/useAutocomplete';
|
|
6
6
|
|
|
7
7
|
import Autocomplete, { Props as AutocompleteProps } from '..';
|
|
@@ -18,6 +18,7 @@ const useStyles = makeStyles()((theme) => ({
|
|
|
18
18
|
width: theme.spacing(1.5)
|
|
19
19
|
},
|
|
20
20
|
tag: {
|
|
21
|
+
backgroundColor: theme.palette.divider,
|
|
21
22
|
fontSize: theme.typography.caption.fontSize
|
|
22
23
|
}
|
|
23
24
|
}));
|
|
@@ -32,7 +33,6 @@ export interface Props
|
|
|
32
33
|
UseAutocompleteProps<SelectEntry, Multiple, DisableClearable, FreeSolo>,
|
|
33
34
|
'multiple'
|
|
34
35
|
> {
|
|
35
|
-
chipProps?: ChipProps;
|
|
36
36
|
disableSortedOptions?: boolean;
|
|
37
37
|
getTagLabel?: (option) => string;
|
|
38
38
|
optionProperty?: string;
|
|
@@ -45,7 +45,6 @@ const MultiAutocompleteField = ({
|
|
|
45
45
|
optionProperty = 'name',
|
|
46
46
|
getOptionLabel = (option): string => option.name,
|
|
47
47
|
getTagLabel = (option): string => option[optionProperty],
|
|
48
|
-
chipProps,
|
|
49
48
|
...props
|
|
50
49
|
}: Props): JSX.Element => {
|
|
51
50
|
const { classes } = useStyles();
|
|
@@ -61,7 +60,6 @@ const MultiAutocompleteField = ({
|
|
|
61
60
|
label={getTagLabel(option)}
|
|
62
61
|
size="medium"
|
|
63
62
|
{...getTagProps({ index })}
|
|
64
|
-
{...chipProps}
|
|
65
63
|
/>
|
|
66
64
|
));
|
|
67
65
|
|
|
@@ -32,7 +32,6 @@ export type Props = {
|
|
|
32
32
|
displayPopupIcon?: boolean;
|
|
33
33
|
endAdornment?: React.ReactElement;
|
|
34
34
|
error?: string;
|
|
35
|
-
getOptionItemLabel?: (option) => string;
|
|
36
35
|
hideInput?: boolean;
|
|
37
36
|
label: string;
|
|
38
37
|
loading?: boolean;
|
|
@@ -159,7 +158,6 @@ const AutocompleteField = ({
|
|
|
159
158
|
autoSize = false,
|
|
160
159
|
autoSizeDefaultWidth = 0,
|
|
161
160
|
autoSizeCustomPadding,
|
|
162
|
-
getOptionItemLabel = (option) => option.name,
|
|
163
161
|
...autocompleteProps
|
|
164
162
|
}: Props): JSX.Element => {
|
|
165
163
|
const { classes, cx } = useStyles({ hideInput });
|
|
@@ -195,7 +193,6 @@ const AutocompleteField = ({
|
|
|
195
193
|
</>
|
|
196
194
|
),
|
|
197
195
|
style: {
|
|
198
|
-
background: 'transparent',
|
|
199
196
|
paddingRight: theme.spacing(5)
|
|
200
197
|
}
|
|
201
198
|
}}
|
|
@@ -252,7 +249,7 @@ const AutocompleteField = ({
|
|
|
252
249
|
<Option
|
|
253
250
|
thumbnailUrl={displayOptionThumbnail ? option.url : undefined}
|
|
254
251
|
>
|
|
255
|
-
{
|
|
252
|
+
{option.name}
|
|
256
253
|
</Option>
|
|
257
254
|
</li>
|
|
258
255
|
);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { forwardRef, useCallback } from 'react';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { isNil } from 'ramda';
|
|
4
4
|
import { makeStyles } from 'tss-react/mui';
|
|
5
5
|
|
|
6
6
|
import {
|
|
@@ -9,8 +9,7 @@ import {
|
|
|
9
9
|
TextFieldProps,
|
|
10
10
|
Theme,
|
|
11
11
|
Tooltip,
|
|
12
|
-
Typography
|
|
13
|
-
Box
|
|
12
|
+
Typography
|
|
14
13
|
} from '@mui/material';
|
|
15
14
|
|
|
16
15
|
import { getNormalizedId } from '../../utils';
|
|
@@ -19,9 +18,8 @@ import useAutoSize from './useAutoSize';
|
|
|
19
18
|
|
|
20
19
|
const useStyles = makeStyles<{ displayAsBlock: boolean }>()(
|
|
21
20
|
(theme: Theme, { displayAsBlock }) => ({
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
paddingTop: theme.spacing(0.6)
|
|
21
|
+
compact: {
|
|
22
|
+
fontSize: 'x-small'
|
|
25
23
|
},
|
|
26
24
|
hiddenText: {
|
|
27
25
|
display: 'table',
|
|
@@ -142,7 +140,7 @@ const TextField = forwardRef(
|
|
|
142
140
|
}, [innerValue, debounced, defaultValue]);
|
|
143
141
|
|
|
144
142
|
return (
|
|
145
|
-
|
|
143
|
+
<>
|
|
146
144
|
<Tooltip placement="top" title={tooltipTitle}>
|
|
147
145
|
<MuiTextField
|
|
148
146
|
data-testid={dataTestId}
|
|
@@ -164,8 +162,7 @@ const TextField = forwardRef(
|
|
|
164
162
|
className: cx(
|
|
165
163
|
classes.inputBase,
|
|
166
164
|
{
|
|
167
|
-
[classes.transparent]: transparent
|
|
168
|
-
[classes.autoSizeCompact]: autoSize && equals(size, 'compact')
|
|
165
|
+
[classes.transparent]: transparent
|
|
169
166
|
},
|
|
170
167
|
className
|
|
171
168
|
),
|
|
@@ -198,7 +195,7 @@ const TextField = forwardRef(
|
|
|
198
195
|
{rest.value || externalValueForAutoSize || innerValue}
|
|
199
196
|
</Typography>
|
|
200
197
|
)}
|
|
201
|
-
|
|
198
|
+
</>
|
|
202
199
|
);
|
|
203
200
|
}
|
|
204
201
|
);
|
|
@@ -90,10 +90,10 @@ const useStyles = makeStyles<StylesProps>()(
|
|
|
90
90
|
})
|
|
91
91
|
},
|
|
92
92
|
caretLess: {
|
|
93
|
-
transform: 'rotate3d(0,0,1,
|
|
93
|
+
transform: 'rotate3d(0,0,1,180deg)'
|
|
94
94
|
},
|
|
95
95
|
caretMore: {
|
|
96
|
-
transform: 'rotate3d(0,0,1,
|
|
96
|
+
transform: 'rotate3d(0,0,1,0deg)'
|
|
97
97
|
},
|
|
98
98
|
fakeCaret: {
|
|
99
99
|
marginLeft: theme.spacing(3)
|
|
@@ -56,7 +56,7 @@ describe('Rich Text Editor', () => {
|
|
|
56
56
|
.should('be.visible')
|
|
57
57
|
.and('have.value', '');
|
|
58
58
|
|
|
59
|
-
cy.
|
|
59
|
+
cy.get('#RichTextEditor').contains('Type here...');
|
|
60
60
|
});
|
|
61
61
|
|
|
62
62
|
it('displays changes with undo redo buttons', () => {
|
|
@@ -187,6 +187,11 @@ describe('Rich Text Editor', () => {
|
|
|
187
187
|
});
|
|
188
188
|
|
|
189
189
|
it('displays editor when editable props is false and an initialState exist', () => {
|
|
190
|
+
cy.get('[data-testid="RichTextEditor"]').should(
|
|
191
|
+
'have.attr',
|
|
192
|
+
'contenteditable',
|
|
193
|
+
'false'
|
|
194
|
+
);
|
|
190
195
|
cy.findByLabelText('Undo').should('not.exist');
|
|
191
196
|
cy.findByLabelText('Redo').should('not.exist');
|
|
192
197
|
cy.findByLabelText('bold').should('not.exist');
|
|
@@ -211,6 +216,11 @@ describe('Rich Text Editor', () => {
|
|
|
211
216
|
});
|
|
212
217
|
|
|
213
218
|
it('displays editor when editable props is false and an initialState exist', () => {
|
|
219
|
+
cy.get('[data-testid="RichTextEditor"]').should(
|
|
220
|
+
'have.attr',
|
|
221
|
+
'contenteditable',
|
|
222
|
+
'false'
|
|
223
|
+
);
|
|
214
224
|
cy.findByLabelText('Undo').should('be.disabled');
|
|
215
225
|
cy.findByLabelText('Redo').should('be.disabled');
|
|
216
226
|
cy.findByLabelText('bold').should('be.disabled');
|
|
@@ -235,14 +245,12 @@ describe('Rich Text Editor', () => {
|
|
|
235
245
|
});
|
|
236
246
|
});
|
|
237
247
|
it('displays editor with custom namespace', () => {
|
|
238
|
-
cy.get('
|
|
248
|
+
cy.get('#CypressComponentTest > p').should('be.exist');
|
|
239
249
|
cy.get('[data-testid="CypressComponentTest"]').should('be.exist');
|
|
240
250
|
});
|
|
241
251
|
|
|
242
252
|
it('displays editor with custom placeholder', () => {
|
|
243
|
-
cy.get('
|
|
244
|
-
.parent()
|
|
245
|
-
.contains('Type Cypress test...');
|
|
253
|
+
cy.get('#CypressComponentTest > p').contains('Type Cypress test...');
|
|
246
254
|
});
|
|
247
255
|
|
|
248
256
|
it('displays editor with custom minimum input height', () => {
|
|
@@ -23,7 +23,6 @@ import FloatingLinkEditorPlugin from './plugins/FloatingLinkEditorPlugin';
|
|
|
23
23
|
export interface RichTextEditorProps {
|
|
24
24
|
contentClassName?: string;
|
|
25
25
|
disabled?: boolean;
|
|
26
|
-
displayBlockButtons?: boolean;
|
|
27
26
|
displayMacrosButton?: boolean;
|
|
28
27
|
editable: boolean;
|
|
29
28
|
editorState?: string;
|
|
@@ -133,10 +132,9 @@ const RichTextEditor = ({
|
|
|
133
132
|
onBlur,
|
|
134
133
|
contentClassName,
|
|
135
134
|
displayMacrosButton = false,
|
|
136
|
-
disabled
|
|
135
|
+
disabled,
|
|
137
136
|
openLinkInNewTab = true,
|
|
138
|
-
initialize
|
|
139
|
-
displayBlockButtons = true
|
|
137
|
+
initialize
|
|
140
138
|
}: RichTextEditorProps): JSX.Element => {
|
|
141
139
|
const { classes } = useStyles({ toolbarPositions });
|
|
142
140
|
|
|
@@ -176,7 +174,6 @@ const RichTextEditor = ({
|
|
|
176
174
|
<div className={classes.toolbar}>
|
|
177
175
|
<ToolbarPlugin
|
|
178
176
|
disabled={disabled}
|
|
179
|
-
displayBlockButtons={displayBlockButtons}
|
|
180
177
|
displayMacrosButton={displayMacrosButton}
|
|
181
178
|
editable={editable}
|
|
182
179
|
/>
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react';
|
|
2
|
-
|
|
3
1
|
import {
|
|
4
2
|
AutoLinkPlugin,
|
|
5
3
|
LinkMatcher
|
|
6
4
|
} from '@lexical/react/LexicalAutoLinkPlugin';
|
|
7
|
-
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
8
|
-
import { BLUR_COMMAND, COMMAND_PRIORITY_LOW, FOCUS_COMMAND } from 'lexical';
|
|
9
5
|
|
|
10
6
|
interface LinkAttributes {
|
|
11
7
|
rel?: null | string;
|
|
@@ -60,42 +56,7 @@ const AutoCompleteLinkPlugin = ({
|
|
|
60
56
|
openLinkInNewTab
|
|
61
57
|
}: {
|
|
62
58
|
openLinkInNewTab: boolean;
|
|
63
|
-
}): JSX.Element
|
|
64
|
-
const [editor] = useLexicalComposerContext();
|
|
65
|
-
const [hasFocus, setFocus] = useState(false);
|
|
66
|
-
|
|
67
|
-
useEffect(
|
|
68
|
-
() =>
|
|
69
|
-
editor.registerCommand(
|
|
70
|
-
BLUR_COMMAND,
|
|
71
|
-
() => {
|
|
72
|
-
setFocus(false);
|
|
73
|
-
|
|
74
|
-
return false;
|
|
75
|
-
},
|
|
76
|
-
COMMAND_PRIORITY_LOW
|
|
77
|
-
),
|
|
78
|
-
[]
|
|
79
|
-
);
|
|
80
|
-
|
|
81
|
-
useEffect(
|
|
82
|
-
() =>
|
|
83
|
-
editor.registerCommand(
|
|
84
|
-
FOCUS_COMMAND,
|
|
85
|
-
() => {
|
|
86
|
-
setFocus(true);
|
|
87
|
-
|
|
88
|
-
return false;
|
|
89
|
-
},
|
|
90
|
-
COMMAND_PRIORITY_LOW
|
|
91
|
-
),
|
|
92
|
-
[]
|
|
93
|
-
);
|
|
94
|
-
|
|
95
|
-
if (!hasFocus) {
|
|
96
|
-
return null;
|
|
97
|
-
}
|
|
98
|
-
|
|
59
|
+
}): JSX.Element => {
|
|
99
60
|
return <AutoLinkPlugin matchers={getMatchers(openLinkInNewTab)} />;
|
|
100
61
|
};
|
|
101
62
|
|