@finsemble/finsemble-ui 6.1.3 → 6.2.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 +20 -17
- package/react/actions/smartDesktopDesignerActions.d.ts +5 -4
- package/react/actions/smartDesktopDesignerActions.js.map +1 -1
- package/react/assets/css/defaultTheme.css +1 -1
- package/react/assets/css/notificationsCenter.css +1 -0
- package/react/assets/css/userPreferences.css +4 -2
- package/react/assets/css/windowTitleBar.css +1 -0
- package/react/assets/icons/check-square.svg +6 -0
- package/react/assets/icons/lock.svg +6 -0
- package/react/components/common/Button.d.ts +1 -0
- package/react/components/common/Button.js +2 -2
- package/react/components/common/Button.js.map +1 -1
- package/react/components/common/ButtonRow.d.ts +15 -0
- package/react/components/common/ButtonRow.js +32 -0
- package/react/components/common/ButtonRow.js.map +1 -0
- package/react/components/common/Checkbox.d.ts +8 -0
- package/react/components/common/Checkbox.js +22 -0
- package/react/components/common/Checkbox.js.map +1 -0
- package/react/components/common/FinsembleIcon.d.ts +1 -1
- package/react/components/common/FinsembleIcon.js +4 -0
- package/react/components/common/FinsembleIcon.js.map +1 -1
- package/react/components/common/FinsembleSelect.d.ts +3 -2
- package/react/components/common/FinsembleSelect.js +2 -2
- package/react/components/common/FinsembleSelect.js.map +1 -1
- package/react/components/common/Tooltip.d.ts +4 -3
- package/react/components/common/Tooltip.js +3 -3
- package/react/components/common/Tooltip.js.map +1 -1
- package/react/components/common/css/tooltip.css +10 -0
- package/react/components/common/helpers.js +12 -0
- package/react/components/common/helpers.js.map +1 -1
- package/react/components/common/stories/ButtonRow.stories.d.ts +14 -0
- package/react/components/common/stories/ButtonRow.stories.js +39 -0
- package/react/components/common/stories/ButtonRow.stories.js.map +1 -0
- package/react/components/common/stories/Checkbox.stories.d.ts +13 -0
- package/react/components/common/stories/Checkbox.stories.js +29 -0
- package/react/components/common/stories/Checkbox.stories.js.map +1 -0
- package/react/components/common/stories/DropdownButton.stories.d.ts +22 -0
- package/react/components/common/stories/DropdownButton.stories.js +29 -0
- package/react/components/common/stories/DropdownButton.stories.js.map +1 -0
- package/react/components/common/stories/FinsembleIcon.stories.js +2 -0
- package/react/components/common/stories/FinsembleIcon.stories.js.map +1 -1
- package/react/components/common/stories/FinsembleSelect.stories.d.ts +1 -1
- package/react/components/common/stories/Tooltip.stories.d.ts +1 -1
- package/react/components/{shared/addProtocolToValidURL.spec.d.ts → common/tests/ButtonRow.spec.d.ts} +0 -0
- package/react/components/common/tests/ButtonRow.spec.js +25 -0
- package/react/components/common/tests/ButtonRow.spec.js.map +1 -0
- package/react/components/common/tests/Checkbox.spec.d.ts +1 -0
- package/react/components/common/tests/Checkbox.spec.js +33 -0
- package/react/components/common/tests/Checkbox.spec.js.map +1 -0
- package/react/components/fdc3Resolver/ResolverDialog.css +1 -0
- package/react/components/fdc3Resolver/ResolverDialog.js +4 -5
- package/react/components/fdc3Resolver/ResolverDialog.js.map +1 -1
- package/react/components/fdc3Resolver/ResolverDialog.spec.js +1 -8
- package/react/components/fdc3Resolver/ResolverDialog.spec.js.map +1 -1
- package/react/components/fdc3Resolver/ResolverDialog.stories.js +45 -45
- package/react/components/fdc3Resolver/ResolverDialog.stories.js.map +1 -1
- package/react/components/notifications/components/drawer/DrawerHeader.js +6 -6
- package/react/components/notifications/components/drawer/DrawerHeader.js.map +1 -1
- package/react/components/notifications/components/notificationsCenter/NotificationsCenter.js +32 -31
- package/react/components/notifications/components/notificationsCenter/NotificationsCenter.js.map +1 -1
- package/react/components/notifications/components/notificationsToasts/NotificationsToasts.js +4 -6
- package/react/components/notifications/components/notificationsToasts/NotificationsToasts.js.map +1 -1
- package/react/components/notifications/components/views/ListView.js +1 -1
- package/react/components/notifications/components/views/ListView.js.map +1 -1
- package/react/components/notifications/components/views/NotificationDetailsView.js +3 -2
- package/react/components/notifications/components/views/NotificationDetailsView.js.map +1 -1
- package/react/components/notifications/constants.d.ts +13 -0
- package/react/components/notifications/constants.js.map +1 -1
- package/react/components/search/Highlight.js +13 -3
- package/react/components/search/Highlight.js.map +1 -1
- package/react/components/shared/DefaultDropdownButton.d.ts +1 -0
- package/react/components/shared/DefaultDropdownButton.js +14 -4
- package/react/components/shared/DefaultDropdownButton.js.map +1 -1
- package/react/components/shared/tests/DefaultDropdownButton.spec.d.ts +1 -0
- package/react/components/shared/tests/DefaultDropdownButton.spec.js +54 -0
- package/react/components/shared/tests/DefaultDropdownButton.spec.js.map +1 -0
- package/react/components/shared/tests/addProtocolToValidURL.spec.d.ts +1 -0
- package/react/components/shared/{addProtocolToValidURL.spec.js → tests/addProtocolToValidURL.spec.js} +1 -1
- package/react/components/shared/tests/addProtocolToValidURL.spec.js.map +1 -0
- package/react/components/smartDesktopDesigner/AppEditAccess.d.ts +15 -0
- package/react/components/smartDesktopDesigner/AppEditAccess.js +155 -0
- package/react/components/smartDesktopDesigner/AppEditAccess.js.map +1 -0
- package/react/components/smartDesktopDesigner/AppEditPage.d.ts +7 -1
- package/react/components/smartDesktopDesigner/AppEditPage.js +5 -1
- package/react/components/smartDesktopDesigner/AppEditPage.js.map +1 -1
- package/react/components/smartDesktopDesigner/Application.d.ts +4 -1
- package/react/components/smartDesktopDesigner/Application.js +20 -10
- package/react/components/smartDesktopDesigner/Application.js.map +1 -1
- package/react/components/smartDesktopDesigner/ApplicationEdit.d.ts +3 -0
- package/react/components/smartDesktopDesigner/ApplicationEdit.js +2 -2
- package/react/components/smartDesktopDesigner/ApplicationEdit.js.map +1 -1
- package/react/components/smartDesktopDesigner/ApplicationList.js +11 -1
- package/react/components/smartDesktopDesigner/ApplicationList.js.map +1 -1
- package/react/components/smartDesktopDesigner/ApplicationSetup.d.ts +6 -1
- package/react/components/smartDesktopDesigner/ApplicationSetup.js.map +1 -1
- package/react/components/smartDesktopDesigner/Applications.d.ts +2 -0
- package/react/components/smartDesktopDesigner/Applications.js +2 -2
- package/react/components/smartDesktopDesigner/Applications.js.map +1 -1
- package/react/components/smartDesktopDesigner/common/views.js +2 -0
- package/react/components/smartDesktopDesigner/common/views.js.map +1 -1
- package/react/components/smartDesktopDesigner/css/applications.css +38 -0
- package/react/components/smartDesktopDesigner/fixtures/applicationEditProps.js +18 -0
- package/react/components/smartDesktopDesigner/fixtures/applicationEditProps.js.map +1 -1
- package/react/components/smartDesktopDesigner/fixtures/applicationSetupProps.js +9 -0
- package/react/components/smartDesktopDesigner/fixtures/applicationSetupProps.js.map +1 -1
- package/react/components/smartDesktopDesigner/fixtures/applicationsProps.js +6 -2
- package/react/components/smartDesktopDesigner/fixtures/applicationsProps.js.map +1 -1
- package/react/components/smartDesktopDesigner/fixtures/apps.d.ts +71 -2
- package/react/components/smartDesktopDesigner/fixtures/apps.js +16 -5
- package/react/components/smartDesktopDesigner/fixtures/apps.js.map +1 -1
- package/react/components/smartDesktopDesigner/stories/AppEditPage.stories.d.ts +1 -1
- package/react/components/smartDesktopDesigner/stories/AppEditPage.stories.js +20 -0
- package/react/components/smartDesktopDesigner/stories/AppEditPage.stories.js.map +1 -1
- package/react/components/smartDesktopDesigner/stories/Applications.stories.js +2 -1
- package/react/components/smartDesktopDesigner/stories/Applications.stories.js.map +1 -1
- package/react/components/smartDesktopDesigner/tests/AppEditPage.spec.js +1 -0
- package/react/components/smartDesktopDesigner/tests/AppEditPage.spec.js.map +1 -1
- package/react/components/smartDesktopDesigner/tests/Applications.spec.d.ts +1 -1
- package/react/components/smartDesktopDesigner/tests/Applications.spec.js +84 -7
- package/react/components/smartDesktopDesigner/tests/Applications.spec.js.map +1 -1
- package/react/components/toolbar/advancedAppLauncher/components/Content.js +2 -3
- package/react/components/toolbar/advancedAppLauncher/components/Content.js.map +1 -1
- package/react/components/toolbar/advancedAppLauncher/components/FoldersList.js +1 -1
- package/react/components/toolbar/advancedAppLauncher/components/FoldersList.js.map +1 -1
- package/react/components/toolbar/dashbar/Dashbar.js +23 -11
- package/react/components/toolbar/dashbar/Dashbar.js.map +1 -1
- package/react/components/userPreferences/UserPreferences.js +8 -23
- package/react/components/userPreferences/UserPreferences.js.map +1 -1
- package/react/components/userPreferences/UserPreferencesBase.d.ts +3 -1
- package/react/components/userPreferences/UserPreferencesBase.js +5 -6
- package/react/components/userPreferences/UserPreferencesBase.js.map +1 -1
- package/react/components/userPreferences/UserPreferencesWrapper.d.ts +4 -0
- package/react/components/userPreferences/UserPreferencesWrapper.js +27 -0
- package/react/components/userPreferences/UserPreferencesWrapper.js.map +1 -0
- package/react/components/userPreferences/components/ContentSection.d.ts +18 -3
- package/react/components/userPreferences/components/ContentSection.js +4 -2
- package/react/components/userPreferences/components/ContentSection.js.map +1 -1
- package/react/components/userPreferences/components/LeftNav.d.ts +19 -4
- package/react/components/userPreferences/components/LeftNav.js +11 -10
- package/react/components/userPreferences/components/LeftNav.js.map +1 -1
- package/react/components/userPreferences/components/content/DashbarEditor.d.ts +20 -5
- package/react/components/userPreferences/components/content/DashbarEditor.js +11 -11
- package/react/components/userPreferences/components/content/DashbarEditor.js.map +1 -1
- package/react/components/userPreferences/components/content/DashbarEditorItem.d.ts +10 -0
- package/react/components/userPreferences/components/content/DashbarEditorItem.js +11 -0
- package/react/components/userPreferences/components/content/DashbarEditorItem.js.map +1 -0
- package/react/components/userPreferences/components/content/General.d.ts +10 -3
- package/react/components/userPreferences/components/content/General.js +2 -2
- package/react/components/userPreferences/components/content/General.js.map +1 -1
- package/react/components/userPreferences/components/content/Workspaces.js +39 -112
- package/react/components/userPreferences/components/content/Workspaces.js.map +1 -1
- package/react/components/userPreferences/components/content/notificationViews/NotificationsPreferencesHome.js +9 -11
- package/react/components/userPreferences/components/content/notificationViews/NotificationsPreferencesHome.js.map +1 -1
- package/react/components/userPreferences/components/content/notificationViews/NotificationsSourceTypes.d.ts +1 -1
- package/react/components/userPreferences/components/content/notificationViews/NotificationsSourceTypes.js +9 -7
- package/react/components/userPreferences/components/content/notificationViews/NotificationsSourceTypes.js.map +1 -1
- package/react/components/userPreferences/components/content/notificationViews/NotificationsSourcesPreferences.d.ts +3 -1
- package/react/components/userPreferences/components/content/notificationViews/NotificationsSourcesPreferences.js +13 -12
- package/react/components/userPreferences/components/content/notificationViews/NotificationsSourcesPreferences.js.map +1 -1
- package/react/components/userPreferences/components/general/ScheduledRestart.d.ts +24 -7
- package/react/components/userPreferences/components/general/ScheduledRestart.js +71 -22
- package/react/components/userPreferences/components/general/ScheduledRestart.js.map +1 -1
- package/react/components/userPreferences/components/workspaces/WorkspaceButton.d.ts +9 -0
- package/react/components/userPreferences/components/workspaces/WorkspaceButton.js +5 -0
- package/react/components/userPreferences/components/workspaces/WorkspaceButton.js.map +1 -0
- package/react/components/userPreferences/components/workspaces/WorkspaceComponents.d.ts +6 -0
- package/react/components/userPreferences/components/workspaces/WorkspaceComponents.js +8 -0
- package/react/components/userPreferences/components/workspaces/WorkspaceComponents.js.map +1 -0
- package/react/components/userPreferences/components/workspaces/WorkspaceItem.d.ts +45 -0
- package/react/components/userPreferences/components/workspaces/WorkspaceItem.js +82 -0
- package/react/components/userPreferences/components/workspaces/WorkspaceItem.js.map +1 -0
- package/react/components/userPreferences/components/workspaces/WorkspaceItemList.d.ts +8 -0
- package/react/components/userPreferences/components/workspaces/WorkspaceItemList.js +7 -0
- package/react/components/userPreferences/components/workspaces/WorkspaceItemList.js.map +1 -0
- package/react/components/userPreferences/index.d.ts +1 -1
- package/react/components/userPreferences/index.js +1 -1
- package/react/components/userPreferences/index.js.map +1 -1
- package/react/components/userPreferences/stores/UserPreferencesStore.d.ts +0 -1
- package/react/components/userPreferences/stores/UserPreferencesStore.js +4 -9
- package/react/components/userPreferences/stores/UserPreferencesStore.js.map +1 -1
- package/react/components/userPreferences/stories/DashbarEditor.stories.d.ts +2 -1
- package/react/components/userPreferences/stories/DashbarEditor.stories.js +35 -4
- package/react/components/userPreferences/stories/DashbarEditor.stories.js.map +1 -1
- package/react/components/userPreferences/stories/DashbarEditorItem.stories.d.ts +11 -0
- package/react/components/userPreferences/stories/DashbarEditorItem.stories.js +21 -0
- package/react/components/userPreferences/stories/DashbarEditorItem.stories.js.map +1 -0
- package/react/components/userPreferences/stories/General.stories.d.ts +9 -0
- package/react/components/userPreferences/stories/General.stories.js +16 -0
- package/react/components/userPreferences/stories/General.stories.js.map +1 -0
- package/react/components/userPreferences/stories/Notifications.stories.d.ts +9 -0
- package/react/components/userPreferences/stories/Notifications.stories.js +17 -0
- package/react/components/userPreferences/stories/Notifications.stories.js.map +1 -0
- package/react/components/userPreferences/stories/NotificationsSourceTypes.stories.d.ts +9 -0
- package/react/components/userPreferences/stories/NotificationsSourceTypes.stories.js +20 -0
- package/react/components/userPreferences/stories/NotificationsSourceTypes.stories.js.map +1 -0
- package/react/components/userPreferences/stories/NotificationsSources.stories.d.ts +12 -0
- package/react/components/userPreferences/stories/NotificationsSources.stories.js +28 -0
- package/react/components/userPreferences/stories/NotificationsSources.stories.js.map +1 -0
- package/react/components/userPreferences/stories/UserPreferences.stories.d.ts +8 -0
- package/react/components/userPreferences/stories/UserPreferences.stories.js +53 -0
- package/react/components/userPreferences/stories/UserPreferences.stories.js.map +1 -0
- package/react/components/userPreferences/stories/WorkspaceButton.stories.d.ts +15 -0
- package/react/components/userPreferences/stories/WorkspaceButton.stories.js +13 -0
- package/react/components/userPreferences/stories/WorkspaceButton.stories.js.map +1 -0
- package/react/components/userPreferences/stories/WorkspaceComponents.stories.d.ts +13 -0
- package/react/components/userPreferences/stories/WorkspaceComponents.stories.js +26 -0
- package/react/components/userPreferences/stories/WorkspaceComponents.stories.js.map +1 -0
- package/react/components/userPreferences/stories/WorkspaceItem.stories.d.ts +9 -0
- package/react/components/userPreferences/stories/WorkspaceItem.stories.js +30 -0
- package/react/components/userPreferences/stories/WorkspaceItem.stories.js.map +1 -0
- package/react/components/userPreferences/stories/WorkspaceItemList.stories.d.ts +10 -0
- package/react/components/userPreferences/stories/WorkspaceItemList.stories.js +57 -0
- package/react/components/userPreferences/stories/WorkspaceItemList.stories.js.map +1 -0
- package/react/components/userPreferences/stories/Workspaces.stories.d.ts +9 -0
- package/react/components/userPreferences/stories/Workspaces.stories.js +44 -0
- package/react/components/userPreferences/stories/Workspaces.stories.js.map +1 -0
- package/react/components/userPreferences/tests/ContentSection.spec.d.ts +1 -0
- package/react/components/userPreferences/tests/ContentSection.spec.js +41 -0
- package/react/components/userPreferences/tests/ContentSection.spec.js.map +1 -0
- package/react/components/userPreferences/tests/DashbarEditor.spec.d.ts +1 -0
- package/react/components/userPreferences/tests/DashbarEditor.spec.js +37 -0
- package/react/components/userPreferences/tests/DashbarEditor.spec.js.map +1 -0
- package/react/components/userPreferences/tests/DashbarEditorItem.spec.d.ts +1 -0
- package/react/components/userPreferences/tests/DashbarEditorItem.spec.js +38 -0
- package/react/components/userPreferences/tests/DashbarEditorItem.spec.js.map +1 -0
- package/react/components/userPreferences/tests/General.spec.d.ts +1 -0
- package/react/components/userPreferences/tests/General.spec.js +28 -0
- package/react/components/userPreferences/tests/General.spec.js.map +1 -0
- package/react/components/userPreferences/tests/LeftNav.spec.d.ts +1 -0
- package/react/components/userPreferences/tests/LeftNav.spec.js +12 -0
- package/react/components/userPreferences/tests/LeftNav.spec.js.map +1 -0
- package/react/components/userPreferences/tests/NotificationSourceTypes.spec.d.ts +1 -0
- package/react/components/userPreferences/tests/NotificationSourceTypes.spec.js +14 -0
- package/react/components/userPreferences/tests/NotificationSourceTypes.spec.js.map +1 -0
- package/react/components/userPreferences/tests/Notifications.spec.d.ts +1 -0
- package/react/components/userPreferences/tests/Notifications.spec.js +17 -0
- package/react/components/userPreferences/tests/Notifications.spec.js.map +1 -0
- package/react/components/userPreferences/tests/NotificationsPreferencesHome.spec.d.ts +1 -0
- package/react/components/userPreferences/tests/NotificationsPreferencesHome.spec.js +39 -0
- package/react/components/userPreferences/tests/NotificationsPreferencesHome.spec.js.map +1 -0
- package/react/components/userPreferences/tests/NotificationsSourcesPreferences.spec.d.ts +1 -0
- package/react/components/userPreferences/tests/NotificationsSourcesPreferences.spec.js +22 -0
- package/react/components/userPreferences/tests/NotificationsSourcesPreferences.spec.js.map +1 -0
- package/react/components/userPreferences/tests/ScheduledRestart.spec.d.ts +1 -0
- package/react/components/userPreferences/tests/ScheduledRestart.spec.js +70 -0
- package/react/components/userPreferences/tests/ScheduledRestart.spec.js.map +1 -0
- package/react/components/userPreferences/tests/WorkspaceButton.spec.d.ts +1 -0
- package/react/components/userPreferences/tests/WorkspaceButton.spec.js +24 -0
- package/react/components/userPreferences/tests/WorkspaceButton.spec.js.map +1 -0
- package/react/components/userPreferences/tests/WorkspaceComponents.spec.d.ts +1 -0
- package/react/components/userPreferences/tests/WorkspaceComponents.spec.js +22 -0
- package/react/components/userPreferences/tests/WorkspaceComponents.spec.js.map +1 -0
- package/react/components/userPreferences/tests/WorkspaceItem.spec.d.ts +1 -0
- package/react/components/userPreferences/tests/WorkspaceItem.spec.js +64 -0
- package/react/components/userPreferences/tests/WorkspaceItem.spec.js.map +1 -0
- package/react/components/userPreferences/tests/WorkspaceItemList.spec.d.ts +1 -0
- package/react/components/userPreferences/tests/WorkspaceItemList.spec.js +45 -0
- package/react/components/userPreferences/tests/WorkspaceItemList.spec.js.map +1 -0
- package/react/hooks/useNotifications.d.ts +4 -0
- package/react/hooks/useNotifications.js +47 -40
- package/react/hooks/useNotifications.js.map +1 -1
- package/react/hooks/usePubSub.js.map +1 -1
- package/react/hooks/useToolbar.js +71 -48
- package/react/hooks/useToolbar.js.map +1 -1
- package/react/reducers/rootReducer.d.ts +2 -2
- package/react/store.d.ts +4 -4
- package/react/types/dashbarTypes.d.ts +1 -1
- package/react/types/dashbarTypes.js.map +1 -1
- package/react/types/fdc3.d.ts +8 -22
- package/react/types/fdc3.js.map +1 -1
- package/react/types/smartDesktopDesignerTypes.d.ts +4 -1
- package/react/types/smartDesktopDesignerTypes.js.map +1 -1
- package/react/components/shared/addProtocolToValidURL.spec.js.map +0 -1
- package/react/components/userPreferences/components/Checkbox.d.ts +0 -4
- package/react/components/userPreferences/components/Checkbox.js +0 -27
- package/react/components/userPreferences/components/Checkbox.js.map +0 -1
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { mount } from "enzyme";
|
|
3
|
+
import { describe, it } from "mocha";
|
|
4
|
+
import { expect } from "chai";
|
|
5
|
+
import sinon from "sinon";
|
|
6
|
+
import addons, { mockChannel } from "@storybook/addons";
|
|
7
|
+
import WorkspaceItem, { WorkspaceEditor } from "../components/workspaces/WorkspaceItem";
|
|
8
|
+
import { Item } from "../stories/WorkspaceItem.stories";
|
|
9
|
+
import { initFSBL } from "../../common/helpers";
|
|
10
|
+
import { FinsembleProvider } from "../../FinsembleProvider";
|
|
11
|
+
import { FinsembleDnDContext } from "../../legacyControls/FinsembleDnDContext";
|
|
12
|
+
addons.setChannel(mockChannel());
|
|
13
|
+
describe("<WorkspaceItem/>", () => {
|
|
14
|
+
afterEach(() => {
|
|
15
|
+
sinon.restore();
|
|
16
|
+
});
|
|
17
|
+
it("should render workspace name and edit/ delete icons", async () => {
|
|
18
|
+
initFSBL(window);
|
|
19
|
+
const wrapper = mount(React.createElement(FinsembleProvider, null,
|
|
20
|
+
React.createElement(FinsembleDnDContext, { onDragEnd: () => { } },
|
|
21
|
+
React.createElement(WorkspaceItem, { workspace: { name: "Default" } }))));
|
|
22
|
+
expect(wrapper.find(".workspace-name").text()).to.equal("Default");
|
|
23
|
+
expect(wrapper.find(".ff-adp-edit")).to.be.length(1);
|
|
24
|
+
expect(wrapper.find(".ff-adp-trash-outline")).to.be.length(1);
|
|
25
|
+
});
|
|
26
|
+
it("should render <WorkspaceEditor/> when editing is true", async () => {
|
|
27
|
+
initFSBL(window);
|
|
28
|
+
const wrapper = mount(React.createElement(FinsembleProvider, null,
|
|
29
|
+
React.createElement(FinsembleDnDContext, { onDragEnd: () => { } },
|
|
30
|
+
React.createElement(WorkspaceItem, { workspace: { name: "Default" }, focusedWorkspace: "Default", renameButtonClasses: "individual-workspace-action", allowRename: true, editing: true }))));
|
|
31
|
+
expect(wrapper.containsMatchingElement(React.createElement(WorkspaceEditor, null))).to.equal(true);
|
|
32
|
+
});
|
|
33
|
+
it("should render <WorkspaceEditor/> on edit icon click ", async () => {
|
|
34
|
+
initFSBL(window);
|
|
35
|
+
const wrapper = mount(React.createElement(FinsembleProvider, null,
|
|
36
|
+
React.createElement(FinsembleDnDContext, { onDragEnd: () => { } },
|
|
37
|
+
React.createElement(Item, null))));
|
|
38
|
+
wrapper.find(".individual-workspace-action").at(0).simulate("click");
|
|
39
|
+
expect(wrapper.containsMatchingElement(React.createElement(WorkspaceEditor, null))).to.equal(true);
|
|
40
|
+
});
|
|
41
|
+
it("should exit WorkspaceEditor on enter ", async () => {
|
|
42
|
+
initFSBL(window);
|
|
43
|
+
const wrapper = mount(React.createElement(FinsembleProvider, null,
|
|
44
|
+
React.createElement(FinsembleDnDContext, { onDragEnd: () => { } },
|
|
45
|
+
React.createElement(Item, null))));
|
|
46
|
+
wrapper.find(".individual-workspace-action").at(0).simulate("click");
|
|
47
|
+
expect(wrapper.containsMatchingElement(React.createElement(WorkspaceEditor, null))).to.equal(true);
|
|
48
|
+
wrapper.find("input").at(0).simulate("keydown", { key: "Enter" });
|
|
49
|
+
expect(wrapper.containsMatchingElement(React.createElement(WorkspaceEditor, null))).to.equal(false);
|
|
50
|
+
expect(wrapper.find(".workspace-name").text()).to.equal("Default");
|
|
51
|
+
});
|
|
52
|
+
it("should exit WorkspaceEditor on esc ", async () => {
|
|
53
|
+
initFSBL(window);
|
|
54
|
+
const wrapper = mount(React.createElement(FinsembleProvider, null,
|
|
55
|
+
React.createElement(FinsembleDnDContext, { onDragEnd: () => { } },
|
|
56
|
+
React.createElement(Item, null))));
|
|
57
|
+
wrapper.find(".individual-workspace-action").at(0).simulate("click");
|
|
58
|
+
expect(wrapper.containsMatchingElement(React.createElement(WorkspaceEditor, null))).to.equal(true);
|
|
59
|
+
wrapper.find("input").at(0).simulate("keydown", { key: "Escape" });
|
|
60
|
+
expect(wrapper.containsMatchingElement(React.createElement(WorkspaceEditor, null))).to.equal(false);
|
|
61
|
+
expect(wrapper.find(".workspace-name").text()).to.equal("Default");
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
//# sourceMappingURL=WorkspaceItem.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WorkspaceItem.spec.js","sourceRoot":"","sources":["../../../../src/components/userPreferences/tests/WorkspaceItem.spec.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,KAAK,EAAW,MAAM,QAAQ,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,MAAM,EAAE,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAExD,OAAO,aAAa,EAAE,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAC;AACxF,OAAO,EAAE,IAAI,EAAE,MAAM,kCAAkC,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AAE/E,MAAM,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC,CAAC;AAEjC,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;IACjC,SAAS,CAAC,GAAG,EAAE;QACd,KAAK,CAAC,OAAO,EAAE,CAAC;IACjB,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,qDAAqD,EAAE,KAAK,IAAI,EAAE;QACpE,QAAQ,CAAC,MAAM,CAAC,CAAC;QACjB,MAAM,OAAO,GAAG,KAAK,CACpB,oBAAC,iBAAiB;YACjB,oBAAC,mBAAmB,IAAC,SAAS,EAAE,GAAG,EAAE,GAAE,CAAC;gBACvC,oBAAC,aAAa,IAAC,SAA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AqC,EAAE,KAAK,IAAI,EAAE;QACpD,QAAQ,CAAC,MAAM,CAAC,CAAC;QACjB,MAAM,OAAO,GAAG,KAAK,CACpB,oBAAC,iBAAiB;YACjB,oBAAC,mBAAmB,IAAC,SAAS,EAAE,GAAG,EAAE,GAAE,CAAC;gBACvC,oBAAC,IAAI,OAAG,CACa,CACH,CACpB,CAAC;QAEF,OAAO,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QACrE,MAAM,CAAC,OAAO,CAAC,uBAAuB,CAAC,oBAAC,eAAe,OAAG,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC5E,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,SAAS,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,CAAC;QACnE,MAAM,CAAC,OAAO,CAAC,uBAAuB,CAAC,oBAAC,eAAe,OAAG,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC7E,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IACpE,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["import * as React from \"react\";\r\nimport { mount, shallow } from \"enzyme\";\r\nimport { describe, it } from \"mocha\";\r\nimport { expect } from \"chai\";\r\nimport sinon from \"sinon\";\r\nimport addons, { mockChannel } from \"@storybook/addons\";\r\nimport { waitTime } from \"../../smartDesktopDesigner/sdd_helpers\";\r\nimport WorkspaceItem, { WorkspaceEditor } from \"../components/workspaces/WorkspaceItem\";\r\nimport { Item } from \"../stories/WorkspaceItem.stories\";\r\nimport { initFSBL } from \"../../common/helpers\";\r\nimport { FinsembleProvider } from \"../../FinsembleProvider\";\r\nimport { FinsembleDnDContext } from \"../../legacyControls/FinsembleDnDContext\";\r\n\r\naddons.setChannel(mockChannel());\r\n\r\ndescribe(\"<WorkspaceItem/>\", () => {\r\n\tafterEach(() => {\r\n\t\tsinon.restore();\r\n\t});\r\n\r\n\tit(\"should render workspace name and edit/ delete icons\", async () => {\r\n\t\tinitFSBL(window);\r\n\t\tconst wrapper = mount(\r\n\t\t\t<FinsembleProvider>\r\n\t\t\t\t<FinsembleDnDContext onDragEnd={() => {}}>\r\n\t\t\t\t\t<WorkspaceItem workspace={{ name: \"Default\" }} />\r\n\t\t\t\t</FinsembleDnDContext>\r\n\t\t\t</FinsembleProvider>\r\n\t\t);\r\n\t\texpect(wrapper.find(\".workspace-name\").text()).to.equal(\"Default\");\r\n\t\texpect(wrapper.find(\".ff-adp-edit\")).to.be.length(1);\r\n\t\texpect(wrapper.find(\".ff-adp-trash-outline\")).to.be.length(1);\r\n\t});\r\n\r\n\tit(\"should render <WorkspaceEditor/> when editing is true\", async () => {\r\n\t\tinitFSBL(window);\r\n\t\tconst wrapper = mount(\r\n\t\t\t<FinsembleProvider>\r\n\t\t\t\t<FinsembleDnDContext onDragEnd={() => {}}>\r\n\t\t\t\t\t<WorkspaceItem\r\n\t\t\t\t\t\tworkspace={{ name: \"Default\" }}\r\n\t\t\t\t\t\tfocusedWorkspace=\"Default\"\r\n\t\t\t\t\t\trenameButtonClasses=\"individual-workspace-action\"\r\n\t\t\t\t\t\tallowRename={true}\r\n\t\t\t\t\t\tediting={true}\r\n\t\t\t\t\t/>\r\n\t\t\t\t</FinsembleDnDContext>\r\n\t\t\t</FinsembleProvider>\r\n\t\t);\r\n\t\texpect(wrapper.containsMatchingElement(<WorkspaceEditor />)).to.equal(true);\r\n\t});\r\n\r\n\tit(\"should render <WorkspaceEditor/> on edit icon click \", async () => {\r\n\t\tinitFSBL(window);\r\n\t\tconst wrapper = mount(\r\n\t\t\t<FinsembleProvider>\r\n\t\t\t\t<FinsembleDnDContext onDragEnd={() => {}}>\r\n\t\t\t\t\t<Item />\r\n\t\t\t\t</FinsembleDnDContext>\r\n\t\t\t</FinsembleProvider>\r\n\t\t);\r\n\r\n\t\twrapper.find(\".individual-workspace-action\").at(0).simulate(\"click\");\r\n\r\n\t\texpect(wrapper.containsMatchingElement(<WorkspaceEditor />)).to.equal(true);\r\n\t});\r\n\r\n\tit(\"should exit WorkspaceEditor on enter \", async () => {\r\n\t\tinitFSBL(window);\r\n\t\tconst wrapper = mount(\r\n\t\t\t<FinsembleProvider>\r\n\t\t\t\t<FinsembleDnDContext onDragEnd={() => {}}>\r\n\t\t\t\t\t<Item />\r\n\t\t\t\t</FinsembleDnDContext>\r\n\t\t\t</FinsembleProvider>\r\n\t\t);\r\n\r\n\t\twrapper.find(\".individual-workspace-action\").at(0).simulate(\"click\");\r\n\t\texpect(wrapper.containsMatchingElement(<WorkspaceEditor />)).to.equal(true);\r\n\t\twrapper.find(\"input\").at(0).simulate(\"keydown\", { key: \"Enter\" });\r\n\t\texpect(wrapper.containsMatchingElement(<WorkspaceEditor />)).to.equal(false);\r\n\t\texpect(wrapper.find(\".workspace-name\").text()).to.equal(\"Default\");\r\n\t});\r\n\r\n\tit(\"should exit WorkspaceEditor on esc \", async () => {\r\n\t\tinitFSBL(window);\r\n\t\tconst wrapper = mount(\r\n\t\t\t<FinsembleProvider>\r\n\t\t\t\t<FinsembleDnDContext onDragEnd={() => {}}>\r\n\t\t\t\t\t<Item />\r\n\t\t\t\t</FinsembleDnDContext>\r\n\t\t\t</FinsembleProvider>\r\n\t\t);\r\n\r\n\t\twrapper.find(\".individual-workspace-action\").at(0).simulate(\"click\");\r\n\t\texpect(wrapper.containsMatchingElement(<WorkspaceEditor />)).to.equal(true);\r\n\t\twrapper.find(\"input\").at(0).simulate(\"keydown\", { key: \"Escape\" });\r\n\t\texpect(wrapper.containsMatchingElement(<WorkspaceEditor />)).to.equal(false);\r\n\t\texpect(wrapper.find(\".workspace-name\").text()).to.equal(\"Default\");\r\n\t});\r\n});\r\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { mount } from "enzyme";
|
|
3
|
+
import { describe, it } from "mocha";
|
|
4
|
+
import { expect } from "chai";
|
|
5
|
+
import sinon from "sinon";
|
|
6
|
+
import addons, { mockChannel } from "@storybook/addons";
|
|
7
|
+
import WorkspaceItemList from "../components/workspaces/WorkspaceItemList";
|
|
8
|
+
import WorkspaceItem from "../components/workspaces/WorkspaceItem";
|
|
9
|
+
import { initFSBL } from "../../common/helpers";
|
|
10
|
+
import { FinsembleProvider } from "../../FinsembleProvider";
|
|
11
|
+
import { TenItems } from "../stories/WorkspaceItemList.stories";
|
|
12
|
+
addons.setChannel(mockChannel());
|
|
13
|
+
describe("<WorkspaceItemList/>", () => {
|
|
14
|
+
afterEach(() => {
|
|
15
|
+
sinon.restore();
|
|
16
|
+
});
|
|
17
|
+
it("should render list", async () => {
|
|
18
|
+
initFSBL(window);
|
|
19
|
+
const wrapper = mount(React.createElement(FinsembleProvider, null,
|
|
20
|
+
React.createElement(WorkspaceItemList, { workspaceList: [{ name: "Default" }, { name: "Trading" }, { name: "Customer Account Management" }] })));
|
|
21
|
+
expect(wrapper.find(".workspace-list")).to.be.length(1);
|
|
22
|
+
});
|
|
23
|
+
it("should render no workspace items on empty workspace list", async () => {
|
|
24
|
+
initFSBL(window);
|
|
25
|
+
const wrapper = mount(React.createElement(FinsembleProvider, null,
|
|
26
|
+
React.createElement(WorkspaceItemList, { workspaceList: [] })));
|
|
27
|
+
expect(wrapper.containsMatchingElement(React.createElement(WorkspaceItem, { workspace: { name: "Default" } }))).to.equal(false);
|
|
28
|
+
});
|
|
29
|
+
it("should render list of WorkspaceItems with proper workspace props", async () => {
|
|
30
|
+
initFSBL(window);
|
|
31
|
+
const wrapper = mount(React.createElement(FinsembleProvider, null,
|
|
32
|
+
React.createElement(WorkspaceItemList, { workspaceList: [{ name: "Default" }, { name: "Trading" }, { name: "Customer Account Management" }] })));
|
|
33
|
+
expect(wrapper.containsMatchingElement(React.createElement(WorkspaceItem, { workspace: { name: "Default" } }))).to.equal(true);
|
|
34
|
+
expect(wrapper.containsMatchingElement(React.createElement(WorkspaceItem, { workspace: { name: "Trading" } }))).to.equal(true);
|
|
35
|
+
expect(wrapper.containsMatchingElement(React.createElement(WorkspaceItem, { workspace: { name: "Customer Account Management" } }))).to.equal(true);
|
|
36
|
+
});
|
|
37
|
+
it("should be able to delete workspaces", async () => {
|
|
38
|
+
initFSBL(window);
|
|
39
|
+
const wrapper = mount(React.createElement(FinsembleProvider, null,
|
|
40
|
+
React.createElement(TenItems, null)));
|
|
41
|
+
wrapper.find(".delete-workspace").at(0).simulate("click");
|
|
42
|
+
expect(wrapper.containsMatchingElement(React.createElement(WorkspaceItem, { workspace: { name: "Default" } }))).to.equal(false);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
//# sourceMappingURL=WorkspaceItemList.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WorkspaceItemList.spec.js","sourceRoot":"","sources":["../../../../src/components/userPreferences/tests/WorkspaceItemList.spec.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,KAAK,EAAW,MAAM,QAAQ,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,MAAM,EAAE,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAExD,OAAO,iBAAiB,MAAM,4CAA4C,CAAC;AAC3E,OAAO,aAAa,MAAM,wCAAwC,CAAC;AACnE,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CA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,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC5G,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["import * as React from \"react\";\r\nimport { mount, shallow } from \"enzyme\";\r\nimport { describe, it } from \"mocha\";\r\nimport { expect } from \"chai\";\r\nimport sinon from \"sinon\";\r\nimport addons, { mockChannel } from \"@storybook/addons\";\r\nimport { waitTime } from \"../../smartDesktopDesigner/sdd_helpers\";\r\nimport WorkspaceItemList from \"../components/workspaces/WorkspaceItemList\";\r\nimport WorkspaceItem from \"../components/workspaces/WorkspaceItem\";\r\nimport { initFSBL } from \"../../common/helpers\";\r\nimport { FinsembleProvider } from \"../../FinsembleProvider\";\r\nimport { TenItems } from \"../stories/WorkspaceItemList.stories\";\r\n\r\naddons.setChannel(mockChannel());\r\n\r\ndescribe(\"<WorkspaceItemList/>\", () => {\r\n\tafterEach(() => {\r\n\t\tsinon.restore();\r\n\t});\r\n\r\n\tit(\"should render list\", async () => {\r\n\t\tinitFSBL(window);\r\n\t\tconst wrapper = mount(\r\n\t\t\t<FinsembleProvider>\r\n\t\t\t\t<WorkspaceItemList\r\n\t\t\t\t\tworkspaceList={[{ name: \"Default\" }, { name: \"Trading\" }, { name: \"Customer Account Management\" }]}\r\n\t\t\t\t/>\r\n\t\t\t</FinsembleProvider>\r\n\t\t);\r\n\t\texpect(wrapper.find(\".workspace-list\")).to.be.length(1);\r\n\t});\r\n\r\n\tit(\"should render no workspace items on empty workspace list\", async () => {\r\n\t\tinitFSBL(window);\r\n\t\tconst wrapper = mount(\r\n\t\t\t<FinsembleProvider>\r\n\t\t\t\t<WorkspaceItemList workspaceList={[]} />\r\n\t\t\t</FinsembleProvider>\r\n\t\t);\r\n\t\texpect(wrapper.containsMatchingElement(<WorkspaceItem workspace={{ name: \"Default\" }} />)).to.equal(false);\r\n\t});\r\n\r\n\tit(\"should render list of WorkspaceItems with proper workspace props\", async () => {\r\n\t\tinitFSBL(window);\r\n\t\tconst wrapper = mount(\r\n\t\t\t<FinsembleProvider>\r\n\t\t\t\t<WorkspaceItemList\r\n\t\t\t\t\tworkspaceList={[{ name: \"Default\" }, { name: \"Trading\" }, { name: \"Customer Account Management\" }]}\r\n\t\t\t\t/>\r\n\t\t\t</FinsembleProvider>\r\n\t\t);\r\n\t\texpect(wrapper.containsMatchingElement(<WorkspaceItem workspace={{ name: \"Default\" }} />)).to.equal(true);\r\n\t\texpect(wrapper.containsMatchingElement(<WorkspaceItem workspace={{ name: \"Trading\" }} />)).to.equal(true);\r\n\t\texpect(\r\n\t\t\twrapper.containsMatchingElement(<WorkspaceItem workspace={{ name: \"Customer Account Management\" }} />)\r\n\t\t).to.equal(true);\r\n\t});\r\n\r\n\tit(\"should be able to delete workspaces\", async () => {\r\n\t\tinitFSBL(window);\r\n\t\tconst wrapper = mount(\r\n\t\t\t<FinsembleProvider>\r\n\t\t\t\t<TenItems />\r\n\t\t\t</FinsembleProvider>\r\n\t\t);\r\n\t\twrapper.find(\".delete-workspace\").at(0).simulate(\"click\");\r\n\t\texpect(wrapper.containsMatchingElement(<WorkspaceItem workspace={{ name: \"Default\" }} />)).to.equal(false);\r\n\t});\r\n});\r\n"]}
|
|
@@ -3,7 +3,10 @@ import { INotification } from "common/notifications/definitions/INotification";
|
|
|
3
3
|
import IFilter from "common/notifications/definitions/IFilter";
|
|
4
4
|
import IMuteFilter from "common/notifications/definitions/IMuteFilter";
|
|
5
5
|
import { NotificationsConfig } from "../components/notifications/types";
|
|
6
|
+
import { NotificationServiceState } from "../components/notifications/constants";
|
|
6
7
|
import { INotificationHistoryOptions } from "@finsemble/finsemble-core/src/common/notifications/definitions/INotificationHistoryOptions";
|
|
8
|
+
declare type NotificationUIStatePublish = (state: NotificationServiceState) => void;
|
|
9
|
+
export declare const useNotificationUI: () => [state: NotificationServiceState, setState: NotificationUIStatePublish];
|
|
7
10
|
export declare const moveToToolbarMonitor: () => Promise<void>;
|
|
8
11
|
export declare const getOS: () => "Windows" | "Linux" | "Mac" | undefined;
|
|
9
12
|
export declare const doAction: (notification: INotification, action: any) => void;
|
|
@@ -30,3 +33,4 @@ export default function useNotifications(params?: any): {
|
|
|
30
33
|
removeNotification: (notification: INotification) => void;
|
|
31
34
|
setOpaqueClassName: (isOpaque: boolean) => void;
|
|
32
35
|
};
|
|
36
|
+
export {};
|
|
@@ -12,12 +12,13 @@ function reducer(state, action) {
|
|
|
12
12
|
return {
|
|
13
13
|
notifications: [...state.notifications, ...action.payload],
|
|
14
14
|
};
|
|
15
|
-
case UPDATE:
|
|
15
|
+
case UPDATE: {
|
|
16
16
|
const notificationExistsInArray = state.notifications.find((notification) => notification.id === action.payload.id);
|
|
17
17
|
const notifications = notificationExistsInArray
|
|
18
18
|
? state.notifications.map((notification) => notification.id === action.payload.id ? action.payload : notification)
|
|
19
19
|
: [action.payload, ...state.notifications];
|
|
20
20
|
return { notifications };
|
|
21
|
+
}
|
|
21
22
|
case REMOVE:
|
|
22
23
|
return {
|
|
23
24
|
notifications: state.notifications.filter((notification) => notification.id !== action.payload.id),
|
|
@@ -26,43 +27,49 @@ function reducer(state, action) {
|
|
|
26
27
|
throw new Error();
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
30
|
+
export const useNotificationUI = () => {
|
|
31
|
+
const [state, setState] = usePubSub(NOTIFICATIONS_PUBSUB_TOPIC);
|
|
32
|
+
const setStateAndAddWindowName = (newState) => {
|
|
33
|
+
setState({
|
|
34
|
+
...newState,
|
|
35
|
+
mostRecentWindowName: finsembleWindow.name,
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
return [state, setStateAndAddWindowName];
|
|
39
|
+
};
|
|
40
|
+
const getActiveDescriptorsByType = (componentType) => new Promise(async (resolve, reject) => {
|
|
41
|
+
FSBL.Clients.LauncherClient.getActiveDescriptors((err, data) => {
|
|
42
|
+
const activeDescriptors = [];
|
|
43
|
+
if (err) {
|
|
44
|
+
reject(err);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
for (const key in data) {
|
|
48
|
+
if (data.hasOwnProperty(key) && data[key]?.componentType === componentType) {
|
|
49
|
+
activeDescriptors.push(data[key]);
|
|
41
50
|
}
|
|
42
51
|
}
|
|
43
|
-
|
|
44
|
-
|
|
52
|
+
}
|
|
53
|
+
resolve(activeDescriptors);
|
|
45
54
|
});
|
|
46
|
-
};
|
|
55
|
+
});
|
|
47
56
|
let toolbarWindowName;
|
|
48
57
|
export const moveToToolbarMonitor = async () => {
|
|
49
|
-
const getToolbarMonitorData = async () => {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
});
|
|
65
|
-
};
|
|
58
|
+
const getToolbarMonitorData = async () => new Promise(async (resolve, reject) => {
|
|
59
|
+
if (!toolbarWindowName) {
|
|
60
|
+
const activeDescriptors = await getActiveDescriptorsByType("Toolbar");
|
|
61
|
+
toolbarWindowName = activeDescriptors[0]?.name;
|
|
62
|
+
}
|
|
63
|
+
const { err, data } = (await FSBL.Clients.LauncherClient.getMonitorInfo({
|
|
64
|
+
windowIdentifier: { windowName: toolbarWindowName },
|
|
65
|
+
}));
|
|
66
|
+
if (err) {
|
|
67
|
+
FSBL.Clients.Logger.error("Could not get Monitor info", err);
|
|
68
|
+
reject(err);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
resolve(data);
|
|
72
|
+
});
|
|
66
73
|
const data = (await getToolbarMonitorData());
|
|
67
74
|
const bounds = (await finsembleWindow.getBounds({}));
|
|
68
75
|
const width = bounds.data.right - bounds.data.left;
|
|
@@ -161,12 +168,12 @@ export const dismissNotification = (notifications) => {
|
|
|
161
168
|
}
|
|
162
169
|
};
|
|
163
170
|
export const initializeCenterToggle = () => {
|
|
164
|
-
const [
|
|
171
|
+
const [uiState, setUIState] = useNotificationUI();
|
|
165
172
|
const toggleCenter = () => {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
173
|
+
setUIState({
|
|
174
|
+
...uiState,
|
|
175
|
+
showCenter: !uiState.showCenter,
|
|
176
|
+
});
|
|
170
177
|
};
|
|
171
178
|
return {
|
|
172
179
|
toggleCenter,
|
|
@@ -239,8 +246,8 @@ export default function useNotifications(params = {}) {
|
|
|
239
246
|
subscription.filter = filter;
|
|
240
247
|
const notificationsHistory = notificationConfig?.notificationsHistory || params?.config?.notificationsHistory;
|
|
241
248
|
if (notificationsHistory) {
|
|
242
|
-
const [options,
|
|
243
|
-
const pastNotifications = await getNotificationHistory(options,
|
|
249
|
+
const [options, historyFilter] = getFetchHistoryParams(notificationConfig, params);
|
|
250
|
+
const pastNotifications = await getNotificationHistory(options, historyFilter);
|
|
244
251
|
addMultipleNotifications(pastNotifications);
|
|
245
252
|
}
|
|
246
253
|
const onNotification = function (notification) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNotifications.js","sourceRoot":"","sources":["../../src/hooks/useNotifications.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAK9C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,0BAA0B,EAAE,MAAM,uCAAuC,CAAC;AAGnF,MAAM,EAAE,YAAY,EAAE,kBAAkB,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC;AAE1D,MAAM,YAAY,GAAQ,EAAE,aAAa,EAAE,EAAE,EAAE,CAAC;AAKhD,MAAM,eAAe,GAAG,iBAAiB,CAAC;AAC1C,MAAM,MAAM,GAAG,QAAQ,CAAC;AACxB,MAAM,MAAM,GAAG,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C;iBACjC;qBAAM;oBACN,eAAe,CAAC,YAAY,CAAC,CAAC;iBAC9B;YACF,CAAC,CAAC;YAEF,OAAO,kBAAkB,CAAC,SAAS,CAAC,YAAY,EAAE,cAAc,CAAC,CAAC;SAClE;QAAC,OAAO,KAAK,EAAE;YACf,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;SACrB;IACF,CAAC;IAKD,SAAS,kBAAkB,CAAC,QAAiB;QAC5C,IAAI,QAAQ,EAAE;YACb,MAAM,WAAW,GAAG,QAAQ,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;YAC7D,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE;gBAC9C,WAAW,CAAC,SAAS,GAAG,GAAG,WAAW,CAAC,SAAS,SAAS,CAAC;aAC1D;SACD;IACF,CAAC;IAGD,SAAS,CAAC,GAAG,EAAE;QACd,MAAM,SAAS,GAAG,IAAI,EAAE,CAAC;QACzB,OAAO,GAAG,EAAE;YAEX,CAAC,KAAK,IAAI,EAAE;gBACX,MAAM,eAAe,GAAG,CAAC,MAAM,SAAS,CAAQ,CAAC;gBACjD,IAAI,eAAe,EAAE;oBACpB,MAAM,kBAAkB,CAAC,WAAW,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC;iBACzD;YACF,CAAC,CAAC,EAAE,CAAC;QACN,CAAC,CAAC;IACH,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO;QACN,mBAAmB;QACnB,eAAe;QACf,oBAAoB;QACpB,sBAAsB;QACtB,wBAAwB;QACxB,aAAa,EAAE,KAAK,CAAC,aAAa;QAClC,kBAAkB;QAClB,kBAAkB;KAClB,CAAC;AACH,CAAC","sourcesContent":["import { useEffect, useReducer } from \"react\";\r\nimport { INotification } from \"common/notifications/definitions/INotification\";\r\nimport IFilter from \"common/notifications/definitions/IFilter\";\r\nimport IMuteFilter from \"common/notifications/definitions/IMuteFilter\";\r\nimport { WindowConfig, NotificationsConfig } from \"../components/notifications/types\";\r\nimport { usePubSub } from \"./usePubSub\";\r\nimport { NOTIFICATIONS_PUBSUB_TOPIC } from \"../components/notifications/constants\";\r\nimport { INotificationHistoryOptions } from \"@finsemble/finsemble-core/src/common/notifications/definitions/INotificationHistoryOptions\";\r\n\r\nconst { WindowClient, NotificationClient } = FSBL.Clients;\r\n\r\nconst initialState: any = { notifications: [] };\r\n\r\n/*\r\nAction Types\r\n*/\r\nconst CREATE_MULTIPLE = \"CREATE_MULTIPLE\";\r\nconst UPDATE = \"UPDATE\";\r\nconst REMOVE = \"REMOVE\";\r\n\r\n/*\r\n\tReducer\r\n\t*/\r\nfunction reducer(state: { notifications: INotification[] }, action: { type: string; payload: any }) {\r\n\tswitch (action.type) {\r\n\t\tcase CREATE_MULTIPLE:\r\n\t\t\treturn {\r\n\t\t\t\tnotifications: [...state.notifications, ...action.payload],\r\n\t\t\t};\r\n\t\tcase UPDATE:\r\n\t\t\t// check to see if the notification exists if so update the values\r\n\t\t\tconst notificationExistsInArray = state.notifications.find(\r\n\t\t\t\t(notification: INotification) => notification.id === action.payload.id\r\n\t\t\t);\r\n\r\n\t\t\t//if the notification exists then do nothing and return the current state else add the the new notification to the state\r\n\t\t\tconst notifications = notificationExistsInArray\r\n\t\t\t\t? state.notifications.map((notification: INotification) =>\r\n\t\t\t\t\t\tnotification.id === action.payload.id ? action.payload : notification\r\n\t\t\t\t )\r\n\t\t\t\t: [action.payload, ...state.notifications];\r\n\r\n\t\t\treturn { notifications };\r\n\t\tcase REMOVE:\r\n\t\t\treturn {\r\n\t\t\t\tnotifications: state.notifications.filter((notification) => notification.id !== action.payload.id),\r\n\t\t\t};\r\n\t\tdefault:\r\n\t\t\tthrow new Error();\r\n\t}\r\n}\r\n\r\nconst getActiveDescriptorsByType = (componentType: string): Promise<any[]> => {\r\n\treturn new Promise(async (resolve, reject) => {\r\n\t\tFSBL.Clients.LauncherClient.getActiveDescriptors((err: any, data: any) => {\r\n\t\t\tconst activeDescriptors: any[] = [];\r\n\t\t\tif (err) {\r\n\t\t\t\treject(err);\r\n\t\t\t} else {\r\n\t\t\t\tfor (const key in data) {\r\n\t\t\t\t\tif (data.hasOwnProperty(key) && data[key]?.componentType === componentType) {\r\n\t\t\t\t\t\tactiveDescriptors.push(data[key]);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tresolve(activeDescriptors);\r\n\t\t});\r\n\t});\r\n};\r\n\r\nlet toolbarWindowName: string;\r\n\r\nexport const moveToToolbarMonitor = async () => {\r\n\tconst getToolbarMonitorData = async () => {\r\n\t\treturn new Promise(async (resolve, reject) => {\r\n\t\t\tif (!toolbarWindowName) {\r\n\t\t\t\tconst activeDescriptors = await getActiveDescriptorsByType(\"Toolbar\");\r\n\t\t\t\ttoolbarWindowName = activeDescriptors[0]?.name;\r\n\t\t\t}\r\n\t\t\tconst { err, data } = (await FSBL.Clients.LauncherClient.getMonitorInfo({\r\n\t\t\t\twindowIdentifier: { windowName: toolbarWindowName },\r\n\t\t\t})) as any;\r\n\r\n\t\t\tif (err) {\r\n\t\t\t\tFSBL.Clients.Logger.error(\"Could not get Monitor info\", err);\r\n\t\t\t\treject(err);\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\tresolve(data);\r\n\t\t});\r\n\t};\r\n\r\n\tconst data = (await getToolbarMonitorData()) as any;\r\n\tconst bounds = (await finsembleWindow.getBounds({})) as any;\r\n\tconst width = bounds.data.right - bounds.data.left;\r\n\r\n\tfinsembleWindow.setBounds(\r\n\t\t{\r\n\t\t\tbounds: {\r\n\t\t\t\ttop: data[\"availableRect\"][\"top\"],\r\n\t\t\t\tleft: data[\"availableRect\"][\"right\"] - width,\r\n\t\t\t\theight: data[\"availableRect\"][\"height\"],\r\n\t\t\t\twidth: width,\r\n\t\t\t},\r\n\t\t},\r\n\t\t(err: any) => {\r\n\t\t\tif (err) {\r\n\t\t\t\tFSBL.Clients.Logger.error(\"Could not update position\", err);\r\n\t\t\t}\r\n\t\t}\r\n\t);\r\n};\r\n\r\nexport const getOS = () => {\r\n\tif (navigator.platform.indexOf(\"Win\") != -1) {\r\n\t\treturn \"Windows\";\r\n\t} else if (navigator.platform.indexOf(\"Linux\") != -1) {\r\n\t\treturn \"Linux\";\r\n\t} else if (navigator.platform.indexOf(\"Mac\") != -1) {\r\n\t\treturn \"Mac\";\r\n\t}\r\n};\r\n\r\n/**\r\n * Example for setting up button clicks\r\n *\r\n * @param notification\r\n * @param action\r\n */\r\nexport const doAction = (notification: INotification, action: any) => {\r\n\ttry {\r\n\t\tNotificationClient.performAction([notification], action).then(() => {\r\n\t\t\t// NOTE: The request to perform the action has be sent to the notifications service successfully\r\n\t\t\t// The action itself has not necessarily been perform successfully\r\n\t\t\t// 1) alert user notification has been sent (action may not have completed)\r\n\t\t});\r\n\t} catch (e) {\r\n\t\t// NOTE: The request to perform the action has failed\r\n\t\tconsole.error(\"could not create a notification client\", e);\r\n\t\tFSBL.Clients.Logger.error(\"could not create a notification client\", e);\r\n\t}\r\n};\r\n\r\n/**\r\n * Example for setting up button clicks\r\n *\r\n * @param filter\r\n */\r\nexport const mute = async (filter: IMuteFilter) => {\r\n\ttry {\r\n\t\tawait NotificationClient.mute(filter);\r\n\t} catch (e) {\r\n\t\t// NOTE: The request to perform the action has failed\r\n\t\tconsole.error(\"Could not save mute preferences\", e);\r\n\t\tFSBL.Clients.Logger.error(\"Could not save mute preferences\", e);\r\n\t}\r\n};\r\n\r\n/**\r\n * Example for setting up button clicks\r\n *\r\n * @param filter\r\n */\r\nexport const unmute = async (filter: IMuteFilter) => {\r\n\ttry {\r\n\t\tawait NotificationClient.unmute(filter);\r\n\t} catch (e) {\r\n\t\t// NOTE: The request to perform the action has failed\r\n\t\tconsole.error(\"Could not save mute preferences\", e);\r\n\t\tFSBL.Clients.Logger.error(\"Could not save mute preferences\", e);\r\n\t}\r\n};\r\n\r\n/**\r\n * Snooze a notification\r\n *\r\n * @param {INotification[]} notifications\r\n */\r\nexport const snoozeNotifications = async (notifications: INotification[]) => {\r\n\tconst preferences: any = await FSBL.Clients.NotificationClient.getPreferences();\r\n\tconst snoozeAction = new FSBL.Clients.NotificationClient.Action();\r\n\tsnoozeAction.type = FSBL.Clients.NotificationClient.ActionTypes.SNOOZE;\r\n\tif (preferences && preferences.defaultSnoozePeriodSeconds) {\r\n\t\tsnoozeAction.milliseconds = preferences.defaultSnoozePeriodSeconds * 1000;\r\n\t}\r\n\tsnoozeAction.buttonText = \"Snooze\";\r\n\r\n\tfor (let i = 0; i < notifications.length; i++) {\r\n\t\tdoAction(notifications[i], snoozeAction);\r\n\t}\r\n};\r\n\r\n/**\r\n * Marks a notification as read\r\n *\r\n * @param {INotification[]} notifications\r\n */\r\nexport const markNotificationsUnread = (notifications: INotification[]) => {\r\n\ttry {\r\n\t\tNotificationClient.markUnread(notifications).then(() => {\r\n\t\t\t// NOTE: The request to perform the action has be sent to the notifications service successfully\r\n\t\t\t// The action itself has not necessarily been perform successfully\r\n\t\t});\r\n\t} catch (e) {\r\n\t\tconsole.error(\"Error marking messages as unread\", e);\r\n\t\tFSBL.Clients.Logger.error(\"Could not mark notification as unread\", e);\r\n\t}\r\n};\r\n\r\n/**\r\n * Marks a notification as read\r\n *\r\n * @param {INotification[]} notifications\r\n */\r\nexport const markNotificationsRead = (notifications: INotification[]) => {\r\n\ttry {\r\n\t\tNotificationClient.markRead(notifications).then(() => {\r\n\t\t\t// NOTE: The request to perform the action has be sent to the notifications service successfully\r\n\t\t\t// The action itself has not necessarily been perform successfully\r\n\t\t});\r\n\t} catch (e) {\r\n\t\tconsole.error(\"Error marking messages as read\", e);\r\n\t\tFSBL.Clients.Logger.error(\"Could not mark notification as read\", e);\r\n\t}\r\n};\r\n\r\n/**\r\n * Dismisses a notification\r\n *\r\n * @param {INotification[]} notifications\r\n */\r\nexport const dismissNotification = (notifications: INotification[]) => {\r\n\ttry {\r\n\t\tNotificationClient.deleteNotifications(notifications).then(() => {\r\n\t\t\t// NOTE: The request to perform the action has be sent to the notifications service successfully\r\n\t\t\t// The action itself has not necessarily been perform successfully\r\n\t\t});\r\n\t} catch (e) {\r\n\t\tconsole.error(\"Error marking messages as read\", e);\r\n\t\tFSBL.Clients.Logger.error(\"Could not mark notification as read\", e);\r\n\t}\r\n};\r\n\r\nexport const initializeCenterToggle = () => {\r\n\tconst [notificationSubscribeMessage, notificationsPublish] = usePubSub(NOTIFICATIONS_PUBSUB_TOPIC);\r\n\r\n\tconst toggleCenter = () => {\r\n\t\tconst { showCenter } = notificationSubscribeMessage;\r\n\t\tconst publishValue = { ...notificationSubscribeMessage };\r\n\t\tpublishValue.showCenter = !showCenter;\r\n\t\tnotificationsPublish(publishValue);\r\n\t};\r\n\r\n\treturn {\r\n\t\ttoggleCenter,\r\n\t};\r\n};\r\n\r\n/**\r\n * Get Notification's config from\r\n */\r\nexport const getNotificationConfig = (): NotificationsConfig => {\r\n\tconst config: WindowConfig = WindowClient.options.customData;\r\n\r\n\treturn Object.assign(config?.window?.data?.notifications || {}, {\r\n\t\tisTransparent: config?.window?.options?.transparent || false,\r\n\t});\r\n};\r\n\r\nexport const getFetchHistoryParams = (config: any, params: any) => {\r\n\tconst notificationsHistory = config?.notificationsHistory || params?.config?.notificationsHistory;\r\n\r\n\t// Backwards compatibility - `since` replaced with `options` object\r\n\tlet options = notificationsHistory.since ? notificationsHistory.since : null;\r\n\r\n\t// Use options object if it's been set in the component config\r\n\tif (!options) {\r\n\t\toptions = notificationsHistory?.options;\r\n\t}\r\n\r\n\t// If no options object set and notificationsHistory is true set in config, use the params\r\n\tif (!options && typeof notificationsHistory === \"boolean\" && notificationsHistory) {\r\n\t\toptions = params?.config?.notificationsHistory.options;\r\n\t}\r\n\r\n\tconst filter = notificationsHistory.filter ? notificationsHistory.filter : null;\r\n\r\n\treturn [options, filter];\r\n};\r\n\r\nexport default function useNotifications(params: any = {}) {\r\n\tconst [state, dispatch] = useReducer(reducer, initialState);\r\n\r\n\t/*\r\n\t\tAction Creators\r\n\t*/\r\n\tconst removeNotification = (notification: INotification) => {\r\n\t\tdispatch({ type: REMOVE, payload: notification });\r\n\t};\r\n\r\n\tconst addNotification = (notification: INotification) => {\r\n\t\tdispatch({ type: UPDATE, payload: notification });\r\n\t};\r\n\r\n\tconst addMultipleNotifications = (notifications: INotification[]) => {\r\n\t\tdispatch({ type: CREATE_MULTIPLE, payload: notifications });\r\n\t};\r\n\r\n\t/**\r\n\t * Group Notifications by Type\r\n\t * @param notifications\r\n\t */\r\n\tconst groupNotificationsByType = (notifications: INotification[]) => {\r\n\t\tconst groupBy = (arr: INotification[], type: keyof INotification) =>\r\n\t\t\tarr\r\n\t\t\t\t.map(\r\n\t\t\t\t\t(notification: INotification): string =>\r\n\t\t\t\t\t\t//@ts-ignore\r\n\t\t\t\t\t\tnotification[type]\r\n\t\t\t\t)\r\n\t\t\t\t.reduce((acc: { [x: string]: any }, notificationType: string, index: number) => {\r\n\t\t\t\t\tacc[notificationType] = [...(acc[notificationType] || []), arr[index]];\r\n\t\t\t\t\treturn acc;\r\n\t\t\t\t}, {});\r\n\r\n\t\treturn groupBy(notifications, \"type\");\r\n\t};\r\n\r\n\t/**\r\n\t * \t * get the past notifications\r\n\t * WARNING - The default will get all notifications all the way back from 1969!!!\r\n\t * @param since\r\n\t * @param filter\r\n\t */\r\n\tconst getNotificationHistory = (\r\n\t\tsince: INotificationHistoryOptions = { sentAfter: \"1969-12-31T23:59:59.999Z\" },\r\n\t\tfilter: null | IFilter = null\r\n\t): Promise<INotification[]> => NotificationClient.fetchHistory(since, filter as IFilter);\r\n\r\n\tconst notificationIsActive = (notification: INotification, applyMuteFilterOverride?: boolean | undefined) => {\r\n\t\tlet applyMuteFilters = applyMuteFilterOverride;\r\n\r\n\t\tif (typeof applyMuteFilterOverride === \"undefined\") {\r\n\t\t\tconst config = getNotificationConfig();\r\n\t\t\tapplyMuteFilters = config?.applyMuteFilters ? config.applyMuteFilters : false;\r\n\t\t}\r\n\r\n\t\treturn (\r\n\t\t\t!notification.isSnoozed &&\r\n\t\t\t!notification.isRead &&\r\n\t\t\t!notification.isDeleted &&\r\n\t\t\t(applyMuteFilters ? !notification.isMuted : true)\r\n\t\t);\r\n\t};\r\n\r\n\tconst activeNotifications = (notifications: INotification[], applyMuteFilterOverride?: boolean | undefined) =>\r\n\t\tnotifications.filter((notification) => notificationIsActive(notification, applyMuteFilterOverride));\r\n\r\n\t/**\r\n\t * Main init function to start the subscription\r\n\t */\r\n\tasync function init() {\r\n\t\ttry {\r\n\t\t\tconst subscription = new NotificationClient.Subscription();\r\n\r\n\t\t\tconst notificationConfig: NotificationsConfig = getNotificationConfig();\r\n\r\n\t\t\tconst filter: IFilter = new NotificationClient.Filter();\r\n\r\n\t\t\t// make filters from the config\r\n\t\t\tif (notificationConfig) {\r\n\t\t\t\tnotificationConfig.filter &&\r\n\t\t\t\t\tnotificationConfig.filter.include &&\r\n\t\t\t\t\tfilter.include.push(...notificationConfig.filter.include);\r\n\r\n\t\t\t\tnotificationConfig.filter &&\r\n\t\t\t\t\tnotificationConfig.filter.exclude &&\r\n\t\t\t\t\tfilter.exclude.push(...notificationConfig.filter.exclude);\r\n\t\t\t}\r\n\r\n\t\t\tsubscription.filter = filter;\r\n\r\n\t\t\tconst notificationsHistory = notificationConfig?.notificationsHistory || params?.config?.notificationsHistory;\r\n\r\n\t\t\tif (notificationsHistory) {\r\n\t\t\t\tconst [options, filter] = getFetchHistoryParams(notificationConfig, params);\r\n\r\n\t\t\t\tconst pastNotifications = await getNotificationHistory(options, filter);\r\n\t\t\t\taddMultipleNotifications(pastNotifications);\r\n\t\t\t}\r\n\t\t\tconst onNotification = function (notification: INotification) {\r\n\t\t\t\t// This function will be called when a notification arrives\r\n\t\t\t\tif (notification.isDeleted) {\r\n\t\t\t\t\tremoveNotification(notification);\r\n\t\t\t\t} else {\r\n\t\t\t\t\taddNotification(notification);\r\n\t\t\t\t}\r\n\t\t\t};\r\n\r\n\t\t\treturn NotificationClient.subscribe(subscription, onNotification);\r\n\t\t} catch (error) {\r\n\t\t\tconsole.error(error);\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Set opaque class to html element\r\n\t */\r\n\tfunction setOpaqueClassName(isOpaque: boolean) {\r\n\t\tif (isOpaque) {\r\n\t\t\tconst htmlElement = document.getElementsByTagName(\"html\")[0];\r\n\t\t\tif (!htmlElement.className.includes(\"opaque\")) {\r\n\t\t\t\thtmlElement.className = `${htmlElement.className} opaque`;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t// start receiving Notifications and putting them in state\r\n\tuseEffect(() => {\r\n\t\tconst subscribe = init();\r\n\t\treturn () => {\r\n\t\t\t// Unsubscribe using the subscription ID\r\n\t\t\t(async () => {\r\n\t\t\t\tconst subscribeObject = (await subscribe) as any;\r\n\t\t\t\tif (subscribeObject) {\r\n\t\t\t\t\tawait NotificationClient.unsubscribe(subscribeObject.id);\r\n\t\t\t\t}\r\n\t\t\t})();\r\n\t\t};\r\n\t}, []);\r\n\r\n\treturn {\r\n\t\tactiveNotifications,\r\n\t\taddNotification,\r\n\t\tnotificationIsActive,\r\n\t\tgetNotificationHistory,\r\n\t\tgroupNotificationsByType,\r\n\t\tnotifications: state.notifications,\r\n\t\tremoveNotification,\r\n\t\tsetOpaqueClassName,\r\n\t};\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"useNotifications.js","sourceRoot":"","sources":["../../src/hooks/useNotifications.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAK9C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,0BAA0B,EAA4B,MAAM,uCAAuC,CAAC;AAG7G,MAAM,EAAE,YAAY,EAAE,kBAAkB,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC;AAE1D,MAAM,YAAY,GAAQ,EAAE,aAAa,EAAE,EAAE,EAAE,CAAC;AAKhD,MAAM,eAAe,GAAG,i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B,eAAe;QACf,oBAAoB;QACpB,sBAAsB;QACtB,wBAAwB;QACxB,aAAa,EAAE,KAAK,CAAC,aAAa;QAClC,kBAAkB;QAClB,kBAAkB;KAClB,CAAC;AACH,CAAC","sourcesContent":["import { useEffect, useReducer } from \"react\";\r\nimport { INotification } from \"common/notifications/definitions/INotification\";\r\nimport IFilter from \"common/notifications/definitions/IFilter\";\r\nimport IMuteFilter from \"common/notifications/definitions/IMuteFilter\";\r\nimport { WindowConfig, NotificationsConfig } from \"../components/notifications/types\";\r\nimport { usePubSub } from \"./usePubSub\";\r\nimport { NOTIFICATIONS_PUBSUB_TOPIC, NotificationServiceState } from \"../components/notifications/constants\";\r\nimport { INotificationHistoryOptions } from \"@finsemble/finsemble-core/src/common/notifications/definitions/INotificationHistoryOptions\";\r\n\r\nconst { WindowClient, NotificationClient } = FSBL.Clients;\r\n\r\nconst initialState: any = { notifications: [] };\r\n\r\n/*\r\nAction Types\r\n*/\r\nconst CREATE_MULTIPLE = \"CREATE_MULTIPLE\";\r\nconst UPDATE = \"UPDATE\";\r\nconst REMOVE = \"REMOVE\";\r\n\r\n/*\r\n\tReducer\r\n\t*/\r\nfunction reducer(state: { notifications: INotification[] }, action: { type: string; payload: any }) {\r\n\tswitch (action.type) {\r\n\t\tcase CREATE_MULTIPLE:\r\n\t\t\treturn {\r\n\t\t\t\tnotifications: [...state.notifications, ...action.payload],\r\n\t\t\t};\r\n\t\tcase UPDATE: {\r\n\t\t\t// check to see if the notification exists if so update the values\r\n\t\t\tconst notificationExistsInArray = state.notifications.find(\r\n\t\t\t\t(notification: INotification) => notification.id === action.payload.id\r\n\t\t\t);\r\n\r\n\t\t\t//if the notification exists then do nothing and return the current state else add the the new notification to the state\r\n\t\t\tconst notifications = notificationExistsInArray\r\n\t\t\t\t? state.notifications.map((notification: INotification) =>\r\n\t\t\t\t\t\tnotification.id === action.payload.id ? action.payload : notification\r\n\t\t\t\t )\r\n\t\t\t\t: [action.payload, ...state.notifications];\r\n\r\n\t\t\treturn { notifications };\r\n\t\t}\r\n\t\tcase REMOVE:\r\n\t\t\treturn {\r\n\t\t\t\tnotifications: state.notifications.filter((notification) => notification.id !== action.payload.id),\r\n\t\t\t};\r\n\t\tdefault:\r\n\t\t\tthrow new Error();\r\n\t}\r\n}\r\n\r\ntype NotificationUIStatePublish = (state: NotificationServiceState) => void;\r\n\r\n/**\r\n * Thin wrapper around usePubSub to give us typesafety for the notification service's UI state.\r\n * Automatically appends this client's windowName which is used by the notification service to\r\n * display the notification center on an appropriate monitor.\r\n */\r\nexport const useNotificationUI = (): [state: NotificationServiceState, setState: NotificationUIStatePublish] => {\r\n\tconst [state, setState] = usePubSub(NOTIFICATIONS_PUBSUB_TOPIC);\r\n\r\n\tconst setStateAndAddWindowName = (newState: NotificationServiceState) => {\r\n\t\tsetState({\r\n\t\t\t...newState,\r\n\t\t\tmostRecentWindowName: finsembleWindow.name,\r\n\t\t});\r\n\t};\r\n\treturn [state as NotificationServiceState, setStateAndAddWindowName];\r\n};\r\n\r\nconst getActiveDescriptorsByType = (componentType: string): Promise<any[]> =>\r\n\tnew Promise(async (resolve, reject) => {\r\n\t\tFSBL.Clients.LauncherClient.getActiveDescriptors((err: any, data: any) => {\r\n\t\t\tconst activeDescriptors: any[] = [];\r\n\t\t\tif (err) {\r\n\t\t\t\treject(err);\r\n\t\t\t} else {\r\n\t\t\t\tfor (const key in data) {\r\n\t\t\t\t\tif (data.hasOwnProperty(key) && data[key]?.componentType === componentType) {\r\n\t\t\t\t\t\tactiveDescriptors.push(data[key]);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tresolve(activeDescriptors);\r\n\t\t});\r\n\t});\r\n\r\nlet toolbarWindowName: string;\r\n\r\nexport const moveToToolbarMonitor = async () => {\r\n\tconst getToolbarMonitorData = async () =>\r\n\t\tnew Promise(async (resolve, reject) => {\r\n\t\t\tif (!toolbarWindowName) {\r\n\t\t\t\tconst activeDescriptors = await getActiveDescriptorsByType(\"Toolbar\");\r\n\t\t\t\ttoolbarWindowName = activeDescriptors[0]?.name;\r\n\t\t\t}\r\n\t\t\tconst { err, data } = (await FSBL.Clients.LauncherClient.getMonitorInfo({\r\n\t\t\t\twindowIdentifier: { windowName: toolbarWindowName },\r\n\t\t\t})) as any;\r\n\r\n\t\t\tif (err) {\r\n\t\t\t\tFSBL.Clients.Logger.error(\"Could not get Monitor info\", err);\r\n\t\t\t\treject(err);\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\tresolve(data);\r\n\t\t});\r\n\r\n\tconst data = (await getToolbarMonitorData()) as any;\r\n\tconst bounds = (await finsembleWindow.getBounds({})) as any;\r\n\tconst width = bounds.data.right - bounds.data.left;\r\n\r\n\tfinsembleWindow.setBounds(\r\n\t\t{\r\n\t\t\tbounds: {\r\n\t\t\t\ttop: data[\"availableRect\"][\"top\"],\r\n\t\t\t\tleft: data[\"availableRect\"][\"right\"] - width,\r\n\t\t\t\theight: data[\"availableRect\"][\"height\"],\r\n\t\t\t\twidth: width,\r\n\t\t\t},\r\n\t\t},\r\n\t\t(err: any) => {\r\n\t\t\tif (err) {\r\n\t\t\t\tFSBL.Clients.Logger.error(\"Could not update position\", err);\r\n\t\t\t}\r\n\t\t}\r\n\t);\r\n};\r\n\r\nexport const getOS = () => {\r\n\tif (navigator.platform.indexOf(\"Win\") != -1) {\r\n\t\treturn \"Windows\";\r\n\t} else if (navigator.platform.indexOf(\"Linux\") != -1) {\r\n\t\treturn \"Linux\";\r\n\t} else if (navigator.platform.indexOf(\"Mac\") != -1) {\r\n\t\treturn \"Mac\";\r\n\t}\r\n};\r\n\r\n/**\r\n * Example for setting up button clicks\r\n *\r\n * @param notification\r\n * @param action\r\n */\r\nexport const doAction = (notification: INotification, action: any) => {\r\n\ttry {\r\n\t\tNotificationClient.performAction([notification], action).then(() => {\r\n\t\t\t// NOTE: The request to perform the action has be sent to the notifications service successfully\r\n\t\t\t// The action itself has not necessarily been perform successfully\r\n\t\t\t// 1) alert user notification has been sent (action may not have completed)\r\n\t\t});\r\n\t} catch (e) {\r\n\t\t// NOTE: The request to perform the action has failed\r\n\t\tconsole.error(\"could not create a notification client\", e);\r\n\t\tFSBL.Clients.Logger.error(\"could not create a notification client\", e);\r\n\t}\r\n};\r\n\r\n/**\r\n * Example for setting up button clicks\r\n *\r\n * @param filter\r\n */\r\nexport const mute = async (filter: IMuteFilter) => {\r\n\ttry {\r\n\t\tawait NotificationClient.mute(filter);\r\n\t} catch (e) {\r\n\t\t// NOTE: The request to perform the action has failed\r\n\t\tconsole.error(\"Could not save mute preferences\", e);\r\n\t\tFSBL.Clients.Logger.error(\"Could not save mute preferences\", e);\r\n\t}\r\n};\r\n\r\n/**\r\n * Example for setting up button clicks\r\n *\r\n * @param filter\r\n */\r\nexport const unmute = async (filter: IMuteFilter) => {\r\n\ttry {\r\n\t\tawait NotificationClient.unmute(filter);\r\n\t} catch (e) {\r\n\t\t// NOTE: The request to perform the action has failed\r\n\t\tconsole.error(\"Could not save mute preferences\", e);\r\n\t\tFSBL.Clients.Logger.error(\"Could not save mute preferences\", e);\r\n\t}\r\n};\r\n\r\n/**\r\n * Snooze a notification\r\n *\r\n * @param {INotification[]} notifications\r\n */\r\nexport const snoozeNotifications = async (notifications: INotification[]) => {\r\n\tconst preferences: any = await FSBL.Clients.NotificationClient.getPreferences();\r\n\tconst snoozeAction = new FSBL.Clients.NotificationClient.Action();\r\n\tsnoozeAction.type = FSBL.Clients.NotificationClient.ActionTypes.SNOOZE;\r\n\tif (preferences && preferences.defaultSnoozePeriodSeconds) {\r\n\t\tsnoozeAction.milliseconds = preferences.defaultSnoozePeriodSeconds * 1000;\r\n\t}\r\n\tsnoozeAction.buttonText = \"Snooze\";\r\n\r\n\tfor (let i = 0; i < notifications.length; i++) {\r\n\t\tdoAction(notifications[i], snoozeAction);\r\n\t}\r\n};\r\n\r\n/**\r\n * Marks a notification as read\r\n *\r\n * @param {INotification[]} notifications\r\n */\r\nexport const markNotificationsUnread = (notifications: INotification[]) => {\r\n\ttry {\r\n\t\tNotificationClient.markUnread(notifications).then(() => {\r\n\t\t\t// NOTE: The request to perform the action has be sent to the notifications service successfully\r\n\t\t\t// The action itself has not necessarily been perform successfully\r\n\t\t});\r\n\t} catch (e) {\r\n\t\tconsole.error(\"Error marking messages as unread\", e);\r\n\t\tFSBL.Clients.Logger.error(\"Could not mark notification as unread\", e);\r\n\t}\r\n};\r\n\r\n/**\r\n * Marks a notification as read\r\n *\r\n * @param {INotification[]} notifications\r\n */\r\nexport const markNotificationsRead = (notifications: INotification[]) => {\r\n\ttry {\r\n\t\tNotificationClient.markRead(notifications).then(() => {\r\n\t\t\t// NOTE: The request to perform the action has be sent to the notifications service successfully\r\n\t\t\t// The action itself has not necessarily been perform successfully\r\n\t\t});\r\n\t} catch (e) {\r\n\t\tconsole.error(\"Error marking messages as read\", e);\r\n\t\tFSBL.Clients.Logger.error(\"Could not mark notification as read\", e);\r\n\t}\r\n};\r\n\r\n/**\r\n * Dismisses a notification\r\n *\r\n * @param {INotification[]} notifications\r\n */\r\nexport const dismissNotification = (notifications: INotification[]) => {\r\n\ttry {\r\n\t\tNotificationClient.deleteNotifications(notifications).then(() => {\r\n\t\t\t// NOTE: The request to perform the action has be sent to the notifications service successfully\r\n\t\t\t// The action itself has not necessarily been perform successfully\r\n\t\t});\r\n\t} catch (e) {\r\n\t\tconsole.error(\"Error marking messages as read\", e);\r\n\t\tFSBL.Clients.Logger.error(\"Could not mark notification as read\", e);\r\n\t}\r\n};\r\n\r\nexport const initializeCenterToggle = () => {\r\n\tconst [uiState, setUIState] = useNotificationUI();\r\n\r\n\tconst toggleCenter = () => {\r\n\t\tsetUIState({\r\n\t\t\t...uiState,\r\n\t\t\tshowCenter: !uiState.showCenter,\r\n\t\t});\r\n\t};\r\n\r\n\treturn {\r\n\t\ttoggleCenter,\r\n\t};\r\n};\r\n\r\n/**\r\n * Get Notification's config from\r\n */\r\nexport const getNotificationConfig = (): NotificationsConfig => {\r\n\tconst config: WindowConfig = WindowClient.options.customData;\r\n\r\n\treturn Object.assign(config?.window?.data?.notifications || {}, {\r\n\t\tisTransparent: config?.window?.options?.transparent || false,\r\n\t});\r\n};\r\n\r\nexport const getFetchHistoryParams = (config: any, params: any) => {\r\n\tconst notificationsHistory = config?.notificationsHistory || params?.config?.notificationsHistory;\r\n\r\n\t// Backwards compatibility - `since` replaced with `options` object\r\n\tlet options = notificationsHistory.since ? notificationsHistory.since : null;\r\n\r\n\t// Use options object if it's been set in the component config\r\n\tif (!options) {\r\n\t\toptions = notificationsHistory?.options;\r\n\t}\r\n\r\n\t// If no options object set and notificationsHistory is true set in config, use the params\r\n\tif (!options && typeof notificationsHistory === \"boolean\" && notificationsHistory) {\r\n\t\toptions = params?.config?.notificationsHistory.options;\r\n\t}\r\n\r\n\tconst filter = notificationsHistory.filter ? notificationsHistory.filter : null;\r\n\r\n\treturn [options, filter];\r\n};\r\n\r\nexport default function useNotifications(params: any = {}) {\r\n\tconst [state, dispatch] = useReducer(reducer, initialState);\r\n\r\n\t/*\r\n\t\tAction Creators\r\n\t*/\r\n\tconst removeNotification = (notification: INotification) => {\r\n\t\tdispatch({ type: REMOVE, payload: notification });\r\n\t};\r\n\r\n\tconst addNotification = (notification: INotification) => {\r\n\t\tdispatch({ type: UPDATE, payload: notification });\r\n\t};\r\n\r\n\tconst addMultipleNotifications = (notifications: INotification[]) => {\r\n\t\tdispatch({ type: CREATE_MULTIPLE, payload: notifications });\r\n\t};\r\n\r\n\t/**\r\n\t * Group Notifications by Type\r\n\t * @param notifications\r\n\t */\r\n\tconst groupNotificationsByType = (notifications: INotification[]) => {\r\n\t\tconst groupBy = (arr: INotification[], type: keyof INotification) =>\r\n\t\t\tarr\r\n\t\t\t\t.map(\r\n\t\t\t\t\t(notification: INotification): string =>\r\n\t\t\t\t\t\t//@ts-ignore\r\n\t\t\t\t\t\tnotification[type]\r\n\t\t\t\t)\r\n\t\t\t\t.reduce((acc: { [x: string]: any }, notificationType: string, index: number) => {\r\n\t\t\t\t\tacc[notificationType] = [...(acc[notificationType] || []), arr[index]];\r\n\t\t\t\t\treturn acc;\r\n\t\t\t\t}, {});\r\n\r\n\t\treturn groupBy(notifications, \"type\");\r\n\t};\r\n\r\n\t/**\r\n\t * \t * get the past notifications\r\n\t * WARNING - The default will get all notifications all the way back from 1969!!!\r\n\t * @param since\r\n\t * @param filter\r\n\t */\r\n\tconst getNotificationHistory = (\r\n\t\tsince: INotificationHistoryOptions = { sentAfter: \"1969-12-31T23:59:59.999Z\" },\r\n\t\tfilter: null | IFilter = null\r\n\t): Promise<INotification[]> => NotificationClient.fetchHistory(since, filter as IFilter);\r\n\r\n\tconst notificationIsActive = (notification: INotification, applyMuteFilterOverride?: boolean | undefined) => {\r\n\t\tlet applyMuteFilters = applyMuteFilterOverride;\r\n\r\n\t\tif (typeof applyMuteFilterOverride === \"undefined\") {\r\n\t\t\tconst config = getNotificationConfig();\r\n\t\t\tapplyMuteFilters = config?.applyMuteFilters ? config.applyMuteFilters : false;\r\n\t\t}\r\n\r\n\t\treturn (\r\n\t\t\t!notification.isSnoozed &&\r\n\t\t\t!notification.isRead &&\r\n\t\t\t!notification.isDeleted &&\r\n\t\t\t(applyMuteFilters ? !notification.isMuted : true)\r\n\t\t);\r\n\t};\r\n\r\n\tconst activeNotifications = (notifications: INotification[], applyMuteFilterOverride?: boolean | undefined) =>\r\n\t\tnotifications.filter((notification) => notificationIsActive(notification, applyMuteFilterOverride));\r\n\r\n\t/**\r\n\t * Main init function to start the subscription\r\n\t */\r\n\tasync function init() {\r\n\t\ttry {\r\n\t\t\tconst subscription = new NotificationClient.Subscription();\r\n\r\n\t\t\tconst notificationConfig: NotificationsConfig = getNotificationConfig();\r\n\r\n\t\t\tconst filter: IFilter = new NotificationClient.Filter();\r\n\r\n\t\t\t// make filters from the config\r\n\t\t\tif (notificationConfig) {\r\n\t\t\t\tnotificationConfig.filter &&\r\n\t\t\t\t\tnotificationConfig.filter.include &&\r\n\t\t\t\t\tfilter.include.push(...notificationConfig.filter.include);\r\n\r\n\t\t\t\tnotificationConfig.filter &&\r\n\t\t\t\t\tnotificationConfig.filter.exclude &&\r\n\t\t\t\t\tfilter.exclude.push(...notificationConfig.filter.exclude);\r\n\t\t\t}\r\n\r\n\t\t\tsubscription.filter = filter;\r\n\r\n\t\t\tconst notificationsHistory = notificationConfig?.notificationsHistory || params?.config?.notificationsHistory;\r\n\r\n\t\t\tif (notificationsHistory) {\r\n\t\t\t\tconst [options, historyFilter] = getFetchHistoryParams(notificationConfig, params);\r\n\r\n\t\t\t\tconst pastNotifications = await getNotificationHistory(options, historyFilter);\r\n\t\t\t\taddMultipleNotifications(pastNotifications);\r\n\t\t\t}\r\n\t\t\tconst onNotification = function (notification: INotification) {\r\n\t\t\t\t// This function will be called when a notification arrives\r\n\t\t\t\tif (notification.isDeleted) {\r\n\t\t\t\t\tremoveNotification(notification);\r\n\t\t\t\t} else {\r\n\t\t\t\t\taddNotification(notification);\r\n\t\t\t\t}\r\n\t\t\t};\r\n\r\n\t\t\treturn NotificationClient.subscribe(subscription, onNotification);\r\n\t\t} catch (error) {\r\n\t\t\tconsole.error(error);\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * Set opaque class to html element\r\n\t */\r\n\tfunction setOpaqueClassName(isOpaque: boolean) {\r\n\t\tif (isOpaque) {\r\n\t\t\tconst htmlElement = document.getElementsByTagName(\"html\")[0];\r\n\t\t\tif (!htmlElement.className.includes(\"opaque\")) {\r\n\t\t\t\thtmlElement.className = `${htmlElement.className} opaque`;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t// start receiving Notifications and putting them in state\r\n\tuseEffect(() => {\r\n\t\tconst subscribe = init();\r\n\t\treturn () => {\r\n\t\t\t// Unsubscribe using the subscription ID\r\n\t\t\t(async () => {\r\n\t\t\t\tconst subscribeObject = (await subscribe) as any;\r\n\t\t\t\tif (subscribeObject) {\r\n\t\t\t\t\tawait NotificationClient.unsubscribe(subscribeObject.id);\r\n\t\t\t\t}\r\n\t\t\t})();\r\n\t\t};\r\n\t}, []);\r\n\r\n\treturn {\r\n\t\tactiveNotifications,\r\n\t\taddNotification,\r\n\t\tnotificationIsActive,\r\n\t\tgetNotificationHistory,\r\n\t\tgroupNotificationsByType,\r\n\t\tnotifications: state.notifications,\r\n\t\tremoveNotification,\r\n\t\tsetOpaqueClassName,\r\n\t};\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePubSub.js","sourceRoot":"","sources":["../../src/hooks/usePubSub.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,KAAK,CAAC;AACtC,MAAM,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC;AACtC,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,GAAG,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"usePubSub.js","sourceRoot":"","sources":["../../src/hooks/usePubSub.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,KAAK,CAAC;AACtC,MAAM,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC;AACtC,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,GAAG,YAAY,CAAC;AAmBzD,SAAS,SAAS,CAAC,KAAa,EAAE,iBAAyB,EAAE;IAC5D,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,cAAc,CAAC,CAAC;IAEvD,MAAM,GAAG,GAAG,CAAC,KAAU,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IAElD,SAAS,CAAC,GAAG,EAAE;QACd,MAAM,WAAW,GAAG,SAAS,CAAC,KAAK,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;YACjD,IAAI,GAAG,EAAE;gBAER,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;aACnB;YACD,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACtB,CAAC,CAAC,CAAC;QACH,OAAO,GAAG,EAAE;YACX,WAAW,CAAC,WAAW,CAAC,CAAC;QAC1B,CAAC,CAAC;IACH,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AACvB,CAAC;AAED,OAAO,EAAE,SAAS,EAAE,CAAC","sourcesContent":["import * as React from \"react\";\r\n\r\nconst { useState, useEffect } = React;\r\nconst { RouterClient } = FSBL.Clients;\r\nconst { publish, subscribe, unsubscribe } = RouterClient;\r\n\r\n/**\r\n * A generic effect for getting and setting state dynamically from a Router pubsub channel.\r\n *\r\n * @param {string} topic The pubsub topic (i.e. channel) to subscribe\r\n * @param {object} initialMessage The initial state (defaults to empty object)\r\n * @returns [object, function] The current state of the pubsub channel (or initialMessage if no state exists).\r\n * The second returned array parameter is a publish function which can be used to update state.\r\n *\r\n * @example\r\n * // Inside a React functional component\r\n * const [currentState, publish] = usePubSub(\"topic\", {});\r\n * console.log(currentState);\r\n *\r\n * onClick = () => {\r\n * publish(someNewState);\r\n * }\r\n */\r\nfunction usePubSub(topic: string, initialMessage: object = {}): [{ [key: string]: any }, Function] {\r\n\tconst [message, setMessage] = useState(initialMessage);\r\n\r\n\tconst pub = (value: any) => publish(topic, value);\r\n\r\n\tuseEffect(() => {\r\n\t\tconst subscribeId = subscribe(topic, (err, res) => {\r\n\t\t\tif (err) {\r\n\t\t\t\t// Use Finsemble Logger?\r\n\t\t\t\tconsole.error(err);\r\n\t\t\t}\r\n\t\t\tsetMessage(res.data);\r\n\t\t});\r\n\t\treturn () => {\r\n\t\t\tunsubscribe(subscribeId);\r\n\t\t};\r\n\t}, []);\r\n\r\n\treturn [message, pub];\r\n}\r\n\r\nexport { usePubSub };\r\n"]}
|
|
@@ -83,6 +83,23 @@ export const useToolbar = () => {
|
|
|
83
83
|
preventSystemClose();
|
|
84
84
|
}
|
|
85
85
|
}, []);
|
|
86
|
+
useEffect(() => {
|
|
87
|
+
if (typeof FSBL.Clients.WindowClient["getSpawnData"] === "function") {
|
|
88
|
+
const { dashbar } = FSBL.Clients.WindowClient.getSpawnData();
|
|
89
|
+
if (dashbar && dashbar.height) {
|
|
90
|
+
const fsblWindow = FSBL.Clients.WindowClient.getCurrentWindow();
|
|
91
|
+
fsblWindow.getBounds(async (bounds) => {
|
|
92
|
+
const response = await FSBL.Clients.ConfigClient.getValue({
|
|
93
|
+
field: "finsemble.components.Toolbar.window.height",
|
|
94
|
+
});
|
|
95
|
+
const expectedToolbarHeight = response.data + dashbar.height;
|
|
96
|
+
if (bounds.height !== expectedToolbarHeight) {
|
|
97
|
+
fsblWindow.setBounds(bounds.left, bounds.top, bounds.width, expectedToolbarHeight);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}, []);
|
|
86
103
|
async function setDashbarItems(error, data) {
|
|
87
104
|
const { data: availableDashbarItems } = await FSBL.Clients.ConfigClient.getValue({
|
|
88
105
|
field: "finsemble.availableDashbarItems",
|
|
@@ -98,64 +115,70 @@ export const useToolbar = () => {
|
|
|
98
115
|
dispatch(ToolbarActions.SET_DASHBAR_ITEMS(newDashbarItems));
|
|
99
116
|
}
|
|
100
117
|
useDeepEffect(() => {
|
|
101
|
-
async function
|
|
118
|
+
async function createStoreAndFetchDashbarItems() {
|
|
102
119
|
try {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
});
|
|
116
|
-
let dashbarItemList;
|
|
117
|
-
if (DashbarStore && Object.keys(DashbarStore.values).length > 0) {
|
|
118
|
-
({ dashbaritems: dashbarItemList } = DashbarStore.values);
|
|
119
|
-
}
|
|
120
|
-
if (!dashbarItemList) {
|
|
121
|
-
const spawnData = FSBL.Clients.WindowClient.getSpawnData();
|
|
122
|
-
if (spawnData.hasOwnProperty("dashbar") &&
|
|
123
|
-
spawnData.dashbar.hasOwnProperty("items") &&
|
|
124
|
-
Array.isArray(spawnData.dashbar.items)) {
|
|
125
|
-
dashbarItemList = spawnData.dashbar.items;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
if (!dashbarItemList)
|
|
129
|
-
dashbarItemList = [];
|
|
130
|
-
const newDashbarItems = [];
|
|
131
|
-
if (dashbarItemList.length > 0) {
|
|
132
|
-
dashbarItemList.forEach((itemName) => {
|
|
133
|
-
if (availableDashbarItems.hasOwnProperty(itemName)) {
|
|
134
|
-
const newItem = availableDashbarItems[itemName];
|
|
135
|
-
newItem.id = itemName;
|
|
136
|
-
newDashbarItems.push(newItem);
|
|
120
|
+
FSBL.Clients.RouterClient.subscribe("distributedStoresLoading", (subscribeErr, notify) => {
|
|
121
|
+
if (!subscribeErr && notify.data.State === "done") {
|
|
122
|
+
if (storageIsInitialized)
|
|
123
|
+
return;
|
|
124
|
+
storageIsInitialized = true;
|
|
125
|
+
FSBL.Clients.DistributedStoreClient.createStore({
|
|
126
|
+
store: "Finsemble-Dashbar-Store",
|
|
127
|
+
global: true,
|
|
128
|
+
persist: true,
|
|
129
|
+
}, async (getDashbarStoreErr, store) => {
|
|
130
|
+
if (getDashbarStoreErr) {
|
|
131
|
+
FSBL.Clients.Logger.error("Error initializing dashbar: unable to retrieve stored items, falling back to config", getDashbarStoreErr);
|
|
137
132
|
}
|
|
133
|
+
DashbarStore = store;
|
|
134
|
+
const { data: availableDashbarItems } = await FSBL.Clients.ConfigClient.getValue({
|
|
135
|
+
field: "finsemble.availableDashbarItems",
|
|
136
|
+
});
|
|
137
|
+
let dashbarItemList;
|
|
138
|
+
if (DashbarStore && Object.keys(DashbarStore.values).length > 0) {
|
|
139
|
+
({ dashbaritems: dashbarItemList } = DashbarStore.values);
|
|
140
|
+
}
|
|
141
|
+
if (!dashbarItemList) {
|
|
142
|
+
const spawnData = FSBL.Clients.WindowClient.getSpawnData();
|
|
143
|
+
if (spawnData.hasOwnProperty("dashbar") &&
|
|
144
|
+
spawnData.dashbar.hasOwnProperty("items") &&
|
|
145
|
+
Array.isArray(spawnData.dashbar.items)) {
|
|
146
|
+
dashbarItemList = spawnData.dashbar.items;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (!dashbarItemList)
|
|
150
|
+
dashbarItemList = [];
|
|
151
|
+
const newDashbarItems = [];
|
|
152
|
+
if (dashbarItemList.length > 0) {
|
|
153
|
+
dashbarItemList.forEach((itemName) => {
|
|
154
|
+
if (availableDashbarItems.hasOwnProperty(itemName)) {
|
|
155
|
+
const newItem = availableDashbarItems[itemName];
|
|
156
|
+
newItem.id = itemName;
|
|
157
|
+
newDashbarItems.push(newItem);
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
if (!DashbarStore.values.dashbaritems) {
|
|
162
|
+
DashbarStore.setValue({
|
|
163
|
+
field: "dashbaritems",
|
|
164
|
+
value: dashbarItemList,
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
dispatch(ToolbarActions.SET_DASHBAR_ITEMS(newDashbarItems));
|
|
169
|
+
}
|
|
170
|
+
DashbarStore.addListener({ field: "dashbaritems" }, setDashbarItems);
|
|
138
171
|
});
|
|
139
172
|
}
|
|
140
|
-
if (!DashbarStore.values.dashbaritems) {
|
|
141
|
-
DashbarStore.setValue({
|
|
142
|
-
field: "dashbaritems",
|
|
143
|
-
value: dashbarItemList,
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
dispatch(ToolbarActions.SET_DASHBAR_ITEMS(newDashbarItems));
|
|
148
|
-
}
|
|
149
|
-
DashbarStore.addListener({ field: "dashbaritems" }, setDashbarItems);
|
|
150
173
|
});
|
|
151
174
|
}
|
|
152
175
|
catch (majorErr) {
|
|
153
176
|
return FSBL.Clients.Logger.error(`Fatal error retrieving dashbar items`, majorErr);
|
|
154
177
|
}
|
|
155
178
|
}
|
|
156
|
-
if (storageIsInitialized)
|
|
157
|
-
|
|
158
|
-
|
|
179
|
+
if (!storageIsInitialized) {
|
|
180
|
+
createStoreAndFetchDashbarItems();
|
|
181
|
+
}
|
|
159
182
|
return function cleanup() {
|
|
160
183
|
DashbarStore.removeListener({ field: "dashbaritems" }, setDashbarItems);
|
|
161
184
|
};
|