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

[frontend] Fix instance triggers subscription (#6313) #6317

Merged
merged 1 commit into from
Mar 13, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { MESSAGING$ } from '../../../../relay/environment';
import { convertEventTypes, convertNotifiers, instanceEventTypesOptions } from '../../../../utils/edition';
import { fieldSpacingContainerStyle } from '../../../../utils/field';
import { deleteNode, insertNode } from '../../../../utils/store';
import useAuth from '../../../../utils/hooks/useAuth';
import { TriggerLiveAddInput, TriggerLiveCreationKnowledgeMutation } from '../../profile/triggers/__generated__/TriggerLiveCreationKnowledgeMutation.graphql';
import { triggerMutationFieldPatch } from '../../profile/triggers/TriggerEditionOverview';
import { instanceTriggerDescription, triggerLiveKnowledgeCreationMutation } from '../../profile/triggers/TriggerLiveCreation';
Expand Down Expand Up @@ -95,14 +96,16 @@ StixCoreObjectQuickSubscriptionContentProps
> = ({ triggerData, instanceId, paginationOptions, instanceName }) => {
const classes = useStyles();
const { t_i18n } = useFormatter();
const { me } = useAuth();
const [open, setOpen] = useState(false);
const [deleting, setDeleting] = useState<boolean>(false);
const [expandedLines, setExpandedLines] = useState<boolean>(false);

const [existingInstanceTriggersData, refetch] = useRefetchableFragment<TriggerQuery, FragmentKey>(stixCoreObjectTriggersFragment, triggerData);

const existingInstanceTriggersEdges = existingInstanceTriggersData?.triggersKnowledge?.edges ?? [];
const triggerUpdate = existingInstanceTriggersEdges.length > 0;
const myInstanceTriggers = existingInstanceTriggersEdges.filter((e) => e.node.recipients?.some((r) => r.id === me.id)) ?? [];
const triggerUpdate = myInstanceTriggers.length > 0;

const [commitAddTrigger] = useMutation<TriggerLiveCreationKnowledgeMutation>(
triggerLiveKnowledgeCreationMutation,
Expand Down Expand Up @@ -392,7 +395,7 @@ StixCoreObjectQuickSubscriptionContentProps
};

const updateInstanceTrigger = () => {
const triggerValues = existingInstanceTriggersEdges
const triggerValues = myInstanceTriggers
.filter((l) => l)
.map((n) => ({
...pick(['id', 'name', 'description', 'filters'], n?.node),
Expand Down
Loading