Simplify pending URLs computation

parent 09ed16d8
...@@ -12,7 +12,7 @@ import ProfilesList from './dast_profiles_list.vue'; ...@@ -12,7 +12,7 @@ import ProfilesList from './dast_profiles_list.vue';
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin'; import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import { fetchPolicies } from '~/lib/graphql'; import { fetchPolicies } from '~/lib/graphql';
const { PENDING, INPROGRESS, FAILED, PASSED } = DAST_SITE_VALIDATION_STATUS; const { PENDING, INPROGRESS, FAILED } = DAST_SITE_VALIDATION_STATUS;
export default { export default {
components: { components: {
...@@ -34,14 +34,15 @@ export default { ...@@ -34,14 +34,15 @@ export default {
}, },
pollInterval: DAST_SITE_VALIDATION_POLLING_INTERVAL, pollInterval: DAST_SITE_VALIDATION_POLLING_INTERVAL,
skip() { skip() {
return !this.urlsPendingValidation.length; return (
!this.glFeatures.securityOnDemandScansSiteValidation || !this.urlsPendingValidation.length
);
}, },
result(response) { result({
const {
data: { data: {
validations: { nodes = [] }, validations: { nodes = [] },
}, },
} = response; }) {
const store = this.$apolloProvider.defaultClient; const store = this.$apolloProvider.defaultClient;
nodes.forEach(({ normalizedTargetUrl, status }) => { nodes.forEach(({ normalizedTargetUrl, status }) => {
updateSiteProfilesStatuses({ updateSiteProfilesStatuses({
...@@ -50,11 +51,6 @@ export default { ...@@ -50,11 +51,6 @@ export default {
status, status,
store, store,
}); });
if ([PASSED, FAILED].includes(status)) {
this.urlsPendingValidation = this.urlsPendingValidation.filter(
url => url !== normalizedTargetUrl,
);
}
}); });
}, },
}, },
...@@ -76,26 +72,20 @@ export default { ...@@ -76,26 +72,20 @@ export default {
data() { data() {
return { return {
validatingProfile: null, validatingProfile: null,
urlsPendingValidation: [],
}; };
}, },
statuses: DAST_SITE_VALIDATION_STATUS_PROPS, statuses: DAST_SITE_VALIDATION_STATUS_PROPS,
watch: { computed: {
profiles: { urlsPendingValidation() {
immediate: true, return this.profiles.reduce((acc, { validationStatus, normalizedTargetUrl }) => {
handler(profiles = []) {
if (!this.glFeatures.securityOnDemandScansSiteValidation) {
return;
}
profiles.forEach(({ validationStatus, normalizedTargetUrl }) => {
if ( if (
[PENDING, INPROGRESS].includes(validationStatus) && [PENDING, INPROGRESS].includes(validationStatus) &&
!this.urlsPendingValidation.includes(normalizedTargetUrl) !acc.includes(normalizedTargetUrl)
) { ) {
this.urlsPendingValidation.push(normalizedTargetUrl); return [...acc, normalizedTargetUrl];
} }
}); return acc;
}, }, []);
}, },
}, },
methods: { methods: {
......
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