-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: Clint Andrew Hall <[email protected]>
- Loading branch information
1 parent
dd7af2a
commit 0e3943d
Showing
50 changed files
with
1,294 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
|
||
export const UNIFIED_TOOLBAR = 'labs:presentation:unifiedToolbar'; | ||
|
||
export const projectIDs = [UNIFIED_TOOLBAR] as const; | ||
export const environmentNames = ['kibana', 'browser', 'session'] as const; | ||
export const solutionNames = ['canvas', 'dashboard', 'presentation'] as const; | ||
|
||
/** | ||
* This is a list of active Labs Projects for the Presentation Team. It is the "source of truth" for all projects | ||
* provided to users of our solutions in Kibana. | ||
*/ | ||
export const projects: { [ID in ProjectID]: ProjectConfig & { id: ID } } = { | ||
[UNIFIED_TOOLBAR]: { | ||
id: UNIFIED_TOOLBAR, | ||
isActive: false, | ||
environments: ['kibana', 'browser', 'session'], | ||
name: i18n.translate('presentationUtil.labs.enableUnifiedToolbarProjectName', { | ||
defaultMessage: 'Unified Toolbar', | ||
}), | ||
description: i18n.translate('presentationUtil.labs.enableUnifiedToolbarProjectDescription', { | ||
defaultMessage: 'Enable the new unified toolbar design for Presentation solutions', | ||
}), | ||
solutions: ['dashboard', 'canvas'], | ||
}, | ||
}; | ||
|
||
export type ProjectID = typeof projectIDs[number]; | ||
export type EnvironmentName = typeof environmentNames[number]; | ||
export type SolutionName = typeof solutionNames[number]; | ||
|
||
export type EnvironmentStatus = { | ||
[env in EnvironmentName]?: boolean; | ||
}; | ||
|
||
export type ProjectStatus = { | ||
defaultValue: boolean; | ||
isEnabled: boolean; | ||
isOverride: boolean; | ||
} & EnvironmentStatus; | ||
|
||
export interface ProjectConfig { | ||
id: ProjectID; | ||
name: string; | ||
isActive: boolean; | ||
environments: EnvironmentName[]; | ||
description: string; | ||
solutions: SolutionName[]; | ||
} | ||
|
||
export type Project = ProjectConfig & { status: ProjectStatus }; | ||
|
||
export const getProjectIDs = () => projectIDs; | ||
|
||
export const isProjectEnabledByStatus = (active: boolean, status: EnvironmentStatus): boolean => { | ||
// If the project is enabled by default, then any false flag will flip the switch, and vice-versa. | ||
return active | ||
? Object.values(status).every((value) => value === true) | ||
: Object.values(status).some((value) => value === true); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/plugins/presentation_util/public/components/labs/environment_switch.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiSwitch, | ||
EuiIconTip, | ||
EuiSpacer, | ||
EuiScreenReaderOnly, | ||
} from '@elastic/eui'; | ||
|
||
import { EnvironmentName } from '../../../common/labs'; | ||
import { LabsStrings } from '../../i18n'; | ||
|
||
const { Switch: strings } = LabsStrings.Components; | ||
|
||
const switchText: { [env in EnvironmentName]: { name: string; help: string } } = { | ||
kibana: strings.getKibanaSwitchText(), | ||
browser: strings.getBrowserSwitchText(), | ||
session: strings.getSessionSwitchText(), | ||
}; | ||
|
||
export interface Props { | ||
env: EnvironmentName; | ||
isChecked: boolean; | ||
onChange: (checked: boolean) => void; | ||
name: string; | ||
} | ||
|
||
export const EnvironmentSwitch = ({ env, isChecked, onChange, name }: Props) => ( | ||
<EuiFlexItem grow={false} style={{ marginBottom: '.25rem' }}> | ||
<EuiFlexGroup gutterSize="xs" alignItems="flexEnd" responsive={false}> | ||
<EuiFlexItem grow={false}> | ||
<EuiSwitch | ||
checked={isChecked} | ||
style={{ marginTop: 1 }} | ||
label={ | ||
<EuiFlexItem grow={false}> | ||
<EuiScreenReaderOnly> | ||
<span>{name} - </span> | ||
</EuiScreenReaderOnly> | ||
{switchText[env].name} | ||
</EuiFlexItem> | ||
} | ||
onChange={(e) => onChange(e.target.checked)} | ||
compressed | ||
/> | ||
</EuiFlexItem> | ||
<EuiFlexItem style={{ textAlign: 'right' }}> | ||
<EuiIconTip content={switchText[env].help} position="left" /> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
<EuiSpacer size="xs" /> | ||
</EuiFlexItem> | ||
); |
32 changes: 32 additions & 0 deletions
32
src/plugins/presentation_util/public/components/labs/labs.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { action } from '@storybook/addon-actions'; | ||
|
||
import { LabsBeakerButton } from './labs_beaker_button'; | ||
import { LabsFlyout } from './labs_flyout'; | ||
|
||
export default { | ||
title: 'Labs/Flyout', | ||
description: | ||
'A set of components used for providing Labs controls and projects in another solution.', | ||
argTypes: {}, | ||
}; | ||
|
||
export function BeakerButton() { | ||
return <LabsBeakerButton />; | ||
} | ||
|
||
export function Flyout() { | ||
return <LabsFlyout onClose={action('onClose')} />; | ||
} | ||
|
||
export function EmptyFlyout() { | ||
return <LabsFlyout onClose={action('onClose')} solutions={[]} />; | ||
} |
48 changes: 48 additions & 0 deletions
48
src/plugins/presentation_util/public/components/labs/labs_beaker_button.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import React, { useState } from 'react'; | ||
import { EuiButton, EuiIcon, EuiNotificationBadge, EuiButtonProps } from '@elastic/eui'; | ||
|
||
import { pluginServices } from '../../services'; | ||
import { LabsFlyout, Props as FlyoutProps } from './labs_flyout'; | ||
|
||
export type Props = EuiButtonProps & Pick<FlyoutProps, 'solutions'>; | ||
|
||
export const LabsBeakerButton = ({ solutions, ...props }: Props) => { | ||
const { labs: labsService } = pluginServices.getHooks(); | ||
const { getProjects } = labsService.useService(); | ||
const [isOpen, setIsOpen] = useState(false); | ||
|
||
const projects = getProjects(); | ||
|
||
const [overrideCount, onEnabledCountChange] = useState( | ||
Object.values(projects).filter((project) => project.status.isOverride).length | ||
); | ||
|
||
const onButtonClick = () => setIsOpen((open) => !open); | ||
const onClose = () => setIsOpen(false); | ||
|
||
return ( | ||
<> | ||
<EuiButton {...props} onClick={onButtonClick} minWidth={0}> | ||
<EuiIcon type="beaker" /> | ||
{overrideCount > 0 ? ( | ||
<EuiNotificationBadge color="subdued" style={{ marginLeft: 2 }}> | ||
{overrideCount} | ||
</EuiNotificationBadge> | ||
) : null} | ||
</EuiButton> | ||
{isOpen ? <LabsFlyout {...{ onClose, solutions, onEnabledCountChange }} /> : null} | ||
</> | ||
); | ||
}; | ||
|
||
// required for dynamic import using React.lazy() | ||
// eslint-disable-next-line import/no-default-export | ||
export default LabsBeakerButton; |
Oops, something went wrong.