-
Notifications
You must be signed in to change notification settings - Fork 903
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(google): improve performance of GCE image selection (#7208)
- Loading branch information
1 parent
68ee670
commit 97db30b
Showing
8 changed files
with
95 additions
and
96 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { module } from 'angular'; | ||
|
||
import { chain } from 'lodash'; | ||
import * as React from 'react'; | ||
import { Async, AutocompleteResult, Option } from 'react-select'; | ||
import { react2angular } from 'react2angular'; | ||
|
||
interface IImage { | ||
imageName: string; | ||
} | ||
|
||
interface IImageSelectProps { | ||
availableImages: IImage[]; | ||
selectedImage: string; | ||
selectImage: (image: string, target?: any) => void; | ||
target?: any; | ||
} | ||
|
||
export class ImageSelect extends React.Component<IImageSelectProps> { | ||
private loadOptions = (inputValue: string): Promise<AutocompleteResult<string>> => { | ||
return new Promise(resolve => { | ||
if (!inputValue || inputValue.length < 3) { | ||
resolve({ | ||
options: [], | ||
complete: false, | ||
}); | ||
} else { | ||
const filteredOptions = chain(this.props.availableImages) | ||
.filter(i => i.imageName.toLowerCase().includes(inputValue)) | ||
.take(20) | ||
.map(i => ({ value: i.imageName, label: i.imageName })) | ||
.value(); | ||
resolve({ | ||
options: filteredOptions, | ||
complete: false, | ||
}); | ||
} | ||
}); | ||
}; | ||
|
||
public render() { | ||
return ( | ||
<Async | ||
cache={null} | ||
clearable={false} | ||
ignoreAccents={false} | ||
loadOptions={this.loadOptions} | ||
onChange={(selected: Option<string>) => this.props.selectImage(selected.value, this.props.target)} | ||
placeholder="Type at least 3 characters to search for an image..." | ||
searchPromptText="Type at least 3 characters to search for an image..." | ||
value={{ value: this.props.selectedImage, label: this.props.selectedImage }} | ||
/> | ||
); | ||
} | ||
} | ||
|
||
export const GCE_IMAGE_SELECT = 'spinnaker.gce.imageSelect'; | ||
module(GCE_IMAGE_SELECT, []).component( | ||
'gceImageSelect', | ||
react2angular(ImageSelect, ['availableImages', 'selectedImage', 'selectImage', 'target']), | ||
); |
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
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
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
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