Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imp(notifications): add rule form endpoint validation #655

Merged
merged 3 commits into from
Feb 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 46 additions & 18 deletions src/components/project/settings/NotificationsAddRule.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,26 @@
{{ $t('projects.settings.notifications.sectionWhereToReceive') }}
</div>
<div class="grid-form__section-content">
<section>
<FormTextFieldset
v-model="form.channels.telegram.endpoint"
:label="$t('projects.settings.notifications.telegram')"
:description="$t('projects.settings.notifications.telegramDescription')"
:hidden="!form.channels.telegram.isEnabled"
:is-invalid="!isChannelEndpointValid('telegram') && endpointShouldBeValidated.telegram"
placeholder="https://notify.bot.codex.so/u/XXXXXXXXXXXX"
/>
<UiCheckbox
v-model="form.channels.telegram.isEnabled"
/>
</section>
<section>
<FormTextFieldset
v-model="form.channels.email.endpoint"
:label="$t('projects.settings.notifications.email')"
:description="$t('projects.settings.notifications.emailDescription')"
:hidden="!form.channels.email.isEnabled"
:is-invalid="!isChannelEndpointValid('email')"
:is-invalid="!isChannelEndpointValid('email') && endpointShouldBeValidated.email"
placeholder="[email protected]"
/>
<UiCheckbox
Expand All @@ -27,26 +40,13 @@
:label="$t('projects.settings.notifications.slack')"
:description="$t('projects.settings.notifications.slackDescription')"
:hidden="!form.channels.slack.isEnabled"
:is-invalid="!isChannelEndpointValid('slack')"
:is-invalid="!isChannelEndpointValid('slack') && endpointShouldBeValidated.slack"
placeholder="Webhook App endpoint"
/>
<UiCheckbox
v-model="form.channels.slack.isEnabled"
/>
</section>
<section>
<FormTextFieldset
v-model="form.channels.telegram.endpoint"
:label="$t('projects.settings.notifications.telegram')"
:description="$t('projects.settings.notifications.telegramDescription')"
:hidden="!form.channels.telegram.isEnabled"
:is-invalid="!isChannelEndpointValid('telegram')"
placeholder="@hawkso_bot endpoint"
/>
<UiCheckbox
v-model="form.channels.telegram.isEnabled"
/>
</section>
</div>
</section>
<section class="grid-form__section">
Expand Down Expand Up @@ -180,6 +180,25 @@ export default Vue.extend({
receiveTypesEnum: typeof ReceiveTypes,
selectedThreshold: string,
selectedThresholdPeriod: CustomSelectOption,
/**
* Object that represents displaying of the validation state of each endpoint
*/
endpointShouldBeValidated: {
/**
* Flag that represents, if validation state of the telegram endpoint should be displayed in textfield state
*/
telegram: boolean,

/**
* Flag that represents, if validation state of the slack endpoint should be displayed in textfield state
*/
slack: boolean,

/**
* Flag that represents, if validation state of the email endpoint should be displayed in textfield state
*/
email: boolean,
},
} {
const selectedThreshold = '100';
const selectedThresholdPeriod: CustomSelectOption = {
Expand All @@ -195,15 +214,15 @@ export default Vue.extend({
form: {
projectId: this.projectId,
channels: {
email: {
telegram: {
endpoint: '',
isEnabled: true,
},
slack: {
email: {
endpoint: '',
isEnabled: false,
},
telegram: {
slack: {
endpoint: '',
isEnabled: false,
},
Expand Down Expand Up @@ -262,6 +281,11 @@ export default Vue.extend({

selectedThreshold,
selectedThresholdPeriod,
endpointShouldBeValidated: {
telegram: false,
slack: false,
email: false
},
};
},
computed: {
Expand Down Expand Up @@ -414,6 +438,10 @@ export default Vue.extend({
* Validate saved form fields and return valid-status
*/
validateForm(): boolean {
this.endpointShouldBeValidated.telegram = this.form.channels.telegram!.isEnabled;
this.endpointShouldBeValidated.slack = this.form.channels.slack!.isEnabled;
this.endpointShouldBeValidated.email = this.form.channels.email!.isEnabled;

let allChannelsValid = true;

/**
Expand Down
Loading