|
@@ -4,7 +4,7 @@ import yaml from 'js-yaml';
|
|
|
import close from '../../../../assets/close.png';
|
|
import close from '../../../../assets/close.png';
|
|
|
import _ from 'lodash';
|
|
import _ from 'lodash';
|
|
|
|
|
|
|
|
-import { ResourceType, ChartType, StorageType, ChoiceType } from '../../../../shared/types';
|
|
|
|
|
|
|
+import { ResourceType, ChartType, StorageType, Cluster } from '../../../../shared/types';
|
|
|
import { Context } from '../../../../shared/Context';
|
|
import { Context } from '../../../../shared/Context';
|
|
|
import api from '../../../../shared/api';
|
|
import api from '../../../../shared/api';
|
|
|
|
|
|
|
@@ -19,18 +19,20 @@ import SettingsSection from './SettingsSection';
|
|
|
import { NavLink } from 'react-router-dom';
|
|
import { NavLink } from 'react-router-dom';
|
|
|
|
|
|
|
|
type PropsType = {
|
|
type PropsType = {
|
|
|
|
|
+ namespace: string,
|
|
|
currentChart: ChartType,
|
|
currentChart: ChartType,
|
|
|
|
|
+ currentCluster: Cluster,
|
|
|
setCurrentChart: (x: ChartType | null) => void,
|
|
setCurrentChart: (x: ChartType | null) => void,
|
|
|
- refreshChart: () => void,
|
|
|
|
|
setSidebar: (x: boolean) => void,
|
|
setSidebar: (x: boolean) => void,
|
|
|
setCurrentView: (x: string) => void,
|
|
setCurrentView: (x: string) => void,
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
type StateType = {
|
|
type StateType = {
|
|
|
|
|
+ loading: boolean,
|
|
|
showRevisions: boolean,
|
|
showRevisions: boolean,
|
|
|
components: ResourceType[],
|
|
components: ResourceType[],
|
|
|
podSelectors: string[]
|
|
podSelectors: string[]
|
|
|
- revisionPreview: ChartType | null,
|
|
|
|
|
|
|
+ isPreview: boolean,
|
|
|
devOpsMode: boolean,
|
|
devOpsMode: boolean,
|
|
|
tabOptions: any[],
|
|
tabOptions: any[],
|
|
|
tabContents: any,
|
|
tabContents: any,
|
|
@@ -39,20 +41,13 @@ type StateType = {
|
|
|
forceRefreshRevisions: boolean, // Update revisions after upgrading values
|
|
forceRefreshRevisions: boolean, // Update revisions after upgrading values
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-/*
|
|
|
|
|
- TODO: consolidate revisionPreview and currentChart (currentChart can just be the initial state)
|
|
|
|
|
- In general, tab management for ExpandedChart should be refactored. Cases to handle:
|
|
|
|
|
- - Hiding logs, deploy, and settings tabs when previewing old charts
|
|
|
|
|
- - Toggling additional DevOps tabs
|
|
|
|
|
- - Handling the currently selected tab becoming hidden (for both preview and DevOps)
|
|
|
|
|
- As part of consolidating currentChart and revisionPreview, can add an isPreview bool.
|
|
|
|
|
-*/
|
|
|
|
|
export default class ExpandedChart extends Component<PropsType, StateType> {
|
|
export default class ExpandedChart extends Component<PropsType, StateType> {
|
|
|
state = {
|
|
state = {
|
|
|
|
|
+ loading: true,
|
|
|
showRevisions: false,
|
|
showRevisions: false,
|
|
|
components: [] as ResourceType[],
|
|
components: [] as ResourceType[],
|
|
|
podSelectors: [] as string[],
|
|
podSelectors: [] as string[],
|
|
|
- revisionPreview: null as (ChartType | null),
|
|
|
|
|
|
|
+ isPreview: false,
|
|
|
devOpsMode: localStorage.getItem('devOpsMode') === 'true',
|
|
devOpsMode: localStorage.getItem('devOpsMode') === 'true',
|
|
|
tabOptions: [] as any[],
|
|
tabOptions: [] as any[],
|
|
|
tabContents: [] as any,
|
|
tabContents: [] as any,
|
|
@@ -61,6 +56,33 @@ export default class ExpandedChart extends Component<PropsType, StateType> {
|
|
|
forceRefreshRevisions: false,
|
|
forceRefreshRevisions: false,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // Retrieve full chart data (includes form and values)
|
|
|
|
|
+ getChartData = (chart: ChartType) => {
|
|
|
|
|
+ let { currentProject } = this.context;
|
|
|
|
|
+ let { currentCluster, setCurrentChart } = this.props;
|
|
|
|
|
+ this.setState({ loading: true })
|
|
|
|
|
+ api.getChart('<token>', {
|
|
|
|
|
+ namespace: this.props.namespace,
|
|
|
|
|
+ cluster_id: currentCluster.id,
|
|
|
|
|
+ storage: StorageType.Secret
|
|
|
|
|
+ }, {
|
|
|
|
|
+ name: chart.name,
|
|
|
|
|
+ revision: chart.version,
|
|
|
|
|
+ id: currentProject.id
|
|
|
|
|
+ }, (err: any, res: any) => {
|
|
|
|
|
+ if (err) {
|
|
|
|
|
+ console.log(err);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ setCurrentChart(res.data);
|
|
|
|
|
+ this.setState({ loading: false });
|
|
|
|
|
+
|
|
|
|
|
+ // After retrieving full chart data, update tabs and resources
|
|
|
|
|
+ this.updateTabs();
|
|
|
|
|
+ this.updateResources();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
updateResources = () => {
|
|
updateResources = () => {
|
|
|
let { currentCluster, currentProject } = this.context;
|
|
let { currentCluster, currentProject } = this.context;
|
|
|
let { currentChart } = this.props;
|
|
let { currentChart } = this.props;
|
|
@@ -82,42 +104,21 @@ export default class ExpandedChart extends Component<PropsType, StateType> {
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ refreshChart = () => this.getChartData(this.props.currentChart);
|
|
|
|
|
+
|
|
|
componentDidMount() {
|
|
componentDidMount() {
|
|
|
- this.updateTabs();
|
|
|
|
|
- this.updateResources();
|
|
|
|
|
|
|
+ this.getChartData(this.props.currentChart);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate(prevProps: PropsType) {
|
|
componentDidUpdate(prevProps: PropsType) {
|
|
|
|
|
+ /*
|
|
|
if (this.props.currentChart !== prevProps.currentChart) {
|
|
if (this.props.currentChart !== prevProps.currentChart) {
|
|
|
this.updateResources();
|
|
this.updateResources();
|
|
|
}
|
|
}
|
|
|
|
|
+ */
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- getFormData = (): any => {
|
|
|
|
|
- return new Promise(resolve => {
|
|
|
|
|
- let { files } = this.props.currentChart.chart;
|
|
|
|
|
- for (let file of files) {
|
|
|
|
|
- if (file.name === 'form.yaml') {
|
|
|
|
|
- let chartName = this.props.currentChart.chart.metadata.name;
|
|
|
|
|
- api.getTemplateInfo('<token>', {}, {
|
|
|
|
|
- name: chartName.toLowerCase().trim(),
|
|
|
|
|
- version: 'latest',
|
|
|
|
|
- }, (err: any, res: any) => {
|
|
|
|
|
- if (err) {
|
|
|
|
|
- console.log(err);
|
|
|
|
|
- resolve(null);
|
|
|
|
|
- } else {
|
|
|
|
|
- console.log(res.data)
|
|
|
|
|
- let { form } = res.data;
|
|
|
|
|
- resolve(form);
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
- };
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- upgradeValues = (rawValues: any) => {
|
|
|
|
|
|
|
+ onSubmit = (rawValues: any) => {
|
|
|
let { currentProject, currentCluster, setCurrentError } = this.context;
|
|
let { currentProject, currentCluster, setCurrentError } = this.context;
|
|
|
|
|
|
|
|
// Convert dotted keys to nested objects
|
|
// Convert dotted keys to nested objects
|
|
@@ -130,7 +131,7 @@ export default class ExpandedChart extends Component<PropsType, StateType> {
|
|
|
let valuesYaml = yaml.dump({ ...(this.props.currentChart.config as Object), ...values });
|
|
let valuesYaml = yaml.dump({ ...(this.props.currentChart.config as Object), ...values });
|
|
|
|
|
|
|
|
this.setState({ saveValuesStatus: 'loading' });
|
|
this.setState({ saveValuesStatus: 'loading' });
|
|
|
- this.props.refreshChart();
|
|
|
|
|
|
|
+ this.refreshChart();
|
|
|
api.upgradeChartValues('<token>', {
|
|
api.upgradeChartValues('<token>', {
|
|
|
namespace: this.props.currentChart.namespace,
|
|
namespace: this.props.currentChart.namespace,
|
|
|
storage: StorageType.Secret,
|
|
storage: StorageType.Secret,
|
|
@@ -141,8 +142,8 @@ export default class ExpandedChart extends Component<PropsType, StateType> {
|
|
|
cluster_id: currentCluster.id,
|
|
cluster_id: currentCluster.id,
|
|
|
}, (err: any, res: any) => {
|
|
}, (err: any, res: any) => {
|
|
|
if (err) {
|
|
if (err) {
|
|
|
- setCurrentError(err);
|
|
|
|
|
this.setState({ saveValuesStatus: 'error' });
|
|
this.setState({ saveValuesStatus: 'error' });
|
|
|
|
|
+ console.log(err)
|
|
|
} else {
|
|
} else {
|
|
|
this.setState({
|
|
this.setState({
|
|
|
saveValuesStatus: 'successful',
|
|
saveValuesStatus: 'successful',
|
|
@@ -160,11 +161,11 @@ export default class ExpandedChart extends Component<PropsType, StateType> {
|
|
|
showRevisions,
|
|
showRevisions,
|
|
|
saveValuesStatus,
|
|
saveValuesStatus,
|
|
|
tabOptions,
|
|
tabOptions,
|
|
|
- revisionPreview,
|
|
|
|
|
|
|
+ isPreview,
|
|
|
} = this.state;
|
|
} = this.state;
|
|
|
- let { currentChart, refreshChart, setSidebar, setCurrentView } = this.props;
|
|
|
|
|
- let chart = revisionPreview || currentChart;
|
|
|
|
|
-
|
|
|
|
|
|
|
+ let { currentChart, setSidebar, setCurrentView } = this.props;
|
|
|
|
|
+ let chart = currentChart;
|
|
|
|
|
+
|
|
|
switch (currentTab) {
|
|
switch (currentTab) {
|
|
|
case 'status':
|
|
case 'status':
|
|
|
return (
|
|
return (
|
|
@@ -178,7 +179,7 @@ export default class ExpandedChart extends Component<PropsType, StateType> {
|
|
|
return (
|
|
return (
|
|
|
<SettingsSection
|
|
<SettingsSection
|
|
|
currentChart={chart}
|
|
currentChart={chart}
|
|
|
- refreshChart={refreshChart}
|
|
|
|
|
|
|
+ refreshChart={this.refreshChart}
|
|
|
setCurrentView={setCurrentView}
|
|
setCurrentView={setCurrentView}
|
|
|
/>
|
|
/>
|
|
|
);
|
|
);
|
|
@@ -207,7 +208,7 @@ export default class ExpandedChart extends Component<PropsType, StateType> {
|
|
|
return (
|
|
return (
|
|
|
<ValuesYaml
|
|
<ValuesYaml
|
|
|
currentChart={chart}
|
|
currentChart={chart}
|
|
|
- refreshChart={refreshChart}
|
|
|
|
|
|
|
+ refreshChart={this.refreshChart}
|
|
|
/>
|
|
/>
|
|
|
);
|
|
);
|
|
|
default:
|
|
default:
|
|
@@ -220,10 +221,9 @@ export default class ExpandedChart extends Component<PropsType, StateType> {
|
|
|
return (
|
|
return (
|
|
|
<ValuesFormWrapper key={i}>
|
|
<ValuesFormWrapper key={i}>
|
|
|
<ValuesForm
|
|
<ValuesForm
|
|
|
- sections={tab.sections}
|
|
|
|
|
- onSubmit={this.upgradeValues}
|
|
|
|
|
|
|
+ sections={tab.sections}
|
|
|
|
|
+ onSubmit={this.onSubmit}
|
|
|
saveValuesStatus={saveValuesStatus}
|
|
saveValuesStatus={saveValuesStatus}
|
|
|
- config={chart.config}
|
|
|
|
|
/>
|
|
/>
|
|
|
</ValuesFormWrapper>
|
|
</ValuesFormWrapper>
|
|
|
);
|
|
);
|
|
@@ -233,12 +233,12 @@ export default class ExpandedChart extends Component<PropsType, StateType> {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- async updateTabs() {
|
|
|
|
|
- let formData = await this.getFormData();
|
|
|
|
|
|
|
+ updateTabs() {
|
|
|
|
|
+ let formData = this.props.currentChart.form;
|
|
|
let tabOptions = [] as any[];
|
|
let tabOptions = [] as any[];
|
|
|
|
|
|
|
|
// Generate form tabs if form.yaml exists
|
|
// Generate form tabs if form.yaml exists
|
|
|
- if (formData && formData.tabs) {
|
|
|
|
|
|
|
+ if (formData) {
|
|
|
formData.tabs.map((tab: any, i: number) => {
|
|
formData.tabs.map((tab: any, i: number) => {
|
|
|
tabOptions.push({ value: '@' + tab.name, label: tab.label, sections: tab.sections });
|
|
tabOptions.push({ value: '@' + tab.name, label: tab.label, sections: tab.sections });
|
|
|
});
|
|
});
|
|
@@ -260,37 +260,17 @@ export default class ExpandedChart extends Component<PropsType, StateType> {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Filter tabs if previewing an old revision
|
|
// Filter tabs if previewing an old revision
|
|
|
- if (this.state.revisionPreview) {
|
|
|
|
|
|
|
+ if (this.state.isPreview) {
|
|
|
let liveTabs = ['status', 'settings', 'deploy'];
|
|
let liveTabs = ['status', 'settings', 'deploy'];
|
|
|
tabOptions = tabOptions.filter((tab: any) => !liveTabs.includes(tab.value));
|
|
tabOptions = tabOptions.filter((tab: any) => !liveTabs.includes(tab.value));
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
this.setState({ tabOptions });
|
|
this.setState({ tabOptions });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- setRevisionPreview = (oldChart: ChartType) => {
|
|
|
|
|
- let { currentCluster, currentProject } = this.context;
|
|
|
|
|
- this.setState({ revisionPreview: oldChart }, () => this.updateTabs());
|
|
|
|
|
-
|
|
|
|
|
- if (oldChart) {
|
|
|
|
|
- api.getChartComponents('<token>', {
|
|
|
|
|
- namespace: oldChart.namespace,
|
|
|
|
|
- cluster_id: currentCluster.id,
|
|
|
|
|
- storage: StorageType.Secret
|
|
|
|
|
- }, {
|
|
|
|
|
- id: currentProject.id,
|
|
|
|
|
- name: oldChart.name,
|
|
|
|
|
- revision: oldChart.version
|
|
|
|
|
- }, (err: any, res: any) => {
|
|
|
|
|
- if (err) {
|
|
|
|
|
- console.log(err)
|
|
|
|
|
- } else {
|
|
|
|
|
- this.setState({ components: res.data.Objects, podSelectors: res.data.PodSelectors });
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- } else {
|
|
|
|
|
- this.updateResources();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ setRevision = (chart: ChartType, isCurrent?: boolean) => {
|
|
|
|
|
+ this.setState({ isPreview: !isCurrent });
|
|
|
|
|
+ this.getChartData(chart);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// TODO: consolidate with pop + push in refreshTabs
|
|
// TODO: consolidate with pop + push in refreshTabs
|
|
@@ -326,8 +306,8 @@ export default class ExpandedChart extends Component<PropsType, StateType> {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
render() {
|
|
|
- let { currentChart, setCurrentChart, refreshChart } = this.props;
|
|
|
|
|
- let chart = this.state.revisionPreview || currentChart;
|
|
|
|
|
|
|
+ let { currentChart, setCurrentChart } = this.props;
|
|
|
|
|
+ let chart = currentChart;
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
<div>
|
|
<div>
|
|
@@ -362,8 +342,8 @@ export default class ExpandedChart extends Component<PropsType, StateType> {
|
|
|
showRevisions={this.state.showRevisions}
|
|
showRevisions={this.state.showRevisions}
|
|
|
toggleShowRevisions={() => this.setState({ showRevisions: !this.state.showRevisions })}
|
|
toggleShowRevisions={() => this.setState({ showRevisions: !this.state.showRevisions })}
|
|
|
chart={chart}
|
|
chart={chart}
|
|
|
- refreshChart={refreshChart}
|
|
|
|
|
- setRevisionPreview={this.setRevisionPreview}
|
|
|
|
|
|
|
+ refreshChart={this.refreshChart}
|
|
|
|
|
+ setRevision={this.setRevision}
|
|
|
forceRefreshRevisions={this.state.forceRefreshRevisions}
|
|
forceRefreshRevisions={this.state.forceRefreshRevisions}
|
|
|
refreshRevisionsOff={() => this.setState({ forceRefreshRevisions: false })}
|
|
refreshRevisionsOff={() => this.setState({ forceRefreshRevisions: false })}
|
|
|
/>
|
|
/>
|
|
@@ -373,7 +353,7 @@ export default class ExpandedChart extends Component<PropsType, StateType> {
|
|
|
currentTab={this.state.currentTab}
|
|
currentTab={this.state.currentTab}
|
|
|
setCurrentTab={(x: string) => this.setState({ currentTab: x })}
|
|
setCurrentTab={(x: string) => this.setState({ currentTab: x })}
|
|
|
options={this.state.tabOptions}
|
|
options={this.state.tabOptions}
|
|
|
- color={this.state.revisionPreview ? '#f5cb42' : null}
|
|
|
|
|
|
|
+ color={this.state.isPreview ? '#f5cb42' : null}
|
|
|
addendum={
|
|
addendum={
|
|
|
<TabButton onClick={this.toggleDevOpsMode} devOpsMode={this.state.devOpsMode}>
|
|
<TabButton onClick={this.toggleDevOpsMode} devOpsMode={this.state.devOpsMode}>
|
|
|
<i className="material-icons">offline_bolt</i> DevOps Mode
|
|
<i className="material-icons">offline_bolt</i> DevOps Mode
|