Skip to content

Commit

Permalink
fix(k8s): Fix deploy manifest (spinnaker#6833)
Browse files Browse the repository at this point in the history
* fix(k8s): Artifacts in deploy manifest were nested too deep
* chore(react): Apply promise-setting-react-state pattern
  • Loading branch information
jkschneider authored Apr 11, 2019
1 parent ba895f1 commit 5640431
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from 'react';
import { module } from 'angular';
import Select from 'react-select';
import { react2angular } from 'react2angular';
import { Observable, Subject } from 'rxjs';

import { IArtifact, IExpectedArtifact, IPipeline, IStage } from 'core/domain';
import { ArtifactIcon, ExpectedArtifactService } from 'core/artifact';
Expand Down Expand Up @@ -38,6 +39,8 @@ export class StageArtifactSelector extends React.Component<IStageArtifactSelecto
id: DEFINE_NEW_ARTIFACT,
};

private destroy$ = new Subject();

constructor(props: IStageArtifactSelectorProps) {
super(props);

Expand All @@ -46,17 +49,23 @@ export class StageArtifactSelector extends React.Component<IStageArtifactSelecto
};
}

public componentWillUnmount(): void {
this.destroy$.next();
}

public componentDidMount(): void {
const excludedPatterns = this.props.excludedArtifactTypePatterns;
AccountService.getArtifactAccounts().then(artifactAccounts => {
this.setState({
artifactAccounts: excludedPatterns
? artifactAccounts.filter(
account => !account.types.some(typ => excludedPatterns.some(typPattern => typPattern.test(typ))),
)
: artifactAccounts,
Observable.fromPromise(AccountService.getArtifactAccounts())
.takeUntil(this.destroy$)
.subscribe(artifactAccounts => {
this.setState({
artifactAccounts: excludedPatterns
? artifactAccounts.filter(
account => !account.types.some(typ => excludedPatterns.some(typPattern => typPattern.test(typ))),
)
: artifactAccounts,
});
});
});
}

private renderArtifact = (value: IExpectedArtifact) => {
Expand Down Expand Up @@ -123,7 +132,7 @@ export class StageArtifactSelector extends React.Component<IStageArtifactSelecto
return (
<>
<div className="sp-margin-m-bottom">{renderLabel ? renderLabel(select) : select}</div>
{artifact && (
{!!artifact && (
<ArtifactEditor
pipeline={pipeline}
artifact={artifact}
Expand Down
16 changes: 12 additions & 4 deletions app/scripts/modules/core/src/widgets/spelText/SpelText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { SpelAutocompleteService } from './SpelAutocompleteService';
import { ExecutionService } from '../../pipeline/service/execution.service';
import { StateService } from '@uirouter/core';
import { IPipeline } from '../../domain';
import { Observable, Subject } from 'rxjs';

export interface ISpelTextProps {
placeholder: string;
Expand All @@ -25,7 +26,8 @@ export interface ISpelTextState {

export class SpelText extends React.Component<ISpelTextProps, ISpelTextState> {
private autocompleteService: SpelAutocompleteService;
private spelInputRef: any;
private readonly spelInputRef: any;
private destroy$ = new Subject();

constructor(props: ISpelTextProps) {
super(props);
Expand All @@ -34,12 +36,18 @@ export class SpelText extends React.Component<ISpelTextProps, ISpelTextState> {
$q,
new ExecutionService($http, $q, {} as StateService, $timeout),
);
this.autocompleteService.addPipelineInfo(this.props.pipeline).then(textcompleteConfig => {
this.setState({ textcompleteConfig: textcompleteConfig });
});
Observable.fromPromise(this.autocompleteService.addPipelineInfo(this.props.pipeline))
.takeUntil(this.destroy$)
.subscribe(textcompleteConfig => {
this.setState({ textcompleteConfig: textcompleteConfig });
});
this.spelInputRef = React.createRef();
}

public componentWillUnmount(): void {
this.destroy$.next();
}

public componentDidMount(): void {
this.renderSuggestions();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class ManifestBindArtifactsSelector extends React.Component<IManifestBind
pipeline={pipeline}
stage={stage}
expectedArtifactId={binding && binding.expectedArtifactId}
artifact={binding && binding.artifact}
artifact={!!binding && binding.artifact}
onArtifactEdited={(artifact: IArtifact) => this.onChangeBinding(i, { artifact: artifact })}
onExpectedArtifactSelected={(expectedArtifact: IExpectedArtifact) =>
this.onChangeBinding(i, { expectedArtifactId: expectedArtifact.id })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class KubernetesV2DeployManifestConfigCtrl implements IController {
const stage = this.$scope.stage;
this.$scope.bindings = (stage.requiredArtifactIds || [])
.map((id: string) => ({ expectedArtifactId: id }))
.concat((stage.requiredArtifacts || []).map((artifact: IArtifact) => ({ artifact: artifact })));
.concat(stage.requiredArtifacts || []);

this.$scope.excludedManifestArtifactTypes = [
ArtifactTypePatterns.DOCKER_IMAGE,
Expand Down

0 comments on commit 5640431

Please sign in to comment.