Skip to content
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
5 changes: 5 additions & 0 deletions changelog/unreleased/issue-14480.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type = "fixed"
message = "Keep the share settings of an event definition populated when navigating between wizard steps."

issues = ["Graylog2/graylog-plugin-enterprise#14480"]
pulls = ["26990"]
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const ShareForm = ({ onChange, eventDefinition }: Props) => {
entityType="event_definition"
entityTitle=""
dependenciesGRN={[...streamDependenciesGRN, ...notificationDependenciesGRN]}
defaultSharePayload={eventDefinition.share_request}
/>
</Col>
</Row>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import type { SyntheticEvent } from 'react';

import type { StepsType } from 'components/common/Wizard';
import type { EntitySharePayload } from 'actions/permissions/EntityShareActions';
import type { LookupTableParameterJson } from 'views/logic/parameters/LookupTableParameter';
import { SYSTEM_EVENT_DEFINITION_TYPE } from 'components/event-definitions/constants';

Expand Down Expand Up @@ -111,6 +112,7 @@ export type EventDefinition = {
matched_at: string;
scheduler: Scheduler;
event_summary_template: string;
share_request?: EntitySharePayload;
};

export type EventDefinitionFormControlsProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,40 @@ describe('EntityCreateShareFormGroup', () => {
render(<SUT />);

await waitFor(() => {
expect(EntityShareActions.prepare).toHaveBeenCalledWith(mockEntity.entityType, '', mockEntity.entityId, {});
expect(EntityShareActions.prepare).toHaveBeenCalledWith(mockEntity.entityType, '', mockEntity.entityId, {
prepare_request: null,
});
});
});

it('restores a previously made selection from the default share payload', async () => {
const selected_grantee_capabilities = createEntityShareState.selectedGranteeCapabilities.merge({
[everyone.id]: viewer.id,
});

render(<SUT defaultSharePayload={{ selected_grantee_capabilities }} />);

await waitFor(() => {
expect(EntityShareActions.prepare).toHaveBeenCalledWith(mockEntity.entityType, '', mockEntity.entityId, {
selected_grantee_capabilities,
prepare_request: null,
});
});
});

it('re-runs the dependency check when restoring a selection', async () => {
const selected_grantee_capabilities = createEntityShareState.selectedGranteeCapabilities.merge({
[everyone.id]: viewer.id,
});
const dependenciesGRN = ['grn::::stream:stream-id'];

render(<SUT defaultSharePayload={{ selected_grantee_capabilities }} dependenciesGRN={dependenciesGRN} />);

await waitFor(() => {
expect(EntityShareActions.prepare).toHaveBeenCalledWith(mockEntity.entityType, '', mockEntity.entityId, {
selected_grantee_capabilities,
prepare_request: dependenciesGRN,
});
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
import * as React from 'react';
import { useEffect, useState } from 'react';
import isEmpty from 'lodash/isEmpty';

import type SharedEntity from 'logic/permissions/SharedEntity';
import { useStore } from 'stores/connect';
Expand Down Expand Up @@ -88,9 +87,13 @@ const EntityCreateShareFormGroup = ({

useEffect(() => {
const { selected_collections: _, ...rest } = defaultSharePayload ?? {};
// Restoring a selection has to re-run the dependency check, or the missing dependency
// warnings shown before would silently disappear.
const hasSelection = (rest.selected_grantee_capabilities?.size ?? 0) > 0;
const prepare_request = hasSelection && dependenciesGRN?.length ? dependenciesGRN : null;

EntityShareDomain.prepare(entityType, entityTitle, entityGRN, rest);
}, [entityType, entityTitle, entityGRN, defaultSharePayload]);
EntityShareDomain.prepare(entityType, entityTitle, entityGRN, { ...rest, prepare_request });
}, [entityType, entityTitle, entityGRN, defaultSharePayload, dependenciesGRN]);

const resetSelection = () => {
setDisableSubmit(false);
Expand Down Expand Up @@ -122,7 +125,7 @@ const EntityCreateShareFormGroup = ({

setDisableSubmit(true);

const prepare_request = isEmpty(newSelectedCapabilities) ? null : dependenciesGRN;
const prepare_request = (newSelectedCapabilities?.size ?? 0) > 0 ? dependenciesGRN : null;
const payload: EntitySharePayload = {
selected_grantee_capabilities: newSelectedCapabilities,
prepare_request,
Expand Down Expand Up @@ -198,6 +201,8 @@ const EntityCreateShareFormGroup = ({
availableGrantees={entityShareState.availableGrantees}
/>
{PluggableEntityShareFormGroup && (
/* Resolved from the plugin store at render time and cannot be hoisted. */
/* eslint-disable-next-line react-hooks/static-components */
<PluggableEntityShareFormGroup
entityType={entityType}
onChange={handleAdditionalFormChange}
Expand Down
Loading