Skip to content

Commit

Permalink
Bed 4769 refactor: SAML admin UI to SSO admin UI (#899)
Browse files Browse the repository at this point in the history
  • Loading branch information
mistahj67 authored Oct 30, 2024
1 parent 39bed6d commit 9decf72
Show file tree
Hide file tree
Showing 46 changed files with 1,605 additions and 606 deletions.
2 changes: 1 addition & 1 deletion cmd/ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
darkPalette,
typography,
components,
useFeatureFlags,
} from 'bh-shared-ui';
import { createBrowserHistory } from 'history';
import React, { useEffect } from 'react';
Expand All @@ -34,7 +35,6 @@ import { unstable_HistoryRouter as BrowserRouter, useLocation } from 'react-rout
import Header from 'src/components/Header';
import { fullyAuthenticatedSelector, initialize } from 'src/ducks/auth/authSlice';
import { ROUTE_EXPIRED_PASSWORD, ROUTE_LOGIN, ROUTE_USER_DISABLED } from 'src/ducks/global/routes';
import { useFeatureFlags } from 'src/hooks/useFeatureFlags';
import { useAppDispatch, useAppSelector } from 'src/store';
import { initializeBHEClient } from 'src/utils';
import Content from 'src/views/Content';
Expand Down
8 changes: 4 additions & 4 deletions cmd/ui/src/components/Notifier.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0

import { SnackbarKey } from 'notistack';
import { faTimes } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { IconButton, SvgIcon } from '@mui/material';
Expand Down Expand Up @@ -76,12 +76,12 @@ const Notifier: React.FC = () => {
...options,
onClose: (event, reason, myKey) => {
if (options.onClose) {
options.onClose(event, myKey, reason);
options.onClose(event, reason, myKey);
}
},
onExited: (event, myKey: string) => {
onExited: (_, myKey: SnackbarKey) => {
dispatch(removeSnackbar(myKey));
removeDisplayed(myKey);
removeDisplayed(myKey.toString());
},
});

Expand Down
3 changes: 1 addition & 2 deletions cmd/ui/src/components/SettingsMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,13 @@ import ListItemText from '@mui/material/ListItemText';
import Menu, { MenuProps } from '@mui/material/Menu';
import MenuItem from '@mui/material/MenuItem';
import withStyles from '@mui/styles/withStyles';
import { EnterpriseIcon } from 'bh-shared-ui';
import { EnterpriseIcon, FeatureFlag } from 'bh-shared-ui';
import React from 'react';
import { useNavigate } from 'react-router-dom';
import { logout } from 'src/ducks/auth/authSlice';
import { setDarkMode } from 'src/ducks/global/actions.ts';
import * as routes from 'src/ducks/global/routes';
import { useAppDispatch, useAppSelector } from 'src/store';
import FeatureFlag from './FeatureFlag';

