Commit 7e85d808 authored by jerasmus's avatar jerasmus

Add ability to display cluster status

Added the ability to display the cluster status
parent bae06faf
<script> <script>
import { mapState, mapActions } from 'vuex'; import { mapState, mapActions } from 'vuex';
import { GlTable, GlLoadingIcon, GlBadge } from '@gitlab/ui'; import { GlTable, GlLoadingIcon, GlBadge } from '@gitlab/ui';
import { CLUSTER_TYPES } from '../constants'; import tooltip from '~/vue_shared/directives/tooltip';
import { __ } from '~/locale'; import { CLUSTER_TYPES, STATUSES } from '../constants';
import { __, sprintf } from '~/locale';
export default { export default {
components: { components: {
...@@ -10,6 +11,9 @@ export default { ...@@ -10,6 +11,9 @@ export default {
GlLoadingIcon, GlLoadingIcon,
GlBadge, GlBadge,
}, },
directives: {
tooltip,
},
fields: [ fields: [
{ {
key: 'name', key: 'name',
...@@ -38,6 +42,13 @@ export default { ...@@ -38,6 +42,13 @@ export default {
}, },
methods: { methods: {
...mapActions(['fetchClusters']), ...mapActions(['fetchClusters']),
statusClass(status) {
return STATUSES[status].className;
},
statusTitle(status) {
const { title } = STATUSES[status];
return sprintf(__('Status: %{title}'), { title }, false);
},
}, },
}; };
</script> </script>
...@@ -52,6 +63,25 @@ export default { ...@@ -52,6 +63,25 @@ export default {
variant="light" variant="light"
class="qa-clusters-table" class="qa-clusters-table"
> >
<template #cell(name)="{ item }">
<div class="d-flex flex-row-reverse flex-md-row js-status">
{{ item.name }}
<gl-loading-icon
v-if="item.status === 'deleting'"
v-tooltip
:title="statusTitle(item.status)"
size="sm"
class="mr-2 ml-md-2"
/>
<div
v-else
v-tooltip
class="cluster-status-indicator rounded-circle align-self-center gl-w-8 gl-h-8 mr-2 ml-md-2"
:class="statusClass(item.status)"
:title="statusTitle(item.status)"
></div>
</div>
</template>
<template #cell(clusterType)="{value}"> <template #cell(clusterType)="{value}">
<gl-badge variant="light"> <gl-badge variant="light">
{{ value }} {{ value }}
......
...@@ -6,6 +6,10 @@ export const CLUSTER_TYPES = { ...@@ -6,6 +6,10 @@ export const CLUSTER_TYPES = {
instance_type: __('Instance'), instance_type: __('Instance'),
}; };
export default { export const STATUSES = {
CLUSTER_TYPES, disabled: { className: 'disabled', title: __('Disabled') },
connected: { className: 'bg-success', title: __('Connected') },
unreachable: { className: 'bg-danger', title: __('Unreachable') },
authentication_failure: { className: 'bg-warning', title: __('Authentication Failure') },
deleting: { title: __('Deleting') },
}; };
export default (initialState = {}) => ({ export default (initialState = {}) => ({
endpoint: initialState.endpoint, endpoint: initialState.endpoint,
loading: false, // TODO - set this to true once integrated with BE loading: false, // TODO - set this to true once integrated with BE
clusters: [ clusters: [],
// TODO - remove mock data once integrated with BE
// {
// name: 'My Cluster',
// environmentScope: '*',
// size: '3',
// clusterType: 'group_type',
// },
// {
// name: 'My other cluster',
// environmentScope: 'production',
// size: '12',
// clusterType: 'project_type',
// },
],
}); });
...@@ -163,3 +163,9 @@ ...@@ -163,3 +163,9 @@
color: $black; color: $black;
font-weight: $gl-font-weight-bold; font-weight: $gl-font-weight-bold;
} }
.cluster-status-indicator {
&.disabled {
background-color: $gray-600;
}
}
...@@ -54,8 +54,10 @@ ...@@ -54,8 +54,10 @@
.mh-50vh { max-height: 50vh; } .mh-50vh { max-height: 50vh; }
.font-size-inherit { font-size: inherit; } .font-size-inherit { font-size: inherit; }
.gl-w-8 { width: px-to-rem($grid-size); }
.gl-w-16 { width: px-to-rem($grid-size * 2); } .gl-w-16 { width: px-to-rem($grid-size * 2); }
.gl-w-64 { width: px-to-rem($grid-size * 8); } .gl-w-64 { width: px-to-rem($grid-size * 8); }
.gl-h-8 { height: px-to-rem($grid-size); }
.gl-h-32 { height: px-to-rem($grid-size * 4); } .gl-h-32 { height: px-to-rem($grid-size * 4); }
.gl-h-64 { height: px-to-rem($grid-size * 8); } .gl-h-64 { height: px-to-rem($grid-size * 8); }
......
---
title: Show cluster status (FE)
merge_request: 26368
author:
type: added
...@@ -2506,6 +2506,9 @@ msgstr "" ...@@ -2506,6 +2506,9 @@ msgstr ""
msgid "Authenticating" msgid "Authenticating"
msgstr "" msgstr ""
msgid "Authentication Failure"
msgstr ""
msgid "Authentication Log" msgid "Authentication Log"
msgstr "" msgstr ""
...@@ -5166,6 +5169,9 @@ msgstr "" ...@@ -5166,6 +5169,9 @@ msgstr ""
msgid "Connect your external repositories, and CI/CD pipelines will run for new commits. A GitLab project will be created with only CI/CD features enabled." msgid "Connect your external repositories, and CI/CD pipelines will run for new commits. A GitLab project will be created with only CI/CD features enabled."
msgstr "" msgstr ""
msgid "Connected"
msgstr ""
msgid "Connecting" msgid "Connecting"
msgstr "" msgstr ""
...@@ -6334,6 +6340,9 @@ msgstr "" ...@@ -6334,6 +6340,9 @@ msgstr ""
msgid "Deleted in this version" msgid "Deleted in this version"
msgstr "" msgstr ""
msgid "Deleting"
msgstr ""
msgid "Deleting the license failed." msgid "Deleting the license failed."
msgstr "" msgstr ""
...@@ -18699,6 +18708,9 @@ msgstr "" ...@@ -18699,6 +18708,9 @@ msgstr ""
msgid "Status:" msgid "Status:"
msgstr "" msgstr ""
msgid "Status: %{title}"
msgstr ""
msgid "Stay updated about the performance and health of your environment by configuring Prometheus to monitor your deployments." msgid "Stay updated about the performance and health of your environment by configuring Prometheus to monitor your deployments."
msgstr "" msgstr ""
...@@ -21089,6 +21101,9 @@ msgstr "" ...@@ -21089,6 +21101,9 @@ msgstr ""
msgid "Unmarks this %{noun} as Work In Progress." msgid "Unmarks this %{noun} as Work In Progress."
msgstr "" msgstr ""
msgid "Unreachable"
msgstr ""
msgid "Unresolve" msgid "Unresolve"
msgstr "" msgstr ""
......
import Vuex from 'vuex';
import { createLocalVue, mount } from '@vue/test-utils'; import { createLocalVue, mount } from '@vue/test-utils';
import { GlTable, GlLoadingIcon } from '@gitlab/ui'; import { GlTable, GlLoadingIcon } from '@gitlab/ui';
import Clusters from '~/clusters_list/components/clusters.vue'; import Clusters from '~/clusters_list/components/clusters.vue';
import Vuex from 'vuex'; import mockData from '../mock_data';
const localVue = createLocalVue(); const localVue = createLocalVue();
localVue.use(Vuex); localVue.use(Vuex);
...@@ -11,9 +12,10 @@ describe('Clusters', () => { ...@@ -11,9 +12,10 @@ describe('Clusters', () => {
const findTable = () => wrapper.find(GlTable); const findTable = () => wrapper.find(GlTable);
const findLoader = () => wrapper.find(GlLoadingIcon); const findLoader = () => wrapper.find(GlLoadingIcon);
const findStatuses = () => findTable().findAll('.js-status');
const mountComponent = _state => { const mountComponent = _state => {
const state = { clusters: [], endpoint: 'some/endpoint', ..._state }; const state = { clusters: mockData, endpoint: 'some/endpoint', ..._state };
const store = new Vuex.Store({ const store = new Vuex.Store({
state, state,
}); });
...@@ -52,4 +54,25 @@ describe('Clusters', () => { ...@@ -52,4 +54,25 @@ describe('Clusters', () => {
expect(findTable().classes()).toContain('b-table-stacked-md'); expect(findTable().classes()).toContain('b-table-stacked-md');
}); });
}); });
describe('cluster status', () => {
it.each`
statusName | className | lineNumber
${'disabled'} | ${'disabled'} | ${0}
${'unreachable'} | ${'bg-danger'} | ${1}
${'authentication_failure'} | ${'bg-warning'} | ${2}
${'deleting'} | ${null} | ${3}
${'connected'} | ${'bg-success'} | ${4}
`('renders a status for each cluster', ({ statusName, className, lineNumber }) => {
const statuses = findStatuses();
const status = statuses.at(lineNumber);
if (statusName !== 'deleting') {
const statusIndicator = status.find('.cluster-status-indicator');
expect(statusIndicator.exists()).toBe(true);
expect(statusIndicator.classes()).toContain(className);
} else {
expect(status.find(GlLoadingIcon).exists()).toBe(true);
}
});
});
}); });
export default [
{
name: 'My Cluster 1',
environmentScope: '*',
size: '3',
clusterType: 'group_type',
status: 'disabled',
},
{
name: 'My Cluster 2',
environmentScope: 'development',
size: '12',
clusterType: 'project_type',
status: 'unreachable',
},
{
name: 'My Cluster 3',
environmentScope: 'development',
size: '12',
clusterType: 'project_type',
status: 'authentication_failure',
},
{
name: 'My Cluster 4',
environmentScope: 'production',
size: '12',
clusterType: 'project_type',
status: 'deleting',
},
{
name: 'My Cluster 5',
environmentScope: 'development',
size: '12',
clusterType: 'project_type',
status: 'connected',
},
];
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