Commit 182c9fd0 authored by Alexander Turinske's avatar Alexander Turinske

Fix loading performance of policies list

- do not wait for environments request to show policies list
- add busy state to policies list
- update tests
parent 3e15314f
<script> <script>
import { GlFormGroup, GlDropdown, GlDropdownItem } from '@gitlab/ui'; import { GlFormGroup, GlDropdown, GlDropdownItem } from '@gitlab/ui';
import { mapActions, mapGetters, mapState } from 'vuex'; import { mapActions, mapGetters, mapState } from 'vuex';
import { ALL_ENVIRONMENT_NAME } from '../constants'; import { ALL_ENVIRONMENT_NAME, LOADING_TEXT } from '../constants';
export default { export default {
components: { components: {
...@@ -17,12 +17,20 @@ export default { ...@@ -17,12 +17,20 @@ export default {
}, },
}, },
computed: { computed: {
...mapState('threatMonitoring', ['environments', 'currentEnvironmentId', 'allEnvironments']), ...mapState('threatMonitoring', [
'environments',
'currentEnvironmentId',
'allEnvironments',
'isLoadingEnvironments',
]),
...mapGetters('threatMonitoring', ['currentEnvironmentName', 'canChangeEnvironment']), ...mapGetters('threatMonitoring', ['currentEnvironmentName', 'canChangeEnvironment']),
environmentName() { environmentName() {
return this.allEnvironments && this.includeAll if (this.isLoadingEnvironments) {
? ALL_ENVIRONMENT_NAME return LOADING_TEXT;
: this.currentEnvironmentName; } else if (this.allEnvironments && this.includeAll) {
return ALL_ENVIRONMENT_NAME;
}
return this.currentEnvironmentName;
}, },
}, },
methods: { methods: {
...@@ -45,16 +53,18 @@ export default { ...@@ -45,16 +53,18 @@ export default {
toggle-class="gl-truncate" toggle-class="gl-truncate"
:text="environmentName" :text="environmentName"
:disabled="!canChangeEnvironment" :disabled="!canChangeEnvironment"
:loading="isLoadingEnvironments"
> >
<gl-dropdown-item <gl-dropdown-item
v-for="environment in environments" v-for="environment in environments"
:key="environment.id" :key="environment.id"
@click="setCurrentEnvironmentId(environment.id)" @click="setCurrentEnvironmentId(environment.id)"
>{{ environment.name }}</gl-dropdown-item
> >
<gl-dropdown-item v-if="includeAll" @click="setAllEnvironments">{{ {{ environment.name }}
$options.ALL_ENVIRONMENT_NAME </gl-dropdown-item>
}}</gl-dropdown-item> <gl-dropdown-item v-if="includeAll" @click="setAllEnvironments">
{{ $options.ALL_ENVIRONMENT_NAME }}
</gl-dropdown-item>
</gl-dropdown> </gl-dropdown>
</gl-form-group> </gl-form-group>
</template> </template>
<script> <script>
import { GlAlert, GlIcon, GlLink, GlSprintf, GlTable, GlTooltipDirective } from '@gitlab/ui'; import {
GlAlert,
GlIcon,
GlLink,
GlLoadingIcon,
GlSprintf,
GlTable,
GlTooltipDirective,
} from '@gitlab/ui';
import { mapState, mapGetters } from 'vuex'; import { mapState, mapGetters } from 'vuex';
import { PREDEFINED_NETWORK_POLICIES } from 'ee/threat_monitoring/constants'; import { PREDEFINED_NETWORK_POLICIES } from 'ee/threat_monitoring/constants';
import createFlash from '~/flash'; import createFlash from '~/flash';
...@@ -37,6 +45,7 @@ export default { ...@@ -37,6 +45,7 @@ export default {
GlAlert, GlAlert,
GlIcon, GlIcon,
GlLink, GlLink,
GlLoadingIcon,
GlSprintf, GlSprintf,
GlTable, GlTable,
EnvironmentPicker, EnvironmentPicker,
...@@ -81,9 +90,7 @@ export default { ...@@ -81,9 +90,7 @@ export default {
}, },
error: createPolicyFetchError, error: createPolicyFetchError,
skip() { skip() {
return ( return !this.hasEnvironment || !this.shouldShowNetworkPolicies;
!this.hasEnvironment || this.isLoadingEnvironments || !this.shouldShowNetworkPolicies
);
}, },
}, },
scanExecutionPolicies: { scanExecutionPolicies: {
...@@ -108,11 +115,7 @@ export default { ...@@ -108,11 +115,7 @@ export default {
}; };
}, },
computed: { computed: {
...mapState('threatMonitoring', [ ...mapState('threatMonitoring', ['currentEnvironmentId', 'allEnvironments']),
'currentEnvironmentId',
'allEnvironments',
'isLoadingEnvironments',
]),
...mapGetters('threatMonitoring', ['currentEnvironmentGid']), ...mapGetters('threatMonitoring', ['currentEnvironmentGid']),
allPolicyTypes() { allPolicyTypes() {
return { return {
...@@ -142,7 +145,6 @@ export default { ...@@ -142,7 +145,6 @@ export default {
}, },
isLoadingPolicies() { isLoadingPolicies() {
return ( return (
this.isLoadingEnvironments ||
this.$apollo.queries.networkPolicies.loading || this.$apollo.queries.networkPolicies.loading ||
this.$apollo.queries.scanExecutionPolicies.loading this.$apollo.queries.scanExecutionPolicies.loading
); );
...@@ -317,6 +319,10 @@ export default { ...@@ -317,6 +319,10 @@ export default {
{{ getTimeAgoString(value.item.updatedAt) }} {{ getTimeAgoString(value.item.updatedAt) }}
</template> </template>
<template #table-busy>
<gl-loading-icon size="lg" />
</template>
<template #empty> <template #empty>
<no-policies-empty-state :has-existing-policies="hasExistingPolicies" /> <no-policies-empty-state :has-existing-policies="hasExistingPolicies" />
</template> </template>
......
import { s__ } from '~/locale'; import { __, s__ } from '~/locale';
export const DEFAULT_ASSIGNED_POLICY_PROJECT = { fullPath: '', branch: '' }; export const DEFAULT_ASSIGNED_POLICY_PROJECT = { fullPath: '', branch: '' };
export const INVALID_CURRENT_ENVIRONMENT_NAME = ''; export const LOADING_TEXT = __('Loading...');
export const INVALID_CURRENT_ENVIRONMENT_NAME = '-';
export const PREDEFINED_NETWORK_POLICIES = [ export const PREDEFINED_NETWORK_POLICIES = [
{ {
......
...@@ -3,6 +3,7 @@ import { shallowMount } from '@vue/test-utils'; ...@@ -3,6 +3,7 @@ import { shallowMount } from '@vue/test-utils';
import EnvironmentPicker from 'ee/threat_monitoring/components/environment_picker.vue'; import EnvironmentPicker from 'ee/threat_monitoring/components/environment_picker.vue';
import { import {
INVALID_CURRENT_ENVIRONMENT_NAME, INVALID_CURRENT_ENVIRONMENT_NAME,
LOADING_TEXT,
ALL_ENVIRONMENT_NAME, ALL_ENVIRONMENT_NAME,
} from 'ee/threat_monitoring/constants'; } from 'ee/threat_monitoring/constants';
import createStore from 'ee/threat_monitoring/store'; import createStore from 'ee/threat_monitoring/store';
...@@ -40,10 +41,6 @@ describe('EnvironmentPicker component', () => { ...@@ -40,10 +41,6 @@ describe('EnvironmentPicker component', () => {
factory(); factory();
}); });
it('has text set to the INVALID_CURRENT_ENVIRONMENT_NAME', () => {
expect(findEnvironmentsDropdown().attributes().text).toBe(INVALID_CURRENT_ENVIRONMENT_NAME);
});
it('has no dropdown items', () => { it('has no dropdown items', () => {
expect(findEnvironmentsDropdownItems()).toHaveLength(0); expect(findEnvironmentsDropdownItems()).toHaveLength(0);
}); });
...@@ -99,13 +96,19 @@ describe('EnvironmentPicker component', () => { ...@@ -99,13 +96,19 @@ describe('EnvironmentPicker component', () => {
}); });
describe.each` describe.each`
context | isLoadingEnvironments | isLoadingNetworkPolicyStatistics | environments context | isLoadingEnvironments | isLoadingNetworkPolicyStatistics | environments | text | loadingState
${'environments are loading'} | ${true} | ${false} | ${mockEnvironments} ${'environments are loading'} | ${true} | ${false} | ${mockEnvironments} | ${LOADING_TEXT} | ${'true'}
${'NetPol statistics are loading'} | ${false} | ${true} | ${mockEnvironments} ${'NetPol statistics are loading'} | ${false} | ${true} | ${mockEnvironments} | ${INVALID_CURRENT_ENVIRONMENT_NAME} | ${undefined}
${'there are no environments'} | ${false} | ${false} | ${[]} ${'there are no environments'} | ${false} | ${false} | ${[]} | ${INVALID_CURRENT_ENVIRONMENT_NAME} | ${undefined}
`( `(
'given $context', 'given $context',
({ isLoadingEnvironments, isLoadingNetworkPolicyStatistics, environments }) => { ({
isLoadingEnvironments,
isLoadingNetworkPolicyStatistics,
environments,
text,
loadingState,
}) => {
beforeEach(() => { beforeEach(() => {
factory({ factory({
environments, environments,
...@@ -118,6 +121,8 @@ describe('EnvironmentPicker component', () => { ...@@ -118,6 +121,8 @@ describe('EnvironmentPicker component', () => {
it('disables the environments dropdown', () => { it('disables the environments dropdown', () => {
expect(findEnvironmentsDropdown().attributes('disabled')).toBe('true'); expect(findEnvironmentsDropdown().attributes('disabled')).toBe('true');
expect(findEnvironmentsDropdown().attributes('text')).toBe(text);
expect(findEnvironmentsDropdown().attributes('loading')).toBe(loadingState);
}); });
}, },
); );
......
...@@ -321,25 +321,6 @@ describe('PoliciesList component', () => { ...@@ -321,25 +321,6 @@ describe('PoliciesList component', () => {
}); });
}); });
describe('given loading environment', () => {
beforeEach(() => {
mountWrapper({
propsData: {
hasEnvironment: true,
},
state: {
threatMonitoring: {
isLoadingEnvironments: true,
},
},
});
});
it('does not make a request for network policies', () => {
expect(networkPoliciesSpy).not.toHaveBeenCalled();
});
});
describe('given no environments', () => { describe('given no environments', () => {
beforeEach(() => { beforeEach(() => {
mountWrapper({ mountWrapper({
......
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