Skip to content
Snippets Groups Projects

Add custom headers form to streaming audit events

All threads resolved!
4 files
+ 156
21
Compare changes
  • Side-by-side
  • Inline
Files
4
  • - Added automatic row addition when previous roll is filled out
    - Added max limit to row count and message when limit is reached
    - Added delete row functionality (not working 100%)
    - Added ability to disable a row
    - Disabled all active checkboxes for now
    - Styled the headers list as per designs
    - Added tab capture to parent app
@@ -6,13 +6,22 @@ import {
@@ -6,13 +6,22 @@ import {
GlFormCheckbox,
GlFormCheckbox,
GlFormGroup,
GlFormGroup,
GlFormInput,
GlFormInput,
 
GlSprintf,
GlTableLite,
GlTableLite,
} from '@gitlab/ui';
} from '@gitlab/ui';
import createFlash from '~/flash';
import createFlash from '~/flash';
 
import { thWidthPercent } from '~/lib/utils/table_utility';
import externalAuditEventDestinationCreate from '../../graphql/create_external_destination.mutation.graphql';
import externalAuditEventDestinationCreate from '../../graphql/create_external_destination.mutation.graphql';
import { ADD_STREAM_EDITOR_I18N, AUDIT_STREAMS_NETWORK_ERRORS } from '../../constants';
import {
 
ADD_STREAM_EDITOR_I18N,
 
AUDIT_STREAMS_NETWORK_ERRORS,
 
BLANK_CUSTOM_HEADER_OBJECT,
 
CUSTOM_HEADER_INPUT_TYPE,
 
MAX_CUSTOM_HEADERS,
 
} from '../../constants';
const { CREATING_ERROR } = AUDIT_STREAMS_NETWORK_ERRORS;
const { CREATING_ERROR } = AUDIT_STREAMS_NETWORK_ERRORS;
 
export default {
export default {
components: {
components: {
GlAlert,
GlAlert,
@@ -21,6 +30,7 @@ export default {
@@ -21,6 +30,7 @@ export default {
GlFormCheckbox,
GlFormCheckbox,
GlFormGroup,
GlFormGroup,
GlFormInput,
GlFormInput,
 
GlSprintf,
GlTableLite,
GlTableLite,
},
},
inject: ['groupPath', 'showStreamsCustomHeaders'],
inject: ['groupPath', 'showStreamsCustomHeaders'],
@@ -28,9 +38,14 @@ export default {
@@ -28,9 +38,14 @@ export default {
return {
return {
destinationUrl: '',
destinationUrl: '',
loading: false,
loading: false,
customHeaders: [{ name: '', value: '', active: false }],
customHeaders: [{ ...BLANK_CUSTOM_HEADER_OBJECT }],
};
};
},
},
 
computed: {
 
hasMaxCustomHeaders() {
 
return this.customHeaders.length === MAX_CUSTOM_HEADERS;
 
},
 
},
methods: {
methods: {
async addDestinationUrl() {
async addDestinationUrl() {
this.loading = true;
this.loading = true;
@@ -45,7 +60,9 @@ export default {
@@ -45,7 +60,9 @@ export default {
isSingleRequest: true,
isSingleRequest: true,
},
},
});
});
 
const { errors } = data.externalAuditEventDestinationCreate;
const { errors } = data.externalAuditEventDestinationCreate;
 
if (errors.length > 0) {
if (errors.length > 0) {
createFlash({
createFlash({
message: errors[0],
message: errors[0],
@@ -61,13 +78,75 @@ export default {
@@ -61,13 +78,75 @@ export default {
this.loading = false;
this.loading = false;
}
}
},
},
 
isRowFilled(index) {
 
return this.customHeaders[index].name !== '' && this.customHeaders[index].value !== '';
 
},
 
addBlankCustomHeader() {
 
this.customHeaders.push({ ...BLANK_CUSTOM_HEADER_OBJECT });
 
},
 
updateCustomHeader(index, type, value) {
 
switch (type) {
 
case CUSTOM_HEADER_INPUT_TYPE.HEADER:
 
this.customHeaders[index].name = value;
 
 
break;
 
case CUSTOM_HEADER_INPUT_TYPE.VALUE:
 
this.customHeaders[index].value = value;
 
 
break;
 
case CUSTOM_HEADER_INPUT_TYPE.ACTIVE:
 
this.customHeaders[index].active = value;
 
 
break;
 
default:
 
break;
 
}
 
 
// If the maximum custom headers hasn't been reached,
 
// the previous row is filled out
 
// and we're updating the last row in the table
 
// then add a new blank row to the bottom of the table
 
if (
 
!this.hasMaxCustomHeaders &&
 
this.isRowFilled(index) &&
 
this.customHeaders.length === index + 1
 
) {
 
this.addBlankCustomHeader();
 
}
 
},
 
removeCustomHeader(index) {
 
this.customHeaders.splice(index, 1);
 
const headersCount = this.customHeaders.length;
 
 
// Add a new blank row if headers is now empty or the last row is filled out
 
if (headersCount === 0 || this.isRowFilled(headersCount - 1)) {
 
this.addBlankCustomHeader();
 
}
 
},
},
},
i18n: { ...ADD_STREAM_EDITOR_I18N, CREATING_ERROR },
i18n: { ...ADD_STREAM_EDITOR_I18N, CREATING_ERROR },
 
CUSTOM_HEADER_INPUT_TYPE,
 
MAX_CUSTOM_HEADERS,
fields: [
fields: [
{ key: 'name', label: ADD_STREAM_EDITOR_I18N.TABLE_COLUMN_NAME_LABEL },
{
{ key: 'value', label: ADD_STREAM_EDITOR_I18N.TABLE_COLUMN_VALUE_LABEL },
key: 'name',
{ key: 'active', label: ADD_STREAM_EDITOR_I18N.TABLE_COLUMN_ACTIVE_LABEL },
label: ADD_STREAM_EDITOR_I18N.TABLE_COLUMN_NAME_LABEL,
{ key: 'actions', label: '' },
thClass: ['gl-p-3!', thWidthPercent(40)],
 
tdClass: ['gl-p-3!'],
 
},
 
{
 
key: 'value',
 
label: ADD_STREAM_EDITOR_I18N.TABLE_COLUMN_VALUE_LABEL,
 
thClass: ['gl-p-3!', thWidthPercent(50)],
 
tdClass: ['gl-p-3!'],
 
},
 
{
 
key: 'active',
 
label: ADD_STREAM_EDITOR_I18N.TABLE_COLUMN_ACTIVE_LABEL,
 
thClass: ['gl-p-3!', thWidthPercent(5)],
 
tdClass: ['gl-p-3!'],
 
},
 
{ key: 'actions', label: '', thClass: ['gl-p-3!'], tdClass: ['gl-p-3! gl-text-right'] },
],
],
};
};
</script>
</script>
@@ -85,24 +164,49 @@ export default {
@@ -85,24 +164,49 @@ export default {
<gl-form @submit.prevent="addDestinationUrl">
<gl-form @submit.prevent="addDestinationUrl">
<gl-form-group :label="$options.i18n.DESTINATION_URL_LABEL">
<gl-form-group :label="$options.i18n.DESTINATION_URL_LABEL">
<gl-form-input v-model="destinationUrl" :placeholder="$options.i18n.PLACEHOLDER" />
<gl-form-input
 
v-model="destinationUrl"
 
:placeholder="$options.i18n.DESTINATION_URL_PLACEHOLDER"
 
/>
</gl-form-group>
</gl-form-group>
<gl-form-group v-if="showStreamsCustomHeaders" :label="$options.i18n.CUSTOM_HEADERS_LABEL">
<gl-form-group v-if="showStreamsCustomHeaders" :label="$options.i18n.CUSTOM_HEADERS_LABEL">
<gl-table-lite :items="customHeaders" :fields="$options.fields">
<gl-table-lite :items="customHeaders" :fields="$options.fields" primary-key="name">
<template #cell(name)>
<template #cell(name)="{ index, item: { disabled = false } }">
<gl-form-input value="" />
<gl-form-input
 
value=""
 
:placeholder="$options.i18n.HEADER_INPUT_PLACEHOLDER"
 
:disabled="disabled"
 
@input="updateCustomHeader(index, $options.CUSTOM_HEADER_INPUT_TYPE.HEADER, $event)"
 
/>
</template>
</template>
<template #cell(value)>
<template #cell(value)="{ index, item: { disabled = false } }">
<gl-form-input value="" />
<gl-form-input
 
value=""
 
:placeholder="$options.i18n.VALUE_INPUT_PLACEHOLDER"
 
:disabled="disabled"
 
@input="updateCustomHeader(index, $options.CUSTOM_HEADER_INPUT_TYPE.VALUE, $event)"
 
/>
</template>
</template>
<template #cell(active)>
<template #cell(active)="{ index }">
<gl-form-checkbox :checked="false" />
<gl-form-checkbox
 
class="gl-mt-3"
 
:checked="false"
 
:disabled="true"
 
@input="updateCustomHeader(index, $options.CUSTOM_HEADER_INPUT_TYPE.ACTIVE, $event)"
 
/>
</template>
</template>
<template #cell(actions)>
<template #cell(actions)="{ index }">
<gl-button category="tertiary" icon="remove" />
<gl-button category="tertiary" icon="remove" @click="removeCustomHeader(index)" />
</template>
</template>
</gl-table-lite>
</gl-table-lite>
 
<p v-if="hasMaxCustomHeaders" class="gl-mt-5 gl-mb-0 gl-text-gray-500">
 
<gl-sprintf :message="$options.i18n.MAXIMUM_HEADERS_TEXT">
 
<template #number>
 
{{ $options.MAX_CUSTOM_HEADERS }}
 
</template>
 
</gl-sprintf>
 
</p>
</gl-form-group>
</gl-form-group>
<div class="gl-display-flex">
<div class="gl-display-flex">
Loading