Commit e144946e authored by Dennis Tang's avatar Dennis Tang

fix when no GCP projects are found

parent bb0d746e
...@@ -38,6 +38,10 @@ export default { ...@@ -38,6 +38,10 @@ export default {
}, },
computed: { computed: {
results() { results() {
if (!this.items) {
return [];
}
return this.items.filter(item => item.name.toLowerCase().indexOf(this.searchQuery) > -1); return this.items.filter(item => item.name.toLowerCase().indexOf(this.searchQuery) > -1);
}, },
}, },
......
...@@ -19,10 +19,10 @@ export default { ...@@ -19,10 +19,10 @@ export default {
...mapState({ items: 'projects' }), ...mapState({ items: 'projects' }),
...mapGetters(['hasProject']), ...mapGetters(['hasProject']),
hasOneProject() { hasOneProject() {
return this.items.length === 1; return this.items && this.items.length === 1;
}, },
isDisabled() { isDisabled() {
return this.items.length < 2; return this.items && this.items.length < 2;
}, },
toggleText() { toggleText() {
if (this.isLoading) { if (this.isLoading) {
...@@ -33,20 +33,27 @@ export default { ...@@ -33,20 +33,27 @@ export default {
return this.selectedProject.name; return this.selectedProject.name;
} }
return !this.items.length if (!this.items) {
? s__('ClusterIntegration|No projects found') return s__('ClusterIntegration|No projects found');
: s__('ClusterIntegration|Select project'); }
return s__('ClusterIntegration|Select project');
}, },
helpText() { helpText() {
let message; let message;
if (this.hasErrors) { if (this.hasErrors) {
message = this.gapiError;
}
if (!this.items) {
message = message =
'ClusterIntegration|We were unable to fetch any projects. Ensure that you have a project on %{docsLinkStart}Google Cloud Platform%{docsLinkEnd}.'; 'ClusterIntegration|We were unable to fetch any projects. Ensure that you have a project on %{docsLinkStart}Google Cloud Platform%{docsLinkEnd}.';
} }
message = this.items.length message =
? 'ClusterIntegration|To use a new project, first create one on %{docsLinkStart}Google Cloud Platform%{docsLinkEnd}.' this.items && this.items.length
: 'ClusterIntegration|To create a cluster, first create a project on %{docsLinkStart}Google Cloud Platform%{docsLinkEnd}.'; ? 'ClusterIntegration|To use a new project, first create one on %{docsLinkStart}Google Cloud Platform%{docsLinkEnd}.'
: 'ClusterIntegration|To create a cluster, first create a project on %{docsLinkStart}Google Cloud Platform%{docsLinkEnd}.';
return sprintf( return sprintf(
s__(message), s__(message),
......
...@@ -58,7 +58,7 @@ describe('GkeProjectIdDropdown', () => { ...@@ -58,7 +58,7 @@ describe('GkeProjectIdDropdown', () => {
it('returns empty toggle text', done => it('returns empty toggle text', done =>
vm.$nextTick().then(() => { vm.$nextTick().then(() => {
vm.$store.commit(SET_PROJECTS, []); vm.$store.commit(SET_PROJECTS, null);
vm.setItem(emptyProjectMock); vm.setItem(emptyProjectMock);
expect(vm.toggleText).toBe(LABELS.EMPTY); expect(vm.toggleText).toBe(LABELS.EMPTY);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment