-
Notifications
You must be signed in to change notification settings - Fork 900
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6970 from pivotal-cf/4295-trigger-directive-to-react
refactor(core): Convert most triggers from angular to react
- Loading branch information
Showing
49 changed files
with
1,714 additions
and
2,291 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
79 changes: 79 additions & 0 deletions
79
app/scripts/modules/core/src/pipeline/config/triggers/BaseTrigger.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 @@ | ||
import * as React from 'react'; | ||
|
||
import { Observable, Subject } from 'rxjs'; | ||
|
||
import { ITrigger } from 'core/domain'; | ||
import { SETTINGS } from 'core/config/settings'; | ||
import { ServiceAccountReader } from 'core/serviceAccount/ServiceAccountReader'; | ||
import { RunAsUser } from 'core/pipeline'; | ||
|
||
export interface IBaseTriggerConfigProps { | ||
triggerContents: React.ReactNode; | ||
trigger: ITrigger; | ||
triggerUpdated?: (trigger: ITrigger) => void; | ||
} | ||
|
||
export interface IBaseTriggerState { | ||
serviceAccounts?: string[]; | ||
} | ||
|
||
export class BaseTrigger extends React.Component<IBaseTriggerConfigProps, IBaseTriggerState> { | ||
private destroy$ = new Subject(); | ||
|
||
constructor(props: IBaseTriggerConfigProps) { | ||
super(props); | ||
this.state = { | ||
serviceAccounts: [], | ||
}; | ||
} | ||
|
||
public componentDidMount(): void { | ||
if (SETTINGS.feature.fiatEnabled) { | ||
Observable.fromPromise(ServiceAccountReader.getServiceAccounts()) | ||
.takeUntil(this.destroy$) | ||
.subscribe(serviceAccounts => this.setState({ serviceAccounts })); | ||
} | ||
} | ||
|
||
public componentWillUnmount(): void { | ||
this.destroy$.next(); | ||
} | ||
|
||
private onUpdateTrigger = (update: any) => { | ||
this.props.triggerUpdated && | ||
this.props.triggerUpdated({ | ||
...this.props.trigger, | ||
...update, | ||
}); | ||
}; | ||
|
||
private renderRunAsUser = (): React.ReactNode => { | ||
const { trigger } = this.props; | ||
const { serviceAccounts } = this.state; | ||
return ( | ||
<> | ||
{SETTINGS.feature.fiatEnabled && serviceAccounts && ( | ||
<div className="form-group"> | ||
<RunAsUser | ||
serviceAccounts={serviceAccounts} | ||
onChange={(user: string) => this.onUpdateTrigger({ user })} | ||
value={trigger.user} | ||
selectColumns={6} | ||
/> | ||
</div> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
public render() { | ||
const { triggerContents } = this.props; | ||
const { renderRunAsUser } = this; | ||
return ( | ||
<> | ||
{triggerContents} | ||
{renderRunAsUser()} | ||
</> | ||
); | ||
} | ||
} |
6 changes: 0 additions & 6 deletions
6
app/scripts/modules/core/src/pipeline/config/triggers/ITriggerConfigProps.ts
This file was deleted.
Oops, something went wrong.
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
82 changes: 82 additions & 0 deletions
82
app/scripts/modules/core/src/pipeline/config/triggers/artifactory/ArtifactoryTrigger.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,82 @@ | ||
import * as React from 'react'; | ||
import Select, { Option } from 'react-select'; | ||
|
||
import { Observable, Subject } from 'rxjs'; | ||
|
||
import { IArtifactoryTrigger } from 'core/domain/ITrigger'; | ||
import { BaseTrigger } from 'core/pipeline'; | ||
import { ArtifactoryReaderService } from './artifactoryReader.service'; | ||
import { Application } from 'core'; | ||
|
||
export interface IArtifactoryTriggerConfigProps { | ||
trigger: IArtifactoryTrigger; | ||
pipelineId: string; | ||
application: Application; | ||
triggerUpdated: (trigger: IArtifactoryTrigger) => void; | ||
} | ||
|
||
export interface IArtifactoryTriggerConfigState { | ||
artifactorySearchNames: string[]; | ||
} | ||
|
||
export class ArtifactoryTrigger extends React.Component< | ||
IArtifactoryTriggerConfigProps, | ||
IArtifactoryTriggerConfigState | ||
> { | ||
private destroy$ = new Subject(); | ||
|
||
constructor(props: IArtifactoryTriggerConfigProps) { | ||
super(props); | ||
this.state = { | ||
artifactorySearchNames: [], | ||
}; | ||
} | ||
|
||
public componentDidMount() { | ||
Observable.fromPromise(ArtifactoryReaderService.getArtifactoryNames()) | ||
.takeUntil(this.destroy$) | ||
.subscribe((artifactorySearchNames: string[]) => { | ||
this.setState({ artifactorySearchNames }); | ||
}); | ||
} | ||
|
||
public componentWillUnmount(): void { | ||
this.destroy$.next(); | ||
} | ||
|
||
private onUpdateTrigger = (update: any) => { | ||
this.props.triggerUpdated && | ||
this.props.triggerUpdated({ | ||
...this.props.trigger, | ||
...update, | ||
}); | ||
}; | ||
|
||
private ArtifactoryTriggerContents = () => { | ||
const { artifactorySearchNames } = this.state; | ||
const { artifactorySearchName } = this.props.trigger; | ||
return ( | ||
<> | ||
<div className="form-group"> | ||
<div className="col-md-3 sm-label-right"> | ||
<span className="label-text">Artifactory Name</span> | ||
</div> | ||
<div className="col-md-6"> | ||
<Select | ||
value={artifactorySearchName} | ||
placeholder="Select Artifactory search name..." | ||
onChange={(option: Option<string>) => this.onUpdateTrigger({ artifactorySearchName: option.value })} | ||
options={artifactorySearchNames.map((name: string) => ({ label: name, value: name }))} | ||
clearable={false} | ||
/> | ||
</div> | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
public render() { | ||
const { ArtifactoryTriggerContents } = this; | ||
return <BaseTrigger {...this.props} triggerContents={<ArtifactoryTriggerContents />} />; | ||
} | ||
} |
64 changes: 0 additions & 64 deletions
64
...cripts/modules/core/src/pipeline/config/triggers/artifactory/ArtifactoryTriggerConfig.tsx
This file was deleted.
Oops, something went wrong.
4 changes: 2 additions & 2 deletions
4
...riggers/artifactory/artifactoryTrigger.ts → ...iggers/artifactory/artifactory.trigger.ts
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 |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import { Registry } from 'core/registry'; | ||
import { ArtifactoryTriggerConfig } from './ArtifactoryTriggerConfig'; | ||
import { ArtifactoryTrigger } from './ArtifactoryTrigger'; | ||
import { ArtifactTypePatterns, excludeAllTypesExcept } from 'core/artifact'; | ||
|
||
Registry.pipeline.registerTrigger({ | ||
label: 'Artifactory', | ||
description: 'Executes the pipeline on an Artifactory repo update', | ||
key: 'artifactory', | ||
component: ArtifactoryTriggerConfig, | ||
component: ArtifactoryTrigger, | ||
validators: [], | ||
excludedArtifactTypePatterns: excludeAllTypesExcept(ArtifactTypePatterns.MAVEN_FILE), | ||
}); |
Oops, something went wrong.