@centreon/ui 23.10.121 → 24.4.1-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/package.json +59 -41
- package/public/mockServiceWorker.js +2 -2
- package/src/ActionsList/ActionsList.styles.ts +40 -71
- package/src/Button/Icon/index.stories.tsx +1 -1
- package/src/Button/Icon/index.tsx +2 -2
- package/src/Button/Save/StartIcon.tsx +3 -3
- package/src/Button/Save/index.tsx +9 -5
- package/src/Checkbox/Checkbox.tsx +2 -2
- package/src/Checkbox/CheckboxGroup/index.tsx +2 -2
- package/src/Checkbox/fonts/roboto-bold-webfont.ttf +0 -0
- package/src/Checkbox/fonts/roboto-bold-webfont.woff +0 -0
- package/src/Checkbox/fonts/roboto-bold-webfont.woff2 +0 -0
- package/src/Checkbox/fonts/roboto-light-webfont.ttf +0 -0
- package/src/Checkbox/fonts/roboto-light-webfont.woff +0 -0
- package/src/Checkbox/fonts/roboto-light-webfont.woff2 +0 -0
- package/src/Checkbox/fonts/roboto-medium-webfont.ttf +0 -0
- package/src/Checkbox/fonts/roboto-medium-webfont.woff +0 -0
- package/src/Checkbox/fonts/roboto-medium-webfont.woff2 +0 -0
- package/src/Checkbox/fonts/roboto-regular-webfont.ttf +0 -0
- package/src/Checkbox/fonts/roboto-regular-webfont.woff +0 -0
- package/src/Checkbox/fonts/roboto-regular-webfont.woff2 +0 -0
- package/src/Dashboard/Dashboard.styles.ts +6 -5
- package/src/Dashboard/Item.tsx +1 -1
- package/src/Dashboard/Layout.tsx +2 -2
- package/src/Dashboard/utils.ts +1 -1
- package/src/Dialog/Confirm/index.tsx +10 -2
- package/src/Dialog/UnsavedChanges/index.tsx +21 -20
- package/src/Dialog/UnsavedChanges/translatedLabels.ts +4 -6
- package/src/Dialog/index.tsx +9 -2
- package/src/FallbackPage/FallbackPage.tsx +3 -3
- package/src/FileDropZone/index.tsx +3 -1
- package/src/Form/Form.cypress.spec.tsx +133 -0
- package/src/Form/Inputs/Grid.tsx +8 -4
- package/src/Form/Inputs/List/Content.tsx +62 -0
- package/src/Form/Inputs/List/List.styles.ts +29 -0
- package/src/Form/Inputs/List/List.tsx +58 -0
- package/src/Form/Inputs/List/useList.ts +81 -0
- package/src/Form/Inputs/Text.tsx +3 -1
- package/src/Form/Inputs/index.tsx +3 -1
- package/src/Form/Inputs/models.ts +23 -13
- package/src/Graph/BarStack/BarStack.cypress.spec.tsx +139 -0
- package/src/Graph/BarStack/BarStack.stories.tsx +123 -0
- package/src/Graph/BarStack/BarStack.styles.ts +37 -0
- package/src/Graph/BarStack/BarStack.tsx +14 -0
- package/src/Graph/BarStack/ResponsiveBarStack.tsx +211 -0
- package/src/Graph/BarStack/index.ts +1 -0
- package/src/Graph/BarStack/models.ts +20 -0
- package/src/Graph/BarStack/useResponsiveBarStack.ts +131 -0
- package/src/Graph/Gauge/Gauge.cypress.spec.tsx +102 -0
- package/src/Graph/Gauge/Gauge.tsx +1 -1
- package/src/Graph/HeatMap/HeatMap.cypress.spec.tsx +145 -0
- package/src/Graph/HeatMap/HeatMap.stories.tsx +0 -25
- package/src/Graph/HeatMap/HeatMap.styles.tsx +1 -0
- package/src/Graph/HeatMap/ResponsiveHeatMap.tsx +20 -10
- package/src/Graph/HeatMap/model.ts +1 -0
- package/src/Graph/Legend/Legend.tsx +21 -0
- package/src/Graph/Legend/index.ts +1 -0
- package/src/Graph/Legend/models.ts +11 -0
- package/src/Graph/LineChart/BasicComponents/Lines/RegularLines/index.tsx +2 -1
- package/src/Graph/LineChart/BasicComponents/Lines/StackedLines/index.tsx +3 -4
- package/src/Graph/LineChart/BasicComponents/Lines/Threshold/Circle.tsx +2 -2
- package/src/Graph/LineChart/BasicComponents/ThresholdLine.tsx +3 -1
- package/src/Graph/LineChart/BasicComponents/Thresholds.tsx +2 -2
- package/src/Graph/LineChart/BasicComponents/useFilterLines.ts +3 -5
- package/src/Graph/LineChart/Header/index.tsx +3 -31
- package/src/Graph/LineChart/Icons/Downtime.tsx +3 -3
- package/src/Graph/LineChart/InteractiveComponents/AnchorPoint/GuidingLines.tsx +2 -2
- package/src/Graph/LineChart/InteractiveComponents/AnchorPoint/useTickGraph.ts +9 -11
- package/src/Graph/LineChart/InteractiveComponents/Annotations/EventAnnotations.tsx +1 -1
- package/src/Graph/LineChart/InteractiveComponents/GraphValueTooltip/GraphValueTooltip.tsx +68 -0
- package/src/Graph/LineChart/InteractiveComponents/GraphValueTooltip/useGraphValueTooltip.ts +27 -0
- package/src/Graph/LineChart/InteractiveComponents/GraphValueTooltip/useGraphValueTooltipStyles.ts +31 -0
- package/src/Graph/LineChart/InteractiveComponents/ZoomPreview/index.tsx +2 -1
- package/src/Graph/LineChart/InteractiveComponents/index.tsx +132 -17
- package/src/Graph/LineChart/InteractiveComponents/interactionWithGraphAtoms.ts +7 -27
- package/src/Graph/LineChart/Legend/Legend.styles.ts +75 -33
- package/src/Graph/LineChart/Legend/LegendContent.tsx +12 -6
- package/src/Graph/LineChart/Legend/LegendHeader.tsx +66 -27
- package/src/Graph/LineChart/Legend/index.tsx +35 -45
- package/src/Graph/LineChart/Legend/models.ts +5 -0
- package/src/Graph/LineChart/Legend/useLegend.ts +12 -13
- package/src/Graph/LineChart/LineChart.cypress.spec.tsx +144 -0
- package/src/Graph/LineChart/LineChart.styles.ts +8 -0
- package/src/Graph/LineChart/LineChart.tsx +118 -117
- package/src/Graph/LineChart/LoadingSkeleton.tsx +2 -2
- package/src/Graph/LineChart/helpers/doc.ts +16 -13
- package/src/Graph/LineChart/helpers/index.ts +1 -1
- package/src/Graph/LineChart/index.stories.tsx +17 -2
- package/src/Graph/LineChart/index.tsx +6 -7
- package/src/Graph/LineChart/mockedData/curvesWithSameColor.json +252 -0
- package/src/Graph/LineChart/mockedData/lastDayWithIncompleteValues.json +1320 -0
- package/src/Graph/LineChart/mockedData/lastDayWithNullValues.json +1314 -0
- package/src/Graph/LineChart/models.ts +12 -1
- package/src/Graph/LineChart/useLineChartData.ts +57 -18
- package/src/Graph/PieChart/PieChart.cypress.spec.tsx +154 -0
- package/src/Graph/PieChart/PieChart.stories.tsx +194 -0
- package/src/Graph/PieChart/PieChart.styles.ts +39 -0
- package/src/Graph/PieChart/PieChart.tsx +14 -0
- package/src/Graph/PieChart/ResponsivePie.tsx +245 -0
- package/src/Graph/PieChart/index.ts +1 -0
- package/src/Graph/PieChart/models.ts +20 -0
- package/src/Graph/PieChart/useResponsivePie.ts +81 -0
- package/src/Graph/SingleBar/SingleBar.cypress.spec.tsx +121 -0
- package/src/Graph/SingleBar/Thresholds.tsx +2 -2
- package/src/Graph/Text/Text.cypress.spec.tsx +101 -0
- package/src/Graph/Text/Text.stories.tsx +60 -4
- package/src/Graph/Text/Text.styles.ts +12 -1
- package/src/Graph/Text/Text.tsx +17 -12
- package/src/Graph/Tree/DescendantNodes.tsx +88 -0
- package/src/Graph/Tree/Links.tsx +64 -0
- package/src/Graph/Tree/StandaloneTree.tsx +32 -0
- package/src/Graph/Tree/Tree.cypress.spec.tsx +171 -0
- package/src/Graph/Tree/Tree.stories.tsx +144 -0
- package/src/Graph/Tree/Tree.tsx +116 -0
- package/src/Graph/Tree/constants.ts +2 -0
- package/src/Graph/Tree/index.ts +4 -0
- package/src/Graph/Tree/models.ts +52 -0
- package/src/Graph/Tree/stories/contents.tsx +164 -0
- package/src/Graph/Tree/stories/datas.ts +305 -0
- package/src/Graph/Tree/utils.ts +49 -0
- package/src/Graph/common/testUtils.ts +71 -0
- package/src/Graph/common/timeSeries/index.ts +53 -15
- package/src/Graph/common/utils.ts +68 -1
- package/src/Graph/index.ts +4 -0
- package/src/Icon/BaseIcon.tsx +32 -0
- package/src/Icon/DowntimeIcon.tsx +14 -0
- package/src/InputField/Number/Number.cypress.spec.tsx +85 -0
- package/src/InputField/Number/Number.stories.tsx +66 -0
- package/src/InputField/Number/Number.tsx +74 -0
- package/src/InputField/Search/index.tsx +2 -2
- package/src/InputField/Select/Autocomplete/Connected/Multi/index.test.tsx +1 -0
- package/src/InputField/Select/Autocomplete/Connected/index.test.tsx +1 -0
- package/src/InputField/Select/Autocomplete/Connected/index.tsx +25 -10
- package/src/InputField/Select/Autocomplete/Draggable/SortableList.tsx +1 -1
- package/src/InputField/Select/Autocomplete/Draggable/SortableListContent.tsx +1 -1
- package/src/InputField/Select/Autocomplete/Draggable/index.tsx +1 -1
- package/src/InputField/Select/Autocomplete/Multi/index.tsx +4 -2
- package/src/InputField/Select/Autocomplete/index.tsx +129 -116
- package/src/InputField/Select/IconPopover/index.tsx +3 -3
- package/src/InputField/Select/index.tsx +15 -2
- package/src/InputField/Text/index.tsx +46 -41
- package/src/Listing/ActionBar/index.tsx +11 -10
- package/src/Listing/Cell/DataCell.styles.ts +3 -0
- package/src/Listing/Cell/DataCell.tsx +23 -5
- package/src/Listing/Header/ListingHeader.tsx +1 -1
- package/src/Listing/Listing.cypress.spec.tsx +218 -33
- package/src/Listing/Listing.styles.ts +4 -7
- package/src/Listing/Row/Row.tsx +7 -3
- package/src/Listing/index.stories.tsx +39 -5
- package/src/Listing/index.test.tsx +1 -1
- package/src/Listing/index.tsx +207 -149
- package/src/Listing/models.ts +1 -0
- package/src/Listing/useStyleTable.ts +1 -0
- package/src/Module/LicensedModule/LicenseCheck/index.tsx +24 -9
- package/src/Module/LicensedModule/index.tsx +7 -1
- package/src/Module/Module.cypress.spec.tsx +129 -0
- package/src/Module/index.tsx +2 -4
- package/src/Panel/index.tsx +1 -1
- package/src/PopoverMenu/index.tsx +9 -8
- package/src/RichTextEditor/ContentEditable.tsx +195 -195
- package/src/RichTextEditor/RichTextEditor.cypress.spec.tsx +100 -52
- package/src/RichTextEditor/RichTextEditor.tsx +21 -4
- package/src/RichTextEditor/plugins/ToolbarPlugin/AlignPicker.tsx +21 -20
- package/src/RichTextEditor/plugins/ToolbarPlugin/BlockButtons.tsx +35 -77
- package/src/RichTextEditor/plugins/ToolbarPlugin/FormatButtons.tsx +29 -83
- package/src/RichTextEditor/plugins/ToolbarPlugin/LinkButton.tsx +106 -0
- package/src/RichTextEditor/plugins/ToolbarPlugin/ListButton.tsx +155 -0
- package/src/RichTextEditor/plugins/ToolbarPlugin/MacrosButton.tsx +23 -39
- package/src/RichTextEditor/plugins/ToolbarPlugin/ToolbarPlugin.styles.ts +24 -14
- package/src/RichTextEditor/plugins/ToolbarPlugin/UndoRedoButtons.tsx +6 -0
- package/src/RichTextEditor/plugins/ToolbarPlugin/index.tsx +5 -10
- package/src/RichTextEditor/translatedLabels.ts +3 -0
- package/src/SortableItems/index.tsx +2 -7
- package/src/StoryBookThemeProvider/index.tsx +35 -36
- package/src/ThemeProvider/index.tsx +39 -12
- package/src/ThemeProvider/palettes.ts +15 -12
- package/src/TimePeriods/CustomTimePeriod/CompactCustomTimePeriod.styles.ts +6 -7
- package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/PickersStartEndDate.tsx +8 -3
- package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/models.ts +0 -2
- package/src/TimePeriods/DateTimePickerInput.tsx +56 -19
- package/src/TimePeriods/ResolutionTimePeriod.cypress.spec.tsx +12 -9
- package/src/TimePeriods/TimePeriods.cypress.spec.tsx +9 -33
- package/src/TimePeriods/helpers/index.ts +1 -1
- package/src/TimePeriods/index.stories.tsx +12 -4
- package/src/TimePeriods/index.tsx +2 -2
- package/src/TopCounterElements/TopCounterLayout.tsx +3 -0
- package/src/TopCounterElements/useCloseOnLegacyPage.tsx +42 -0
- package/src/Typography/FluidTypography/FluidTypography.cypress.spec.tsx +27 -0
- package/src/Typography/FluidTypography/index.stories.tsx +2 -2
- package/src/Typography/FluidTypography/index.tsx +21 -28
- package/src/Typography/Subtitle.tsx +55 -0
- package/src/api/QueryProvider.tsx +1 -1
- package/src/api/TestQueryProvider.tsx +1 -1
- package/src/api/buildListingEndpoint/models.ts +2 -1
- package/src/api/customFetch.ts +12 -3
- package/src/api/index.ts +3 -3
- package/src/api/useFetchQuery/index.ts +49 -28
- package/src/api/useGraphQuery/index.ts +26 -5
- package/src/api/useGraphQuery/models.ts +5 -0
- package/src/api/useMutationQuery/index.test.ts +4 -4
- package/src/api/useMutationQuery/index.ts +65 -20
- package/src/components/Button/Icon/IconButton.tsx +6 -2
- package/src/components/CollapsibleItem/CollapsibleItem.cypress.spec.tsx +76 -0
- package/src/components/CollapsibleItem/CollapsibleItem.stories.tsx +26 -0
- package/src/components/CollapsibleItem/CollapsibleItem.tsx +43 -14
- package/src/components/CollapsibleItem/useCollapsibleItemStyles.ts +24 -1
- package/src/components/DataTable/DataListing.tsx +6 -0
- package/src/components/DataTable/DataTable.cypress.spec.tsx +174 -0
- package/src/components/DataTable/DataTable.stories.tsx +40 -0
- package/src/components/DataTable/DataTable.styles.ts +3 -0
- package/src/components/DataTable/DataTable.tsx +3 -3
- package/src/components/DataTable/Item/DataTableItem.styles.ts +7 -2
- package/src/components/DataTable/Item/DataTableItem.tsx +4 -60
- package/src/components/DataTable/index.ts +3 -1
- package/src/components/Form/AccessRights/AccessRights.cypress.spec.tsx +373 -0
- package/src/components/Form/AccessRights/AccessRights.stories.tsx +119 -0
- package/src/components/Form/AccessRights/AccessRights.styles.ts +10 -0
- package/src/components/Form/AccessRights/AccessRights.tsx +60 -0
- package/src/components/Form/AccessRights/Actions/Actions.styles.ts +14 -0
- package/src/components/Form/AccessRights/Actions/Actions.tsx +81 -0
- package/src/components/Form/AccessRights/Actions/useActions.ts +79 -0
- package/src/components/Form/AccessRights/List/Item.tsx +90 -0
- package/src/components/Form/AccessRights/List/List.styles.tsx +45 -0
- package/src/components/Form/AccessRights/List/List.tsx +52 -0
- package/src/components/Form/AccessRights/List/ListItemSkeleton.tsx +18 -0
- package/src/components/Form/AccessRights/List/ListSkeleton.tsx +22 -0
- package/src/components/Form/AccessRights/List/RemoveAccessRight.tsx +38 -0
- package/src/components/Form/AccessRights/List/StateChip.tsx +28 -0
- package/src/components/Form/AccessRights/List/useItem.ts +64 -0
- package/src/components/Form/AccessRights/Provider.tsx +15 -0
- package/src/components/Form/AccessRights/ShareInput/ContactSwitch.tsx +50 -0
- package/src/components/Form/AccessRights/ShareInput/ShareInput.styles.ts +17 -0
- package/src/components/Form/AccessRights/ShareInput/ShareInput.tsx +78 -0
- package/src/components/Form/AccessRights/ShareInput/useShareInput.tsx +113 -0
- package/src/components/Form/AccessRights/Stats/Stats.tsx +36 -0
- package/src/components/Form/AccessRights/atoms.ts +97 -0
- package/src/components/Form/AccessRights/common/RoleSelectField.styles.tsx +7 -0
- package/src/components/Form/AccessRights/common/RoleSelectField.tsx +45 -0
- package/src/components/Form/AccessRights/models.ts +55 -0
- package/src/components/Form/AccessRights/storiesData.ts +222 -0
- package/src/components/Form/AccessRights/useAccessRightsInitValues.ts +51 -0
- package/src/components/Form/Dashboard/DashboardDuplicationForm.tsx +85 -0
- package/src/components/Form/Dashboard/DashboardForm.tsx +15 -12
- package/src/components/Form/Dashboard/index.ts +1 -0
- package/src/components/Form/FormActions.tsx +7 -2
- package/src/components/Form/index.ts +2 -1
- package/src/components/ItemComposition/Item.tsx +1 -1
- package/src/components/ItemComposition/ItemComposition.cypress.spec.tsx +113 -0
- package/src/components/ItemComposition/ItemComposition.stories.tsx +14 -0
- package/src/components/ItemComposition/ItemComposition.styles.ts +36 -3
- package/src/components/ItemComposition/ItemComposition.tsx +41 -17
- package/src/components/Layout/PageLayout/PageLayout.tsx +1 -1
- package/src/components/Layout/PageLayout/PageLayoutActions.tsx +1 -0
- package/src/components/Layout/PageLayout/PageLayoutBody.tsx +1 -0
- package/src/components/Layout/PageLayout/PageLayoutHeader.tsx +5 -1
- package/src/components/Layout/PageLayout/PageQuickAccess.tsx +76 -0
- package/src/components/Layout/PageLayout/index.ts +3 -1
- package/src/components/Layout/PageLayout.cypress.spec.tsx +66 -0
- package/src/components/List/Item/ListItem.styles.ts +6 -0
- package/src/components/List/Item/ListItem.tsx +6 -4
- package/src/components/List/Item/Text.tsx +5 -3
- package/src/components/Menu/Button/MenuButton.tsx +4 -2
- package/src/components/Menu/MenuItem.tsx +5 -3
- package/src/components/Menu/MenuItems.tsx +4 -3
- package/src/components/Modal/ConfirmationModal/ConfirmationModal.cypress.spec.tsx +168 -0
- package/src/components/Modal/ConfirmationModal/ConfirmationModal.stories.tsx +62 -0
- package/src/components/Modal/ConfirmationModal/ConfirmationModal.tsx +87 -0
- package/src/components/Modal/Modal.styles.ts +10 -2
- package/src/components/Modal/ModalActions.tsx +4 -2
- package/src/components/Modal/index.ts +2 -0
- package/src/components/Tooltip/ConfirmationTooltip/ConfirmationTooltip.stories.tsx +3 -3
- package/src/components/Tooltip/ConfirmationTooltip/ConfirmationTooltip.tsx +1 -1
- package/src/components/Tooltip/ConfirmationTooltip/models.ts +1 -1
- package/src/components/Zoom/Minimap.tsx +127 -0
- package/src/components/Zoom/Zoom.cypress.spec.tsx +246 -0
- package/src/components/Zoom/Zoom.stories.tsx +115 -0
- package/src/components/Zoom/Zoom.styles.tsx +68 -0
- package/src/components/Zoom/Zoom.tsx +61 -0
- package/src/components/Zoom/ZoomContent.tsx +167 -0
- package/src/components/Zoom/constants.ts +2 -0
- package/src/components/Zoom/localPoint.ts +51 -0
- package/src/components/Zoom/models.ts +25 -0
- package/src/components/Zoom/useMinimap.ts +156 -0
- package/src/components/Zoom/useZoom.ts +70 -0
- package/src/components/Zoom/utils.ts +55 -0
- package/src/components/index.ts +1 -0
- package/src/fonts/roboto-bold-webfont.ttf +0 -0
- package/src/fonts/roboto-bold-webfont.woff +0 -0
- package/src/fonts/roboto-bold-webfont.woff2 +0 -0
- package/src/fonts/roboto-light-webfont.ttf +0 -0
- package/src/fonts/roboto-light-webfont.woff +0 -0
- package/src/fonts/roboto-light-webfont.woff2 +0 -0
- package/src/fonts/roboto-medium-webfont.ttf +0 -0
- package/src/fonts/roboto-medium-webfont.woff +0 -0
- package/src/fonts/roboto-medium-webfont.woff2 +0 -0
- package/src/fonts/roboto-regular-webfont.ttf +0 -0
- package/src/fonts/roboto-regular-webfont.woff +0 -0
- package/src/fonts/roboto-regular-webfont.woff2 +0 -0
- package/src/index.ts +6 -0
- package/src/queryParameters/url/index.ts +5 -1
- package/src/utils/index.ts +3 -1
- package/src/utils/useFullscreen/Fullscreen.cypress.spec.tsx +130 -0
- package/src/utils/useFullscreen/atoms.ts +3 -0
- package/src/utils/useFullscreen/index.ts +2 -0
- package/src/utils/useFullscreen/translatedLabels.ts +1 -0
- package/src/utils/useFullscreen/useFullscreen.ts +73 -0
- package/src/utils/useFullscreen/useFullscreenListener.ts +62 -0
- package/src/utils/useInfiniteScrollListing.ts +31 -8
- package/src/utils/{useLicenseExpirationWarning.cypress.spec.tsx → useLicenseExpirationWarning.test.tsx} +48 -37
- package/src/utils/useLicenseExpirationWarning.ts +18 -18
- package/src/utils/useLocaleDateTimeFormat/index.ts +3 -0
- package/src/utils/usePluralizedTranslation.ts +21 -0
- package/src/@assets/icons/downtime.icon.svg +0 -1
- package/src/Graph/LineChart/BasicComponents/LoadingProgress.tsx +0 -46
- package/src/Graph/LineChart/InteractiveComponents/AnchorPoint/TooltipAnchorPoint.tsx +0 -96
- package/src/Graph/LineChart/InteractiveComponents/AnchorPoint/useTooltipAnchorPoint.ts +0 -107
- package/src/Graph/LineChart/Legend/InteractiveValue.tsx +0 -22
- package/src/Graph/LineChart/Legend/Marker.tsx +0 -43
- package/src/Graph/LineChart/Legend/useInteractiveValues.ts +0 -99
- package/src/Typography/FluidTypography/useFluidResizeObserver.ts +0 -56
- package/src/components/Form/AccessRights/AccessRights.resource.ts +0 -45
- package/src/components/Form/AccessRights/AccessRightsForm.stories.tsx +0 -59
- package/src/components/Form/AccessRights/AccessRightsForm.styles.ts +0 -21
- package/src/components/Form/AccessRights/AccessRightsForm.tsx +0 -67
- package/src/components/Form/AccessRights/AccessRightsFormActions.tsx +0 -80
- package/src/components/Form/AccessRights/Input/AddAction.tsx +0 -31
- package/src/components/Form/AccessRights/Input/ContactAccessRightInput.stories.tsx +0 -54
- package/src/components/Form/AccessRights/Input/ContactAccessRightInput.tsx +0 -72
- package/src/components/Form/AccessRights/Input/ContactAccessRightsInput.styles.ts +0 -22
- package/src/components/Form/AccessRights/Input/ContactInputField.tsx +0 -105
- package/src/components/Form/AccessRights/Input/RoleInputField.tsx +0 -29
- package/src/components/Form/AccessRights/List/ContactAccessRightsList.stories.tsx +0 -97
- package/src/components/Form/AccessRights/List/ContactAccessRightsList.styles.ts +0 -71
- package/src/components/Form/AccessRights/List/ContactAccessRightsList.tsx +0 -51
- package/src/components/Form/AccessRights/List/ContactAccessRightsListItem.stories.tsx +0 -116
- package/src/components/Form/AccessRights/List/ContactAccessRightsListItem.tsx +0 -118
- package/src/components/Form/AccessRights/List/ContactAccessRightsListItemSkeleton.tsx +0 -26
- package/src/components/Form/AccessRights/List/ContactAccessRightsListSkeleton.tsx +0 -28
- package/src/components/Form/AccessRights/Stats/AccessRightsStats.styles.ts +0 -18
- package/src/components/Form/AccessRights/Stats/AccessRightsStats.tsx +0 -41
- package/src/components/Form/AccessRights/__fixtures__/contactAccessRight.mock.ts +0 -52
- package/src/components/Form/AccessRights/common/GroupLabel.styles.ts +0 -18
- package/src/components/Form/AccessRights/common/GroupLabel.tsx +0 -15
- package/src/components/Form/AccessRights/common/Input.styles.ts +0 -48
- package/src/components/Form/AccessRights/common/RoleInputSelect.styles.ts +0 -11
- package/src/components/Form/AccessRights/common/RoleInputSelect.tsx +0 -57
- package/src/components/Form/AccessRights/index.ts +0 -3
- package/src/components/Form/AccessRights/useAccessRightsForm.test.tsx +0 -531
- package/src/components/Form/AccessRights/useAccessRightsForm.tsx +0 -282
- package/src/components/Form/AccessRights/useAccessRightsForm.utils.ts +0 -41
- package/src/screens/dashboard/DashboardsDetail.stories.tsx +0 -108
- package/src/screens/dashboard/DashboardsOverview.stories.tsx +0 -281
- package/src/utils/useDateTimePickerAdapter.ts +0 -309
- /package/{public → src/Button}/fonts/roboto-bold-webfont.ttf +0 -0
- /package/{public → src/Button}/fonts/roboto-bold-webfont.woff +0 -0
- /package/{public → src/Button}/fonts/roboto-bold-webfont.woff2 +0 -0
- /package/{public → src/Button}/fonts/roboto-light-webfont.ttf +0 -0
- /package/{public → src/Button}/fonts/roboto-light-webfont.woff +0 -0
- /package/{public → src/Button}/fonts/roboto-light-webfont.woff2 +0 -0
- /package/{public → src/Button}/fonts/roboto-medium-webfont.ttf +0 -0
- /package/{public → src/Button}/fonts/roboto-medium-webfont.woff +0 -0
- /package/{public → src/Button}/fonts/roboto-medium-webfont.woff2 +0 -0
- /package/{public → src/Button}/fonts/roboto-regular-webfont.ttf +0 -0
- /package/{public → src/Button}/fonts/roboto-regular-webfont.woff +0 -0
- /package/{public → src/Button}/fonts/roboto-regular-webfont.woff2 +0 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { createStore } from 'jotai';
|
|
2
|
+
|
|
3
|
+
import { Method } from '..';
|
|
4
|
+
|
|
5
|
+
import LicensedModule from './LicensedModule';
|
|
6
|
+
|
|
7
|
+
import Module from '.';
|
|
8
|
+
|
|
9
|
+
const initializeModule = (): void => {
|
|
10
|
+
cy.mount({
|
|
11
|
+
Component: (
|
|
12
|
+
<Module seedName="seed" store={createStore()}>
|
|
13
|
+
<p>Module</p>
|
|
14
|
+
</Module>
|
|
15
|
+
)
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const initializeModuleWithValidLicense = (
|
|
20
|
+
isFederatedComponent = false
|
|
21
|
+
): void => {
|
|
22
|
+
cy.interceptAPIRequest({
|
|
23
|
+
alias: 'getValidLicense',
|
|
24
|
+
method: Method.GET,
|
|
25
|
+
path: './api/internal.php?object=centreon_license_manager&action=licenseValid&productName=valid',
|
|
26
|
+
response: {
|
|
27
|
+
success: true
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
cy.mount({
|
|
32
|
+
Component: (
|
|
33
|
+
<div style={{ height: '100vh' }}>
|
|
34
|
+
<LicensedModule
|
|
35
|
+
isFederatedComponent={isFederatedComponent}
|
|
36
|
+
moduleName="valid"
|
|
37
|
+
seedName="seed"
|
|
38
|
+
store={createStore()}
|
|
39
|
+
>
|
|
40
|
+
<p>Module</p>
|
|
41
|
+
</LicensedModule>
|
|
42
|
+
</div>
|
|
43
|
+
)
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const initializeModuleWithInvalidLicense = (
|
|
48
|
+
isFederatedComponent = false
|
|
49
|
+
): void => {
|
|
50
|
+
cy.interceptAPIRequest({
|
|
51
|
+
alias: 'getInvalidLicense',
|
|
52
|
+
method: Method.GET,
|
|
53
|
+
path: './api/internal.php?object=centreon_license_manager&action=licenseValid&productName=invalid',
|
|
54
|
+
response: {
|
|
55
|
+
success: false
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
cy.mount({
|
|
60
|
+
Component: (
|
|
61
|
+
<div style={{ height: '100vh' }}>
|
|
62
|
+
<LicensedModule
|
|
63
|
+
isFederatedComponent={isFederatedComponent}
|
|
64
|
+
moduleName="invalid"
|
|
65
|
+
seedName="seed"
|
|
66
|
+
store={createStore()}
|
|
67
|
+
>
|
|
68
|
+
<p>Module</p>
|
|
69
|
+
</LicensedModule>
|
|
70
|
+
</div>
|
|
71
|
+
)
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
describe('Module', () => {
|
|
76
|
+
beforeEach(() => {
|
|
77
|
+
initializeModule();
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('displays the content of the module', () => {
|
|
81
|
+
cy.contains('Module').should('be.visible');
|
|
82
|
+
|
|
83
|
+
cy.makeSnapshot();
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
describe('Valid license module', () => {
|
|
88
|
+
it('displays the content of the page when the license is valid license', () => {
|
|
89
|
+
initializeModuleWithValidLicense();
|
|
90
|
+
cy.waitForRequest('@getValidLicense');
|
|
91
|
+
|
|
92
|
+
cy.contains('Module').should('be.visible');
|
|
93
|
+
|
|
94
|
+
cy.makeSnapshot();
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('displays the content of the component when the license is valid license', () => {
|
|
98
|
+
initializeModuleWithValidLicense(true);
|
|
99
|
+
|
|
100
|
+
cy.contains('Module').should('be.visible');
|
|
101
|
+
|
|
102
|
+
cy.makeSnapshot();
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
describe('Invalid license module', () => {
|
|
107
|
+
it('displays the content of the page when the license is invalid license', () => {
|
|
108
|
+
initializeModuleWithInvalidLicense();
|
|
109
|
+
cy.waitForRequest('@getInvalidLicense');
|
|
110
|
+
|
|
111
|
+
cy.contains('Module').should('not.exist');
|
|
112
|
+
|
|
113
|
+
cy.contains('Oops').should('be.visible');
|
|
114
|
+
cy.contains('License invalid or expired').should('be.visible');
|
|
115
|
+
cy.contains('Please contact your administrator.').should('be.visible');
|
|
116
|
+
cy.get('img[alt="License invalid or expired !"]').should('be.visible');
|
|
117
|
+
cy.get('img[alt="Centreon Logo"]').should('be.visible');
|
|
118
|
+
|
|
119
|
+
cy.makeSnapshot();
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('displays the content of the module when the license is invalid license', () => {
|
|
123
|
+
initializeModuleWithInvalidLicense(true);
|
|
124
|
+
|
|
125
|
+
cy.contains('Module').should('not.exist');
|
|
126
|
+
|
|
127
|
+
cy.makeSnapshot();
|
|
128
|
+
});
|
|
129
|
+
});
|
package/src/Module/index.tsx
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
|
|
3
1
|
import { Provider as JotaiProvider, createStore } from 'jotai';
|
|
4
2
|
|
|
5
3
|
import { createGenerateClassName, StylesProvider } from '@mui/styles';
|
|
@@ -9,7 +7,7 @@ import SnackbarProvider from '../Snackbar/SnackbarProvider';
|
|
|
9
7
|
|
|
10
8
|
export interface ModuleProps {
|
|
11
9
|
children: React.ReactElement;
|
|
12
|
-
maxSnackbars
|
|
10
|
+
maxSnackbars?: number;
|
|
13
11
|
seedName: string;
|
|
14
12
|
store: ReturnType<typeof createStore>;
|
|
15
13
|
}
|
|
@@ -17,7 +15,7 @@ export interface ModuleProps {
|
|
|
17
15
|
const Module = ({
|
|
18
16
|
children,
|
|
19
17
|
seedName,
|
|
20
|
-
maxSnackbars,
|
|
18
|
+
maxSnackbars = 3,
|
|
21
19
|
store
|
|
22
20
|
}: ModuleProps): JSX.Element => {
|
|
23
21
|
const generateClassName = createGenerateClassName({
|
package/src/Panel/index.tsx
CHANGED
|
@@ -9,7 +9,7 @@ import { makeStyles } from 'tss-react/mui';
|
|
|
9
9
|
import { Paper, Slide, Divider, AppBar, Tabs } from '@mui/material';
|
|
10
10
|
import IconClose from '@mui/icons-material/Clear';
|
|
11
11
|
|
|
12
|
-
import IconButton from '
|
|
12
|
+
import { IconButton } from '..';
|
|
13
13
|
|
|
14
14
|
import { minTabHeight } from './Tab';
|
|
15
15
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Dispatch, SetStateAction, useEffect, useState } from 'react';
|
|
1
|
+
import { type Dispatch, type SetStateAction, useEffect, useState } from 'react';
|
|
2
2
|
|
|
3
3
|
import { makeStyles } from 'tss-react/mui';
|
|
4
4
|
|
|
@@ -6,14 +6,16 @@ import {
|
|
|
6
6
|
ClickAwayListener,
|
|
7
7
|
Paper,
|
|
8
8
|
Popper,
|
|
9
|
-
PopperPlacementType
|
|
10
|
-
useTheme
|
|
9
|
+
type PopperPlacementType
|
|
11
10
|
} from '@mui/material';
|
|
12
|
-
import { PopperProps } from '@mui/material/Popper';
|
|
11
|
+
import type { PopperProps } from '@mui/material/Popper';
|
|
13
12
|
|
|
14
13
|
import { IconButton } from '..';
|
|
15
14
|
|
|
16
|
-
const useStyles = makeStyles()(() => ({
|
|
15
|
+
const useStyles = makeStyles()((theme) => ({
|
|
16
|
+
popover: {
|
|
17
|
+
zIndex: theme.zIndex.tooltip
|
|
18
|
+
},
|
|
17
19
|
popoverIconButton: {
|
|
18
20
|
padding: 0,
|
|
19
21
|
width: '100%'
|
|
@@ -52,7 +54,6 @@ const PopoverMenu = ({
|
|
|
52
54
|
getPopoverData,
|
|
53
55
|
popperProps
|
|
54
56
|
}: Props): JSX.Element => {
|
|
55
|
-
const theme = useTheme();
|
|
56
57
|
const { classes, cx } = useStyles();
|
|
57
58
|
const [anchorEl, setAnchorEl] = useState<HTMLElement | undefined>();
|
|
58
59
|
const isOpen = Boolean(anchorEl);
|
|
@@ -79,7 +80,7 @@ const PopoverMenu = ({
|
|
|
79
80
|
};
|
|
80
81
|
|
|
81
82
|
useEffect(() => {
|
|
82
|
-
if (!canOpen) {
|
|
83
|
+
if (!canOpen && isOpen) {
|
|
83
84
|
close();
|
|
84
85
|
}
|
|
85
86
|
}, [canOpen]);
|
|
@@ -105,9 +106,9 @@ const PopoverMenu = ({
|
|
|
105
106
|
<Popper
|
|
106
107
|
open
|
|
107
108
|
anchorEl={anchorEl}
|
|
109
|
+
className={classes.popover}
|
|
108
110
|
nonce={undefined}
|
|
109
111
|
placement={popperPlacement}
|
|
110
|
-
style={{ zIndex: theme.zIndex.tooltip }}
|
|
111
112
|
onResize={(): undefined => undefined}
|
|
112
113
|
onResizeCapture={(): undefined => undefined}
|
|
113
114
|
{...popperProps}
|
|
@@ -1,195 +1,195 @@
|
|
|
1
|
-
import { useCallback, useEffect, useLayoutEffect, useState } from 'react';
|
|
2
|
-
|
|
3
|
-
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
import { Typography } from '@mui/material';
|
|
9
|
-
|
|
10
|
-
interface StyleProps {
|
|
11
|
-
editable: boolean;
|
|
12
|
-
error?: string;
|
|
13
|
-
minInputHeight: number;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const useStyles = makeStyles<StyleProps>()(
|
|
17
|
-
(theme, { minInputHeight, editable, error }) => ({
|
|
18
|
-
container: {
|
|
19
|
-
backgroundColor: theme.palette.background.paper,
|
|
20
|
-
border: error
|
|
21
|
-
? `1px solid ${theme.palette.error.main}`
|
|
22
|
-
: '1px solid transparent',
|
|
23
|
-
borderRadius: theme.shape.borderRadius,
|
|
24
|
-
padding: theme.spacing(0.5, 1)
|
|
25
|
-
},
|
|
26
|
-
emptyInput: {
|
|
27
|
-
marginTop: '-22px'
|
|
28
|
-
},
|
|
29
|
-
input: {
|
|
30
|
-
minHeight: editable ? minInputHeight : 'min-content',
|
|
31
|
-
outline: '0px solid transparent'
|
|
32
|
-
},
|
|
33
|
-
inputFocused: {
|
|
34
|
-
border: error
|
|
35
|
-
? `1px solid ${theme.palette.error.main}`
|
|
36
|
-
: `1px solid ${theme.palette.primary.main}`
|
|
37
|
-
},
|
|
38
|
-
notEditable: {
|
|
39
|
-
backgroundColor: 'transparent'
|
|
40
|
-
},
|
|
41
|
-
placeholder: {
|
|
42
|
-
color: theme.palette.grey[500],
|
|
43
|
-
pointerEvents: 'none'
|
|
44
|
-
},
|
|
45
|
-
root: {
|
|
46
|
-
'& p,h1,h2,h3,h4,h5,h6,span': {
|
|
47
|
-
margin: 0
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
})
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
interface Props {
|
|
54
|
-
className?: string;
|
|
55
|
-
disabled?: boolean;
|
|
56
|
-
editable: boolean;
|
|
57
|
-
editorState?: string;
|
|
58
|
-
error?: string;
|
|
59
|
-
hasInitialTextContent?: boolean;
|
|
60
|
-
initialEditorState?: string;
|
|
61
|
-
initialize?: (editor) => void;
|
|
62
|
-
inputClassname?: string;
|
|
63
|
-
minInputHeight: number;
|
|
64
|
-
namespace: string;
|
|
65
|
-
onBlur?: (e: string) => void;
|
|
66
|
-
placeholder: string;
|
|
67
|
-
resetEditorToInitialStateCondition?: () => boolean;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const defaultState =
|
|
71
|
-
'{"root":{"children":[{"children":[],"direction":null,"format":"","indent":0,"type":"paragraph","version":1}],"direction":null,"format":"","indent":0,"type":"root","version":1}}';
|
|
72
|
-
|
|
73
|
-
const ContentEditable = ({
|
|
74
|
-
minInputHeight,
|
|
75
|
-
inputClassname,
|
|
76
|
-
placeholder,
|
|
77
|
-
hasInitialTextContent,
|
|
78
|
-
editable,
|
|
79
|
-
editorState,
|
|
80
|
-
namespace,
|
|
81
|
-
resetEditorToInitialStateCondition,
|
|
82
|
-
initialEditorState,
|
|
83
|
-
error,
|
|
84
|
-
onBlur,
|
|
85
|
-
className,
|
|
86
|
-
disabled,
|
|
87
|
-
initialize
|
|
88
|
-
}: Props): JSX.Element => {
|
|
89
|
-
const { classes, cx } = useStyles({ editable, error, minInputHeight });
|
|
90
|
-
const { t } = useTranslation();
|
|
91
|
-
|
|
92
|
-
const [editor] = useLexicalComposerContext();
|
|
93
|
-
const [isFocused, setFocused] = useState(false);
|
|
94
|
-
const [root, setRoot] = useState('');
|
|
95
|
-
|
|
96
|
-
const ref = useCallback(
|
|
97
|
-
(rootElement: null | HTMLElement) => {
|
|
98
|
-
editor.setRootElement(rootElement);
|
|
99
|
-
},
|
|
100
|
-
[editor]
|
|
101
|
-
);
|
|
102
|
-
|
|
103
|
-
useLayoutEffect(() => {
|
|
104
|
-
if (!editable) {
|
|
105
|
-
const newEditorState = editor.parseEditorState(
|
|
106
|
-
editorState || defaultState
|
|
107
|
-
);
|
|
108
|
-
|
|
109
|
-
editor.setEditorState(newEditorState);
|
|
110
|
-
}
|
|
111
|
-
}, [editor, editorState]);
|
|
112
|
-
|
|
113
|
-
useEffect(() => {
|
|
114
|
-
editor.registerTextContentListener((currentRoot) => {
|
|
115
|
-
setRoot(currentRoot);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
if (!hasInitialTextContent) {
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
setRoot(' ');
|
|
123
|
-
}, [editor]);
|
|
124
|
-
|
|
125
|
-
useEffect(() => {
|
|
126
|
-
const shouldResetEditorToInitialState =
|
|
127
|
-
resetEditorToInitialStateCondition?.();
|
|
128
|
-
|
|
129
|
-
if (!shouldResetEditorToInitialState) {
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
const newEditorState = editor.parseEditorState(
|
|
134
|
-
initialEditorState || defaultState
|
|
135
|
-
);
|
|
136
|
-
|
|
137
|
-
editor.setEditorState(newEditorState);
|
|
138
|
-
}, [editorState]);
|
|
139
|
-
|
|
140
|
-
const isTextEmpty =
|
|
141
|
-
isEmpty(root) &&
|
|
142
|
-
!editor.getEditorState().toJSON().root.children?.[0]?.children?.length;
|
|
143
|
-
|
|
144
|
-
const handleBlur = (event: React.FocusEvent<HTMLInputElement>): void => {
|
|
145
|
-
setFocused(false);
|
|
146
|
-
onBlur?.(event);
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
const isEditable = editor.isEditable();
|
|
150
|
-
|
|
151
|
-
useEffect(() => {
|
|
152
|
-
if (isNil(disabled)) {
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
editor.setEditable(!disabled);
|
|
157
|
-
}, [disabled]);
|
|
158
|
-
|
|
159
|
-
useEffect(() => {
|
|
160
|
-
initialize?.(editor);
|
|
161
|
-
}, []);
|
|
162
|
-
|
|
163
|
-
return (
|
|
164
|
-
<div
|
|
165
|
-
className={cx(
|
|
166
|
-
classes.root,
|
|
167
|
-
editable && classes.container,
|
|
168
|
-
!isEditable && !disabled && classes.notEditable,
|
|
169
|
-
className,
|
|
170
|
-
isFocused && classes.inputFocused
|
|
171
|
-
)}
|
|
172
|
-
>
|
|
173
|
-
{editable && isTextEmpty && (
|
|
174
|
-
<Typography className={classes.placeholder}>
|
|
175
|
-
{t(placeholder)}
|
|
176
|
-
</Typography>
|
|
177
|
-
)}
|
|
178
|
-
<div
|
|
179
|
-
aria-label={namespace}
|
|
180
|
-
className={cx(
|
|
181
|
-
editable && isTextEmpty && classes.emptyInput,
|
|
182
|
-
classes.input,
|
|
183
|
-
inputClassname
|
|
184
|
-
)}
|
|
185
|
-
contentEditable={isEditable}
|
|
186
|
-
data-testid={namespace}
|
|
187
|
-
ref={ref}
|
|
188
|
-
onBlur={handleBlur}
|
|
189
|
-
onFocus={(): void => setFocused(true)}
|
|
190
|
-
/>
|
|
191
|
-
</div>
|
|
192
|
-
);
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
export default ContentEditable;
|
|
1
|
+
import { useCallback, useEffect, useLayoutEffect, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
4
|
+
import { isEmpty, isNil } from 'ramda';
|
|
5
|
+
import { useTranslation } from 'react-i18next';
|
|
6
|
+
import { makeStyles } from 'tss-react/mui';
|
|
7
|
+
|
|
8
|
+
import { Typography } from '@mui/material';
|
|
9
|
+
|
|
10
|
+
interface StyleProps {
|
|
11
|
+
editable: boolean;
|
|
12
|
+
error?: string;
|
|
13
|
+
minInputHeight: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const useStyles = makeStyles<StyleProps>()(
|
|
17
|
+
(theme, { minInputHeight, editable, error }) => ({
|
|
18
|
+
container: {
|
|
19
|
+
backgroundColor: theme.palette.background.paper,
|
|
20
|
+
border: error
|
|
21
|
+
? `1px solid ${theme.palette.error.main}`
|
|
22
|
+
: '1px solid transparent',
|
|
23
|
+
borderRadius: theme.shape.borderRadius,
|
|
24
|
+
padding: theme.spacing(0.5, 1)
|
|
25
|
+
},
|
|
26
|
+
emptyInput: {
|
|
27
|
+
marginTop: '-22px'
|
|
28
|
+
},
|
|
29
|
+
input: {
|
|
30
|
+
minHeight: editable ? minInputHeight : 'min-content',
|
|
31
|
+
outline: '0px solid transparent'
|
|
32
|
+
},
|
|
33
|
+
inputFocused: {
|
|
34
|
+
border: error
|
|
35
|
+
? `1px solid ${theme.palette.error.main}`
|
|
36
|
+
: `1px solid ${theme.palette.primary.main}`
|
|
37
|
+
},
|
|
38
|
+
notEditable: {
|
|
39
|
+
backgroundColor: 'transparent'
|
|
40
|
+
},
|
|
41
|
+
placeholder: {
|
|
42
|
+
color: theme.palette.grey[500],
|
|
43
|
+
pointerEvents: 'none'
|
|
44
|
+
},
|
|
45
|
+
root: {
|
|
46
|
+
'& p,h1,h2,h3,h4,h5,h6,span': {
|
|
47
|
+
margin: 0
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
})
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
interface Props {
|
|
54
|
+
className?: string;
|
|
55
|
+
disabled?: boolean;
|
|
56
|
+
editable: boolean;
|
|
57
|
+
editorState?: string;
|
|
58
|
+
error?: string;
|
|
59
|
+
hasInitialTextContent?: boolean;
|
|
60
|
+
initialEditorState?: string;
|
|
61
|
+
initialize?: (editor) => void;
|
|
62
|
+
inputClassname?: string;
|
|
63
|
+
minInputHeight: number;
|
|
64
|
+
namespace: string;
|
|
65
|
+
onBlur?: (e: string) => void;
|
|
66
|
+
placeholder: string;
|
|
67
|
+
resetEditorToInitialStateCondition?: () => boolean;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const defaultState =
|
|
71
|
+
'{"root":{"children":[{"children":[],"direction":null,"format":"","indent":0,"type":"paragraph","version":1}],"direction":null,"format":"","indent":0,"type":"root","version":1}}';
|
|
72
|
+
|
|
73
|
+
const ContentEditable = ({
|
|
74
|
+
minInputHeight,
|
|
75
|
+
inputClassname,
|
|
76
|
+
placeholder,
|
|
77
|
+
hasInitialTextContent,
|
|
78
|
+
editable,
|
|
79
|
+
editorState,
|
|
80
|
+
namespace,
|
|
81
|
+
resetEditorToInitialStateCondition,
|
|
82
|
+
initialEditorState,
|
|
83
|
+
error,
|
|
84
|
+
onBlur,
|
|
85
|
+
className,
|
|
86
|
+
disabled,
|
|
87
|
+
initialize
|
|
88
|
+
}: Props): JSX.Element => {
|
|
89
|
+
const { classes, cx } = useStyles({ editable, error, minInputHeight });
|
|
90
|
+
const { t } = useTranslation();
|
|
91
|
+
|
|
92
|
+
const [editor] = useLexicalComposerContext();
|
|
93
|
+
const [isFocused, setFocused] = useState(false);
|
|
94
|
+
const [root, setRoot] = useState('');
|
|
95
|
+
|
|
96
|
+
const ref = useCallback(
|
|
97
|
+
(rootElement: null | HTMLElement) => {
|
|
98
|
+
editor.setRootElement(rootElement);
|
|
99
|
+
},
|
|
100
|
+
[editor]
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
useLayoutEffect(() => {
|
|
104
|
+
if (!editable) {
|
|
105
|
+
const newEditorState = editor.parseEditorState(
|
|
106
|
+
editorState || defaultState
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
editor.setEditorState(newEditorState);
|
|
110
|
+
}
|
|
111
|
+
}, [editor, editorState]);
|
|
112
|
+
|
|
113
|
+
useEffect(() => {
|
|
114
|
+
editor.registerTextContentListener((currentRoot) => {
|
|
115
|
+
setRoot(currentRoot);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
if (!hasInitialTextContent) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
setRoot(' ');
|
|
123
|
+
}, [editor]);
|
|
124
|
+
|
|
125
|
+
useEffect(() => {
|
|
126
|
+
const shouldResetEditorToInitialState =
|
|
127
|
+
resetEditorToInitialStateCondition?.();
|
|
128
|
+
|
|
129
|
+
if (!shouldResetEditorToInitialState) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const newEditorState = editor.parseEditorState(
|
|
134
|
+
initialEditorState || defaultState
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
editor.setEditorState(newEditorState);
|
|
138
|
+
}, [editorState]);
|
|
139
|
+
|
|
140
|
+
const isTextEmpty =
|
|
141
|
+
isEmpty(root) &&
|
|
142
|
+
!editor.getEditorState().toJSON().root.children?.[0]?.children?.length;
|
|
143
|
+
|
|
144
|
+
const handleBlur = (event: React.FocusEvent<HTMLInputElement>): void => {
|
|
145
|
+
setFocused(false);
|
|
146
|
+
onBlur?.(event);
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
const isEditable = editor.isEditable();
|
|
150
|
+
|
|
151
|
+
useEffect(() => {
|
|
152
|
+
if (isNil(disabled)) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
editor.setEditable(!disabled);
|
|
157
|
+
}, [disabled]);
|
|
158
|
+
|
|
159
|
+
useEffect(() => {
|
|
160
|
+
initialize?.(editor);
|
|
161
|
+
}, []);
|
|
162
|
+
|
|
163
|
+
return (
|
|
164
|
+
<div
|
|
165
|
+
className={cx(
|
|
166
|
+
classes.root,
|
|
167
|
+
editable && classes.container,
|
|
168
|
+
!isEditable && !disabled && classes.notEditable,
|
|
169
|
+
className,
|
|
170
|
+
!disabled && isFocused && classes.inputFocused
|
|
171
|
+
)}
|
|
172
|
+
>
|
|
173
|
+
{editable && isTextEmpty && (
|
|
174
|
+
<Typography className={classes.placeholder}>
|
|
175
|
+
{t(placeholder)}
|
|
176
|
+
</Typography>
|
|
177
|
+
)}
|
|
178
|
+
<div
|
|
179
|
+
aria-label={namespace}
|
|
180
|
+
className={cx(
|
|
181
|
+
editable && isTextEmpty && classes.emptyInput,
|
|
182
|
+
classes.input,
|
|
183
|
+
inputClassname
|
|
184
|
+
)}
|
|
185
|
+
contentEditable={isEditable}
|
|
186
|
+
data-testid={namespace}
|
|
187
|
+
ref={ref}
|
|
188
|
+
onBlur={handleBlur}
|
|
189
|
+
onFocus={(): void => setFocused(true)}
|
|
190
|
+
/>
|
|
191
|
+
</div>
|
|
192
|
+
);
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
export default ContentEditable;
|