Commit c7a0a863 authored by Jose Ivan Vargas's avatar Jose Ivan Vargas

Merge branch '259676-agent-error-message' into 'master'

Added alert error message to Agent List view

See merge request gitlab-org/gitlab!44050
parents 2cf100d5 73105f45
<script> <script>
import { GlLoadingIcon } from '@gitlab/ui'; import { GlAlert, GlLoadingIcon } from '@gitlab/ui';
import AgentEmptyState from './agent_empty_state.vue'; import AgentEmptyState from './agent_empty_state.vue';
import AgentTable from './agent_table.vue'; import AgentTable from './agent_table.vue';
import getAgentsQuery from '../graphql/queries/get_agents.query.graphql'; import getAgentsQuery from '../graphql/queries/get_agents.query.graphql';
...@@ -15,23 +15,17 @@ export default { ...@@ -15,23 +15,17 @@ export default {
}; };
}, },
update: data => { update: data => {
let agentList = data.project.clusterAgents.nodes; return {
const configFolders = data.project.repository.tree?.trees?.nodes; list: data?.project?.clusterAgents?.nodes,
folders: data?.project?.repository?.tree?.trees?.nodes,
if (configFolders) { };
agentList = agentList.map(agent => {
const configFolder = configFolders.find(({ name }) => name === agent.name);
return { ...agent, configFolder };
});
}
return agentList;
}, },
}, },
}, },
components: { components: {
AgentEmptyState, AgentEmptyState,
AgentTable, AgentTable,
GlAlert,
GlLoadingIcon, GlLoadingIcon,
}, },
props: { props: {
...@@ -49,15 +43,37 @@ export default { ...@@ -49,15 +43,37 @@ export default {
type: String, type: String,
}, },
}, },
computed: {
isLoading() {
return this.$apollo.queries.agents.loading;
},
agentList() {
let list = this.agents?.list;
const configFolders = this.agents?.folders;
if (list && configFolders) {
list = list.map(agent => {
const configFolder = configFolders.find(({ name }) => name === agent.name);
return { ...agent, configFolder };
});
}
return list;
},
},
}; };
</script> </script>
<template> <template>
<section v-if="agents" class="gl-mt-3"> <gl-loading-icon v-if="isLoading" size="md" class="gl-mt-3" />
<AgentTable v-if="agents.length" :agents="agents" />
<section v-else-if="agentList" class="gl-mt-3">
<AgentTable v-if="agentList.length" :agents="agentList" />
<AgentEmptyState v-else :image="emptyStateImage" /> <AgentEmptyState v-else :image="emptyStateImage" />
</section> </section>
<gl-loading-icon v-else size="md" class="gl-mt-3" /> <gl-alert v-else variant="danger" :dismissible="false">
{{ s__('ClusterAgents|An error occurred while loading your GitLab Agents') }}
</gl-alert>
</template> </template>
---
title: Add error message to cluster agent list
merge_request: 44050
author:
type: changed
import { createLocalVue, shallowMount } from '@vue/test-utils'; import { createLocalVue, shallowMount } from '@vue/test-utils';
import { GlAlert, GlLoadingIcon } from '@gitlab/ui';
import createMockApollo from 'jest/helpers/mock_apollo_helper'; import createMockApollo from 'jest/helpers/mock_apollo_helper';
import VueApollo from 'vue-apollo'; import VueApollo from 'vue-apollo';
import Agents from 'ee/clusters_list/components/agents.vue'; import Agents from 'ee/clusters_list/components/agents.vue';
...@@ -12,6 +13,12 @@ localVue.use(VueApollo); ...@@ -12,6 +13,12 @@ localVue.use(VueApollo);
describe('Agents', () => { describe('Agents', () => {
let wrapper; let wrapper;
const propsData = {
emptyStateImage: '/path/to/image',
defaultBranchName: 'default',
projectPath: 'path/to/project',
};
const createWrapper = ({ agents }) => { const createWrapper = ({ agents }) => {
const apolloQueryResponse = { const apolloQueryResponse = {
data: { data: {
...@@ -29,11 +36,7 @@ describe('Agents', () => { ...@@ -29,11 +36,7 @@ describe('Agents', () => {
wrapper = shallowMount(Agents, { wrapper = shallowMount(Agents, {
localVue, localVue,
apolloProvider, apolloProvider,
propsData: { propsData,
emptyStateImage: '/path/to/image',
defaultBranchName: 'default',
projectPath: 'path/to/project',
},
}); });
return wrapper.vm.$nextTick(); return wrapper.vm.$nextTick();
...@@ -78,4 +81,36 @@ describe('Agents', () => { ...@@ -78,4 +81,36 @@ describe('Agents', () => {
expect(wrapper.find(AgentEmptyState).exists()).toBe(true); expect(wrapper.find(AgentEmptyState).exists()).toBe(true);
}); });
}); });
describe('when agents query has errored', () => {
beforeEach(() => {
return createWrapper({ agents: null });
});
it('displays an alert message', () => {
expect(wrapper.find(GlAlert).exists()).toBe(true);
});
});
describe('when agents query is loading', () => {
const mocks = {
$apollo: {
queries: {
agents: {
loading: true,
},
},
},
};
beforeEach(() => {
wrapper = shallowMount(Agents, { mocks, propsData });
return wrapper.vm.$nextTick();
});
it('displays a loading icon', () => {
expect(wrapper.find(GlLoadingIcon).exists()).toBe(true);
});
});
}); });
...@@ -5501,6 +5501,9 @@ msgstr "" ...@@ -5501,6 +5501,9 @@ msgstr ""
msgid "Cluster type must be specificed for Stages::ClusterEndpointInserter" msgid "Cluster type must be specificed for Stages::ClusterEndpointInserter"
msgstr "" msgstr ""
msgid "ClusterAgents|An error occurred while loading your GitLab Agents"
msgstr ""
msgid "ClusterAgents|Configuration" msgid "ClusterAgents|Configuration"
msgstr "" msgstr ""
......
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