Commit 302d52ae authored by Emily Ring's avatar Emily Ring

Connected cluster list to backend

Added backend endpoint to clusters/index.html.haml
Updated clusters_list/components/clusters.vue for updated endpoint
Updated clusterable_presenter.rb to allow json paths for index
parent 08efee10
<script> <script>
import { mapState, mapActions } from 'vuex'; import { mapState, mapActions } from 'vuex';
import { GlTable, GlLoadingIcon, GlBadge } from '@gitlab/ui'; import { GlTable, GlLink, GlLoadingIcon, GlBadge } from '@gitlab/ui';
import tooltip from '~/vue_shared/directives/tooltip'; import tooltip from '~/vue_shared/directives/tooltip';
import { CLUSTER_TYPES, STATUSES } from '../constants'; import { CLUSTER_TYPES, STATUSES } from '../constants';
import { __, sprintf } from '~/locale'; import { __, sprintf } from '~/locale';
...@@ -8,6 +8,7 @@ import { __, sprintf } from '~/locale'; ...@@ -8,6 +8,7 @@ import { __, sprintf } from '~/locale';
export default { export default {
components: { components: {
GlTable, GlTable,
GlLink,
GlLoadingIcon, GlLoadingIcon,
GlBadge, GlBadge,
}, },
...@@ -23,18 +24,19 @@ export default { ...@@ -23,18 +24,19 @@ export default {
key: 'environmentScope', key: 'environmentScope',
label: __('Environment scope'), label: __('Environment scope'),
}, },
{ // Wait for backend to send these fields
key: 'size', // {
label: __('Size'), // key: 'size',
}, // label: __('Size'),
{ // },
key: 'cpu', // {
label: __('Total cores (vCPUs)'), // key: 'cpu',
}, // label: __('Total cores (vCPUs)'),
{ // },
key: 'memory', // {
label: __('Total memory (GB)'), // key: 'memory',
}, // label: __('Total memory (GB)'),
// },
{ {
key: 'clusterType', key: 'clusterType',
label: __('Cluster level'), label: __('Cluster level'),
...@@ -45,13 +47,13 @@ export default { ...@@ -45,13 +47,13 @@ export default {
...mapState(['clusters', 'loading']), ...mapState(['clusters', 'loading']),
}, },
mounted() { mounted() {
// TODO - uncomment this once integrated with BE this.fetchClusters();
// this.fetchClusters();
}, },
methods: { methods: {
...mapActions(['fetchClusters']), ...mapActions(['fetchClusters']),
statusClass(status) { statusClass(status) {
return STATUSES[status].className; const { className } = STATUSES[status];
return className || 'disabled';
}, },
statusTitle(status) { statusTitle(status) {
const { title } = STATUSES[status]; const { title } = STATUSES[status];
...@@ -73,7 +75,10 @@ export default { ...@@ -73,7 +75,10 @@ export default {
> >
<template #cell(name)="{ item }"> <template #cell(name)="{ item }">
<div class="d-flex flex-row-reverse flex-md-row js-status"> <div class="d-flex flex-row-reverse flex-md-row js-status">
{{ item.name }} <gl-link data-qa-selector="cluster" :data-qa-cluster-name="item.name" :href="item.path">
{{ item.name }}
</gl-link>
<gl-loading-icon <gl-loading-icon
v-if="item.status === 'deleting'" v-if="item.status === 'deleting'"
v-tooltip v-tooltip
...@@ -84,7 +89,7 @@ export default { ...@@ -84,7 +89,7 @@ export default {
<div <div
v-else v-else
v-tooltip v-tooltip
class="cluster-status-indicator rounded-circle align-self-center gl-w-8 gl-h-8 mr-2 ml-md-2" class="cluster-status-indicator rounded-circle align-self-center gl-w-4 gl-h-4 mr-2 ml-md-2"
:class="statusClass(item.status)" :class="statusClass(item.status)"
:title="statusTitle(item.status)" :title="statusTitle(item.status)"
></div> ></div>
......
...@@ -8,7 +8,7 @@ export const CLUSTER_TYPES = { ...@@ -8,7 +8,7 @@ export const CLUSTER_TYPES = {
export const STATUSES = { export const STATUSES = {
disabled: { className: 'disabled', title: __('Disabled') }, disabled: { className: 'disabled', title: __('Disabled') },
connected: { className: 'bg-success', title: __('Connected') }, created: { className: 'bg-success', title: __('Connected') },
unreachable: { className: 'bg-danger', title: __('Unreachable') }, unreachable: { className: 'bg-danger', title: __('Unreachable') },
authentication_failure: { className: 'bg-warning', title: __('Authentication Failure') }, authentication_failure: { className: 'bg-warning', title: __('Authentication Failure') },
deleting: { title: __('Deleting') }, deleting: { title: __('Deleting') },
......
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils'; import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
import Poll from '~/lib/utils/poll'; import Poll from '~/lib/utils/poll';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import Visibility from 'visibilityjs';
import flash from '~/flash'; import flash from '~/flash';
import { __ } from '~/locale'; import { __ } from '~/locale';
import * as types from './mutation_types'; import * as types from './mutation_types';
...@@ -14,23 +13,16 @@ export const fetchClusters = ({ state, commit }) => { ...@@ -14,23 +13,16 @@ export const fetchClusters = ({ state, commit }) => {
data: state.endpoint, data: state.endpoint,
method: 'fetchClusters', method: 'fetchClusters',
successCallback: ({ data }) => { successCallback: ({ data }) => {
commit(types.SET_CLUSTERS_DATA, convertObjectPropsToCamelCase(data, { deep: true })); if (data.clusters) {
commit(types.SET_LOADING_STATE, false); commit(types.SET_CLUSTERS_DATA, convertObjectPropsToCamelCase(data, { deep: true }));
commit(types.SET_LOADING_STATE, false);
poll.stop();
}
}, },
errorCallback: () => flash(__('An error occurred while loading clusters')), errorCallback: () => flash(__('An error occurred while loading clusters')),
}); });
if (!Visibility.hidden()) { poll.makeRequest();
poll.makeRequest();
}
Visibility.change(() => {
if (!Visibility.hidden()) {
poll.restart();
} else {
poll.stop();
}
});
}; };
// prevent babel-plugin-rewire from generating an invalid default during karma tests // prevent babel-plugin-rewire from generating an invalid default during karma tests
......
...@@ -4,9 +4,10 @@ export default { ...@@ -4,9 +4,10 @@ export default {
[types.SET_LOADING_STATE](state, value) { [types.SET_LOADING_STATE](state, value) {
state.loading = value; state.loading = value;
}, },
[types.SET_CLUSTERS_DATA](state, clusters) { [types.SET_CLUSTERS_DATA](state, data) {
Object.assign(state, { Object.assign(state, {
clusters, clusters: data.clusters,
hasAncestorClusters: data.hasAncestorClusters,
}); });
}, },
}; };
export default (initialState = {}) => ({ export default (initialState = {}) => ({
endpoint: initialState.endpoint, endpoint: initialState.endpoint,
loading: false, // TODO - set this to true once integrated with BE hasAncestorClusters: false,
loading: true,
clusters: [], clusters: [],
}); });
...@@ -21,8 +21,8 @@ class ClusterablePresenter < Gitlab::View::Presenter::Delegated ...@@ -21,8 +21,8 @@ class ClusterablePresenter < Gitlab::View::Presenter::Delegated
can?(current_user, :create_cluster, clusterable) can?(current_user, :create_cluster, clusterable)
end end
def index_path def index_path(options = {})
polymorphic_path([clusterable, :clusters]) polymorphic_path([clusterable, :clusters], options)
end end
def new_path(options = {}) def new_path(options = {})
......
...@@ -13,8 +13,8 @@ class InstanceClusterablePresenter < ClusterablePresenter ...@@ -13,8 +13,8 @@ class InstanceClusterablePresenter < ClusterablePresenter
end end
override :index_path override :index_path
def index_path def index_path(options = {})
admin_clusters_path admin_clusters_path(options)
end end
override :new_path override :new_path
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
= link_to _('More information'), help_page_path('user/group/clusters/index', anchor: 'cluster-precedence') = link_to _('More information'), help_page_path('user/group/clusters/index', anchor: 'cluster-precedence')
- if Feature.enabled?(:clusters_list_redesign) - if Feature.enabled?(:clusters_list_redesign)
#js-clusters-list-app{ data: { endpoint: 'todo/add/endpoint' } } #js-clusters-list-app{ data: { endpoint: clusterable.index_path(format: :json) } }
- else - else
.clusters-table.js-clusters-list .clusters-table.js-clusters-list
.gl-responsive-table-row.table-row-header{ role: "row" } .gl-responsive-table-row.table-row-header{ role: "row" }
......
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