interface Props {
anchorEl: null | HTMLElement;
Expand Down
10 changes: 7 additions & 3 deletions cmd/ui/src/ducks/global/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,21 @@
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0

import { OptionsObject, SnackbarKey } from 'notistack';
import * as types from './types';

export const removeSnackbar = (key: string): types.GlobalViewActionTypes => {
export const removeSnackbar = (key: SnackbarKey): types.GlobalViewActionTypes => {
return {
type: types.GLOBAL_REMOVE_SNACKBAR,
key: key,
};
};

export const addSnackbar = (notification: string, key: string, options: any = {}): types.GlobalViewActionTypes => {
export const addSnackbar = (
notification: string,
key: string,
options: OptionsObject = {}
): types.GlobalViewActionTypes => {
return {
type: types.GLOBAL_ADD_SNACKBAR,
notification: {
Expand Down
4 changes: 2 additions & 2 deletions cmd/ui/src/ducks/global/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//
// SPDX-License-Identifier: Apache-2.0

import { produce } from 'immer';
import { produce, castDraft } from 'immer';
import { combineReducers } from '@reduxjs/toolkit';
import * as types from './types';
import assign from 'lodash/assign';
Expand All @@ -27,7 +27,7 @@ const initialGlobalState: types.GlobalViewState = {
const globalViewReducer = (state = initialGlobalState, action: types.GlobalViewActionTypes) => {
return produce(state, (draft) => {
if (action.type === types.GLOBAL_ADD_SNACKBAR) {
draft.notifications = [...draft.notifications, action.notification];
draft.notifications = [...draft.notifications, castDraft(action.notification)];
} else if (action.type === types.GLOBAL_CLOSE_SNACKBAR) {
draft.notifications = draft.notifications.map((notification) => {
return action.key === null || action.key === notification.key
Expand Down
2 changes: 1 addition & 1 deletion cmd/ui/src/ducks/global/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const ROUTE_ADMINISTRATION_FILE_INGEST = '/administration/file-ingest';
export const ROUTE_ADMINISTRATION_DATA_QUALITY = '/administration/data-quality';
export const ROUTE_ADMINISTRATION_DB_MANAGEMENT = '/administration/database-management';
export const ROUTE_ADMINISTRATION_MANAGE_USERS = '/administration/manage-users';
export const ROUTE_ADMINISTRATION_SAML_CONFIGURATION = '/administration/saml-configuration';
export const ROUTE_ADMINISTRATION_SSO_CONFIGURATION = '/administration/sso-configuration';
export const ROUTE_ADMINISTRATION_EARLY_ACCESS_FEATURES = '/administration/early-access-features';
export const ROUTE_ADMINISTRATION_BLOODHOUND_CONFIGURATION = '/administration/bloodhound-configuration';
export const ROUTE_API_EXPLORER = '/api-explorer';
13 changes: 4 additions & 9 deletions cmd/ui/src/ducks/global/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0
import { SnackbarKey } from 'notistack';
import { Notification } from 'bh-shared-ui';

const GLOBAL_ADD_SNACKBAR = 'app/global/ADDSNACKBAR';
const GLOBAL_CLOSE_SNACKBAR = 'app/global/CLOSESNACKBAR';
Expand Down Expand Up @@ -43,13 +45,6 @@ export interface GlobalViewState {
darkMode: boolean;
}

export interface Notification {
message: string;
key: string;
dismissed: boolean;
options: any;
}

export interface GlobalOptionsState {
domain: Domain | null;
assetGroups: any[];
Expand All @@ -68,12 +63,12 @@ interface AddSnackbarAction {

interface RemoveSnackbarAction {
type: typeof GLOBAL_REMOVE_SNACKBAR;
key: string;
key: SnackbarKey;
}

interface CloseSnackbarAction {
type: typeof GLOBAL_CLOSE_SNACKBAR;
key: string;
key: SnackbarKey;
}

export interface SetDarkModeAction {
Expand Down
8 changes: 4 additions & 4 deletions cmd/ui/src/views/Administration/Administration.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
ROUTE_ADMINISTRATION_DATA_QUALITY,
ROUTE_ADMINISTRATION_EARLY_ACCESS_FEATURES,
ROUTE_ADMINISTRATION_MANAGE_USERS,
ROUTE_ADMINISTRATION_SAML_CONFIGURATION,
ROUTE_ADMINISTRATION_SSO_CONFIGURATION,
} from 'src/ducks/global/routes';
import { render, screen } from 'src/test-utils';
import Administration from './Administration';
Expand All @@ -46,10 +46,10 @@ describe('Administration', () => {
ROUTE_ADMINISTRATION_EARLY_ACCESS_FEATURES
);

expect(await screen.findByRole('link', { name: 'SAML Configuration' })).toBeInTheDocument();
expect(screen.getByRole('link', { name: 'SAML Configuration' })).toHaveAttribute(
expect(await screen.findByRole('link', { name: 'SSO Configuration' })).toBeInTheDocument();
expect(screen.getByRole('link', { name: 'SSO Configuration' })).toHaveAttribute(
'href',
ROUTE_ADMINISTRATION_SAML_CONFIGURATION
ROUTE_ADMINISTRATION_SSO_CONFIGURATION
);
});

Expand Down
13 changes: 8 additions & 5 deletions cmd/ui/src/views/Administration/Administration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,21 @@ import {
ROUTE_ADMINISTRATION_DATA_QUALITY,
ROUTE_ADMINISTRATION_EARLY_ACCESS_FEATURES,
ROUTE_ADMINISTRATION_MANAGE_USERS,
ROUTE_ADMINISTRATION_SAML_CONFIGURATION,
ROUTE_ADMINISTRATION_SSO_CONFIGURATION,
ROUTE_ADMINISTRATION_DB_MANAGEMENT,
ROUTE_ADMINISTRATION_BLOODHOUND_CONFIGURATION,
} from 'src/ducks/global/routes';
import usePermissions from 'src/hooks/usePermissions/usePermissions';

const DatabaseManagement = React.lazy(() => import('src/views/DatabaseManagement'));
const QA = React.lazy(() => import('src/views/QA'));
const Users = React.lazy(() => import('src/views/Users'));
const SAMLConfiguration = React.lazy(() => import('src/views/SAMLConfiguration'));
const EarlyAccessFeatures = React.lazy(() => import('src/views/EarlyAccessFeatures'));
const FileIngest = React.lazy(() => import('bh-shared-ui').then((module) => ({ default: module.FileIngest })));
const BloodHoundConfiguration = React.lazy(() => import('src/views/BloodHoundConfiguration'));
const SSOConfiguration = React.lazy(() =>
import('bh-shared-ui').then((module) => ({ default: module.SSOConfiguration }))
);

const Administration: React.FC = () => {
const sections = [
Expand Down Expand Up @@ -80,9 +83,9 @@ const Administration: React.FC = () => {
title: 'Authentication',
items: [
{
label: 'SAML Configuration',
path: ROUTE_ADMINISTRATION_SAML_CONFIGURATION,
component: SAMLConfiguration,
label: 'SSO Configuration',
path: ROUTE_ADMINISTRATION_SSO_CONFIGURATION,
component: SSOConfiguration,
adminOnly: false,
},
],
Expand Down
3 changes: 1 addition & 2 deletions cmd/ui/src/views/DatabaseManagement/DatabaseManagement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@

import { Button } from '@bloodhoundenterprise/doodleui';
import { Alert, Box, Checkbox, FormControl, FormControlLabel, FormGroup, Typography } from '@mui/material';
import { PageWithTitle, apiClient } from 'bh-shared-ui';
import { PageWithTitle, apiClient, FeatureFlag } from 'bh-shared-ui';
import { useReducer } from 'react';
import ConfirmationDialog from './ConfirmationDialog';
import { useMutation } from 'react-query';
import { useSelector } from 'react-redux';
import { selectAllAssetGroupIds, selectTierZeroAssetGroupId } from 'src/ducks/assetgroups/reducer';
import { ClearDatabaseRequest } from 'js-client-library';
import FeatureFlag from 'src/components/FeatureFlag';

const initialState: State = {
deleteCollectedGraphData: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import userEvent from '@testing-library/user-event';
import { rest } from 'msw';
import { setupServer } from 'msw/node';
import { Flag } from 'src/hooks/useFeatureFlags';
import { Flag } from 'bh-shared-ui';
import { act, render, screen } from 'src/test-utils';
import EarlyAccessFeatures from '.';

Expand Down
3 changes: 1 addition & 2 deletions cmd/ui/src/views/EarlyAccessFeatures/EarlyAccessFeatures.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@ import {
Skeleton,
Typography,
} from '@mui/material';
import { PageWithTitle } from 'bh-shared-ui';
import { PageWithTitle, Flag, useFeatureFlags, useToggleFeatureFlag } from 'bh-shared-ui';
import { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { setDarkMode } from 'src/ducks/global/actions';
import { Flag, useFeatureFlags, useToggleFeatureFlag } from 'src/hooks/useFeatureFlags';
import { useAppDispatch } from 'src/store';

export const EarlyAccessFeatureToggle: React.FC<{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import userEvent from '@testing-library/user-event';
import { render, screen } from 'src/test-utils';
import { EarlyAccessFeatureToggle } from './EarlyAccessFeatures';
import { Flag } from 'src/hooks/useFeatureFlags';
import { Flag } from 'bh-shared-ui';

describe('EarlyAccessFeatureToggle', () => {
it('renders', () => {
Expand Down
145 changes: 0 additions & 145 deletions cmd/ui/src/views/SAMLConfiguration/SAMLConfiguration.test.tsx

This file was deleted.

Loading

0 comments on commit 9decf72

Please sign in to comment.