Commit f8384ca0 authored by Ezekiel Kigbo's avatar Ezekiel Kigbo

Merge branch 'threat-monitoring-tabs' into 'master'

Update Threat Monitoring page

See merge request gitlab-org/gitlab!42541
parents afb033af 574602a6
...@@ -161,7 +161,13 @@ export default { ...@@ -161,7 +161,13 @@ export default {
</header> </header>
<gl-tabs> <gl-tabs>
<gl-tab :title="s__('ThreatMonitoring|Overview')"> <gl-tab ref="networkPolicyTab" :title="s__('ThreatMonitoring|Policies')">
<network-policy-list
:documentation-path="documentationPath"
:new-policy-path="newPolicyPath"
/>
</gl-tab>
<gl-tab :title="s__('ThreatMonitoring|Statistics')">
<threat-monitoring-filters /> <threat-monitoring-filters />
<threat-monitoring-section <threat-monitoring-section
...@@ -196,12 +202,6 @@ export default { ...@@ -196,12 +202,6 @@ export default {
documentation-anchor="container-network-policy" documentation-anchor="container-network-policy"
/> />
</gl-tab> </gl-tab>
<gl-tab ref="networkPolicyTab" :title="s__('ThreatMonitoring|Policies')">
<network-policy-list
:documentation-path="documentationPath"
:new-policy-path="newPolicyPath"
/>
</gl-tab>
</gl-tabs> </gl-tabs>
</section> </section>
</template> </template>
...@@ -91,8 +91,16 @@ export default { ...@@ -91,8 +91,16 @@ export default {
: ''; : '';
}, },
}, },
watch: {
currentEnvironmentId(envId) {
this.fetchPolicies(envId);
},
},
created() {
this.fetchPolicies(this.currentEnvironmentId);
},
methods: { methods: {
...mapActions('networkPolicies', ['createPolicy', 'updatePolicy']), ...mapActions('networkPolicies', ['fetchPolicies', 'createPolicy', 'updatePolicy']),
getTimeAgoString(creationTimestamp) { getTimeAgoString(creationTimestamp) {
if (!creationTimestamp) return ''; if (!creationTimestamp) return '';
return getTimeago().format(creationTimestamp); return getTimeago().format(creationTimestamp);
......
<script> <script>
import { mapState } from 'vuex'; import { mapState, mapActions } from 'vuex';
import { GlEmptyState } from '@gitlab/ui'; import { GlEmptyState } from '@gitlab/ui';
import { setUrlFragment } from '~/lib/utils/url_utility'; import { setUrlFragment } from '~/lib/utils/url_utility';
import LoadingSkeleton from './loading_skeleton.vue'; import LoadingSkeleton from './loading_skeleton.vue';
...@@ -60,6 +60,7 @@ export default { ...@@ -60,6 +60,7 @@ export default {
}, },
}, },
computed: { computed: {
...mapState('threatMonitoring', ['currentEnvironmentId', 'currentTimeWindow']),
...mapState({ ...mapState({
isLoading(state) { isLoading(state) {
return state[this.storeNamespace].isLoadingStatistics; return state[this.storeNamespace].isLoadingStatistics;
...@@ -96,6 +97,24 @@ export default { ...@@ -96,6 +97,24 @@ export default {
return setUrlFragment(this.documentationPath, this.documentationAnchor); return setUrlFragment(this.documentationPath, this.documentationAnchor);
}, },
}, },
watch: {
currentEnvironmentId() {
this.fetchStatistics();
},
currentTimeWindow() {
this.fetchStatistics();
},
},
created() {
this.fetchStatistics();
},
methods: {
...mapActions({
fetchStatistics(dispatch) {
return dispatch(`${this.storeNamespace}/fetchStatistics`);
},
}),
},
}; };
</script> </script>
......
...@@ -54,21 +54,12 @@ export const fetchEnvironments = ({ state, dispatch }) => { ...@@ -54,21 +54,12 @@ export const fetchEnvironments = ({ state, dispatch }) => {
.catch(() => dispatch('receiveEnvironmentsError')); .catch(() => dispatch('receiveEnvironmentsError'));
}; };
export const setCurrentEnvironmentId = ({ commit, dispatch }, environmentId) => { export const setCurrentEnvironmentId = ({ commit }, environmentId) => {
commit(types.SET_CURRENT_ENVIRONMENT_ID, environmentId); commit(types.SET_CURRENT_ENVIRONMENT_ID, environmentId);
dispatch(`threatMonitoringWaf/fetchStatistics`, null, { root: true });
dispatch(`threatMonitoringNetworkPolicy/fetchStatistics`, null, {
root: true,
});
dispatch(`networkPolicies/fetchPolicies`, environmentId, { root: true });
}; };
export const setCurrentTimeWindow = ({ commit, dispatch }, timeWindow) => { export const setCurrentTimeWindow = ({ commit }, timeWindow) => {
commit(types.SET_CURRENT_TIME_WINDOW, timeWindow.name); commit(types.SET_CURRENT_TIME_WINDOW, timeWindow.name);
dispatch(`threatMonitoringWaf/fetchStatistics`, null, { root: true });
dispatch(`threatMonitoringNetworkPolicy/fetchStatistics`, null, {
root: true,
});
}; };
export const setAllEnvironments = ({ commit, dispatch }) => { export const setAllEnvironments = ({ commit, dispatch }) => {
......
---
title: Update Threat Monitoring page
merge_request: 42541
author:
type: changed
...@@ -6,10 +6,10 @@ exports[`NetworkPolicyList component renders policies table 1`] = ` ...@@ -6,10 +6,10 @@ exports[`NetworkPolicyList component renders policies table 1`] = `
<table <table
aria-busy="false" aria-busy="false"
aria-colcount="3" aria-colcount="3"
aria-describedby="__BVID__359__caption_" aria-describedby="__BVID__432__caption_"
aria-multiselectable="false" aria-multiselectable="false"
class="table b-table gl-table table-hover b-table-stacked-md b-table-selectable b-table-select-single" class="table b-table gl-table table-hover b-table-stacked-md b-table-selectable b-table-select-single"
id="__BVID__359" id="__BVID__432"
role="table" role="table"
> >
<!----> <!---->
......
...@@ -70,6 +70,17 @@ describe('NetworkPolicyList component', () => { ...@@ -70,6 +70,17 @@ describe('NetworkPolicyList component', () => {
expect(wrapper.find(PolicyDrawer).exists()).toBe(false); expect(wrapper.find(PolicyDrawer).exists()).toBe(false);
}); });
it('fetches policies', () => {
expect(store.dispatch).toHaveBeenCalledWith('networkPolicies/fetchPolicies', -1);
});
it('fetches policies on environment change', async () => {
store.dispatch.mockReset();
await store.commit('threatMonitoring/SET_CURRENT_ENVIRONMENT_ID', 2);
expect(store.dispatch).toHaveBeenCalledWith('networkPolicies/fetchPolicies', 2);
});
it('does not render edit button', () => { it('does not render edit button', () => {
expect(wrapper.find('[data-testid="edit-button"]').exists()).toBe(false); expect(wrapper.find('[data-testid="edit-button"]').exists()).toBe(false);
}); });
......
...@@ -32,6 +32,8 @@ describe('ThreatMonitoringSection component', () => { ...@@ -32,6 +32,8 @@ describe('ThreatMonitoringSection component', () => {
...state, ...state,
}); });
jest.spyOn(store, 'dispatch').mockImplementation(() => Promise.resolve());
wrapper = shallowMount(ThreatMonitoringSection, { wrapper = shallowMount(ThreatMonitoringSection, {
propsData: { propsData: {
storeNamespace: 'threatMonitoringWaf', storeNamespace: 'threatMonitoringWaf',
...@@ -110,6 +112,24 @@ describe('ThreatMonitoringSection component', () => { ...@@ -110,6 +112,24 @@ describe('ThreatMonitoringSection component', () => {
expect(findChartEmptyState().exists()).toBe(false); expect(findChartEmptyState().exists()).toBe(false);
}); });
it('fetches statistics', () => {
expect(store.dispatch).toHaveBeenCalledWith('threatMonitoringWaf/fetchStatistics');
});
it('fetches statistics on environment change', async () => {
store.dispatch.mockReset();
await store.commit('threatMonitoring/SET_CURRENT_ENVIRONMENT_ID', 2);
expect(store.dispatch).toHaveBeenCalledWith('threatMonitoringWaf/fetchStatistics');
});
it('fetches statistics on time window change', async () => {
store.dispatch.mockReset();
await store.commit('threatMonitoring/SET_CURRENT_TIME_WINDOW', 'hour');
expect(store.dispatch).toHaveBeenCalledWith('threatMonitoringWaf/fetchStatistics');
});
describe('given the statistics are loading', () => { describe('given the statistics are loading', () => {
beforeEach(() => { beforeEach(() => {
factory({ factory({
......
...@@ -202,39 +202,26 @@ describe('Threat Monitoring actions', () => { ...@@ -202,39 +202,26 @@ describe('Threat Monitoring actions', () => {
describe('setCurrentEnvironmentId', () => { describe('setCurrentEnvironmentId', () => {
const environmentId = 1; const environmentId = 1;
it('commits the SET_CURRENT_ENVIRONMENT_ID mutation and dispatches WAF, Network Policy statistics fetch actions and policy fetch action', () => it('commits the SET_CURRENT_ENVIRONMENT_ID mutation', () =>
testAction( testAction(
actions.setCurrentEnvironmentId, actions.setCurrentEnvironmentId,
environmentId, environmentId,
state, state,
[{ type: types.SET_CURRENT_ENVIRONMENT_ID, payload: environmentId }], [{ type: types.SET_CURRENT_ENVIRONMENT_ID, payload: environmentId }],
[ [],
{ type: 'threatMonitoringWaf/fetchStatistics', payload: null },
{
type: 'threatMonitoringNetworkPolicy/fetchStatistics',
payload: null,
},
{ type: 'networkPolicies/fetchPolicies', payload: environmentId },
],
)); ));
}); });
describe('setCurrentTimeWindow', () => { describe('setCurrentTimeWindow', () => {
const timeWindow = { name: 'foo' }; const timeWindow = { name: 'foo' };
it('commits the SET_CURRENT_TIME_WINDOW mutation and dispatches WAF and Network Policy fetch actions', () => it('commits the SET_CURRENT_TIME_WINDOW mutation', () =>
testAction( testAction(
actions.setCurrentTimeWindow, actions.setCurrentTimeWindow,
timeWindow, timeWindow,
state, state,
[{ type: types.SET_CURRENT_TIME_WINDOW, payload: timeWindow.name }], [{ type: types.SET_CURRENT_TIME_WINDOW, payload: timeWindow.name }],
[ [],
{ type: 'threatMonitoringWaf/fetchStatistics', payload: null },
{
type: 'threatMonitoringNetworkPolicy/fetchStatistics',
payload: null,
},
],
)); ));
}); });
......
...@@ -26299,9 +26299,6 @@ msgstr "" ...@@ -26299,9 +26299,6 @@ msgstr ""
msgid "ThreatMonitoring|Operations Per Second" msgid "ThreatMonitoring|Operations Per Second"
msgstr "" msgstr ""
msgid "ThreatMonitoring|Overview"
msgstr ""
msgid "ThreatMonitoring|Packet Activity" msgid "ThreatMonitoring|Packet Activity"
msgstr "" msgstr ""
...@@ -26320,6 +26317,9 @@ msgstr "" ...@@ -26320,6 +26317,9 @@ msgstr ""
msgid "ThreatMonitoring|Something went wrong, unable to fetch statistics" msgid "ThreatMonitoring|Something went wrong, unable to fetch statistics"
msgstr "" msgstr ""
msgid "ThreatMonitoring|Statistics"
msgstr ""
msgid "ThreatMonitoring|The firewall is not installed or has been disabled. To view this data, ensure the web application firewall is installed and enabled for your cluster." msgid "ThreatMonitoring|The firewall is not installed or has been disabled. To view this data, ensure the web application firewall is installed and enabled for your cluster."
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