@scality/core-ui 0.115.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/.babelrc +17 -0
- package/.eslintrc.json +7 -0
- package/.flowconfig +21 -0
- package/.github/ISSUE_TEMPLATE/bug.md +18 -0
- package/.github/ISSUE_TEMPLATE/improvement.md +18 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +24 -0
- package/.github/workflows/codeql.yaml +25 -0
- package/.github/workflows/dependency-review.yaml +16 -0
- package/.github/workflows/github-pages.yml +17 -0
- package/.github/workflows/post-release.yml +52 -0
- package/.github/workflows/tests.yaml +32 -0
- package/.prettierrc +5 -0
- package/.storybook/main.ts +38 -0
- package/.storybook/manager.ts +6 -0
- package/.storybook/preview-head.html +99 -0
- package/.storybook/preview.js +68 -0
- package/.storybook/public/favicon.ico +0 -0
- package/.storybook/public/logo-core-ui.png +0 -0
- package/.storybook/theme.storybook.ts +13 -0
- package/LICENSE +201 -0
- package/README.md +296 -0
- package/__mocks__/fileMock.js +2 -0
- package/__mocks__/styleMock.js +2 -0
- package/dist/components/IconHelper.d.ts +10 -0
- package/dist/components/IconHelper.d.ts.map +1 -0
- package/dist/components/IconHelper.js +4 -0
- package/dist/components/areachart/AreaChart.component.d.ts +14 -0
- package/dist/components/areachart/AreaChart.component.d.ts.map +1 -0
- package/dist/components/areachart/AreaChart.component.js +27 -0
- package/dist/components/banner/Banner.component.d.ts +11 -0
- package/dist/components/banner/Banner.component.d.ts.map +1 -0
- package/dist/components/banner/Banner.component.js +40 -0
- package/dist/components/barchart/BarChart.component.d.ts +13 -0
- package/dist/components/barchart/BarChart.component.d.ts.map +1 -0
- package/dist/components/barchart/BarChart.component.js +22 -0
- package/dist/components/box/Box.d.ts +9 -0
- package/dist/components/box/Box.d.ts.map +1 -0
- package/dist/components/box/Box.js +21 -0
- package/dist/components/breadcrumb/Breadcrumb.component.d.ts +7 -0
- package/dist/components/breadcrumb/Breadcrumb.component.d.ts.map +1 -0
- package/dist/components/breadcrumb/Breadcrumb.component.js +77 -0
- package/dist/components/button/Button.component.d.ts +28 -0
- package/dist/components/button/Button.component.d.ts.map +1 -0
- package/dist/components/button/Button.component.js +227 -0
- package/dist/components/buttonv2/Buttonv2.component.d.ts +34 -0
- package/dist/components/buttonv2/Buttonv2.component.d.ts.map +1 -0
- package/dist/components/buttonv2/Buttonv2.component.js +198 -0
- package/dist/components/buttonv2/CopyButton.component.d.ts +24 -0
- package/dist/components/buttonv2/CopyButton.component.d.ts.map +1 -0
- package/dist/components/buttonv2/CopyButton.component.js +52 -0
- package/dist/components/card/Card.component.d.ts +28 -0
- package/dist/components/card/Card.component.d.ts.map +1 -0
- package/dist/components/card/Card.component.js +105 -0
- package/dist/components/checkbox/Checkbox.component.d.ts +10 -0
- package/dist/components/checkbox/Checkbox.component.d.ts.map +1 -0
- package/dist/components/checkbox/Checkbox.component.js +94 -0
- package/dist/components/chips/Chips.component.d.ts +22 -0
- package/dist/components/chips/Chips.component.d.ts.map +1 -0
- package/dist/components/chips/Chips.component.js +105 -0
- package/dist/components/circularprogressbar/CircularProgressBar.component.d.ts +13 -0
- package/dist/components/circularprogressbar/CircularProgressBar.component.d.ts.map +1 -0
- package/dist/components/circularprogressbar/CircularProgressBar.component.js +9 -0
- package/dist/components/circularprogressbar/CircularProgressBar.component.style.d.ts +11 -0
- package/dist/components/circularprogressbar/CircularProgressBar.component.style.d.ts.map +1 -0
- package/dist/components/circularprogressbar/CircularProgressBar.component.style.js +27 -0
- package/dist/components/cloudprogressbar/CloudProgressBar.component.d.ts +11 -0
- package/dist/components/cloudprogressbar/CloudProgressBar.component.d.ts.map +1 -0
- package/dist/components/cloudprogressbar/CloudProgressBar.component.js +38 -0
- package/dist/components/collapsiblepanel/CollapsiblePanel.component.d.ts +10 -0
- package/dist/components/collapsiblepanel/CollapsiblePanel.component.d.ts.map +1 -0
- package/dist/components/collapsiblepanel/CollapsiblePanel.component.js +44 -0
- package/dist/components/constants.d.ts +27 -0
- package/dist/components/constants.d.ts.map +1 -0
- package/dist/components/constants.js +47 -0
- package/dist/components/constrainedtext/Constrainedtext.component.d.ts +12 -0
- package/dist/components/constrainedtext/Constrainedtext.component.d.ts.map +1 -0
- package/dist/components/constrainedtext/Constrainedtext.component.js +46 -0
- package/dist/components/coreuithemeprovider/CoreUiThemeProvider.d.ts +9 -0
- package/dist/components/coreuithemeprovider/CoreUiThemeProvider.d.ts.map +1 -0
- package/dist/components/coreuithemeprovider/CoreUiThemeProvider.js +13 -0
- package/dist/components/date/FormattedDateTime.d.ts +11 -0
- package/dist/components/date/FormattedDateTime.d.ts.map +1 -0
- package/dist/components/date/FormattedDateTime.js +66 -0
- package/dist/components/date/FormattedDateTime.spec.d.ts +2 -0
- package/dist/components/date/FormattedDateTime.spec.d.ts.map +1 -0
- package/dist/components/date/FormattedDateTime.spec.js +140 -0
- package/dist/components/date/dateDiffer.d.ts +2 -0
- package/dist/components/date/dateDiffer.d.ts.map +1 -0
- package/dist/components/date/dateDiffer.js +7 -0
- package/dist/components/date/dateDiffer.spec.d.ts +2 -0
- package/dist/components/date/dateDiffer.spec.d.ts.map +1 -0
- package/dist/components/date/dateDiffer.spec.js +6 -0
- package/dist/components/dropdown/Dropdown.component.d.ts +20 -0
- package/dist/components/dropdown/Dropdown.component.d.ts.map +1 -0
- package/dist/components/dropdown/Dropdown.component.js +99 -0
- package/dist/components/dropzone/Dropzone.d.ts +16 -0
- package/dist/components/dropzone/Dropzone.d.ts.map +1 -0
- package/dist/components/dropzone/Dropzone.js +79 -0
- package/dist/components/emptystate/Emptystate.component.d.ts +13 -0
- package/dist/components/emptystate/Emptystate.component.d.ts.map +1 -0
- package/dist/components/emptystate/Emptystate.component.js +32 -0
- package/dist/components/emptytable/Emptytable.component.d.ts +8 -0
- package/dist/components/emptytable/Emptytable.component.d.ts.map +1 -0
- package/dist/components/emptytable/Emptytable.component.js +62 -0
- package/dist/components/error-pages/ErrorPage401.component.d.ts +9 -0
- package/dist/components/error-pages/ErrorPage401.component.d.ts.map +1 -0
- package/dist/components/error-pages/ErrorPage401.component.js +28 -0
- package/dist/components/error-pages/ErrorPage404.component.d.ts +8 -0
- package/dist/components/error-pages/ErrorPage404.component.d.ts.map +1 -0
- package/dist/components/error-pages/ErrorPage404.component.js +26 -0
- package/dist/components/error-pages/ErrorPage500.component.d.ts +13 -0
- package/dist/components/error-pages/ErrorPage500.component.d.ts.map +1 -0
- package/dist/components/error-pages/ErrorPage500.component.js +32 -0
- package/dist/components/error-pages/ErrorPageAuth.component.d.ts +8 -0
- package/dist/components/error-pages/ErrorPageAuth.component.d.ts.map +1 -0
- package/dist/components/error-pages/ErrorPageAuth.component.js +27 -0
- package/dist/components/error-pages/ErrorPageStyle.d.ts +7 -0
- package/dist/components/error-pages/ErrorPageStyle.d.ts.map +1 -0
- package/dist/components/error-pages/ErrorPageStyle.js +34 -0
- package/dist/components/form/Form.component.d.ts +61 -0
- package/dist/components/form/Form.component.d.ts.map +1 -0
- package/dist/components/form/Form.component.js +115 -0
- package/dist/components/globalhealthbar/GlobalHealthBar.component.d.ts +20 -0
- package/dist/components/globalhealthbar/GlobalHealthBar.component.d.ts.map +1 -0
- package/dist/components/globalhealthbar/GlobalHealthBar.component.js +169 -0
- package/dist/components/globalhealthbar/tooltip/index.d.ts +8 -0
- package/dist/components/globalhealthbar/tooltip/index.d.ts.map +1 -0
- package/dist/components/globalhealthbar/tooltip/index.js +55 -0
- package/dist/components/healthselectorv2/HealthSelector.component.d.ts +61 -0
- package/dist/components/healthselectorv2/HealthSelector.component.d.ts.map +1 -0
- package/dist/components/healthselectorv2/HealthSelector.component.js +70 -0
- package/dist/components/icon/Icon.component.d.ts +134 -0
- package/dist/components/icon/Icon.component.d.ts.map +1 -0
- package/dist/components/icon/Icon.component.js +209 -0
- package/dist/components/infomessage/InfoMessage.component.d.ts +9 -0
- package/dist/components/infomessage/InfoMessage.component.d.ts.map +1 -0
- package/dist/components/infomessage/InfoMessage.component.js +20 -0
- package/dist/components/infomessage/InfoMessageUtils.d.ts +8 -0
- package/dist/components/infomessage/InfoMessageUtils.d.ts.map +1 -0
- package/dist/components/infomessage/InfoMessageUtils.js +32 -0
- package/dist/components/input/Input.component.d.ts +24 -0
- package/dist/components/input/Input.component.d.ts.map +1 -0
- package/dist/components/input/Input.component.js +55 -0
- package/dist/components/input/Input.component.style.d.ts +9 -0
- package/dist/components/input/Input.component.style.d.ts.map +1 -0
- package/dist/components/input/Input.component.style.js +136 -0
- package/dist/components/inputlist/InputButtons.d.ts +20 -0
- package/dist/components/inputlist/InputButtons.d.ts.map +1 -0
- package/dist/components/inputlist/InputButtons.js +48 -0
- package/dist/components/inputlist/InputList.component.d.ts +27 -0
- package/dist/components/inputlist/InputList.component.d.ts.map +1 -0
- package/dist/components/inputlist/InputList.component.js +30 -0
- package/dist/components/inputv2/inputv2.d.ts +12 -0
- package/dist/components/inputv2/inputv2.d.ts.map +1 -0
- package/dist/components/inputv2/inputv2.js +80 -0
- package/dist/components/lateralnavbarlayout/LateralNavbarLayout.component.d.ts +9 -0
- package/dist/components/lateralnavbarlayout/LateralNavbarLayout.component.d.ts.map +1 -0
- package/dist/components/lateralnavbarlayout/LateralNavbarLayout.component.js +23 -0
- package/dist/components/layout/Layout.component.d.ts +12 -0
- package/dist/components/layout/Layout.component.d.ts.map +1 -0
- package/dist/components/layout/Layout.component.js +26 -0
- package/dist/components/layout/v2/AppContainer.d.ts +28 -0
- package/dist/components/layout/v2/AppContainer.d.ts.map +1 -0
- package/dist/components/layout/v2/AppContainer.js +63 -0
- package/dist/components/layout/v2/index.d.ts +6 -0
- package/dist/components/layout/v2/index.d.ts.map +1 -0
- package/dist/components/layout/v2/index.js +16 -0
- package/dist/components/layout/v2/panels.d.ts +17 -0
- package/dist/components/layout/v2/panels.d.ts.map +1 -0
- package/dist/components/layout/v2/panels.js +52 -0
- package/dist/components/linechart/LineChart.component.d.ts +22 -0
- package/dist/components/linechart/LineChart.component.d.ts.map +1 -0
- package/dist/components/linechart/LineChart.component.js +109 -0
- package/dist/components/linetemporalchart/ChartUtil.d.ts +40 -0
- package/dist/components/linetemporalchart/ChartUtil.d.ts.map +1 -0
- package/dist/components/linetemporalchart/ChartUtil.js +126 -0
- package/dist/components/linetemporalchart/LineTemporalChart.component.d.ts +43 -0
- package/dist/components/linetemporalchart/LineTemporalChart.component.d.ts.map +1 -0
- package/dist/components/linetemporalchart/LineTemporalChart.component.js +576 -0
- package/dist/components/linetemporalchart/MetricTimespanProvider.d.ts +8 -0
- package/dist/components/linetemporalchart/MetricTimespanProvider.d.ts.map +1 -0
- package/dist/components/linetemporalchart/MetricTimespanProvider.js +31 -0
- package/dist/components/linetemporalchart/tooltip/index.d.ts +30 -0
- package/dist/components/linetemporalchart/tooltip/index.d.ts.map +1 -0
- package/dist/components/linetemporalchart/tooltip/index.js +104 -0
- package/dist/components/loader/Loader.component.d.ts +11 -0
- package/dist/components/loader/Loader.component.d.ts.map +1 -0
- package/dist/components/loader/Loader.component.js +41 -0
- package/dist/components/modal/Modal.component.d.ts +13 -0
- package/dist/components/modal/Modal.component.d.ts.map +1 -0
- package/dist/components/modal/Modal.component.js +64 -0
- package/dist/components/multiselect/MultiSelect.component.d.ts +29 -0
- package/dist/components/multiselect/MultiSelect.component.d.ts.map +1 -0
- package/dist/components/multiselect/MultiSelect.component.js +73 -0
- package/dist/components/navbar/Navbar.component.d.ts +23 -0
- package/dist/components/navbar/Navbar.component.d.ts.map +1 -0
- package/dist/components/navbar/Navbar.component.js +151 -0
- package/dist/components/notifications/Notification.component.d.ts +13 -0
- package/dist/components/notifications/Notification.component.d.ts.map +1 -0
- package/dist/components/notifications/Notification.component.js +107 -0
- package/dist/components/notifications/Notifications.component.d.ts +15 -0
- package/dist/components/notifications/Notifications.component.d.ts.map +1 -0
- package/dist/components/notifications/Notifications.component.js +42 -0
- package/dist/components/prettybytes/PrettyBytes.component.d.ts +9 -0
- package/dist/components/prettybytes/PrettyBytes.component.d.ts.map +1 -0
- package/dist/components/prettybytes/PrettyBytes.component.js +24 -0
- package/dist/components/progressbar/ProgressBar.component.d.ts +18 -0
- package/dist/components/progressbar/ProgressBar.component.d.ts.map +1 -0
- package/dist/components/progressbar/ProgressBar.component.js +129 -0
- package/dist/components/scrollbarwrapper/ScrollbarWrapper.component.d.ts +7 -0
- package/dist/components/scrollbarwrapper/ScrollbarWrapper.component.d.ts.map +1 -0
- package/dist/components/scrollbarwrapper/ScrollbarWrapper.component.js +54 -0
- package/dist/components/searchinput/SearchInput.component.d.ts +12 -0
- package/dist/components/searchinput/SearchInput.component.d.ts.map +1 -0
- package/dist/components/searchinput/SearchInput.component.js +91 -0
- package/dist/components/select/Select.component.d.ts +15 -0
- package/dist/components/select/Select.component.d.ts.map +1 -0
- package/dist/components/select/Select.component.js +71 -0
- package/dist/components/selectv2/SelectStyle.d.ts +3 -0
- package/dist/components/selectv2/SelectStyle.d.ts.map +1 -0
- package/dist/components/selectv2/SelectStyle.js +238 -0
- package/dist/components/selectv2/Selectv2.component.d.ts +32 -0
- package/dist/components/selectv2/Selectv2.component.d.ts.map +1 -0
- package/dist/components/selectv2/Selectv2.component.js +267 -0
- package/dist/components/sidebar/Sidebar.component.d.ts +22 -0
- package/dist/components/sidebar/Sidebar.component.d.ts.map +1 -0
- package/dist/components/sidebar/Sidebar.component.js +136 -0
- package/dist/components/spacedbox/SpacedBox.d.ts +34 -0
- package/dist/components/spacedbox/SpacedBox.d.ts.map +1 -0
- package/dist/components/spacedbox/SpacedBox.js +64 -0
- package/dist/components/sparkline/SparkLine.component.d.ts +19 -0
- package/dist/components/sparkline/SparkLine.component.d.ts.map +1 -0
- package/dist/components/sparkline/SparkLine.component.js +148 -0
- package/dist/components/statuswrapper/Statuswrapper.component.d.ts +9 -0
- package/dist/components/statuswrapper/Statuswrapper.component.d.ts.map +1 -0
- package/dist/components/statuswrapper/Statuswrapper.component.js +44 -0
- package/dist/components/steppers/Stepper.component.d.ts +14 -0
- package/dist/components/steppers/Stepper.component.d.ts.map +1 -0
- package/dist/components/steppers/Stepper.component.js +33 -0
- package/dist/components/steppers/Steppers.component.d.ts +18 -0
- package/dist/components/steppers/Steppers.component.d.ts.map +1 -0
- package/dist/components/steppers/Steppers.component.js +96 -0
- package/dist/components/tablev2/MultiSelectableContent.d.ts +22 -0
- package/dist/components/tablev2/MultiSelectableContent.d.ts.map +1 -0
- package/dist/components/tablev2/MultiSelectableContent.js +129 -0
- package/dist/components/tablev2/Search.d.ts +29 -0
- package/dist/components/tablev2/Search.d.ts.map +1 -0
- package/dist/components/tablev2/Search.js +49 -0
- package/dist/components/tablev2/SearchWithQueryParams.d.ts +7 -0
- package/dist/components/tablev2/SearchWithQueryParams.d.ts.map +1 -0
- package/dist/components/tablev2/SearchWithQueryParams.js +24 -0
- package/dist/components/tablev2/SingleSelectableContent.d.ts +17 -0
- package/dist/components/tablev2/SingleSelectableContent.d.ts.map +1 -0
- package/dist/components/tablev2/SingleSelectableContent.js +75 -0
- package/dist/components/tablev2/TableCommon.d.ts +24 -0
- package/dist/components/tablev2/TableCommon.d.ts.map +1 -0
- package/dist/components/tablev2/TableCommon.js +35 -0
- package/dist/components/tablev2/TableUtils.d.ts +18 -0
- package/dist/components/tablev2/TableUtils.d.ts.map +1 -0
- package/dist/components/tablev2/TableUtils.js +32 -0
- package/dist/components/tablev2/Tablestyle.d.ts +36 -0
- package/dist/components/tablev2/Tablestyle.d.ts.map +1 -0
- package/dist/components/tablev2/Tablestyle.js +136 -0
- package/dist/components/tablev2/Tablev2.component.d.ts +71 -0
- package/dist/components/tablev2/Tablev2.component.d.ts.map +1 -0
- package/dist/components/tablev2/Tablev2.component.js +144 -0
- package/dist/components/tablev2/react-table-config.d.ts +28 -0
- package/dist/components/tablev2/react-table-config.d.ts.map +1 -0
- package/dist/components/tablev2/react-table-config.js +1 -0
- package/dist/components/tablev2/useCheckbox.d.ts +6 -0
- package/dist/components/tablev2/useCheckbox.d.ts.map +1 -0
- package/dist/components/tablev2/useCheckbox.js +40 -0
- package/dist/components/tablev2/useSyncedScroll.d.ts +7 -0
- package/dist/components/tablev2/useSyncedScroll.d.ts.map +1 -0
- package/dist/components/tablev2/useSyncedScroll.js +43 -0
- package/dist/components/tabsv2/ScrollButton.d.ts +8 -0
- package/dist/components/tabsv2/ScrollButton.d.ts.map +1 -0
- package/dist/components/tabsv2/ScrollButton.js +32 -0
- package/dist/components/tabsv2/StyledTabs.d.ts +18 -0
- package/dist/components/tabsv2/StyledTabs.d.ts.map +1 -0
- package/dist/components/tabsv2/StyledTabs.js +96 -0
- package/dist/components/tabsv2/Tab.d.ts +17 -0
- package/dist/components/tabsv2/Tab.d.ts.map +1 -0
- package/dist/components/tabsv2/Tab.js +10 -0
- package/dist/components/tabsv2/Tabsv2.component.d.ts +21 -0
- package/dist/components/tabsv2/Tabsv2.component.d.ts.map +1 -0
- package/dist/components/tabsv2/Tabsv2.component.js +89 -0
- package/dist/components/tabsv2/useScrollingTabs.d.ts +17 -0
- package/dist/components/tabsv2/useScrollingTabs.d.ts.map +1 -0
- package/dist/components/tabsv2/useScrollingTabs.js +261 -0
- package/dist/components/text/Text.component.d.ts +33 -0
- package/dist/components/text/Text.component.d.ts.map +1 -0
- package/dist/components/text/Text.component.js +154 -0
- package/dist/components/textarea/TextArea.component.d.ts +10 -0
- package/dist/components/textarea/TextArea.component.d.ts.map +1 -0
- package/dist/components/textarea/TextArea.component.js +60 -0
- package/dist/components/textbadge/TextBadge.component.d.ts +9 -0
- package/dist/components/textbadge/TextBadge.component.d.ts.map +1 -0
- package/dist/components/textbadge/TextBadge.component.js +19 -0
- package/dist/components/toast/DurationBasedProgressBar.d.ts +6 -0
- package/dist/components/toast/DurationBasedProgressBar.d.ts.map +1 -0
- package/dist/components/toast/DurationBasedProgressBar.js +24 -0
- package/dist/components/toast/Toast.component.d.ts +20 -0
- package/dist/components/toast/Toast.component.d.ts.map +1 -0
- package/dist/components/toast/Toast.component.js +106 -0
- package/dist/components/toast/ToastPositionHelpers.d.ts +4 -0
- package/dist/components/toast/ToastPositionHelpers.d.ts.map +1 -0
- package/dist/components/toast/ToastPositionHelpers.js +28 -0
- package/dist/components/toast/ToastProvider.d.ts +14 -0
- package/dist/components/toast/ToastProvider.d.ts.map +1 -0
- package/dist/components/toast/ToastProvider.js +18 -0
- package/dist/components/toast/useMutationsHandler.d.ts +40 -0
- package/dist/components/toast/useMutationsHandler.d.ts.map +1 -0
- package/dist/components/toast/useMutationsHandler.js +66 -0
- package/dist/components/toast/useToastParameters.d.ts +10 -0
- package/dist/components/toast/useToastParameters.d.ts.map +1 -0
- package/dist/components/toast/useToastParameters.js +39 -0
- package/dist/components/toggle/Toggle.component.d.ts +11 -0
- package/dist/components/toggle/Toggle.component.d.ts.map +1 -0
- package/dist/components/toggle/Toggle.component.js +80 -0
- package/dist/components/tooltip/Tooltip.component.d.ts +23 -0
- package/dist/components/tooltip/Tooltip.component.d.ts.map +1 -0
- package/dist/components/tooltip/Tooltip.component.js +82 -0
- package/dist/components/vegachart/VegaChart.component.d.ts +14 -0
- package/dist/components/vegachart/VegaChart.component.d.ts.map +1 -0
- package/dist/components/vegachart/VegaChart.component.js +120 -0
- package/dist/components/vegachartv2/SyncedCursorCharts.d.ts +13 -0
- package/dist/components/vegachartv2/SyncedCursorCharts.d.ts.map +1 -0
- package/dist/components/vegachartv2/SyncedCursorCharts.js +17 -0
- package/dist/components/vegachartv2/VegaChartV2.component.d.ts +16 -0
- package/dist/components/vegachartv2/VegaChartV2.component.d.ts.map +1 -0
- package/dist/components/vegachartv2/VegaChartV2.component.js +216 -0
- package/dist/hooks.d.ts +2 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +19 -0
- package/dist/icons/branding.d.ts +4 -0
- package/dist/icons/branding.d.ts.map +1 -0
- package/dist/icons/branding.js +3 -0
- package/dist/icons/scality-loading.d.ts +4 -0
- package/dist/icons/scality-loading.d.ts.map +1 -0
- package/dist/icons/scality-loading.js +3 -0
- package/dist/index.css +25 -0
- package/dist/index.d.ts +65 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +64 -0
- package/dist/next.d.ts +15 -0
- package/dist/next.d.ts.map +1 -0
- package/dist/next.js +14 -0
- package/dist/organisms/attachments/AttachmentConfirmationModal.d.ts +22 -0
- package/dist/organisms/attachments/AttachmentConfirmationModal.d.ts.map +1 -0
- package/dist/organisms/attachments/AttachmentConfirmationModal.js +142 -0
- package/dist/organisms/attachments/AttachmentTable.d.ts +37 -0
- package/dist/organisms/attachments/AttachmentTable.d.ts.map +1 -0
- package/dist/organisms/attachments/AttachmentTable.js +375 -0
- package/dist/organisms/attachments/AttachmentTypes.d.ts +15 -0
- package/dist/organisms/attachments/AttachmentTypes.d.ts.map +1 -0
- package/dist/organisms/attachments/AttachmentTypes.js +5 -0
- package/dist/spacing.d.ts +44 -0
- package/dist/spacing.d.ts.map +1 -0
- package/dist/spacing.js +60 -0
- package/dist/style/fonts/Lato-Bold.woff +0 -0
- package/dist/style/fonts/Lato-Bold.woff2 +0 -0
- package/dist/style/fonts/Lato-Regular.woff +0 -0
- package/dist/style/fonts/Lato-Regular.woff2 +0 -0
- package/dist/style/theme.d.ts +160 -0
- package/dist/style/theme.d.ts.map +1 -0
- package/dist/style/theme.js +234 -0
- package/dist/testUtils.d.ts +9 -0
- package/dist/testUtils.d.ts.map +1 -0
- package/dist/testUtils.js +11 -0
- package/dist/utils.d.ts +9 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +46 -0
- package/global-setup.js +3 -0
- package/jest.config.js +8 -0
- package/package.json +161 -0
- package/plop-templates/component.hbs +18 -0
- package/plop-templates/component.test.hbs +10 -0
- package/plop-templates/stories.hbs +18 -0
- package/plopfile.js +38 -0
- package/setupTests.js +3 -0
- package/src/lib/components/IconHelper.tsx +23 -0
- package/src/lib/components/areachart/AreaChart.component.tsx +49 -0
- package/src/lib/components/banner/Banner.component.tsx +59 -0
- package/src/lib/components/barchart/BarChart.component.tsx +46 -0
- package/src/lib/components/box/Box.ts +57 -0
- package/src/lib/components/breadcrumb/Breadcrumb.component.tsx +101 -0
- package/src/lib/components/button/Button.component.tsx +312 -0
- package/src/lib/components/buttonv2/Buttonv2.component.tsx +270 -0
- package/src/lib/components/buttonv2/CopyButton.component.tsx +89 -0
- package/src/lib/components/card/Card.component.tsx +196 -0
- package/src/lib/components/checkbox/Checkbox.component.tsx +131 -0
- package/src/lib/components/chips/Chips.component.tsx +169 -0
- package/src/lib/components/circularprogressbar/CircularProgressBar.component.style.ts +31 -0
- package/src/lib/components/circularprogressbar/CircularProgressBar.component.tsx +58 -0
- package/src/lib/components/cloudprogressbar/CloudProgressBar.component.tsx +105 -0
- package/src/lib/components/collapsiblepanel/CollapsiblePanel.component.tsx +77 -0
- package/src/lib/components/constants.ts +67 -0
- package/src/lib/components/constrainedtext/Constrainedtext.component.tsx +93 -0
- package/src/lib/components/coreuithemeprovider/CoreUiThemeProvider.tsx +21 -0
- package/src/lib/components/date/FormattedDateTime.spec.tsx +217 -0
- package/src/lib/components/date/FormattedDateTime.tsx +150 -0
- package/src/lib/components/date/dateDiffer.spec.ts +13 -0
- package/src/lib/components/date/dateDiffer.ts +12 -0
- package/src/lib/components/dropdown/Dropdown.component.tsx +184 -0
- package/src/lib/components/dropzone/Dropzone.tsx +181 -0
- package/src/lib/components/emptystate/Emptystate.component.tsx +66 -0
- package/src/lib/components/emptytable/Emptytable.component.tsx +79 -0
- package/src/lib/components/error-pages/ErrorPage401.component.tsx +77 -0
- package/src/lib/components/error-pages/ErrorPage404.component.tsx +64 -0
- package/src/lib/components/error-pages/ErrorPage500.component.tsx +88 -0
- package/src/lib/components/error-pages/ErrorPageAuth.component.tsx +70 -0
- package/src/lib/components/error-pages/ErrorPageStyle.ts +34 -0
- package/src/lib/components/form/Form.component.tsx +416 -0
- package/src/lib/components/globalhealthbar/GlobalHealthBar.component.tsx +201 -0
- package/src/lib/components/globalhealthbar/tooltip/index.ts +72 -0
- package/src/lib/components/healthselectorv2/HealthSelector.component.test.tsx +62 -0
- package/src/lib/components/healthselectorv2/HealthSelector.component.tsx +103 -0
- package/src/lib/components/icon/Icon.component.tsx +280 -0
- package/src/lib/components/infomessage/InfoMessage.component.tsx +47 -0
- package/src/lib/components/infomessage/InfoMessageUtils.test.tsx +110 -0
- package/src/lib/components/infomessage/InfoMessageUtils.ts +39 -0
- package/src/lib/components/input/Input.component.style.ts +141 -0
- package/src/lib/components/input/Input.component.tsx +174 -0
- package/src/lib/components/inputlist/InputButtons.tsx +111 -0
- package/src/lib/components/inputlist/InputList.component.tsx +98 -0
- package/src/lib/components/inputlist/InputList.test.tsx +102 -0
- package/src/lib/components/inputv2/inputv2.tsx +155 -0
- package/src/lib/components/lateralnavbarlayout/LateralNavbarLayout.component.tsx +38 -0
- package/src/lib/components/layout/Layout.component.tsx +46 -0
- package/src/lib/components/layout/v2/AppContainer.tsx +160 -0
- package/src/lib/components/layout/v2/index.tsx +30 -0
- package/src/lib/components/layout/v2/panels.tsx +105 -0
- package/src/lib/components/linechart/LineChart.component.tsx +152 -0
- package/src/lib/components/linetemporalchart/ChartUtil.test.ts +261 -0
- package/src/lib/components/linetemporalchart/ChartUtil.ts +187 -0
- package/src/lib/components/linetemporalchart/LineTemporalChart.component.tsx +797 -0
- package/src/lib/components/linetemporalchart/MetricTimespanProvider.tsx +50 -0
- package/src/lib/components/linetemporalchart/tooltip/index.ts +178 -0
- package/src/lib/components/loader/Loader.component.tsx +71 -0
- package/src/lib/components/modal/Modal.component.tsx +121 -0
- package/src/lib/components/multiselect/MultiSelect.component.tsx +158 -0
- package/src/lib/components/navbar/Navbar.component.tsx +238 -0
- package/src/lib/components/notifications/Notification.component.tsx +160 -0
- package/src/lib/components/notifications/Notifications.component.tsx +73 -0
- package/src/lib/components/prettybytes/PrettyBytes.component.tsx +39 -0
- package/src/lib/components/prettybytes/prettybytes.test.tsx +217 -0
- package/src/lib/components/progressbar/ProgressBar.component.tsx +217 -0
- package/src/lib/components/scrollbarwrapper/ScrollbarWrapper.component.tsx +66 -0
- package/src/lib/components/searchinput/SearchInput.component.tsx +146 -0
- package/src/lib/components/select/Select.component.tsx +98 -0
- package/src/lib/components/selectv2/SelectStyle.ts +267 -0
- package/src/lib/components/selectv2/Selectv2.component.tsx +487 -0
- package/src/lib/components/selectv2/selectv2.test.tsx +277 -0
- package/src/lib/components/sidebar/Sidebar.component.tsx +217 -0
- package/src/lib/components/spacedbox/SpacedBox.ts +116 -0
- package/src/lib/components/sparkline/SparkLine.component.tsx +176 -0
- package/src/lib/components/statuswrapper/Statuswrapper.component.tsx +66 -0
- package/src/lib/components/steppers/Stepper.component.d.ts +70 -0
- package/src/lib/components/steppers/Stepper.component.tsx +62 -0
- package/src/lib/components/steppers/Steppers.component.tsx +157 -0
- package/src/lib/components/tablev2/MultiSelectableContent.tsx +318 -0
- package/src/lib/components/tablev2/Search.tsx +112 -0
- package/src/lib/components/tablev2/SearchWithQueryParams.tsx +38 -0
- package/src/lib/components/tablev2/SingleSelectableContent.tsx +222 -0
- package/src/lib/components/tablev2/TableCommon.tsx +102 -0
- package/src/lib/components/tablev2/TableUtils.test.ts +17 -0
- package/src/lib/components/tablev2/TableUtils.ts +60 -0
- package/src/lib/components/tablev2/Tablestyle.tsx +184 -0
- package/src/lib/components/tablev2/Tablev2.component.tsx +316 -0
- package/src/lib/components/tablev2/Tablev2.test.tsx +136 -0
- package/src/lib/components/tablev2/react-table-config.ts +90 -0
- package/src/lib/components/tablev2/useCheckbox.tsx +62 -0
- package/src/lib/components/tablev2/useSyncedScroll.ts +64 -0
- package/src/lib/components/tabsv2/ScrollButton.tsx +39 -0
- package/src/lib/components/tabsv2/StyledTabs.ts +108 -0
- package/src/lib/components/tabsv2/Tab.ts +27 -0
- package/src/lib/components/tabsv2/Tabsv2.component.tsx +247 -0
- package/src/lib/components/tabsv2/useScrollingTabs.ts +335 -0
- package/src/lib/components/text/Text.component.tsx +194 -0
- package/src/lib/components/textarea/TextArea.component.tsx +106 -0
- package/src/lib/components/textbadge/TextBadge.component.tsx +44 -0
- package/src/lib/components/toast/DurationBasedProgressBar.tsx +45 -0
- package/src/lib/components/toast/Toast.component.tsx +181 -0
- package/src/lib/components/toast/ToastPositionHelpers.ts +38 -0
- package/src/lib/components/toast/ToastProvider.tsx +40 -0
- package/src/lib/components/toast/useMutationsHandler.test.tsx +238 -0
- package/src/lib/components/toast/useMutationsHandler.ts +172 -0
- package/src/lib/components/toast/useToastParameters.ts +59 -0
- package/src/lib/components/toggle/Toggle.component.tsx +128 -0
- package/src/lib/components/tooltip/Tooltip.component.tsx +136 -0
- package/src/lib/components/vegachart/VegaChart.component.tsx +146 -0
- package/src/lib/components/vegachartv2/SyncedCursorCharts.tsx +30 -0
- package/src/lib/components/vegachartv2/VegaChartV2.component.tsx +279 -0
- package/src/lib/hooks.ts +26 -0
- package/src/lib/icons/branding.tsx +55 -0
- package/src/lib/icons/scality-loading.tsx +118 -0
- package/src/lib/index.css +25 -0
- package/src/lib/index.ts +75 -0
- package/src/lib/next.ts +17 -0
- package/src/lib/organisms/attachments/AttachmentConfirmationModal.tsx +311 -0
- package/src/lib/organisms/attachments/AttachmentTable.tsx +728 -0
- package/src/lib/organisms/attachments/AttachmentTypes.ts +16 -0
- package/src/lib/spacing.tsx +108 -0
- package/src/lib/style/fonts/Lato-Bold.woff +0 -0
- package/src/lib/style/fonts/Lato-Bold.woff2 +0 -0
- package/src/lib/style/fonts/Lato-Regular.woff +0 -0
- package/src/lib/style/fonts/Lato-Regular.woff2 +0 -0
- package/src/lib/style/theme.ts +270 -0
- package/src/lib/testUtils.tsx +18 -0
- package/src/lib/utils.ts +57 -0
- package/stories/Button/button.guideline.mdx +199 -0
- package/stories/Button/button.stories.tsx +299 -0
- package/stories/Icon.mdx +31 -0
- package/stories/InfoMessage/infomessage.guideline.mdx +32 -0
- package/stories/InfoMessage/infomessage.stories.tsx +124 -0
- package/stories/Introduction.mdx +32 -0
- package/stories/Select/select.guideline.mdx +91 -0
- package/stories/Select/selectv2.stories.tsx +169 -0
- package/stories/areachart.stories.tsx +121 -0
- package/stories/banner.stories.tsx +75 -0
- package/stories/barchart.stories.tsx +148 -0
- package/stories/box.stories.tsx +114 -0
- package/stories/breadcrumb.stories.tsx +42 -0
- package/stories/card.stories.tsx +195 -0
- package/stories/checkbox.stories.tsx +63 -0
- package/stories/chips.stories.tsx +107 -0
- package/stories/circularprogressbar.stories.tsx +136 -0
- package/stories/cloudprogressbar.stories.tsx +93 -0
- package/stories/collapsiblepanel.stories.tsx +57 -0
- package/stories/color.mdx +43 -0
- package/stories/common.tsx +39 -0
- package/stories/constrainedtext.stories.tsx +51 -0
- package/stories/controls.ts +59 -0
- package/stories/copybutton.stories.tsx +58 -0
- package/stories/data/areachart.ts +122 -0
- package/stories/data/barchart.ts +1497 -0
- package/stories/data/linechart.ts +1516 -0
- package/stories/data/list.ts +802 -0
- package/stories/data/sparklinechart.ts +164 -0
- package/stories/designprinciples.mdx +29 -0
- package/stories/dropdown.stories.tsx +146 -0
- package/stories/dropzone.stories.tsx +49 -0
- package/stories/emptystate.stories.tsx +22 -0
- package/stories/errorpage401.stories.tsx +25 -0
- package/stories/errorpage404.stories.tsx +24 -0
- package/stories/errorpage500.stories.tsx +44 -0
- package/stories/errorpageauth.stories.tsx +31 -0
- package/stories/form.stories.tsx +255 -0
- package/stories/format.mdx +44 -0
- package/stories/formattedate.stories.tsx +58 -0
- package/stories/globalhealthbar.stories.tsx +171 -0
- package/stories/guideline/chart-guideline.mdx +63 -0
- package/stories/guideline/docs-template.mdx +43 -0
- package/stories/guideline/mdxExampleComponents.tsx +57 -0
- package/stories/healthselectorv2.stories.tsx +74 -0
- package/stories/icon.stories.tsx +146 -0
- package/stories/icons.mdx +108 -0
- package/stories/input.stories.tsx +228 -0
- package/stories/inputlist.stories.tsx +57 -0
- package/stories/lateralnavbarlayout.stories.tsx +127 -0
- package/stories/layout.stories.tsx +378 -0
- package/stories/linechart.stories.tsx +319 -0
- package/stories/linecharttemporal.stories.tsx +88 -0
- package/stories/loader.stories.tsx +49 -0
- package/stories/modal.mdx +17 -0
- package/stories/modal.stories.tsx +177 -0
- package/stories/multiselect.stories.tsx +126 -0
- package/stories/navbar.stories.tsx +156 -0
- package/stories/notifications.stories.tsx +199 -0
- package/stories/pictures/icon-design-system.png +0 -0
- package/stories/prettybytes.stories.tsx +51 -0
- package/stories/progressbar.stories.tsx +174 -0
- package/stories/scrollbar.stories.tsx +76 -0
- package/stories/searchinput.stories.tsx +86 -0
- package/stories/select.stories.tsx +52 -0
- package/stories/selectinput.stories.tsx +73 -0
- package/stories/sidebar.stories.tsx +95 -0
- package/stories/spacing.stories.mdx +50 -0
- package/stories/spacing.stories.tsx +116 -0
- package/stories/sparkline.stories.tsx +85 -0
- package/stories/statuswrapper.stories.tsx +108 -0
- package/stories/stepper.stories.tsx +124 -0
- package/stories/steppers.stories.tsx +115 -0
- package/stories/tablev2.stories.tsx +539 -0
- package/stories/tabsv2.stories.tsx +168 -0
- package/stories/text.stories.tsx +138 -0
- package/stories/textarea.stories.tsx +69 -0
- package/stories/textbadge.stories.tsx +27 -0
- package/stories/toast.stories.tsx +144 -0
- package/stories/toggle.stories.tsx +45 -0
- package/stories/tooltip.stories.tsx +170 -0
- package/stories/typography.mdx +28 -0
- package/stories/vegachart.stories.tsx +98 -0
- package/tsconfig.json +18 -0
- package/types/styled.d.ts +6 -0
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { act, renderHook } from '@testing-library/react-hooks';
|
|
2
|
+
import { useToast } from './ToastProvider';
|
|
3
|
+
import { useMutationsHandler } from './useMutationsHandler';
|
|
4
|
+
|
|
5
|
+
jest.mock('./ToastProvider', () => ({
|
|
6
|
+
useToast: jest.fn(),
|
|
7
|
+
}));
|
|
8
|
+
|
|
9
|
+
const mockUseToast = useToast as jest.MockedFunction<typeof useToast>;
|
|
10
|
+
|
|
11
|
+
const mutationResultMock = {
|
|
12
|
+
context: undefined,
|
|
13
|
+
data: ['mockData'],
|
|
14
|
+
failureCount: 0,
|
|
15
|
+
error: null,
|
|
16
|
+
mutate: jest.fn(),
|
|
17
|
+
mutateAsync: jest.fn(),
|
|
18
|
+
reset: jest.fn(),
|
|
19
|
+
variables: undefined,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
describe('useMutationsHandler', () => {
|
|
23
|
+
const mainMutation = {
|
|
24
|
+
mutation: {
|
|
25
|
+
isError: false,
|
|
26
|
+
isIdle: false,
|
|
27
|
+
isLoading: false,
|
|
28
|
+
isPaused: false,
|
|
29
|
+
isSuccess: true,
|
|
30
|
+
status: 'success',
|
|
31
|
+
...mutationResultMock,
|
|
32
|
+
},
|
|
33
|
+
name: 'mutation1',
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const dependantMutations = [
|
|
37
|
+
{
|
|
38
|
+
mutation: {
|
|
39
|
+
isLoading: false,
|
|
40
|
+
isSuccess: true,
|
|
41
|
+
isError: false,
|
|
42
|
+
isIdle: false,
|
|
43
|
+
status: 'success',
|
|
44
|
+
...mutationResultMock,
|
|
45
|
+
},
|
|
46
|
+
name: 'mutation2',
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
mutation: {
|
|
50
|
+
isLoading: false,
|
|
51
|
+
isSuccess: false,
|
|
52
|
+
isError: false,
|
|
53
|
+
isIdle: true,
|
|
54
|
+
status: 'idle',
|
|
55
|
+
...mutationResultMock,
|
|
56
|
+
},
|
|
57
|
+
name: 'mutation3',
|
|
58
|
+
},
|
|
59
|
+
] as const;
|
|
60
|
+
|
|
61
|
+
const messageDescriptionBuilder = jest.fn(() => 'message');
|
|
62
|
+
|
|
63
|
+
it('should call onMainMutationSuccess when a primary mutation succeeds', async () => {
|
|
64
|
+
const showToast = jest.fn();
|
|
65
|
+
const onMainMutationSuccess = jest.fn();
|
|
66
|
+
|
|
67
|
+
mockUseToast.mockImplementation(() => ({
|
|
68
|
+
showToast,
|
|
69
|
+
}));
|
|
70
|
+
|
|
71
|
+
const { waitFor } = renderHook(() =>
|
|
72
|
+
useMutationsHandler({
|
|
73
|
+
mainMutation,
|
|
74
|
+
dependantMutations,
|
|
75
|
+
messageDescriptionBuilder,
|
|
76
|
+
onMainMutationSuccess,
|
|
77
|
+
}),
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
await act(async () => {
|
|
81
|
+
await waitFor(() => {
|
|
82
|
+
expect(onMainMutationSuccess).toHaveBeenCalled();
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('should show a success toast when all mutations succeed', async () => {
|
|
88
|
+
const showToast = jest.fn();
|
|
89
|
+
|
|
90
|
+
mockUseToast.mockImplementation(() => ({
|
|
91
|
+
showToast,
|
|
92
|
+
}));
|
|
93
|
+
|
|
94
|
+
const { waitFor } = renderHook(() =>
|
|
95
|
+
useMutationsHandler({
|
|
96
|
+
mainMutation,
|
|
97
|
+
dependantMutations,
|
|
98
|
+
messageDescriptionBuilder,
|
|
99
|
+
}),
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
await act(async () => {
|
|
103
|
+
await waitFor(() => {
|
|
104
|
+
expect(showToast).toHaveBeenCalledWith({
|
|
105
|
+
open: true,
|
|
106
|
+
status: 'success',
|
|
107
|
+
message: 'message',
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('should show an error toast when at least one mutation fails', async () => {
|
|
114
|
+
const showToast = jest.fn();
|
|
115
|
+
|
|
116
|
+
mockUseToast.mockImplementation(() => ({
|
|
117
|
+
showToast,
|
|
118
|
+
}));
|
|
119
|
+
|
|
120
|
+
const mutationsWithError = [
|
|
121
|
+
{
|
|
122
|
+
mutation: {
|
|
123
|
+
isLoading: false,
|
|
124
|
+
isSuccess: false,
|
|
125
|
+
isIdle: false,
|
|
126
|
+
isError: true,
|
|
127
|
+
stauts: 'error',
|
|
128
|
+
...mutationResultMock,
|
|
129
|
+
},
|
|
130
|
+
name: 'mutation4',
|
|
131
|
+
},
|
|
132
|
+
] as const;
|
|
133
|
+
|
|
134
|
+
const { waitFor } = renderHook(() =>
|
|
135
|
+
useMutationsHandler({
|
|
136
|
+
mainMutation,
|
|
137
|
+
dependantMutations: mutationsWithError,
|
|
138
|
+
messageDescriptionBuilder,
|
|
139
|
+
}),
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
await act(async () => {
|
|
143
|
+
await waitFor(() => {
|
|
144
|
+
expect(showToast).toHaveBeenCalledWith({
|
|
145
|
+
open: true,
|
|
146
|
+
status: 'error',
|
|
147
|
+
message: 'message',
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it('should call onAllSuccess when all mutations succeeds', async () => {
|
|
154
|
+
const showToast = jest.fn();
|
|
155
|
+
const otherMutations = [
|
|
156
|
+
{
|
|
157
|
+
mutation: {
|
|
158
|
+
isLoading: false,
|
|
159
|
+
isSuccess: true,
|
|
160
|
+
isError: false,
|
|
161
|
+
isIdle: false,
|
|
162
|
+
status: 'success',
|
|
163
|
+
...mutationResultMock,
|
|
164
|
+
},
|
|
165
|
+
name: 'mutation2',
|
|
166
|
+
},
|
|
167
|
+
] as const;
|
|
168
|
+
const onAllMutationsSuccess = jest.fn();
|
|
169
|
+
|
|
170
|
+
mockUseToast.mockImplementation(() => ({
|
|
171
|
+
showToast,
|
|
172
|
+
}));
|
|
173
|
+
|
|
174
|
+
const { waitFor } = renderHook(() =>
|
|
175
|
+
useMutationsHandler({
|
|
176
|
+
mainMutation,
|
|
177
|
+
dependantMutations: otherMutations,
|
|
178
|
+
messageDescriptionBuilder,
|
|
179
|
+
onAllMutationsSuccess,
|
|
180
|
+
}),
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
await act(async () => {
|
|
184
|
+
await waitFor(() => {
|
|
185
|
+
expect(onAllMutationsSuccess).toHaveBeenCalled();
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it('should not call onAllSuccess when all mutations failed', async () => {
|
|
191
|
+
const showToast = jest.fn();
|
|
192
|
+
const firstMutation = {
|
|
193
|
+
mutation: {
|
|
194
|
+
isError: true,
|
|
195
|
+
isIdle: false,
|
|
196
|
+
isLoading: false,
|
|
197
|
+
isPaused: false,
|
|
198
|
+
isSuccess: false,
|
|
199
|
+
status: 'error',
|
|
200
|
+
...mutationResultMock,
|
|
201
|
+
},
|
|
202
|
+
name: 'mutation1',
|
|
203
|
+
};
|
|
204
|
+
const otherMutations = [
|
|
205
|
+
{
|
|
206
|
+
mutation: {
|
|
207
|
+
isLoading: false,
|
|
208
|
+
isSuccess: false,
|
|
209
|
+
isError: true,
|
|
210
|
+
isIdle: false,
|
|
211
|
+
status: 'error',
|
|
212
|
+
...mutationResultMock,
|
|
213
|
+
},
|
|
214
|
+
name: 'mutation2',
|
|
215
|
+
},
|
|
216
|
+
] as const;
|
|
217
|
+
const onAllMutationsSuccess = jest.fn();
|
|
218
|
+
|
|
219
|
+
mockUseToast.mockImplementation(() => ({
|
|
220
|
+
showToast,
|
|
221
|
+
}));
|
|
222
|
+
|
|
223
|
+
const { waitFor } = renderHook(() =>
|
|
224
|
+
useMutationsHandler({
|
|
225
|
+
mainMutation: firstMutation,
|
|
226
|
+
dependantMutations: otherMutations,
|
|
227
|
+
messageDescriptionBuilder,
|
|
228
|
+
onAllMutationsSuccess,
|
|
229
|
+
}),
|
|
230
|
+
);
|
|
231
|
+
|
|
232
|
+
await act(async () => {
|
|
233
|
+
await waitFor(() => {
|
|
234
|
+
expect(onAllMutationsSuccess).not.toHaveBeenCalled();
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
});
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { ReactNode, useCallback, useEffect } from 'react';
|
|
2
|
+
import { UseMutationOptions, UseMutationResult } from 'react-query';
|
|
3
|
+
import { ToastContextState, useToast } from './ToastProvider';
|
|
4
|
+
|
|
5
|
+
export type MutationConfig<T> = {
|
|
6
|
+
mutation: T;
|
|
7
|
+
name: string;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
declare type GetResults<T> = T extends MutationConfig<
|
|
11
|
+
MinimalMutationResult<infer TData, infer TError>
|
|
12
|
+
>
|
|
13
|
+
? MutationConfig<MinimalMutationResult<TData, TError>>
|
|
14
|
+
: T extends MinimalMutationResult<infer TData, infer TError>
|
|
15
|
+
? MutationConfig<MinimalMutationResult<TData, TError>>
|
|
16
|
+
: MutationConfig<MinimalMutationResult<unknown, unknown>>;
|
|
17
|
+
|
|
18
|
+
declare type GetDescriptionBuilder<T> = T extends MutationConfig<
|
|
19
|
+
MinimalMutationResult<infer TData, infer TError>
|
|
20
|
+
>
|
|
21
|
+
? DescriptionBuilder<TData, TError>
|
|
22
|
+
: T extends MutationConfig<UseMutationOptions<infer TData, infer TError>>
|
|
23
|
+
? DescriptionBuilder<TData, TError>
|
|
24
|
+
: T extends MinimalMutationResult<infer TData, infer TError>
|
|
25
|
+
? DescriptionBuilder<TData, TError>
|
|
26
|
+
: never;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* MutationResults reducer recursively maps type param to results
|
|
30
|
+
*/
|
|
31
|
+
declare type MutationsResults<T extends unknown[]> = T extends []
|
|
32
|
+
? []
|
|
33
|
+
: T extends [infer Head, ...infer Tail]
|
|
34
|
+
? [GetResults<Head>, ...MutationsResults<Tail>]
|
|
35
|
+
: T extends [infer Head]
|
|
36
|
+
? [GetResults<Head>]
|
|
37
|
+
: unknown[] extends T
|
|
38
|
+
? T
|
|
39
|
+
: never;
|
|
40
|
+
|
|
41
|
+
enum DescriptionBuilderStatus {
|
|
42
|
+
Success = 'success',
|
|
43
|
+
Error = 'error',
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
type DescriptionBuilder<Data = unknown, Error = unknown> = {
|
|
47
|
+
error?: Error;
|
|
48
|
+
data?: Data;
|
|
49
|
+
status: DescriptionBuilderStatus;
|
|
50
|
+
name: string;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
declare type DescriptionBuilders<T extends any[]> = T extends []
|
|
54
|
+
? []
|
|
55
|
+
: T extends [infer Head, ...infer Tail]
|
|
56
|
+
? [GetDescriptionBuilder<Head>, ...DescriptionBuilders<Tail>]
|
|
57
|
+
: T extends [infer Head]
|
|
58
|
+
? [GetDescriptionBuilder<Head>]
|
|
59
|
+
: T extends UseMutationOptions<
|
|
60
|
+
infer TMutationFnData,
|
|
61
|
+
infer TError,
|
|
62
|
+
infer TData
|
|
63
|
+
>[]
|
|
64
|
+
? DescriptionBuilder<
|
|
65
|
+
unknown extends TData ? TMutationFnData : TData,
|
|
66
|
+
TError
|
|
67
|
+
>[]
|
|
68
|
+
: DescriptionBuilder[];
|
|
69
|
+
|
|
70
|
+
type Props<MainMutationType, T extends any[]> = {
|
|
71
|
+
mainMutation: MutationConfig<MainMutationType>;
|
|
72
|
+
dependantMutations?:
|
|
73
|
+
| readonly [...MutationsResults<T>]
|
|
74
|
+
| MutationConfig<MinimalMutationResult<unknown, unknown>>[];
|
|
75
|
+
messageDescriptionBuilder: (
|
|
76
|
+
mutations: T extends []
|
|
77
|
+
? [GetDescriptionBuilder<MainMutationType>]
|
|
78
|
+
: [GetDescriptionBuilder<MainMutationType>, ...DescriptionBuilders<T>],
|
|
79
|
+
) => ReactNode;
|
|
80
|
+
toastProps?: Pick<
|
|
81
|
+
ToastContextState,
|
|
82
|
+
'style' | 'autoDismiss' | 'position' | 'duration' | 'withProgressBar'
|
|
83
|
+
>;
|
|
84
|
+
} & (
|
|
85
|
+
| { onMainMutationSuccess?: () => void; onAllMutationsSuccess?: never }
|
|
86
|
+
| { onAllMutationsSuccess?: () => void; onMainMutationSuccess?: never }
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
type MinimalMutationResult<TData, TError> = Pick<
|
|
90
|
+
UseMutationResult<TData, TError, unknown, unknown>,
|
|
91
|
+
'isError' | 'isIdle' | 'isSuccess' | 'isLoading' | 'error' | 'data'
|
|
92
|
+
>;
|
|
93
|
+
|
|
94
|
+
export const useMutationsHandler = <
|
|
95
|
+
MainMutationType extends MinimalMutationResult<unknown, unknown>,
|
|
96
|
+
T extends any[] | [],
|
|
97
|
+
>({
|
|
98
|
+
mainMutation,
|
|
99
|
+
dependantMutations,
|
|
100
|
+
messageDescriptionBuilder,
|
|
101
|
+
toastProps,
|
|
102
|
+
...rest
|
|
103
|
+
}: Props<MainMutationType, T>) => {
|
|
104
|
+
const { showToast } = useToast();
|
|
105
|
+
const mutations = [
|
|
106
|
+
mainMutation,
|
|
107
|
+
...(dependantMutations ? dependantMutations : []),
|
|
108
|
+
] as MutationConfig<MinimalMutationResult<unknown, unknown>>[];
|
|
109
|
+
|
|
110
|
+
const handleMutationsCompletion = useCallback(async () => {
|
|
111
|
+
const results = await Promise.all(mutations.map((m) => m.mutation));
|
|
112
|
+
|
|
113
|
+
const loadingMutations = mutations.filter(
|
|
114
|
+
(_, index) => results[index].isLoading,
|
|
115
|
+
);
|
|
116
|
+
const successMutations = mutations.filter(
|
|
117
|
+
(_, index) => results[index].isSuccess,
|
|
118
|
+
);
|
|
119
|
+
const errorMutations = mutations.filter(
|
|
120
|
+
(_, index) => results[index].isError,
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
const mainMutationDesc: GetDescriptionBuilder<MainMutationType> = {
|
|
124
|
+
data: mainMutation.mutation?.data,
|
|
125
|
+
status: DescriptionBuilderStatus.Success,
|
|
126
|
+
name: mainMutation.name,
|
|
127
|
+
} as GetDescriptionBuilder<MainMutationType>;
|
|
128
|
+
const descriptionBuilders = [
|
|
129
|
+
mainMutationDesc,
|
|
130
|
+
...((dependantMutations?.map(({ mutation, name }) => ({
|
|
131
|
+
data: mutation.data,
|
|
132
|
+
error: mutation.isError && mutation.error,
|
|
133
|
+
status: mutation.isSuccess
|
|
134
|
+
? DescriptionBuilderStatus.Success
|
|
135
|
+
: DescriptionBuilderStatus.Error,
|
|
136
|
+
name,
|
|
137
|
+
})) as DescriptionBuilders<T>) || ([] as DescriptionBuilders<T>)),
|
|
138
|
+
] as T extends []
|
|
139
|
+
? [GetDescriptionBuilder<MainMutationType>]
|
|
140
|
+
: [GetDescriptionBuilder<MainMutationType>, ...DescriptionBuilders<T>];
|
|
141
|
+
|
|
142
|
+
if (loadingMutations.length === 0) {
|
|
143
|
+
if (errorMutations.length > 0) {
|
|
144
|
+
if (mainMutation.mutation?.isSuccess) {
|
|
145
|
+
'onMainMutationSuccess' in rest && rest?.onMainMutationSuccess?.();
|
|
146
|
+
}
|
|
147
|
+
showToast({
|
|
148
|
+
open: true,
|
|
149
|
+
status: 'error',
|
|
150
|
+
message: messageDescriptionBuilder(descriptionBuilders),
|
|
151
|
+
...toastProps,
|
|
152
|
+
});
|
|
153
|
+
return;
|
|
154
|
+
} else if (successMutations.length > 0) {
|
|
155
|
+
'onMainMutationSuccess' in rest && rest?.onMainMutationSuccess?.();
|
|
156
|
+
if (successMutations.length === mutations.length) {
|
|
157
|
+
'onAllMutationsSuccess' in rest && rest?.onAllMutationsSuccess?.();
|
|
158
|
+
}
|
|
159
|
+
showToast({
|
|
160
|
+
open: true,
|
|
161
|
+
status: 'success',
|
|
162
|
+
message: messageDescriptionBuilder(descriptionBuilders),
|
|
163
|
+
...(toastProps ? toastProps : {}),
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}, [JSON.stringify(mutations)]);
|
|
168
|
+
|
|
169
|
+
useEffect(() => {
|
|
170
|
+
handleMutationsCompletion();
|
|
171
|
+
}, [handleMutationsCompletion]);
|
|
172
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef } from 'react';
|
|
2
|
+
|
|
3
|
+
interface ToastParameters {
|
|
4
|
+
duration?: number | null;
|
|
5
|
+
open?: boolean;
|
|
6
|
+
onClose?: () => void;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function useToastParameters(params: ToastParameters) {
|
|
10
|
+
const { duration = null, open, onClose } = params;
|
|
11
|
+
|
|
12
|
+
const timerAutoHide = useRef<ReturnType<typeof setTimeout>>();
|
|
13
|
+
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
if (!open) {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function handleKeyDown(nativeEvent: KeyboardEvent) {
|
|
20
|
+
if (!nativeEvent.defaultPrevented) {
|
|
21
|
+
if (nativeEvent.key === 'Escape' || nativeEvent.key === 'Esc') {
|
|
22
|
+
onClose?.();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
document.addEventListener('keydown', handleKeyDown);
|
|
28
|
+
|
|
29
|
+
return () => {
|
|
30
|
+
document.removeEventListener('keydown', handleKeyDown);
|
|
31
|
+
};
|
|
32
|
+
}, [open, onClose]);
|
|
33
|
+
|
|
34
|
+
const setAutoHideTimer = useCallback(
|
|
35
|
+
(autoHideDurationParam: number | null) => {
|
|
36
|
+
if (!onClose || autoHideDurationParam == null) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
clearTimeout(timerAutoHide.current);
|
|
41
|
+
timerAutoHide.current = setTimeout(() => {
|
|
42
|
+
onClose?.();
|
|
43
|
+
}, autoHideDurationParam);
|
|
44
|
+
},
|
|
45
|
+
[onClose],
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
if (open) {
|
|
50
|
+
setAutoHideTimer(duration);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return () => {
|
|
54
|
+
clearTimeout(timerAutoHide.current);
|
|
55
|
+
};
|
|
56
|
+
}, [open, duration, setAutoHideTimer]);
|
|
57
|
+
|
|
58
|
+
return { params };
|
|
59
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { ChangeEvent, InputHTMLAttributes, useRef } from 'react';
|
|
2
|
+
import styled, { css } from 'styled-components';
|
|
3
|
+
|
|
4
|
+
import { spacing } from '../../style/theme';
|
|
5
|
+
import { LABEL_PREFIX, useFieldContext } from '../form/Form.component';
|
|
6
|
+
import { Stack } from '../../spacing';
|
|
7
|
+
import { Text } from '../text/Text.component';
|
|
8
|
+
|
|
9
|
+
type Props = InputHTMLAttributes<HTMLInputElement> & {
|
|
10
|
+
toggle: boolean;
|
|
11
|
+
onChange: (e: ChangeEvent<HTMLInputElement>) => void;
|
|
12
|
+
label?: string;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
};
|
|
15
|
+
const ToggleContainer = styled.span<{ disabled?: boolean }>`
|
|
16
|
+
display: inline-flex;
|
|
17
|
+
align-items: center;
|
|
18
|
+
position: relative;
|
|
19
|
+
opacity: ${(props) => (props.disabled ? 0.5 : 1)};
|
|
20
|
+
`;
|
|
21
|
+
const Switch = styled.label<{ disabled?: boolean }>`
|
|
22
|
+
position: relative;
|
|
23
|
+
width: ${spacing.sp24};
|
|
24
|
+
height: ${spacing.sp14};
|
|
25
|
+
align-self: center;
|
|
26
|
+
${(props) => {
|
|
27
|
+
return css`
|
|
28
|
+
${props.disabled
|
|
29
|
+
? `
|
|
30
|
+
cursor: not-allowed;
|
|
31
|
+
`
|
|
32
|
+
: `
|
|
33
|
+
cursor: pointer;
|
|
34
|
+
`}
|
|
35
|
+
`;
|
|
36
|
+
}}
|
|
37
|
+
`;
|
|
38
|
+
const Slider = styled.div<{ toggle?: boolean }>`
|
|
39
|
+
width: 100%;
|
|
40
|
+
height: 1rem;
|
|
41
|
+
background-color: ${(props) => props.theme.backgroundLevel1};
|
|
42
|
+
border: ${spacing.sp1} solid
|
|
43
|
+
${(props) => props.theme[props.toggle ? 'selectedActive' : 'infoPrimary']};
|
|
44
|
+
border-radius: ${spacing.sp8};
|
|
45
|
+
transition: 0.4s;
|
|
46
|
+
-moz-transform: rotate(0.02deg);
|
|
47
|
+
&:before {
|
|
48
|
+
border-radius: 100%;
|
|
49
|
+
position: absolute;
|
|
50
|
+
content: '';
|
|
51
|
+
height: ${spacing.sp10};
|
|
52
|
+
width: ${spacing.sp10};
|
|
53
|
+
left: 3px;
|
|
54
|
+
top: 3.5px;
|
|
55
|
+
background-color: ${(props) =>
|
|
56
|
+
props.theme[props.toggle ? 'textSecondary' : 'textPrimary']};
|
|
57
|
+
transition: 0.4s;
|
|
58
|
+
-moz-transform: rotate(0.02deg);
|
|
59
|
+
}
|
|
60
|
+
`;
|
|
61
|
+
const ToggleInput = styled.input`
|
|
62
|
+
&:checked + ${Slider} {
|
|
63
|
+
background-color: ${(props) => props.theme.selectedActive};
|
|
64
|
+
}
|
|
65
|
+
&:checked + ${Slider}:before {
|
|
66
|
+
transform: translateX(${spacing.sp10});
|
|
67
|
+
}
|
|
68
|
+
display: none;
|
|
69
|
+
`;
|
|
70
|
+
const StyledSwitchLabel = styled.label<{ toggle?: boolean }>`
|
|
71
|
+
color: ${(props) =>
|
|
72
|
+
props.theme[props.toggle ? 'textPrimary' : 'textPrimary']};
|
|
73
|
+
`;
|
|
74
|
+
|
|
75
|
+
function ToggleSwitch({ toggle, label, onChange, disabled, ...rest }: Props) {
|
|
76
|
+
const { isContextAvailable } = useFieldContext();
|
|
77
|
+
const checkboxRef = useRef<HTMLInputElement | null>(null);
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<StyledSwitchLabel
|
|
81
|
+
toggle={toggle}
|
|
82
|
+
className="text"
|
|
83
|
+
id={`${rest['id']}-label`}
|
|
84
|
+
htmlFor={rest['id']}
|
|
85
|
+
>
|
|
86
|
+
<ToggleContainer className="sc-toggle" disabled={disabled}>
|
|
87
|
+
<Stack gap={'r8'} style={{ alignItems: 'baseline' }}>
|
|
88
|
+
<Switch
|
|
89
|
+
htmlFor={rest['id']}
|
|
90
|
+
role="checkbox"
|
|
91
|
+
aria-checked={toggle}
|
|
92
|
+
tabIndex={disabled ? -1 : 0}
|
|
93
|
+
aria-disabled={disabled}
|
|
94
|
+
disabled={disabled}
|
|
95
|
+
onKeyDown={(e) => {
|
|
96
|
+
if (e.code === 'Space' || e.code === 'Enter') {
|
|
97
|
+
e.preventDefault();
|
|
98
|
+
e.stopPropagation();
|
|
99
|
+
|
|
100
|
+
checkboxRef.current && checkboxRef.current.click();
|
|
101
|
+
}
|
|
102
|
+
}}
|
|
103
|
+
aria-labelledby={
|
|
104
|
+
label
|
|
105
|
+
? `${rest['id']}-label`
|
|
106
|
+
: isContextAvailable
|
|
107
|
+
? `${LABEL_PREFIX}${rest['id']}`
|
|
108
|
+
: undefined
|
|
109
|
+
}
|
|
110
|
+
>
|
|
111
|
+
<ToggleInput
|
|
112
|
+
type="checkbox"
|
|
113
|
+
checked={toggle}
|
|
114
|
+
onChange={onChange}
|
|
115
|
+
disabled={disabled}
|
|
116
|
+
ref={checkboxRef}
|
|
117
|
+
{...rest}
|
|
118
|
+
/>
|
|
119
|
+
<Slider className="sc-slider" toggle={toggle} />
|
|
120
|
+
</Switch>
|
|
121
|
+
{label && <Text>{label}</Text>}
|
|
122
|
+
</Stack>
|
|
123
|
+
</ToggleContainer>
|
|
124
|
+
</StyledSwitchLabel>
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export const Toggle = ToggleSwitch;
|