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

Fix conditions for trigger validation #420

Merged
merged 4 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
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
10 changes: 4 additions & 6 deletions src/Containers/TriggerAddContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ const TriggerAddContainer = (props: Props) => {
const saveTrigger = useSaveTrigger(props.moiraApi, dispatch, props.history);

const handleSubmit = async () =>
trigger?.is_remote ? saveTrigger(trigger) : validateTrigger(trigger);
trigger?.trigger_source == TriggerSource.GRAPHITE_LOCAL
? validateTrigger(trigger)
: saveTrigger(trigger);

const handleChange = (update: Partial<Trigger>, targetIndex?: number) => {
if (!trigger) {
Expand All @@ -87,11 +89,7 @@ const TriggerAddContainer = (props: Props) => {
setTrigger({ ...trigger, ...update });
dispatch(setError(null));

if (update.is_remote) {
dispatch(setIsSaveButtonDisabled(false));
}

if (update.targets) {
if (update.targets || update?.trigger_source) {
dispatch(setIsSaveButtonDisabled(false));
dispatch(resetTargetValidationState(targetIndex));
}
Expand Down
12 changes: 5 additions & 7 deletions src/Containers/TriggerDuplicateContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Button } from "@skbkontur/react-ui/components/Button";
import { useSaveTrigger } from "../hooks/useSaveTrigger";
import MoiraApi from "../Api/MoiraApi";
import { withMoiraApi } from "../Api/MoiraApiInjection";
import { Trigger } from "../Domain/Trigger";
import TriggerSource, { Trigger } from "../Domain/Trigger";
import { getPageLink } from "../Domain/Global";
import { Config } from "../Domain/Config";
import RouterLink from "../Components/RouterLink/RouterLink";
Expand Down Expand Up @@ -58,7 +58,9 @@ const TriggerDuplicateContainer = (props: Props) => {
};

const handleSubmit = async () =>
trigger?.is_remote ? saveTrigger(trigger) : validateTrigger(trigger);
trigger?.trigger_source === TriggerSource.GRAPHITE_LOCAL
? validateTrigger(trigger)
: saveTrigger(trigger);

const handleChange = (update: Partial<Trigger>, targetIndex?: number) => {
if (!trigger) {
Expand All @@ -68,11 +70,7 @@ const TriggerDuplicateContainer = (props: Props) => {
setTrigger({ ...trigger, ...update });
dispatch(setError(null));

if (update.is_remote) {
dispatch(setIsSaveButtonDisabled(false));
}

if (update.targets) {
if (update.targets || update?.trigger_source) {
dispatch(setIsSaveButtonDisabled(false));
dispatch(resetTargetValidationState(targetIndex));
}
Expand Down
12 changes: 5 additions & 7 deletions src/Containers/TriggerEditContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import TrashIcon from "@skbkontur/react-icons/Trash";
import { useSaveTrigger } from "../hooks/useSaveTrigger";
import MoiraApi from "../Api/MoiraApi";
import { withMoiraApi } from "../Api/MoiraApiInjection";
import type { Trigger } from "../Domain/Trigger";
import { Trigger, TriggerSource } from "../Domain/Trigger";
import { getPageLink } from "../Domain/Global";
import { Config } from "../Domain/Config";
import RouterLink from "../Components/RouterLink/RouterLink";
Expand Down Expand Up @@ -44,7 +44,9 @@ const TriggerEditContainer = (props: Props) => {
const saveTrigger = useSaveTrigger(props.moiraApi, dispatch, props.history);

const handleSubmit = async () =>
trigger?.is_remote ? saveTrigger(trigger) : validateTrigger(trigger);
trigger?.trigger_source === TriggerSource.GRAPHITE_LOCAL
? validateTrigger(trigger)
: saveTrigger(trigger);

const handleChange = (update: Partial<Trigger>, targetIndex?: number) => {
if (!trigger) {
Expand All @@ -54,11 +56,7 @@ const TriggerEditContainer = (props: Props) => {
setTrigger({ ...trigger, ...update });
dispatch(setError(null));

if (update.is_remote) {
dispatch(setIsSaveButtonDisabled(false));
}

if (update.targets) {
if (update.targets || update?.trigger_source) {
dispatch(setIsSaveButtonDisabled(false));
dispatch(resetTargetValidationState(targetIndex));
}
Expand Down
1 change: 0 additions & 1 deletion src/Domain/Trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export type Trigger = {
[target_id: string]: boolean;
};
mute_new_metrics: boolean;
is_remote: boolean;
};

export type TriggerList = {
Expand Down