-
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.
- Loading branch information
Showing
8 changed files
with
277 additions
and
29 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
79 changes: 79 additions & 0 deletions
79
x-pack/legacy/plugins/epm/public/screens/add_data_source/add_data_source_steps.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,79 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
import React, { useState, Fragment, useCallback } from 'react'; | ||
import styled from 'styled-components'; | ||
import { EuiPanel, EuiSteps, EuiButton, EuiHorizontalRule } from '@elastic/eui'; | ||
import { Redirect } from 'react-router-dom'; | ||
import { StepOneTemplate } from './step_one'; | ||
import { installDatasource } from '../../data'; | ||
import { useCore, useLinks } from '../../hooks'; | ||
|
||
const StyledSteps = styled.div` | ||
.euiStep__titleWrapper { | ||
border-bottom: 1px solid ${props => props.theme.eui.euiBorderColor}; | ||
padding-bottom: ${props => props.theme.eui.paddingSizes.l}; | ||
} | ||
.euiStep__content { | ||
padding-bottom: 0; | ||
} | ||
`; | ||
interface AddDataSourceStepsProps { | ||
pkgName: string; | ||
pkgTitle: string; | ||
pkgVersion: string; | ||
} | ||
const FormNav = styled.div` | ||
text-align: right; | ||
`; | ||
export const AddDataSourceSteps = (props: AddDataSourceStepsProps) => { | ||
const [addDataSourceSuccess, setAddDataSourceSuccess] = useState<boolean>(false); | ||
const { notifications } = useCore(); | ||
const { toDetailViewRelative } = useLinks(); | ||
const { pkgName, pkgTitle, pkgVersion } = props; | ||
const handleRequestInstallDatasource = useCallback(async () => { | ||
try { | ||
await installDatasource(`${pkgName}-${pkgVersion}`); | ||
setAddDataSourceSuccess(true); | ||
notifications.toasts.addSuccess({ | ||
title: `Added ${pkgTitle} data source`, | ||
}); | ||
return; | ||
} catch (err) { | ||
notifications.toasts.addWarning({ | ||
title: `Failed to add data source to ${pkgTitle}`, | ||
iconType: 'alert', | ||
}); | ||
} | ||
}, [notifications.toasts, pkgName, pkgTitle, pkgVersion]); | ||
const stepOne = [ | ||
{ | ||
title: 'Define your data source', | ||
children: <StepOneTemplate />, | ||
}, | ||
]; | ||
|
||
return ( | ||
<Fragment> | ||
{addDataSourceSuccess ? ( | ||
<Redirect | ||
to={toDetailViewRelative({ name: pkgName, version: pkgVersion, panel: 'data-sources' })} | ||
/> | ||
) : ( | ||
<EuiPanel> | ||
<StyledSteps> | ||
<EuiSteps steps={stepOne} /> | ||
</StyledSteps> | ||
<FormNav> | ||
<EuiHorizontalRule margin="xl" /> | ||
<EuiButton fill onClick={handleRequestInstallDatasource}> | ||
Continue | ||
</EuiButton> | ||
</FormNav> | ||
</EuiPanel> | ||
)} | ||
</Fragment> | ||
); | ||
}; |
84 changes: 84 additions & 0 deletions
84
x-pack/legacy/plugins/epm/public/screens/add_data_source/index.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,84 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
import React, { useState, useEffect } from 'react'; | ||
import { ICON_TYPES, EuiPageHeader, EuiTitle, EuiFlexGroup, EuiIcon, EuiPanel } from '@elastic/eui'; | ||
import styled from 'styled-components'; | ||
import { NavButtonBack } from '../../components/nav_button_back'; | ||
import { useLinks } from '../../hooks'; | ||
import { PackageInfo } from '../../../common/types'; | ||
import { getPackageInfoByKey } from '../../data'; | ||
import { AddDataSourceSteps } from './add_data_source_steps'; | ||
|
||
export interface AddDataSourceProps { | ||
pkgkey: string; | ||
} | ||
|
||
// TODO: change to percentages? | ||
const SIDEBAR_WIDTH = '168px'; | ||
|
||
const PageContainer = styled.div` | ||
margin: 0 auto; | ||
min-width: 1200px; | ||
`; | ||
const PageBody = styled.div` | ||
max-width: 772px; | ||
`; | ||
const NavButtonBackWrapper = styled.div` | ||
padding: ${props => props.theme.eui.paddingSizes.xl} 0 ${props => props.theme.eui.paddingSizes.m} | ||
0; | ||
`; | ||
const SideBar = styled.div` | ||
margin-right: ${props => props.theme.eui.paddingSizes.xl}; | ||
max-width: ${SIDEBAR_WIDTH}; | ||
`; | ||
const IconPanel = styled(EuiPanel)` | ||
padding: ${props => props.theme.eui.paddingSizes.xl} !important; | ||
text-align: center; | ||
width: ${SIDEBAR_WIDTH}; | ||
height: ${SIDEBAR_WIDTH}; | ||
`; | ||
export function AddDataSource({ pkgkey }: AddDataSourceProps) { | ||
const [info, setInfo] = useState<PackageInfo | null>(null); | ||
const { toDetailView } = useLinks(); | ||
|
||
useEffect(() => { | ||
getPackageInfoByKey(pkgkey).then(response => { | ||
setInfo({ ...response }); | ||
}); | ||
}, [pkgkey]); | ||
|
||
// don't have designs for loading/empty states | ||
if (!info) return null; | ||
|
||
const { version, name, title } = info; | ||
const iconType = ICON_TYPES.find(key => key.toLowerCase() === `logo${name}`); | ||
|
||
return ( | ||
<PageContainer> | ||
<NavButtonBackWrapper> | ||
<NavButtonBack | ||
href={toDetailView({ name, panel: 'data-sources', version })} | ||
text="Cancel" | ||
/> | ||
</NavButtonBackWrapper> | ||
<EuiFlexGroup gutterSize="none"> | ||
<SideBar> | ||
<IconPanel> | ||
{iconType ? <EuiIcon width="102" height="102" type={iconType} size="original" /> : null} | ||
</IconPanel> | ||
</SideBar> | ||
<PageBody> | ||
<EuiPageHeader> | ||
<EuiTitle size="l"> | ||
<h1>Add {title} data source</h1> | ||
</EuiTitle> | ||
</EuiPageHeader> | ||
<AddDataSourceSteps pkgName={name} pkgVersion={version} pkgTitle={title} /> | ||
</PageBody> | ||
</EuiFlexGroup> | ||
</PageContainer> | ||
); | ||
} |
Oops, something went wrong.