Skip to content

Commit

Permalink
[Security Solution][Endpoint] Unify remove artifact from policy messa…
Browse files Browse the repository at this point in the history
…ge and fix back buttons (elastic#124936)

* Updates delete messages for event filters and host isolation exceptions list

* Fixes back buttons when click on view full details. Open create dialog by default from artifacts policy view

* Fixes ts checks
  • Loading branch information
dasansol92 authored Feb 9, 2022
1 parent ed36a13 commit 939bc3d
Show file tree
Hide file tree
Showing 17 changed files with 69 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ describe('Policy details event filter delete modal', () => {
renderResult = mockedContext.render(
<PolicyEventFiltersDeleteModal
policyId={policyId}
policyName="fakeName"
onCancel={onCancel}
exception={exception}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ import { useBulkUpdateEventFilters } from '../hooks';

export const PolicyEventFiltersDeleteModal = ({
policyId,
policyName,
exception,
onCancel,
}: {
policyId: string;
policyName: string;
exception: ExceptionListItemSchema;
onCancel: () => void;
}) => {
Expand All @@ -36,8 +38,8 @@ export const PolicyEventFiltersDeleteModal = ({
text: i18n.translate(
'xpack.securitySolution.endpoint.policy.eventFilters.list.removeDialog.successToastText',
{
defaultMessage: '"{exception}" has been removed from policy',
values: { exception: exception.name },
defaultMessage: '"{eventFilterName}" has been removed from {policyName} policy',
values: { eventFilterName: exception.name, policyName },
}
),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface CommonProps {
}

export const PolicyEventFiltersEmptyUnexisting = memo<CommonProps>(({ policyId, policyName }) => {
const { onClickHandler, toRouteUrl } = useGetLinkTo(policyId, policyName);
const { onClickHandler, toRouteUrl } = useGetLinkTo(policyId, policyName, { show: 'create' });
return (
<EuiPageTemplate template="centeredContent">
<EuiEmptyPrompt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,21 @@ import { useNavigateToAppEventHandler } from '../../../../../../common/hooks/end
import { useAppUrl } from '../../../../../../common/lib/kibana/hooks';
import { getPolicyEventFiltersPath, getEventFiltersListPath } from '../../../../../common/routing';
import { APP_UI_ID } from '../../../../../../../common/constants';
import { EventFiltersPageLocation } from '../../../../event_filters/types';

export const useGetLinkTo = (policyId: string, policyName: string) => {
export const useGetLinkTo = (
policyId: string,
policyName: string,
location?: Partial<EventFiltersPageLocation>
) => {
const { getAppUrl } = useAppUrl();
const { toRoutePath, toRouteUrl } = useMemo(() => {
const path = getEventFiltersListPath();
const path = getEventFiltersListPath(location);
return {
toRoutePath: path,
toRouteUrl: getAppUrl({ path }),
};
}, [getAppUrl]);
}, [getAppUrl, location]);

const policyEventFiltersPath = useMemo(() => getPolicyEventFiltersPath(policyId), [policyId]);
const policyEventFilterRouteState = useMemo(() => {
Expand Down Expand Up @@ -55,5 +60,6 @@ export const useGetLinkTo = (policyId: string, policyName: string) => {
return {
onClickHandler,
toRouteUrl,
state: policyEventFilterRouteState,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { PolicyEventFiltersDeleteModal } from '../delete_modal';
import { isGlobalPolicyEffected } from '../../../../../components/effected_policy_select/utils';
import { getEventFiltersListPath } from '../../../../../common/routing';
import { useUserPrivileges } from '../../../../../../common/components/user_privileges';
import { useGetLinkTo } from '../empty/use_policy_event_filters_empty_hooks';

interface PolicyEventFiltersListProps {
policy: ImmutableObject<PolicyData>;
Expand All @@ -47,6 +48,7 @@ export const PolicyEventFiltersList = React.memo<PolicyEventFiltersListProps>(({
const [exceptionItemToDelete, setExceptionItemToDelete] = useState<
ExceptionListItemSchema | undefined
>();
const { state } = useGetLinkTo(policy.id, policy.name);

const {
data: eventFilters,
Expand Down Expand Up @@ -116,7 +118,7 @@ export const PolicyEventFiltersList = React.memo<PolicyEventFiltersListProps>(({
),
href: getAppUrl({ appId: APP_UI_ID, path: viewUrlPath }),
navigateAppId: APP_UI_ID,
navigateOptions: { path: viewUrlPath },
navigateOptions: { path: viewUrlPath, state },
'data-test-subj': 'view-full-details-action',
};
const item = artifact as ExceptionListItemSchema;
Expand Down Expand Up @@ -159,6 +161,7 @@ export const PolicyEventFiltersList = React.memo<PolicyEventFiltersListProps>(({
{exceptionItemToDelete && (
<PolicyEventFiltersDeleteModal
policyId={policy.id}
policyName={policy.name}
exception={exceptionItemToDelete}
onCancel={handleDeleteModalClose}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ describe('Policy details host isolation exceptions delete modal', () => {
(renderResult = mockedContext.render(
<PolicyHostIsolationExceptionsDeleteModal
policyId={policyId}
policyName="fakeName"
exception={exception}
onCancel={onCancel}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ import { updateOneHostIsolationExceptionItem } from '../../../../host_isolation_

export const PolicyHostIsolationExceptionsDeleteModal = ({
policyId,
policyName,
exception,
onCancel,
}: {
policyId: string;
policyName: string;
exception: ExceptionListItemSchema;
onCancel: () => void;
}) => {
Expand Down Expand Up @@ -51,8 +53,9 @@ export const PolicyHostIsolationExceptionsDeleteModal = ({
text: i18n.translate(
'xpack.securitySolution.endpoint.policy.hostIsolationExceptions.list.removeDialog.successToastText',
{
defaultMessage: '"{exception}" has been removed from policy',
values: { exception: exception.name },
defaultMessage:
'"{hostIsolationExceptionName}" has been removed from {policyName} policy',
values: { hostIsolationExceptionName: exception.name, policyName },
}
),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const PolicyHostIsolationExceptionsEmptyUnexisting = ({
}: {
policy: PolicyData;
}) => {
const { onClickHandler, toRouteUrl } = useGetLinkTo(policy.id, policy.name);
const { onClickHandler, toRouteUrl } = useGetLinkTo(policy.id, policy.name, { show: 'create' });

return (
<EuiPageTemplate template="centeredContent">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('Policy details host isolation exceptions tab', () => {
({ history } = mockedContext);
render = () =>
(renderResult = mockedContext.render(
<PolicyHostIsolationExceptionsList policyId={policyId} />
<PolicyHostIsolationExceptionsList policyId={policyId} policyName="fakeName" />
));

act(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,23 @@ import { getCurrentArtifactsLocation } from '../../../store/policy_details/selec
import { usePolicyDetailsSelector } from '../../policy_hooks';
import { PolicyHostIsolationExceptionsDeleteModal } from './delete_modal';
import { useFetchHostIsolationExceptionsList } from '../../../../host_isolation_exceptions/view/hooks';

export const PolicyHostIsolationExceptionsList = ({ policyId }: { policyId: string }) => {
import { useGetLinkTo } from './use_policy_host_isolation_exceptions_empty_hooks';

export const PolicyHostIsolationExceptionsList = ({
policyId,
policyName,
}: {
policyId: string;
policyName: string;
}) => {
const history = useHistory();
const { getAppUrl } = useAppUrl();

const privileges = useUserPrivileges().endpointPrivileges;
const location = usePolicyDetailsSelector(getCurrentArtifactsLocation);

const { state } = useGetLinkTo(policyId, policyName);

// load the list of policies>
const policiesRequest = useGetEndpointSpecificPolicies();
const urlParams = usePolicyDetailsSelector(getCurrentArtifactsLocation);
Expand Down Expand Up @@ -127,7 +136,7 @@ export const PolicyHostIsolationExceptionsList = ({ policyId }: { policyId: stri
),
href: getAppUrl({ appId: APP_UI_ID, path: viewUrlPath }),
navigateAppId: APP_UI_ID,
navigateOptions: { path: viewUrlPath },
navigateOptions: { path: viewUrlPath, state },
'data-test-subj': 'view-full-details-action',
};

Expand Down Expand Up @@ -172,6 +181,7 @@ export const PolicyHostIsolationExceptionsList = ({ policyId }: { policyId: stri
{exceptionItemToDelete ? (
<PolicyHostIsolationExceptionsDeleteModal
policyId={policyId}
policyName={policyName}
exception={exceptionItemToDelete}
onCancel={handleDeleteModalClose}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,21 @@ import {
getHostIsolationExceptionsListPath,
} from '../../../../../common/routing';
import { APP_UI_ID } from '../../../../../../../common/constants';
import { HostIsolationExceptionsPageLocation } from '../../../../host_isolation_exceptions/types';

export const useGetLinkTo = (policyId: string, policyName: string) => {
export const useGetLinkTo = (
policyId: string,
policyName: string,
location?: Partial<HostIsolationExceptionsPageLocation>
) => {
const { getAppUrl } = useAppUrl();
const { toRoutePath, toRouteUrl } = useMemo(() => {
const path = getHostIsolationExceptionsListPath();
const path = getHostIsolationExceptionsListPath(location);
return {
toRoutePath: path,
toRouteUrl: getAppUrl({ path }),
};
}, [getAppUrl]);
}, [getAppUrl, location]);

const policyHostIsolationExceptionsPath = useMemo(
() => getPolicyHostIsolationExceptionsPath(policyId),
Expand Down Expand Up @@ -61,5 +66,6 @@ export const useGetLinkTo = (policyId: string, policyName: string) => {
return {
onClickHandler,
toRouteUrl,
state: policyHostIsolationExceptionsRouteState,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export const PolicyHostIsolationExceptionsTab = ({ policy }: { policy: PolicyDat
color="transparent"
borderRadius="none"
>
<PolicyHostIsolationExceptionsList policyId={policyId} />
<PolicyHostIsolationExceptionsList policyId={policyId} policyName={policy.name} />
</EuiPageContent>
</div>
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface CommonProps {
}

export const PolicyTrustedAppsEmptyUnexisting = memo<CommonProps>(({ policyId, policyName }) => {
const { onClickHandler, toRouteUrl } = useGetLinkTo(policyId, policyName);
const { onClickHandler, toRouteUrl } = useGetLinkTo(policyId, policyName, { show: 'create' });
return (
<EuiPageTemplate template="centeredContent">
<EuiEmptyPrompt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,21 @@ import { useNavigateToAppEventHandler } from '../../../../../../common/hooks/end
import { useAppUrl } from '../../../../../../common/lib/kibana/hooks';
import { getPolicyTrustedAppsPath, getTrustedAppsListPath } from '../../../../../common/routing';
import { APP_UI_ID } from '../../../../../../../common/constants';
import { TrustedAppsListPageLocation } from '../../../../trusted_apps/state';

export const useGetLinkTo = (policyId: string, policyName: string) => {
export const useGetLinkTo = (
policyId: string,
policyName: string,
location?: Partial<TrustedAppsListPageLocation>
) => {
const { getAppUrl } = useAppUrl();
const { toRoutePath, toRouteUrl } = useMemo(() => {
const path = getTrustedAppsListPath();
const path = getTrustedAppsListPath(location);
return {
toRoutePath: path,
toRouteUrl: getAppUrl({ path }),
};
}, [getAppUrl]);
}, [getAppUrl, location]);

const policyTrustedAppsPath = useMemo(() => getPolicyTrustedAppsPath(policyId), [policyId]);
const policyTrustedAppRouteState = useMemo(() => {
Expand Down Expand Up @@ -55,5 +60,6 @@ export const useGetLinkTo = (policyId: string, policyName: string) => {
return {
onClickHandler,
toRouteUrl,
state: policyTrustedAppRouteState,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export const PolicyTrustedAppsLayout = React.memo(() => {
/>
)
) : displayHeaderAndContent ? (
<PolicyTrustedAppsList />
<PolicyTrustedAppsList policyId={policyItem.id} policyName={policyItem.name} />
) : (
<ManagementPageLoader data-test-subj="policyTrustedAppsListLoader" />
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe('when rendering the PolicyTrustedAppsList', () => {

mockedApis = policyDetailsPageAllApiHttpMocks(appTestContext.coreStart.http);
waitForAction = appTestContext.middlewareSpy.waitForAction;
componentRenderProps = {};
componentRenderProps = { policyId: '9f08b220-342d-4c8d-8971-4cf96adcac29', policyName: 'test' };

render = async (waitForLoadedState: boolean = true) => {
appTestContext.history.push(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
getPolicyTrustedAppsListPagination,
getTrustedAppsAllPoliciesById,
isPolicyTrustedAppListLoading,
policyIdFromParams,
getCurrentPolicyArtifactsFilter,
} from '../../../store/policy_details/selectors';
import {
Expand All @@ -39,21 +38,23 @@ import { ArtifactEntryCollapsibleCardProps } from '../../../../../components/art
import { useTestIdGenerator } from '../../../../../components/hooks/use_test_id_generator';
import { RemoveTrustedAppFromPolicyModal } from './remove_trusted_app_from_policy_modal';
import { useUserPrivileges } from '../../../../../../common/components/user_privileges';
import { useGetLinkTo } from '../empty/use_policy_trusted_apps_empty_hooks';

const DATA_TEST_SUBJ = 'policyTrustedAppsGrid';

export interface PolicyTrustedAppsListProps {
hideTotalShowingLabel?: boolean;
policyId: string;
policyName: string;
}

export const PolicyTrustedAppsList = memo<PolicyTrustedAppsListProps>(
({ hideTotalShowingLabel = false }) => {
({ hideTotalShowingLabel = false, policyId, policyName }) => {
const getTestId = useTestIdGenerator(DATA_TEST_SUBJ);
const toasts = useToasts();
const history = useHistory();
const { getAppUrl } = useAppUrl();
const { canCreateArtifactsByPolicy } = useUserPrivileges().endpointPrivileges;
const policyId = usePolicyDetailsSelector(policyIdFromParams);
const isLoading = usePolicyDetailsSelector(isPolicyTrustedAppListLoading);
const defaultFilter = usePolicyDetailsSelector(getCurrentPolicyArtifactsFilter);
const trustedAppItems = usePolicyDetailsSelector(getPolicyTrustedAppList);
Expand All @@ -62,6 +63,7 @@ export const PolicyTrustedAppsList = memo<PolicyTrustedAppsListProps>(
const allPoliciesById = usePolicyDetailsSelector(getTrustedAppsAllPoliciesById);
const trustedAppsApiError = usePolicyDetailsSelector(getPolicyTrustedAppListError);
const navigateCallback = usePolicyDetailsNavigateCallback();
const { state } = useGetLinkTo(policyId, policyName);

const [isCardExpanded, setCardExpanded] = useState<Record<string, boolean>>({});
const [trustedAppsForRemoval, setTrustedAppsForRemoval] = useState<typeof trustedAppItems>([]);
Expand Down Expand Up @@ -152,7 +154,7 @@ export const PolicyTrustedAppsList = memo<PolicyTrustedAppsListProps>(
),
href: getAppUrl({ appId: APP_UI_ID, path: viewUrlPath }),
navigateAppId: APP_UI_ID,
navigateOptions: { path: viewUrlPath },
navigateOptions: { path: viewUrlPath, state },
'data-test-subj': getTestId('viewFullDetailsAction'),
},
];
Expand Down Expand Up @@ -201,6 +203,7 @@ export const PolicyTrustedAppsList = memo<PolicyTrustedAppsListProps>(
isCardExpanded,
trustedAppItems,
canCreateArtifactsByPolicy,
state,
]);

const provideCardProps = useCallback<Required<ArtifactCardGridProps>['cardComponentProps']>(
Expand Down

0 comments on commit 939bc3d

Please sign in to comment.