Skip to content

Commit

Permalink
[security solution] fix darkMode access
Browse files Browse the repository at this point in the history
  • Loading branch information
pgayvallet committed Dec 22, 2023
1 parent b40cd02 commit 0e36767
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 25 deletions.
1 change: 0 additions & 1 deletion x-pack/plugins/security_solution/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export const ADD_THREAT_INTELLIGENCE_DATA_PATH = `/app/integrations/browse/threa
export const DEFAULT_BYTES_FORMAT = 'format:bytes:defaultPattern' as const;
export const DEFAULT_DATE_FORMAT = 'dateFormat' as const;
export const DEFAULT_DATE_FORMAT_TZ = 'dateFormat:tz' as const;
export const DEFAULT_DARK_MODE = 'theme:darkMode' as const;
export const DEFAULT_INDEX_KEY = 'securitySolution:defaultIndex' as const;
export const DEFAULT_NUMBER_FORMAT = 'format:number:defaultPattern' as const;
export const DEFAULT_DATA_VIEW_ID = 'security-solution' as const;
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/security_solution/public/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import { KibanaErrorBoundary, KibanaErrorBoundaryProvider } from '@kbn/shared-ux
import { NavigationProvider } from '@kbn/security-solution-navigation';
import { UpsellingProvider } from '../common/components/upselling_provider';
import { ManageUserInfo } from '../detections/components/user_info';
import { DEFAULT_DARK_MODE, APP_NAME } from '../../common/constants';
import { APP_NAME } from '../../common/constants';
import { ErrorToastDispatcher } from '../common/components/error_toast_dispatcher';
import { MlCapabilitiesProvider } from '../common/components/ml/permissions/ml_capabilities_provider';
import { GlobalToaster, ManageGlobalToaster } from '../common/components/toasters';
import { KibanaContextProvider, useKibana, useUiSetting$ } from '../common/lib/kibana';
import { KibanaContextProvider, useKibana, useDarkMode } from '../common/lib/kibana';
import type { State } from '../common/store';
import type { StartServices } from '../types';
import { PageRouter } from './routes';
Expand Down Expand Up @@ -57,7 +57,7 @@ const StartAppComponent: FC<StartAppComponent> = ({
upselling,
} = services;

const [darkMode] = useUiSetting$<boolean>(DEFAULT_DARK_MODE);
const darkMode = useDarkMode();

return (
<KibanaErrorBoundaryProvider analytics={analytics}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ import { EuiFlexGroup } from '@elastic/eui';
import React from 'react';
import styled from 'styled-components';

import { DEFAULT_DARK_MODE } from '../../../../common/constants';
import { useUiSetting } from '../../lib/kibana';
import { useDarkMode } from '../../lib/kibana';

export const defaultChartHeight = '100%';
export const defaultChartWidth = '100%';
Expand Down Expand Up @@ -113,7 +112,7 @@ const theme: PartialTheme = {
},
};
export const useThemes = (): { baseTheme: Theme; theme: PartialTheme } => {
const isDarkMode = useUiSetting<boolean>(DEFAULT_DARK_MODE);
const isDarkMode = useDarkMode();
// TODO connect to charts.theme service see src/plugins/charts/public/services/theme/README.md
const baseTheme = isDarkMode ? LEGACY_DARK_THEME : LEGACY_LIGHT_THEME;
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
DEFAULT_APP_REFRESH_INTERVAL,
DEFAULT_APP_TIME_RANGE,
DEFAULT_BYTES_FORMAT,
DEFAULT_DARK_MODE,
DEFAULT_DATE_FORMAT,
DEFAULT_DATE_FORMAT_TZ,
DEFAULT_FROM,
Expand Down Expand Up @@ -69,7 +68,6 @@ const mockUiSettings: Record<string, unknown> = {
[DEFAULT_BYTES_FORMAT]: '0,0.[0]b',
[DEFAULT_DATE_FORMAT_TZ]: 'UTC',
[DEFAULT_DATE_FORMAT]: 'MMM D, YYYY @ HH:mm:ss.SSS',
[DEFAULT_DARK_MODE]: false,
[DEFAULT_RULES_TABLE_REFRESH_SETTING]: {
on: DEFAULT_RULE_REFRESH_INTERVAL_ON,
value: DEFAULT_RULE_REFRESH_INTERVAL_VALUE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
useKibana,
useUiSetting,
useUiSetting$,
useDarkMode,
withKibana,
} from '@kbn/kibana-react-plugin/public';
import type { ApmBase } from '@elastic/apm-rum';
Expand All @@ -23,5 +24,6 @@ export {
useTypedKibana as useKibana,
useUiSetting,
useUiSetting$,
useDarkMode,
withKibana,
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@

import { euiLightVars as lightTheme, euiDarkVars as darkTheme } from '@kbn/ui-theme';

import { DEFAULT_DARK_MODE } from '../../../../common/constants';
import { useUiSetting$ } from '../kibana';
import { useDarkMode } from '../kibana';

export const useEuiTheme = () => {
const [darkMode] = useUiSetting$<boolean>(DEFAULT_DARK_MODE);
const darkMode = useDarkMode();
return darkMode ? darkTheme : lightTheme;
};
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ export const AppRootProvider = memo<{
queryClient: QueryClient;
children: ReactNode | ReactNode[];
}>(({ store, history, coreStart, depsStart: { data }, queryClient, startServices, children }) => {
const { uiSettings } = coreStart;
const isDarkMode = useObservable<boolean>(uiSettings.get$('theme:darkMode'));
const { theme: themeStart } = coreStart;
const theme = useObservable(themeStart.theme$, themeStart.getTheme());
const isDarkMode = theme.darkMode;

return (
<Provider store={store}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
import { euiLightVars as lightTheme, euiDarkVars as darkTheme } from '@kbn/ui-theme';
import React from 'react';

import { DEFAULT_DARK_MODE } from '../../../../../common/constants';
import type { DescriptionList } from '../../../../../common/utility_types';
import { useUiSetting$ } from '../../../../common/lib/kibana';
import { useDarkMode } from '../../../../common/lib/kibana';
import type {
FlowTargetSourceDest,
NetworkDetailsStrategyResponse,
Expand Down Expand Up @@ -79,7 +78,7 @@ export const IpOverview = React.memo<IpOverviewProps>(
}) => {
const capabilities = useMlCapabilities();
const userPermissions = hasMlUserPermissions(capabilities);
const [darkMode] = useUiSetting$<boolean>(DEFAULT_DARK_MODE);
const darkMode = useDarkMode();
const typeData = data[flowTarget];
const column: DescriptionList[] = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ import styled from 'styled-components';
import { useRiskScore } from '../../../entity_analytics/api/hooks/use_risk_score';
import type { HostItem } from '../../../../common/search_strategy';
import { buildHostNamesFilter, RiskScoreEntity } from '../../../../common/search_strategy';
import { DEFAULT_DARK_MODE } from '../../../../common/constants';
import type { DescriptionList } from '../../../../common/utility_types';
import { useUiSetting$ } from '../../../common/lib/kibana';
import { useDarkMode } from '../../../common/lib/kibana';
import { getEmptyTagValue } from '../../../common/components/empty_value';
import {
DefaultFieldRenderer,
Expand Down Expand Up @@ -84,7 +83,7 @@ export const HostOverview = React.memo<HostSummaryProps>(
}) => {
const capabilities = useMlCapabilities();
const userPermissions = hasMlUserPermissions(capabilities);
const [darkMode] = useUiSetting$<boolean>(DEFAULT_DARK_MODE);
const darkMode = useDarkMode();
const filterQuery = useMemo(
() => (hostName ? buildHostNamesFilter([hostName]) : undefined),
[hostName]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ import React, { useCallback, useMemo } from 'react';
import styled from 'styled-components';
import { useRiskScore } from '../../../entity_analytics/api/hooks/use_risk_score';
import { buildUserNamesFilter, RiskScoreEntity } from '../../../../common/search_strategy';
import { DEFAULT_DARK_MODE } from '../../../../common/constants';
import type { DescriptionList } from '../../../../common/utility_types';
import { useUiSetting$ } from '../../../common/lib/kibana';
import { useDarkMode } from '../../../common/lib/kibana';
import { getEmptyTagValue } from '../../../common/components/empty_value';
import { DefaultFieldRenderer } from '../../../timelines/components/field_renderers/field_renderers';
import {
Expand Down Expand Up @@ -82,7 +81,7 @@ export const UserOverview = React.memo<UserSummaryProps>(
}) => {
const capabilities = useMlCapabilities();
const userPermissions = hasMlUserPermissions(capabilities);
const [darkMode] = useUiSetting$<boolean>(DEFAULT_DARK_MODE);
const darkMode = useDarkMode();
const filterQuery = useMemo(
() => (userName ? buildUserNamesFilter([userName]) : undefined),
[userName]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import React, { memo } from 'react';
import styled from 'styled-components';
import { i18n } from '@kbn/i18n';
import { useUiSetting } from '@kbn/kibana-react-plugin/public';
import { useDarkMode } from '@kbn/kibana-react-plugin/public';
import { useSymbolIDs } from './use_symbol_ids';
import { usePaintServerIDs } from './use_paint_server_ids';

Expand Down Expand Up @@ -435,7 +435,7 @@ const SymbolsAndShapes = memo(({ id, isDarkMode }: { id: string; isDarkMode: boo
*/
// eslint-disable-next-line react/display-name
export const SymbolDefinitions = memo(({ id }: { id: string }) => {
const isDarkMode = useUiSetting<boolean>('theme:darkMode');
const isDarkMode = useDarkMode();
return (
<HiddenSVG>
<defs>
Expand Down

0 comments on commit 0e36767

Please sign in to comment.