forked from spinnaker/deck
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): Add ability to set Default Tag filters for an application…
… in application config (spinnaker#10020) Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
- Loading branch information
1 parent
7b8b31d
commit e13dda5
Showing
7 changed files
with
307 additions
and
0 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
75 changes: 75 additions & 0 deletions
75
packages/core/src/application/config/defaultTagFilter/DefaultTagFilterConfig.spec.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,75 @@ | ||
import { shallow } from 'enzyme'; | ||
import React from 'react'; | ||
|
||
import type { IDefaultTagFilterConfig } from './DefaultTagFilterConfig'; | ||
import { DefaultTagFilterConfig } from './DefaultTagFilterConfig'; | ||
import { noop } from '../../../utils'; | ||
|
||
describe('<DefaultTagFilterConfig />', () => { | ||
let tagConfigs: IDefaultTagFilterConfig[]; | ||
let wrapper: any; | ||
|
||
beforeEach(() => { | ||
tagConfigs = getTestDefaultFilterTagConfigs(); | ||
wrapper = shallow( | ||
<DefaultTagFilterConfig | ||
defaultTagFilterConfigs={tagConfigs} | ||
isSaving={false} | ||
saveError={false} | ||
updateDefaultTagFilterConfigs={noop} | ||
/>, | ||
); | ||
}); | ||
|
||
describe('view', () => { | ||
it('renders a row for each banner config', () => { | ||
expect(wrapper.find('.default-filter-config-row').length).toEqual(tagConfigs.length); | ||
}); | ||
it('renders an "add" button', () => { | ||
expect(wrapper.find('.add-new').length).toEqual(1); | ||
}); | ||
}); | ||
|
||
describe('functionality', () => { | ||
it('update default tag filter config', () => { | ||
expect(wrapper.state('defaultTagFilterConfigsEditing')).toEqual(tagConfigs); | ||
wrapper | ||
.find('textarea') | ||
.at(1) | ||
.simulate('change', { target: { value: 'hello' } }); | ||
const updatedConfigs = [ | ||
{ | ||
...tagConfigs[0], | ||
tagValue: 'hello', | ||
}, | ||
{ | ||
...tagConfigs[1], | ||
}, | ||
]; | ||
expect(wrapper.state('defaultTagFilterConfigsEditing')).toEqual(updatedConfigs); | ||
}); | ||
it('add default filter tag config', () => { | ||
expect(wrapper.state('defaultTagFilterConfigsEditing').length).toEqual(2); | ||
wrapper.find('.add-new').simulate('click'); | ||
expect(wrapper.state('defaultTagFilterConfigsEditing').length).toEqual(3); | ||
}); | ||
it('remove default filter tag config', () => { | ||
expect(wrapper.state('defaultTagFilterConfigsEditing').length).toEqual(2); | ||
wrapper.find('.default-filter-config-remove').at(1).simulate('click'); | ||
expect(wrapper.state('defaultTagFilterConfigsEditing').length).toEqual(1); | ||
}); | ||
}); | ||
}); | ||
|
||
export function getTestDefaultFilterTagConfigs(): IDefaultTagFilterConfig[] { | ||
return [ | ||
{ | ||
tagName: 'Pipeline Type', | ||
tagValue: 'Deployment Pipelines', | ||
}, | ||
{ | ||
tagName: 'Pipeline Type', | ||
tagValue: 'Repair Pipelines', | ||
}, | ||
]; | ||
} |
161 changes: 161 additions & 0 deletions
161
packages/core/src/application/config/defaultTagFilter/DefaultTagFilterConfig.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,161 @@ | ||
import { isEqual } from 'lodash'; | ||
import React from 'react'; | ||
|
||
import { ConfigSectionFooter } from '../footer/ConfigSectionFooter'; | ||
import { noop } from '../../../utils'; | ||
|
||
import './defaultTagFilterConfig.less'; | ||
|
||
export interface IDefaultTagFilterConfig { | ||
tagName: string; | ||
tagValue: string; | ||
} | ||
|
||
export interface IDefaultTagFilterProps { | ||
defaultTagFilterConfigs: IDefaultTagFilterConfig[]; | ||
isSaving: boolean; | ||
saveError: boolean; | ||
updateDefaultTagFilterConfigs: (defaultTagFilterConfigs: IDefaultTagFilterConfig[]) => void; | ||
} | ||
|
||
export interface IDefaultTagFilterState { | ||
defaultTagFilterConfigsEditing: IDefaultTagFilterConfig[]; | ||
} | ||
|
||
export class DefaultTagFilterConfig extends React.Component<IDefaultTagFilterProps, IDefaultTagFilterState> { | ||
public static defaultProps: Partial<IDefaultTagFilterProps> = { | ||
defaultTagFilterConfigs: [], | ||
isSaving: false, | ||
saveError: false, | ||
updateDefaultTagFilterConfigs: noop, | ||
}; | ||
|
||
constructor(props: IDefaultTagFilterProps) { | ||
super(props); | ||
this.state = { | ||
defaultTagFilterConfigsEditing: props.defaultTagFilterConfigs, | ||
}; | ||
} | ||
|
||
private onTagNameChange = (idx: number, text: string) => { | ||
this.setState({ | ||
defaultTagFilterConfigsEditing: this.state.defaultTagFilterConfigsEditing.map((config, i) => { | ||
if (i === idx) { | ||
return { | ||
...config, | ||
tagName: text, | ||
}; | ||
} | ||
return config; | ||
}), | ||
}); | ||
}; | ||
|
||
private onTagValueChange = (idx: number, text: string) => { | ||
this.setState({ | ||
defaultTagFilterConfigsEditing: this.state.defaultTagFilterConfigsEditing.map((config, i) => { | ||
if (i === idx) { | ||
return { | ||
...config, | ||
tagValue: text, | ||
}; | ||
} | ||
return config; | ||
}), | ||
}); | ||
}; | ||
|
||
private addFilterTag = (): void => { | ||
this.setState({ | ||
defaultTagFilterConfigsEditing: this.state.defaultTagFilterConfigsEditing.concat([ | ||
{ | ||
tagName: 'Name of the tag (E.g. Pipeline Type)', | ||
tagValue: 'Value of the tag (E.g. Default Pipelines)', | ||
} as IDefaultTagFilterConfig, | ||
]), | ||
}); | ||
}; | ||
|
||
private removeFilterTag = (idx: number): void => { | ||
this.setState({ | ||
defaultTagFilterConfigsEditing: this.state.defaultTagFilterConfigsEditing.filter((_config, i) => i !== idx), | ||
}); | ||
}; | ||
|
||
private isDirty = (): boolean => { | ||
return !isEqual(this.props.defaultTagFilterConfigs, this.state.defaultTagFilterConfigsEditing); | ||
}; | ||
|
||
private onRevertClicked = (): void => { | ||
this.setState({ | ||
defaultTagFilterConfigsEditing: this.props.defaultTagFilterConfigs, | ||
}); | ||
}; | ||
|
||
private onSaveClicked = (): void => { | ||
this.props.updateDefaultTagFilterConfigs(this.state.defaultTagFilterConfigsEditing); | ||
}; | ||
|
||
public render() { | ||
return ( | ||
<div className="default-filter-config-container"> | ||
<div className="default-filter-config-description"> | ||
Default Tag filters allow you to specify which tags are immediately filtered to when the pipeline execution | ||
page is loaded in. | ||
</div> | ||
<div className="col-md-10 col-md-offset-1"> | ||
<table className="table table-condensed"> | ||
<thead> | ||
<tr> | ||
<th>Tag Name</th> | ||
<th>Tag Value</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{this.state.defaultTagFilterConfigsEditing.map((defaultTagFilter, idx) => ( | ||
<tr key={idx} className="default-filter-config-row"> | ||
<td> | ||
<textarea | ||
className="form-control input-sm" | ||
onChange={(e: React.ChangeEvent<HTMLTextAreaElement>) => | ||
this.onTagNameChange(idx, e.target.value) | ||
} | ||
value={defaultTagFilter.tagName} | ||
/> | ||
</td> | ||
<td> | ||
<textarea | ||
className="form-control input-sm" | ||
onChange={(e: React.ChangeEvent<HTMLTextAreaElement>) => | ||
this.onTagValueChange(idx, e.target.value) | ||
} | ||
value={defaultTagFilter.tagValue} | ||
/> | ||
</td> | ||
<td> | ||
<button className="link default-filter-config-remove" onClick={() => this.removeFilterTag(idx)}> | ||
<span className="glyphicon glyphicon-trash" /> | ||
</button> | ||
</td> | ||
</tr> | ||
))} | ||
</tbody> | ||
</table> | ||
</div> | ||
<div className="col-md-10 col-md-offset-1"> | ||
<button className="btn btn-block add-new" onClick={this.addFilterTag}> | ||
<span className="glyphicon glyphicon-plus-sign" /> Add Default Filter | ||
</button> | ||
</div> | ||
<ConfigSectionFooter | ||
isDirty={this.isDirty()} | ||
isValid={true} | ||
isSaving={this.props.isSaving} | ||
saveError={false} | ||
onRevertClicked={this.onRevertClicked} | ||
onSaveClicked={this.onSaveClicked} | ||
/> | ||
</div> | ||
); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
packages/core/src/application/config/defaultTagFilter/defaultTagFilterConfig.component.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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { module } from 'angular'; | ||
import { react2angular } from 'react2angular'; | ||
import { DefaultTagFilterConfig } from './DefaultTagFilterConfig'; | ||
import { withErrorBoundary } from '../../../presentation/SpinErrorBoundary'; | ||
|
||
export const DEFAULT_TAG_FILTER_CONFIG = 'spinnaker.micros.application.defaultTagFilterConfig.component'; | ||
module(DEFAULT_TAG_FILTER_CONFIG, []).component( | ||
'defaultTagFilterConfig', | ||
react2angular(withErrorBoundary(DefaultTagFilterConfig, 'defaultTagFilterConfig'), [ | ||
'defaultTagFilterConfigs', | ||
'isSaving', | ||
'saveError', | ||
'updateDefaultTagFilterConfigs', | ||
]), | ||
); |
8 changes: 8 additions & 0 deletions
8
packages/core/src/application/config/defaultTagFilter/defaultTagFilterConfig.less
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,8 @@ | ||
.default-filter-config-container { | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
|
||
.default-filter-config-description { | ||
margin-bottom: 10px; | ||
} |
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