diff --git a/graylog2-web-interface/src/@types/graylog-web-plugin/index.d.ts b/graylog2-web-interface/src/@types/graylog-web-plugin/index.d.ts index 787838f9f3df..3834c093334a 100644 --- a/graylog2-web-interface/src/@types/graylog-web-plugin/index.d.ts +++ b/graylog2-web-interface/src/@types/graylog-web-plugin/index.d.ts @@ -400,8 +400,7 @@ declare module 'graylog-web-plugin/plugin' { // and provide the result for all components in your plugin. globalContextProviders?: Array>>; // Difference between page context providers and global context providers - // is that page context providers are rendered within the giving it - // access to certain contexts like PerspectivesContext + // is that page context providers are rendered within the . pageContextProviders?: Array>>; routes?: Array; pages?: PluginPages; diff --git a/graylog2-web-interface/src/components/events/events/hooks/usePluggableEventActions.tsx b/graylog2-web-interface/src/components/events/events/hooks/usePluggableEventActions.tsx index b43d0278711b..0a7234d547dd 100644 --- a/graylog2-web-interface/src/components/events/events/hooks/usePluggableEventActions.tsx +++ b/graylog2-web-interface/src/components/events/events/hooks/usePluggableEventActions.tsx @@ -24,8 +24,7 @@ const usePluggableEventActions = (events: Array, onlyBulk: boolean = fals const modalRefs = useRef({}); const pluggableActions = usePluginEntities('views.components.eventActions'); const availableActions = pluggableActions.filter( - (perspective) => - (onlyBulk ? perspective.isBulk : true) && (perspective.useCondition ? !!perspective.useCondition(events) : true), + (action) => (onlyBulk ? action.isBulk : true) && (action.useCondition ? !!action.useCondition(events) : true), ); const actions = availableActions.map( diff --git a/graylog2-web-interface/src/components/events/events/hooks/useSendEventActionTelemetry.ts b/graylog2-web-interface/src/components/events/events/hooks/useSendEventActionTelemetry.ts index 370ff76485e3..ac2bba7a281b 100644 --- a/graylog2-web-interface/src/components/events/events/hooks/useSendEventActionTelemetry.ts +++ b/graylog2-web-interface/src/components/events/events/hooks/useSendEventActionTelemetry.ts @@ -18,7 +18,6 @@ import { useCallback } from 'react'; import useSendTelemetry from 'logic/telemetry/useSendTelemetry'; -import useActivePerspective from 'components/perspectives/hooks/useActivePerspective'; import { TELEMETRY_EVENT_TYPE } from 'logic/telemetry/Constants'; import { getPathnameWithoutId } from 'util/URLUtils'; import useLocation from 'routing/useLocation'; @@ -26,7 +25,6 @@ import useLocation from 'routing/useLocation'; const useSendEventActionTelemetry = () => { const sendTelemetry = useSendTelemetry(); const { pathname } = useLocation(); - const { activePerspective } = useActivePerspective(); return useCallback( (actionName: string, fromBulk: boolean, eventDetails: { [key: string]: unknown } = {}) => @@ -36,11 +34,10 @@ const useSendEventActionTelemetry = () => { event_details: { actionName, fromBulk: !!fromBulk, - perspectiveId: activePerspective.id, ...eventDetails, }, }), - [activePerspective.id, pathname, sendTelemetry], + [pathname, sendTelemetry], ); }; diff --git a/graylog2-web-interface/src/components/login/LoginChrome.tsx b/graylog2-web-interface/src/components/login/LoginChrome.tsx index f7b7bd5e3947..bd0712e8ee47 100644 --- a/graylog2-web-interface/src/components/login/LoginChrome.tsx +++ b/graylog2-web-interface/src/components/login/LoginChrome.tsx @@ -22,7 +22,7 @@ import DOMPurify from 'dompurify'; import LoginBox from 'components/login/LoginBox'; import PublicNotifications from 'components/common/PublicNotifications'; import backgroundImage from 'images/auth/login-bg.svg'; -import { Logo } from 'components/perspectives/DefaultBrand'; +import { Logo } from 'components/navigation/NavigationBrand'; import AppConfig from 'util/AppConfig'; import useThemes from 'theme/hooks/useThemes'; import useCustomLogo from 'brand-customization/useCustomLogo'; diff --git a/graylog2-web-interface/src/components/navigation/MainNavbar.test.tsx b/graylog2-web-interface/src/components/navigation/MainNavbar.test.tsx index 8e547a149b12..91604f981acd 100644 --- a/graylog2-web-interface/src/components/navigation/MainNavbar.test.tsx +++ b/graylog2-web-interface/src/components/navigation/MainNavbar.test.tsx @@ -18,7 +18,7 @@ import { render, screen } from 'wrappedTestingLibrary'; import Immutable from 'immutable'; import * as React from 'react'; import type { PluginExports } from 'graylog-web-plugin/plugin'; -import { PluginManifest, PluginStore } from 'graylog-web-plugin/plugin'; +import { PluginStore } from 'graylog-web-plugin/plugin'; import { defaultUser } from 'defaultMockValues'; import userEvent from '@testing-library/user-event'; @@ -26,24 +26,13 @@ import AppConfig from 'util/AppConfig'; import { asMock } from 'helpers/mocking'; import useCurrentUser from 'hooks/useCurrentUser'; import { adminUser } from 'fixtures/users'; -import PerspectivesProvider from 'components/perspectives/contexts/PerspectivesProvider'; -import PerspectivesBindings from 'components/perspectives/bindings'; -import { examplePerspective } from 'fixtures/perspectives'; import MainNavbar from './MainNavbar'; jest.mock('hooks/useCurrentUser'); describe('MainNavbar', () => { - const SUT = (props: Partial>) => ( - - - - ); - - beforeAll(() => { - PluginStore.register(new PluginManifest({}, PerspectivesBindings)); - }); + const SUT = (props: Partial>) => ; beforeEach(() => { asMock(useCurrentUser).mockReturnValue(defaultUser); @@ -96,7 +85,6 @@ describe('MainNavbar', () => { { description: 'Merged dropdown test', path: '/', - perspective: examplePerspective.id, children: [{ path: '/another-route', description: 'Menu item for specific perspective' }], }, ], @@ -219,16 +207,6 @@ describe('MainNavbar', () => { await screen.findByRole('menuitem', { name: /Merged item for general perspective/i }); }); - it('should not merge navigation dropdowns when their assigned perspective varies', async () => { - render(); - - userEvent.click(await screen.findByRole('button', { name: /Merged dropdown test/i })); - - await screen.findByRole('menuitem', { name: /Menu item for general perspective/i }); - - expect(screen.queryByRole('menuitem', { name: /Menu item for specific perspective/i })).not.toBeInTheDocument(); - }); - describe('uses correct position', () => { it('should render an item after a specified item', async () => { render(); diff --git a/graylog2-web-interface/src/components/navigation/MainNavbar.tsx b/graylog2-web-interface/src/components/navigation/MainNavbar.tsx index ccbf681f0ed1..f2fea6a3bb61 100644 --- a/graylog2-web-interface/src/components/navigation/MainNavbar.tsx +++ b/graylog2-web-interface/src/components/navigation/MainNavbar.tsx @@ -21,9 +21,7 @@ import type { PluginNavigation } from 'graylog-web-plugin'; import { Nav } from 'components/bootstrap'; import { isPermitted } from 'util/PermissionsMixin'; -import filterByPerspective from 'components/perspectives/util/filterByPerspective'; import useCurrentUser from 'hooks/useCurrentUser'; -import useActivePerspective from 'components/perspectives/hooks/useActivePerspective'; import usePluginEntities from 'hooks/usePluginEntities'; import NavigationItem from 'components/navigation/NavigationItem'; import { DEFAULT_SECURITY_NAV_ITEM } from 'components/security/bindings'; @@ -49,7 +47,6 @@ const pluginLicenseValid = (navigationItems: Array, descriptio const useNavigationItems = () => { const { permissions } = useCurrentUser(); - const { activePerspective } = useActivePerspective(); const allNavigationItems = usePluginEntities('navigation'); const navigationItems = useMemo(() => mergeNavigationItems(allNavigationItems), [allNavigationItems]); @@ -78,10 +75,8 @@ const useNavigationItems = () => { navigationItems.push(DEFAULT_SECURITY_NAV_ITEM); } - const itemsForActivePerspective = filterByPerspective(navigationItems, activePerspective?.id); - - return sortNavigationItems(itemsForActivePerspective); - }, [activePerspective?.id, navigationItems, permissions, securityLicenseInvalid]); + return sortNavigationItems(navigationItems); + }, [navigationItems, permissions, securityLicenseInvalid]); }; const MainNavbar = ({ pathname }: { pathname: string }) => { diff --git a/graylog2-web-interface/src/components/navigation/Navigation.test.tsx b/graylog2-web-interface/src/components/navigation/Navigation.test.tsx index b29eaf29b1c5..1191a09a68c1 100644 --- a/graylog2-web-interface/src/components/navigation/Navigation.test.tsx +++ b/graylog2-web-interface/src/components/navigation/Navigation.test.tsx @@ -23,11 +23,8 @@ import mockComponent from 'helpers/mocking/MockComponent'; import { asMock } from 'helpers/mocking'; import Navigation from 'components/navigation/Navigation'; import useCurrentUser from 'hooks/useCurrentUser'; -import PerspectivesBindings from 'components/perspectives/bindings'; -import PerspectivesProvider from 'components/perspectives/contexts/PerspectivesProvider'; import useLocation from 'routing/useLocation'; import HotkeysProvider from 'contexts/HotkeysProvider'; -import { usePluginExports } from 'views/test/testPlugins'; jest.mock('./ScratchpadToggle', () => mockComponent('ScratchpadToggle')); jest.mock('hooks/useCurrentUser'); @@ -38,14 +35,10 @@ jest.mock('routing/useLocation', () => jest.fn(() => ({ pathname: '' }))); describe('Navigation', () => { const SUT = () => ( - - - + ); - usePluginExports(PerspectivesBindings); - beforeEach(() => { asMock(useCurrentUser).mockReturnValue(defaultUser); asMock(useLocation).mockReturnValue({ pathname: '/' } as Location); diff --git a/graylog2-web-interface/src/components/navigation/Navigation.tsx b/graylog2-web-interface/src/components/navigation/Navigation.tsx index 902c3fb4f7ac..fa22f8530853 100644 --- a/graylog2-web-interface/src/components/navigation/Navigation.tsx +++ b/graylog2-web-interface/src/components/navigation/Navigation.tsx @@ -15,17 +15,19 @@ * . */ import * as React from 'react'; +import styled, { css } from 'styled-components'; import useLocation from 'routing/useLocation'; -import { LinkContainer } from 'components/common/router'; +import { Link, LinkContainer } from 'components/common/router'; import AppConfig from 'util/AppConfig'; import { Navbar, Nav } from 'components/bootstrap'; import GlobalThroughput from 'components/throughput/GlobalThroughput'; import Routes from 'routing/Routes'; -import PerspectivesSwitcher from 'components/perspectives/PerspectivesSwitcher'; +import BrandNavLogo from 'components/navigation/NavigationBrand'; import usePluginEntities from 'hooks/usePluginEntities'; import MainNavbar from 'components/navigation/MainNavbar'; import { FEATURE_FLAG } from 'components/quick-jump/Constants'; +import { NAV_ITEM_HEIGHT } from 'theme/constants'; import UserMenu from './UserMenu'; import HelpMenu from './HelpMenu'; @@ -41,6 +43,22 @@ type Props = { pathname: string; }; +const BrandLink = styled(Link)( + ({ theme }) => css` + display: inline-flex; + align-items: center; + min-height: ${NAV_ITEM_HEIGHT}; + color: ${theme.colors.text.primary}; + + &:hover, + &:active, + &:focus { + text-decoration: none; + color: ${theme.colors.text.primary}; + } + `, +); + const Navigation = React.memo(({ pathname }: Props) => { const pluginItems = usePluginEntities('navigationItems'); @@ -48,7 +66,9 @@ const Navigation = React.memo(({ pathname }: Props) => { - + + + diff --git a/graylog2-web-interface/src/components/navigation/NavigationBrand.tsx b/graylog2-web-interface/src/components/navigation/NavigationBrand.tsx index 088b6b8ea5e4..ca96a88e03b7 100644 --- a/graylog2-web-interface/src/components/navigation/NavigationBrand.tsx +++ b/graylog2-web-interface/src/components/navigation/NavigationBrand.tsx @@ -17,80 +17,70 @@ import React from 'react'; import styled, { useTheme } from 'styled-components'; -import { NAV_ITEM_HEIGHT } from 'theme/constants'; +import { NAV_LOGO_HEIGHT, MAX_NAV_LOGO_WIDTH } from 'theme/constants'; +import useCustomLogo from 'brand-customization/useCustomLogo'; -const Link = styled.a( - ({ theme }) => ` - display: flex; - color: ${theme.colors.variant.default}; - align-items: center; - justify-content: center; - padding: 0 15px; - min-height: ${NAV_ITEM_HEIGHT}; - - &:hover, - &:focus { - color: ${theme.colors.variant.dark.default}; - background-color: transparent; - } -`, +export const Logo = ({ color }: { color: string }) => ( + + Graylog Logo + + + + + + + + + ); -type Props = { - active?: boolean; - className?: string; -}; +const StyledSvgContainer = styled.div` + svg { + width: 100%; + max-width: ${MAX_NAV_LOGO_WIDTH}; + height: ${NAV_LOGO_HEIGHT}; + display: block; + } +`; -// Don't pass active prop, since `a` tag doesn't support it. -const BrandComponent = ({ active: _active = false, ...props }: Props) => { +const NavigationBrand = () => { const theme = useTheme(); + const customLogo = useCustomLogo(theme.mode); + + if (customLogo) return ; - return ( - - - Graylog Logo - - - - - - - - - - - ); + return ; }; -export default BrandComponent; +export default NavigationBrand; diff --git a/graylog2-web-interface/src/components/navigation/util/mergeNavigationItems.ts b/graylog2-web-interface/src/components/navigation/util/mergeNavigationItems.ts index aff70d8d3553..623160e72579 100644 --- a/graylog2-web-interface/src/components/navigation/util/mergeNavigationItems.ts +++ b/graylog2-web-interface/src/components/navigation/util/mergeNavigationItems.ts @@ -25,8 +25,7 @@ const _existingDropdownItemIndex = ( } return existingNavigationItems.findIndex( - ({ description, perspective, children }) => - newNavigationItem.description === description && newNavigationItem.perspective === perspective && children, + ({ description, children }) => newNavigationItem.description === description && children, ); }; diff --git a/graylog2-web-interface/src/components/perspectives/ActivePerspectiveBrand.tsx b/graylog2-web-interface/src/components/perspectives/ActivePerspectiveBrand.tsx deleted file mode 100644 index 8076bd977db7..000000000000 --- a/graylog2-web-interface/src/components/perspectives/ActivePerspectiveBrand.tsx +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2020 Graylog, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * . - */ -import * as React from 'react'; -import type { PropsWithChildren } from 'react'; -import styled, { css } from 'styled-components'; - -import { Link } from 'components/common/router'; -import { NAV_ITEM_HEIGHT } from 'theme/constants'; -import useActivePerspective from 'components/perspectives/hooks/useActivePerspective'; - -const BrandContainer = styled.div` - display: flex; - align-items: center; -`; - -const BrandLink = styled(Link)( - ({ theme }) => css` - display: inline-flex; - align-items: center; - min-height: ${NAV_ITEM_HEIGHT}; - color: ${theme.colors.text.primary}; - - &:hover, - &:active, - &:focus { - text-decoration: none; - color: ${theme.colors.text.primary}; - } - `, -); - -const ActivePerspectiveBrand = ({ - children = undefined, - className = '', -}: PropsWithChildren<{ className?: string }>) => { - const { activePerspective } = useActivePerspective(); - const ActiveBrandComponent = activePerspective?.brandComponent; - - if (!ActiveBrandComponent) { - return null; - } - - return ( - - - - - {children} - - ); -}; - -export default ActivePerspectiveBrand; diff --git a/graylog2-web-interface/src/components/perspectives/DefaultBrand.tsx b/graylog2-web-interface/src/components/perspectives/DefaultBrand.tsx deleted file mode 100644 index 0dc532413b3c..000000000000 --- a/graylog2-web-interface/src/components/perspectives/DefaultBrand.tsx +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (C) 2020 Graylog, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * . - */ -import React from 'react'; -import styled, { useTheme } from 'styled-components'; - -import { NAV_LOGO_HEIGHT, MAX_NAV_LOGO_WIDTH } from 'theme/constants'; -import useCustomLogo from 'brand-customization/useCustomLogo'; - -export const Logo = ({ color }: { color: string }) => ( - - Graylog Logo - - - - - - - - - -); - -const Container = styled.div` - display: inline-flex; -`; - -type Props = { - className?: string; -}; - -const StyledSvgContainer = styled.div` - svg { - width: 100%; - max-width: ${MAX_NAV_LOGO_WIDTH}; - height: ${NAV_LOGO_HEIGHT}; - display: block; - } -`; -export const BrandNavLogo = () => { - const theme = useTheme(); - const customLogo = useCustomLogo(theme.mode); - - if (customLogo) return ; - - return ; -}; - -const DefaultBrand = ({ className = '' }: Props) => ( - - - -); - -export default DefaultBrand; diff --git a/graylog2-web-interface/src/components/perspectives/PerspectivesSwitcher.test.tsx b/graylog2-web-interface/src/components/perspectives/PerspectivesSwitcher.test.tsx deleted file mode 100644 index b2201a8f9bcf..000000000000 --- a/graylog2-web-interface/src/components/perspectives/PerspectivesSwitcher.test.tsx +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2020 Graylog, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * . - */ -import React from 'react'; -import { render, screen, waitFor } from 'wrappedTestingLibrary'; -import userEvent from '@testing-library/user-event'; - -import useHistory from 'routing/useHistory'; -import usePerspectives from 'components/perspectives/hooks/usePerspectives'; -import { asMock } from 'helpers/mocking'; -import useActivePerspective from 'components/perspectives/hooks/useActivePerspective'; -import mockHistory from 'helpers/mocking/mockHistory'; -import { defaultPerspective, examplePerspective } from 'fixtures/perspectives'; - -import PerspectivesSwitcher from './PerspectivesSwitcher'; - -jest.mock('components/perspectives/hooks/usePerspectives', () => jest.fn()); -jest.mock('components/perspectives/hooks/useActivePerspective', () => jest.fn()); -jest.mock('routing/useHistory'); - -describe('PerspectivesSwitcher', () => { - let history; - const setActivePerspective = jest.fn(); - const mockedPerspectives = [defaultPerspective, examplePerspective]; - - beforeEach(() => { - history = mockHistory(); - asMock(useHistory).mockReturnValue(history); - - asMock(usePerspectives).mockReturnValue(mockedPerspectives); - - asMock(useActivePerspective).mockReturnValue({ - activePerspective: mockedPerspectives[0], - setActivePerspective, - }); - }); - - it('should render brand for active perspective', async () => { - render(); - - await screen.findByText('Default perspective'); - }); - - it('should render dropdown with available perspectives', async () => { - render(); - - userEvent.click(await screen.findByRole('button', { name: /change ui perspective/i })); - userEvent.click(await screen.findByText(new RegExp(examplePerspective.title, 'i'))); - - await waitFor(() => expect(history.push).toHaveBeenCalledWith(examplePerspective.welcomeRoute)); - - expect(setActivePerspective).toHaveBeenCalledWith(examplePerspective.id); - }); -}); diff --git a/graylog2-web-interface/src/components/perspectives/PerspectivesSwitcher.tsx b/graylog2-web-interface/src/components/perspectives/PerspectivesSwitcher.tsx deleted file mode 100644 index 1a5b95a803b1..000000000000 --- a/graylog2-web-interface/src/components/perspectives/PerspectivesSwitcher.tsx +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (C) 2020 Graylog, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * . - */ -import * as React from 'react'; -import styled, { css } from 'styled-components'; -import { useCallback } from 'react'; - -import Menu from 'components/bootstrap/Menu'; -import Icon from 'components/common/Icon'; -import usePerspectives from 'components/perspectives/hooks/usePerspectives'; -import useActivePerspective from 'components/perspectives/hooks/useActivePerspective'; -import useHistory from 'routing/useHistory'; -import { MenuItem } from 'components/bootstrap'; - -import ActivePerspectiveBrand from './ActivePerspectiveBrand'; - -const CONTAINER_CLASS = 'navbar-brand'; - -const Container = styled.span` - display: flex; - flex-direction: row; - align-content: center; - align-items: center; - padding-right: 0; -`; - -const ItemContainer = styled.span( - ({ theme }) => css` - font-size: ${theme.fonts.size.large}; - display: flex; - flex-direction: row; - align-content: center; - align-items: center; - `, -); - -const DropdownTrigger = styled.button` - background: transparent; - border: 0; -`; - -const StyledMenuDropdown = styled(Menu.Dropdown)` - z-index: 1032 !important; -`; - -const DropdownIcon = styled(Icon)( - ({ theme }) => css` - color: ${theme.colors.text.primary}; - `, -); - -const Switcher = () => { - const { setActivePerspective } = useActivePerspective(); - const perspectives = usePerspectives(); - const history = useHistory(); - - const onChangePerspective = useCallback( - (nextPerspectiveId: string) => () => { - const { welcomeRoute } = perspectives.find(({ id }) => id === nextPerspectiveId); - - history.push(welcomeRoute); - setActivePerspective(nextPerspectiveId); - }, - [history, perspectives, setActivePerspective], - ); - - return ( - - - - - - - - - - - {perspectives.map(({ title, id }) => ( - - {title} - - ))} - - - - ); -}; - -const PerspectivesSwitcher = () => { - const perspectives = usePerspectives(); - - if (perspectives.length === 1) { - return ; - } - - return ; -}; - -export default PerspectivesSwitcher; diff --git a/graylog2-web-interface/src/components/perspectives/bindings.ts b/graylog2-web-interface/src/components/perspectives/bindings.ts deleted file mode 100644 index 22e20a5942e5..000000000000 --- a/graylog2-web-interface/src/components/perspectives/bindings.ts +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) 2020 Graylog, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * . - */ - -import Routes from 'routing/Routes'; - -import DefaultBrand from './DefaultBrand'; - -const perspectivesBindings = { - perspectives: [ - { - id: 'default', - title: 'General', - welcomeRoute: Routes.WELCOME, - brandComponent: DefaultBrand, - }, - ], -}; - -export default perspectivesBindings; diff --git a/graylog2-web-interface/src/components/perspectives/contexts/PerspectivesContext.ts b/graylog2-web-interface/src/components/perspectives/contexts/PerspectivesContext.ts deleted file mode 100644 index b7658ced1e87..000000000000 --- a/graylog2-web-interface/src/components/perspectives/contexts/PerspectivesContext.ts +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (C) 2020 Graylog, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * . - */ -import * as React from 'react'; - -import { singleton } from 'logic/singleton'; -import type { Perspective } from 'components/perspectives/types'; - -type PerspectivesContextType = { - activePerspective: Perspective; - availablePerspectives: Array; - setActivePerspective: (perspectiveId: string) => void; -}; - -const PerspectivesContext = React.createContext(undefined); - -export default singleton('contexts.PerspectivesContext', () => PerspectivesContext); diff --git a/graylog2-web-interface/src/components/perspectives/contexts/PerspectivesProvider.tsx b/graylog2-web-interface/src/components/perspectives/contexts/PerspectivesProvider.tsx deleted file mode 100644 index e192ba1de060..000000000000 --- a/graylog2-web-interface/src/components/perspectives/contexts/PerspectivesProvider.tsx +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (C) 2020 Graylog, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * . - */ -import * as React from 'react'; -import type { PropsWithChildren } from 'react'; -import { useCallback, useMemo, useState } from 'react'; - -import usePluginEntities from 'hooks/usePluginEntities'; -import type { Perspective } from 'components/perspectives/types'; -import usePersistedSetting from 'hooks/usePersistedSetting'; - -import PerspectivesContext from './PerspectivesContext'; - -export const DEFAULT_PERSPECTIVE = 'default'; - -const findPerspective = (perspectives: Array, perspectiveId: string) => - perspectives.find(({ id }) => id === perspectiveId); - -const useActivePerspectiveState = (availablePerspectives: Array) => { - const [persistedPerspective, setPersistedPerspective] = usePersistedSetting('perspective'); - const [activePerspective, setActivePerspective] = useState( - findPerspective(availablePerspectives, persistedPerspective) ? persistedPerspective : DEFAULT_PERSPECTIVE, - ); - const setActivePerspectiveWithPersistence = useCallback( - (newPerspective: string) => { - setActivePerspective(newPerspective); - - return setPersistedPerspective(newPerspective); - }, - [setPersistedPerspective], - ); - - return { - activePerspective: findPerspective(availablePerspectives, activePerspective), - setActivePerspective: setActivePerspectiveWithPersistence, - }; -}; - -const PerspectivesProvider = ({ children }: PropsWithChildren) => { - const allPerspectives = usePluginEntities('perspectives'); - const availablePerspectives = allPerspectives.filter((perspective) => - perspective.useCondition ? !!perspective.useCondition() : true, - ); - const { activePerspective, setActivePerspective } = useActivePerspectiveState(availablePerspectives); - const contextValue = useMemo( - () => ({ - activePerspective, - availablePerspectives, - setActivePerspective, - }), - [activePerspective, availablePerspectives, setActivePerspective], - ); - - return {children}; -}; - -export default PerspectivesProvider; diff --git a/graylog2-web-interface/src/components/perspectives/hooks/__mocks__/useActivePerspective.ts b/graylog2-web-interface/src/components/perspectives/hooks/__mocks__/useActivePerspective.ts deleted file mode 100644 index 9135348f885b..000000000000 --- a/graylog2-web-interface/src/components/perspectives/hooks/__mocks__/useActivePerspective.ts +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (C) 2020 Graylog, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * . - */ -const useActivePerspective = jest.fn(() => ({ activePerspective: 'foo' })); -export default useActivePerspective; diff --git a/graylog2-web-interface/src/components/perspectives/hooks/useActivePerspective.test.tsx b/graylog2-web-interface/src/components/perspectives/hooks/useActivePerspective.test.tsx deleted file mode 100644 index 92b4bbd0a0c3..000000000000 --- a/graylog2-web-interface/src/components/perspectives/hooks/useActivePerspective.test.tsx +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2020 Graylog, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * . - */ -import React from 'react'; -import { renderHook } from 'wrappedTestingLibrary/hooks'; - -import useActivePerspective from 'components/perspectives/hooks/useActivePerspective'; -import PerspectivesProvider from 'components/perspectives/contexts/PerspectivesProvider'; -import usePluginEntities from 'hooks/usePluginEntities'; -import { asMock } from 'helpers/mocking'; -import { defaultPerspective } from 'fixtures/perspectives'; - -jest.mock('hooks/usePluginEntities'); - -describe('useActivePerspective', () => { - beforeEach(() => { - asMock(usePluginEntities).mockImplementation( - (entityKey) => - ({ - perspectives: [defaultPerspective], - })[entityKey], - ); - }); - - const wrapper = ({ children }: React.PropsWithChildren) => {children}; - - it('should return active perspective', async () => { - const { result } = renderHook(() => useActivePerspective(), { wrapper }); - - expect(result.current.activePerspective).toEqual(defaultPerspective); - }); - - it('should throw error when being used outside of PerspectivesContext', async () => { - expect(() => renderHook(() => useActivePerspective())).toThrow( - 'useActivePerspective hook needs to be used inside PerspectivesContext.Provider', - ); - }); -}); diff --git a/graylog2-web-interface/src/components/perspectives/hooks/useActivePerspective.ts b/graylog2-web-interface/src/components/perspectives/hooks/useActivePerspective.ts deleted file mode 100644 index b435112256ab..000000000000 --- a/graylog2-web-interface/src/components/perspectives/hooks/useActivePerspective.ts +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2020 Graylog, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * . - */ -import { useContext } from 'react'; - -import PerspectivesContext from '../contexts/PerspectivesContext'; - -const useActivePerspective = () => { - const perspectivesContextValue = useContext(PerspectivesContext); - - if (!perspectivesContextValue) { - throw new Error('useActivePerspective hook needs to be used inside PerspectivesContext.Provider'); - } - - return { - activePerspective: perspectivesContextValue.activePerspective, - setActivePerspective: perspectivesContextValue.setActivePerspective, - }; -}; - -export default useActivePerspective; diff --git a/graylog2-web-interface/src/components/perspectives/hooks/usePerspectives.test.tsx b/graylog2-web-interface/src/components/perspectives/hooks/usePerspectives.test.tsx deleted file mode 100644 index d92ee0d28900..000000000000 --- a/graylog2-web-interface/src/components/perspectives/hooks/usePerspectives.test.tsx +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (C) 2020 Graylog, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * . - */ -import React from 'react'; -import { renderHook } from 'wrappedTestingLibrary/hooks'; - -import usePerspectives from 'components/perspectives/hooks/usePerspectives'; -import PerspectivesProvider from 'components/perspectives/contexts/PerspectivesProvider'; -import { defaultPerspective, examplePerspective, unavailablePerspective } from 'fixtures/perspectives'; - -const mockedPerspectives = [defaultPerspective, examplePerspective, unavailablePerspective]; -jest.mock('hooks/usePluginEntities', () => () => mockedPerspectives); - -describe('usePerspectives', () => { - afterEach(() => { - jest.clearAllMocks(); - }); - - const wrapper = ({ children }: React.PropsWithChildren) => {children}; - - it('should return available perspectives', async () => { - const { result } = renderHook(() => usePerspectives(), { wrapper }); - - expect(result.current.map(({ id }) => id)).toEqual([defaultPerspective.id, examplePerspective.id]); - }); - - it('should throw error when being used outside of PerspectivesContext', async () => { - expect(() => renderHook(() => usePerspectives())).toThrow( - 'usePerspectives hook needs to be used inside PerspectivesContext.Provider', - ); - }); -}); diff --git a/graylog2-web-interface/src/components/perspectives/hooks/usePerspectives.ts b/graylog2-web-interface/src/components/perspectives/hooks/usePerspectives.ts deleted file mode 100644 index 3c03cb337270..000000000000 --- a/graylog2-web-interface/src/components/perspectives/hooks/usePerspectives.ts +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2020 Graylog, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * . - */ -import { useContext } from 'react'; - -import PerspectivesContext from '../contexts/PerspectivesContext'; - -const usePerspectives = () => { - const perspectivesContextValue = useContext(PerspectivesContext); - - if (!perspectivesContextValue) { - throw new Error('usePerspectives hook needs to be used inside PerspectivesContext.Provider'); - } - - return perspectivesContextValue.availablePerspectives; -}; - -export default usePerspectives; diff --git a/graylog2-web-interface/src/components/perspectives/index.d.ts b/graylog2-web-interface/src/components/perspectives/index.d.ts deleted file mode 100644 index 1783fce05ba6..000000000000 --- a/graylog2-web-interface/src/components/perspectives/index.d.ts +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (C) 2020 Graylog, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * . - */ - -import type { Perspective } from './types'; - -declare module 'graylog-web-plugin/plugin' { - export interface PluginExports { - perspectives?: Array; - } -} diff --git a/graylog2-web-interface/src/components/perspectives/types.ts b/graylog2-web-interface/src/components/perspectives/types.ts deleted file mode 100644 index 8847477030b1..000000000000 --- a/graylog2-web-interface/src/components/perspectives/types.ts +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (C) 2020 Graylog, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * . - */ - -import type * as React from 'react'; - -export type Perspective = { - id: string; - title: string; - welcomeRoute: string; - brandComponent: React.ComponentType<{ - className?: string; - disabled?: boolean; - href?: string; - }>; - useCondition?: () => boolean; -}; diff --git a/graylog2-web-interface/src/components/perspectives/util/filterByPerspective.ts b/graylog2-web-interface/src/components/perspectives/util/filterByPerspective.ts deleted file mode 100644 index 9c40e72da051..000000000000 --- a/graylog2-web-interface/src/components/perspectives/util/filterByPerspective.ts +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) 2020 Graylog, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * . - */ - -const filterByPerspective = ( - items: Array, - perspective: string | undefined, -): Array => - items.filter(({ perspective: itemPerspective }) => - perspective === 'default' ? !itemPerspective || itemPerspective === 'default' : perspective === itemPerspective, - ); - -export default filterByPerspective; diff --git a/graylog2-web-interface/src/components/quick-jump/hooks/useNavItems.test.tsx b/graylog2-web-interface/src/components/quick-jump/hooks/useNavItems.test.tsx index 6a6437163631..f289c3ca498d 100644 --- a/graylog2-web-interface/src/components/quick-jump/hooks/useNavItems.test.tsx +++ b/graylog2-web-interface/src/components/quick-jump/hooks/useNavItems.test.tsx @@ -21,8 +21,6 @@ import { renderHookWithDataRouter } from 'wrappedTestingLibrary/hooks'; import { usePluginExports } from 'views/test/testPlugins'; import CurrentUserContext from 'contexts/CurrentUserContext'; import { adminUser } from 'fixtures/users'; -import PerspectivesContext from 'components/perspectives/contexts/PerspectivesContext'; -import { defaultPerspective } from 'fixtures/perspectives'; import { ScratchpadContext } from 'contexts/ScratchpadProvider'; import useNavItems from './useNavItems'; @@ -44,14 +42,7 @@ const Wrapper = ({ children }: { children: React.ReactNode }) => ( setScratchpadVisibility: jest.fn(), toggleScratchpadVisibility: jest.fn(), }}> - {}, - }}> - {children} - + {children} ); diff --git a/graylog2-web-interface/src/components/quick-jump/hooks/useNavItems.ts b/graylog2-web-interface/src/components/quick-jump/hooks/useNavItems.ts index d7901779704f..296a048365d2 100644 --- a/graylog2-web-interface/src/components/quick-jump/hooks/useNavItems.ts +++ b/graylog2-web-interface/src/components/quick-jump/hooks/useNavItems.ts @@ -17,9 +17,7 @@ import { useContext, useMemo } from 'react'; import type { Permission } from 'graylog-web-plugin/plugin'; -import { DEFAULT_PERSPECTIVE } from 'components/perspectives/contexts/PerspectivesProvider'; import usePluginEntities from 'hooks/usePluginEntities'; -import useActivePerspective from 'components/perspectives/hooks/useActivePerspective'; import { PAGE_TYPE, ACTION_TYPE, LINK_TYPE } from 'components/quick-jump/Constants'; import usePermissions from 'hooks/usePermissions'; import type { QualifiedUrl } from 'routing/Routes'; @@ -28,8 +26,6 @@ import AppConfig from 'util/AppConfig'; import type { SearchResultItem } from 'components/quick-jump/Types'; import useCurrentUser from 'hooks/useCurrentUser'; import { ScratchpadContext } from 'contexts/ScratchpadProvider'; -import PerspectivesContext from 'components/perspectives/contexts/PerspectivesContext'; -import useHistory from 'routing/useHistory'; const useEntityCreatorItems = () => { const { isPermitted } = usePermissions(); @@ -67,22 +63,6 @@ const useConfigurationPages = () => { const useQuickJumpActions = (): SearchResultItem[] => { const { isScratchpadVisible } = useContext(ScratchpadContext); - const { activePerspective, availablePerspectives, setActivePerspective } = useContext(PerspectivesContext); - const history = useHistory(); - const perspectiveActions = useMemo( - () => - availablePerspectives - .filter((perspective) => perspective !== activePerspective) - .map((perspective) => ({ - type: ACTION_TYPE, - title: `Switch to ${perspective.title} perspective`, - action: () => { - setActivePerspective(perspective.id); - history.push(perspective.welcomeRoute); - }, - })), - [activePerspective, availablePerspectives, history, setActivePerspective], - ); return [ { @@ -106,7 +86,6 @@ const useQuickJumpActions = (): SearchResultItem[] => { toggleScratchpad(); }, }, - ...perspectiveActions, ]; }; @@ -162,9 +141,6 @@ const useHelpMenuItems = () => { }); }; -const matchesPerspective = (activePerspective: string, itemPerspective: string) => - activePerspective === DEFAULT_PERSPECTIVE ? !itemPerspective : itemPerspective === activePerspective; - const isFeatureEnabled = (featureFlag?: string) => { if (!featureFlag) return true; @@ -181,37 +157,32 @@ type BaseNavigationItem = { const useMainNavigationItems = () => { const { isPermitted } = usePermissions(); const navigationItems = usePluginEntities('navigation'); - const { activePerspective } = useActivePerspective(); const allNavigationItems = navigationItems.flatMap((item) => 'children' in item ? item.children.map((child) => ({ ...child, description: `${item.description} / ${child.description}`, - perspective: item.perspective, })) : [item], ); return allNavigationItems - .filter((item) => isPermitted(item.permissions) && matchesPerspective(activePerspective.id, item.perspective)) + .filter((item) => isPermitted(item.permissions)) .map((item) => ({ type: PAGE_TYPE, link: item.path, title: item.description })); }; const usePageNavigationItems = () => { - const { activePerspective } = useActivePerspective(); const { isPermitted } = usePermissions(); const pageNavigationItems = usePluginEntities('pageNavigation'); - return pageNavigationItems - .filter((group) => matchesPerspective(activePerspective.id, group.perspective)) - .flatMap((group) => - [...group.children] - .filter((page) => isFeatureEnabled(page.requiredFeatureFlag)) - .filter((page) => isPermitted(page.permissions)) - .slice(1) - .map((page) => ({ type: PAGE_TYPE, link: page.path, title: `${group.description} / ${page.description}` })), - ); + return pageNavigationItems.flatMap((group) => + [...group.children] + .filter((page) => isFeatureEnabled(page.requiredFeatureFlag)) + .filter((page) => isPermitted(page.permissions)) + .slice(1) + .map((page) => ({ type: PAGE_TYPE, link: page.path, title: `${group.description} / ${page.description}` })), + ); }; const useNavItems = () => { diff --git a/graylog2-web-interface/src/index.tsx b/graylog2-web-interface/src/index.tsx index 256b1f85611b..9e3562a9bc64 100644 --- a/graylog2-web-interface/src/index.tsx +++ b/graylog2-web-interface/src/index.tsx @@ -33,7 +33,6 @@ import FieldValueProvidersBindings from 'components/event-definitions/event-defi import CancellablePromise from 'logic/rest/CancellablePromise'; import TelemetryInit from 'logic/telemetry/TelemetryInit'; import LoginQueryClientProvider from 'contexts/LoginQueryClientProvider'; -import PerspectivesBindings from 'components/perspectives/bindings'; import NavigationBindings from 'components/navigation/bindings'; import SecurityBindings from 'components/security/bindings'; import EventsBindings from 'components/events/bindings'; @@ -62,7 +61,6 @@ PluginStore.register(new PluginManifest({}, IntegrationsBindings)); PluginStore.register(new PluginManifest({}, EventDefinitionsBindings)); PluginStore.register(new PluginManifest({}, EventNotificationsBindings)); PluginStore.register(new PluginManifest({}, FieldValueProvidersBindings)); -PluginStore.register(new PluginManifest({}, PerspectivesBindings)); PluginStore.register(new PluginManifest({}, NavigationBindings)); PluginStore.register(new PluginManifest({}, SecurityBindings)); PluginStore.register(new PluginManifest({}, EventsBindings)); diff --git a/graylog2-web-interface/src/pages/StartPage.tsx b/graylog2-web-interface/src/pages/StartPage.tsx index 044e119e0ddc..0efe232c24d1 100644 --- a/graylog2-web-interface/src/pages/StartPage.tsx +++ b/graylog2-web-interface/src/pages/StartPage.tsx @@ -21,11 +21,9 @@ import Routes from 'routing/Routes'; import { CurrentUserStore } from 'stores/users/CurrentUserStore'; import { useStore } from 'stores/connect'; import useHistory from 'routing/useHistory'; -import useActivePerspective from 'components/perspectives/hooks/useActivePerspective'; const StartPage = () => { const { currentUser } = useStore(CurrentUserStore); - const { activePerspective } = useActivePerspective(); const isLoading = !currentUser; const history = useHistory(); @@ -56,8 +54,8 @@ const StartPage = () => { return; } - redirect(activePerspective.welcomeRoute); - }, [activePerspective, currentUser?.startpage, redirect]); + redirect(Routes.WELCOME); + }, [currentUser?.startpage, redirect]); useEffect(() => { CurrentUserStore.reload(); diff --git a/graylog2-web-interface/src/preflight/navigation/Navigation.tsx b/graylog2-web-interface/src/preflight/navigation/Navigation.tsx index 90f2f3cbd912..220a9c8f5570 100644 --- a/graylog2-web-interface/src/preflight/navigation/Navigation.tsx +++ b/graylog2-web-interface/src/preflight/navigation/Navigation.tsx @@ -20,7 +20,7 @@ import styled, { css } from 'styled-components'; import HelpMenu from 'preflight/navigation/HelpMenu'; import { Group, AppShell, Text } from 'preflight/components/common'; -import NavigationBrand from 'components/perspectives/DefaultBrand'; +import NavigationBrand from 'components/navigation/NavigationBrand'; import ThemeModeToggle from './ThemeModeToggle'; diff --git a/graylog2-web-interface/src/routing/App.tsx b/graylog2-web-interface/src/routing/App.tsx index 83180aa60c6e..3573bfb846cd 100644 --- a/graylog2-web-interface/src/routing/App.tsx +++ b/graylog2-web-interface/src/routing/App.tsx @@ -28,7 +28,6 @@ import RuntimeErrorBoundary from 'components/errors/RuntimeErrorBoundary'; import NavigationTelemetry from 'logic/telemetry/NavigationTelemetry'; import HotkeysProvider from 'contexts/HotkeysProvider'; import HotkeysModalContainer from 'components/hotkeys/HotkeysModalContainer'; -import PerspectivesProvider from 'components/perspectives/contexts/PerspectivesProvider'; import PageContextProviders from 'components/page/contexts/PageContextProviders'; import { singleton } from 'logic/singleton'; import DefaultQueryParamProvider from 'routing/DefaultQueryParamProvider'; @@ -54,29 +53,27 @@ const App = () => ( } return ( - - - - - <> - - - - - - - - - - - - - - - - - - + + + + <> + + + + + + + + + + + + + + + + + ); }} diff --git a/graylog2-web-interface/src/routing/AppRouter.test.tsx b/graylog2-web-interface/src/routing/AppRouter.test.tsx index 4239165675aa..7d5829fcbcfa 100644 --- a/graylog2-web-interface/src/routing/AppRouter.test.tsx +++ b/graylog2-web-interface/src/routing/AppRouter.test.tsx @@ -30,7 +30,6 @@ import usePluginEntities from 'hooks/usePluginEntities'; import AppConfig from 'util/AppConfig'; import GlobalContextProviders from 'contexts/GlobalContextProviders'; import HotkeysProvider from 'contexts/HotkeysProvider'; -import { defaultPerspective as mockDefaultPerspective } from 'fixtures/perspectives'; import AppRouter from './AppRouter'; @@ -85,13 +84,9 @@ const mockRoutes = (routes: PluginExports['routes']) => { }; describe('AppRouter', () => { - const defaultPlugins = { - perspectives: [mockDefaultPerspective], - }; - beforeEach(() => { - asMock(usePluginEntities).mockImplementation((entityKey) => defaultPlugins[entityKey] ?? []); AppConfig.isFeatureEnabled = jest.fn(() => false); + asMock(usePluginEntities).mockReturnValue([]); asMock(createBrowserRouter).mockImplementation((routes: RouteObject[]) => createMemoryRouter(routes)); }); diff --git a/graylog2-web-interface/src/views/components/widgets/events/EventsList/EventDetails.test.tsx b/graylog2-web-interface/src/views/components/widgets/events/EventsList/EventDetails.test.tsx index 9fc07a5ef1a9..4bcd6189b6aa 100644 --- a/graylog2-web-interface/src/views/components/widgets/events/EventsList/EventDetails.test.tsx +++ b/graylog2-web-interface/src/views/components/widgets/events/EventsList/EventDetails.test.tsx @@ -24,8 +24,6 @@ import usePluginEntities from 'hooks/usePluginEntities'; import useEventById from 'hooks/useEventById'; import { mockEventData, mockEventDefinitionTwoAggregations } from 'helpers/mocking/EventAndEventDefinitions_mock'; import useEventDefinition from 'components/events/events/hooks/useEventDefinition'; -import PerspectivesProvider from 'components/perspectives/contexts/PerspectivesProvider'; -import { defaultPerspective } from 'fixtures/perspectives'; import EventDetails from './EventDetails'; @@ -34,12 +32,7 @@ jest.mock('hooks/useEventById'); jest.mock('hooks/useCurrentUser'); jest.mock('components/events/events/hooks/useEventDefinition'); -const renderEventDetails = () => - render( - - - , - ); +const renderEventDetails = () => render(); describe('EventDetails', () => { beforeEach(() => { @@ -49,7 +42,6 @@ describe('EventDetails', () => { 'views.components.widgets.events.detailsComponent': [], 'views.components.eventActions': [], eventDefinitionTypes: [], - perspectives: [defaultPerspective], 'views.components.eventProcedureSummary': [], })[entityKey], ); @@ -76,7 +68,6 @@ describe('EventDetails', () => { key: 'details-component', }, ], - perspectives: [defaultPerspective], })[entityKey], ); diff --git a/graylog2-web-interface/src/views/components/widgets/events/EventsList/RowActions.tsx b/graylog2-web-interface/src/views/components/widgets/events/EventsList/RowActions.tsx index d8f5939574c4..15cde9ad2d6e 100644 --- a/graylog2-web-interface/src/views/components/widgets/events/EventsList/RowActions.tsx +++ b/graylog2-web-interface/src/views/components/widgets/events/EventsList/RowActions.tsx @@ -29,9 +29,7 @@ import EventDetails from './EventDetails'; const usePluggableDashboardActions = (eventId: string) => { const modalRefs = useRef({}); const pluggableActions = usePluginEntities('views.components.widgets.events.actions'); - const availableActions = pluggableActions.filter((perspective) => - perspective.useCondition ? !!perspective.useCondition() : true, - ); + const availableActions = pluggableActions.filter((action) => (action.useCondition ? !!action.useCondition() : true)); const actions = availableActions.map(({ component: PluggableDashboardAction, key }) => ( modalRefs.current[key]} /> )); diff --git a/graylog2-web-interface/test/fixtures/perspectives.tsx b/graylog2-web-interface/test/fixtures/perspectives.tsx deleted file mode 100644 index d33a16e35858..000000000000 --- a/graylog2-web-interface/test/fixtures/perspectives.tsx +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2020 Graylog, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * . - */ - -import React from 'react'; - -export const defaultPerspective = { - id: 'default', - title: 'Default Perspective', - brandComponent: () =>
Default perspective
, - welcomeRoute: '', -}; - -export const examplePerspective = { - id: 'example-perspective', - title: 'Example Perspective', - brandComponent: () =>
, - welcomeRoute: '', -}; - -export const unavailablePerspective = { - id: 'unavailable-perspective', - title: 'Unavailable Perspective', - brandComponent: () =>
, - welcomeRoute: '', - useCondition: () => false, -};