|
|
@@ -3,27 +3,90 @@ import styled from 'styled-components';
|
|
|
|
|
|
import { Context } from '../../../shared/Context';
|
|
|
import api from '../../../shared/api';
|
|
|
-import { getRegistryIcon } from '../../../shared/common';
|
|
|
+import { getIntegrationIcon } from '../../../shared/common';
|
|
|
+import { ChoiceType } from '../../../shared/types';
|
|
|
|
|
|
import IntegrationList from './IntegrationList';
|
|
|
-import DockerHubForm from './integration-forms/DockerHubForm';
|
|
|
+import IntegrationForm from './integration-form/IntegrationForm';
|
|
|
|
|
|
type PropsType = {
|
|
|
};
|
|
|
|
|
|
type StateType = {
|
|
|
- currentIntegration: null | any
|
|
|
+ currentCategory: ChoiceType | null,
|
|
|
+ currentIntegration: any | null,
|
|
|
+ currentOptions: any[],
|
|
|
};
|
|
|
|
|
|
+const categories = [
|
|
|
+ {
|
|
|
+ value: 'kubernetes',
|
|
|
+ label: 'Kubernetes',
|
|
|
+ buttonText: 'Add a Cluster',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ value: 'registry',
|
|
|
+ label: 'Docker Registry',
|
|
|
+ buttonText: 'Add a Registry',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ value: 'repo',
|
|
|
+ label: 'Git Repository',
|
|
|
+ buttonText: 'Add a Repository',
|
|
|
+ },
|
|
|
+];
|
|
|
+
|
|
|
export default class Integrations extends Component<PropsType, StateType> {
|
|
|
state = {
|
|
|
- currentIntegration: null as null | any,
|
|
|
+ currentCategory: null as any | null,
|
|
|
+ currentIntegration: null as any | null,
|
|
|
+ currentOptions: [] as any[],
|
|
|
+ }
|
|
|
+
|
|
|
+ getIntegrations = (categoryType: string): any[] => {
|
|
|
+ switch (categoryType) {
|
|
|
+ case 'kubernetes':
|
|
|
+ return [
|
|
|
+ {
|
|
|
+ value: 'gke',
|
|
|
+ label: 'Google Kubernetes Engine (GKE)',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ value: 'eks',
|
|
|
+ label: 'Amazon Elastic Kubernetes Service (EKS)',
|
|
|
+ },
|
|
|
+ ];
|
|
|
+ case 'registry':
|
|
|
+ return [
|
|
|
+ {
|
|
|
+ value: 'gcr',
|
|
|
+ label: 'Google Container Registry (GCR)',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ value: 'ecr',
|
|
|
+ label: 'Elastic Container Registry (ECR)',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ value: 'docker-hub',
|
|
|
+ label: 'Docker Hub',
|
|
|
+ },
|
|
|
+ ];
|
|
|
+ default:
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ componentDidUpdate(prevProps: PropsType, prevState: StateType) {
|
|
|
+ if (this.state.currentCategory && this.state.currentCategory !== prevState.currentCategory) {
|
|
|
+ this.setState({ currentOptions: this.getIntegrations(this.state.currentCategory.value) });
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
renderContents = () => {
|
|
|
- let { currentIntegration } = this.state;
|
|
|
+ let { currentCategory, currentIntegration } = this.state;
|
|
|
+
|
|
|
if (currentIntegration) {
|
|
|
- let icon = getRegistryIcon(currentIntegration.name);
|
|
|
+ let icon = getIntegrationIcon(currentIntegration.value);
|
|
|
return (
|
|
|
<div>
|
|
|
<TitleSectionAlt>
|
|
|
@@ -36,7 +99,38 @@ export default class Integrations extends Component<PropsType, StateType> {
|
|
|
</Flex>
|
|
|
</TitleSectionAlt>
|
|
|
|
|
|
- <DockerHubForm />
|
|
|
+ <IntegrationForm integrationName={currentIntegration.value} />
|
|
|
+ <Br />
|
|
|
+ </div>
|
|
|
+ );
|
|
|
+ } else if (currentCategory) {
|
|
|
+ let icon = getIntegrationIcon(currentCategory.value);
|
|
|
+ return (
|
|
|
+ <div>
|
|
|
+ <TitleSectionAlt>
|
|
|
+ <Flex>
|
|
|
+ <i className="material-icons" onClick={() => this.setState({ currentCategory: null })}>
|
|
|
+ keyboard_backspace
|
|
|
+ </i>
|
|
|
+ <Icon src={icon && icon} />
|
|
|
+ <Title>{currentCategory.label}</Title>
|
|
|
+ </Flex>
|
|
|
+
|
|
|
+ <Button
|
|
|
+ onClick={() => this.context.setCurrentModal('IntegrationsModal', {
|
|
|
+ integrations: this.state.currentOptions,
|
|
|
+ setCurrentIntegration: (x: any) => this.setState({ currentIntegration: x })
|
|
|
+ })}
|
|
|
+ >
|
|
|
+ <i className="material-icons">add</i>
|
|
|
+ {currentCategory.buttonText}
|
|
|
+ </Button>
|
|
|
+ </TitleSectionAlt>
|
|
|
+
|
|
|
+ <IntegrationList
|
|
|
+ integrations={this.state.currentOptions}
|
|
|
+ setCurrent={(x: any) => this.setState({ currentIntegration: x })}
|
|
|
+ />
|
|
|
</div>
|
|
|
);
|
|
|
}
|
|
|
@@ -44,14 +138,12 @@ export default class Integrations extends Component<PropsType, StateType> {
|
|
|
<div>
|
|
|
<TitleSection>
|
|
|
<Title>Integrations</Title>
|
|
|
- <Button onClick={() => this.context.setCurrentModal('IntegrationsModal', {})}>
|
|
|
- <i className="material-icons">add</i>
|
|
|
- Add Integration
|
|
|
- </Button>
|
|
|
</TitleSection>
|
|
|
|
|
|
<IntegrationList
|
|
|
- setCurrentIntegration={(x: any) => this.setState({ currentIntegration: x })}
|
|
|
+ integrations={categories}
|
|
|
+ setCurrent={(x: any) => this.setState({ currentCategory: x })}
|
|
|
+ isCategory={true}
|
|
|
/>
|
|
|
</div>
|
|
|
);
|
|
|
@@ -68,6 +160,11 @@ export default class Integrations extends Component<PropsType, StateType> {
|
|
|
|
|
|
Integrations.contextType = Context;
|
|
|
|
|
|
+const Br = styled.div`
|
|
|
+ width: 100%;
|
|
|
+ height: 150px;
|
|
|
+`;
|
|
|
+
|
|
|
const Icon = styled.img`
|
|
|
width: 27px;
|
|
|
margin-right: 12px;
|