forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Endpoint] add policy details route (elastic#59951)
Adds policy details route as a target for the Policy forms
- Loading branch information
Showing
17 changed files
with
272 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
x-pack/plugins/endpoint/public/applications/endpoint/store/policy_details/action.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { PolicyData } from '../../types'; | ||
|
||
interface ServerReturnedPolicyDetailsData { | ||
type: 'serverReturnedPolicyDetailsData'; | ||
payload: { | ||
policyItem: PolicyData | undefined; | ||
}; | ||
} | ||
|
||
export type PolicyDetailsAction = ServerReturnedPolicyDetailsData; |
9 changes: 9 additions & 0 deletions
9
x-pack/plugins/endpoint/public/applications/endpoint/store/policy_details/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export { policyDetailsMiddlewareFactory } from './middleware'; | ||
export { PolicyDetailsAction } from './action'; | ||
export { policyDetailsReducer } from './reducer'; |
29 changes: 29 additions & 0 deletions
29
x-pack/plugins/endpoint/public/applications/endpoint/store/policy_details/middleware.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { MiddlewareFactory, PolicyDetailsState } from '../../types'; | ||
import { selectPolicyIdFromParams, isOnPolicyDetailsPage } from './selectors'; | ||
|
||
export const policyDetailsMiddlewareFactory: MiddlewareFactory<PolicyDetailsState> = coreStart => { | ||
return ({ getState, dispatch }) => next => async action => { | ||
next(action); | ||
const state = getState(); | ||
|
||
if (action.type === 'userChangedUrl' && isOnPolicyDetailsPage(state)) { | ||
const id = selectPolicyIdFromParams(state); | ||
|
||
const { getFakeDatasourceDetailsApiResponse } = await import('../policy_list/fake_data'); | ||
const policyItem = await getFakeDatasourceDetailsApiResponse(id); | ||
|
||
dispatch({ | ||
type: 'serverReturnedPolicyDetailsData', | ||
payload: { | ||
policyItem, | ||
}, | ||
}); | ||
} | ||
}; | ||
}; |
48 changes: 48 additions & 0 deletions
48
x-pack/plugins/endpoint/public/applications/endpoint/store/policy_details/reducer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { Reducer } from 'redux'; | ||
import { PolicyDetailsState } from '../../types'; | ||
import { AppAction } from '../action'; | ||
|
||
const initialPolicyDetailsState = (): PolicyDetailsState => { | ||
return { | ||
policyItem: { | ||
name: '', | ||
total: 0, | ||
pending: 0, | ||
failed: 0, | ||
id: '', | ||
created_by: '', | ||
created: '', | ||
updated_by: '', | ||
updated: '', | ||
}, | ||
isLoading: false, | ||
}; | ||
}; | ||
|
||
export const policyDetailsReducer: Reducer<PolicyDetailsState, AppAction> = ( | ||
state = initialPolicyDetailsState(), | ||
action | ||
) => { | ||
if (action.type === 'serverReturnedPolicyDetailsData') { | ||
return { | ||
...state, | ||
...action.payload, | ||
isLoading: false, | ||
}; | ||
} | ||
|
||
if (action.type === 'userChangedUrl') { | ||
return { | ||
...state, | ||
location: action.payload, | ||
}; | ||
} | ||
|
||
return state; | ||
}; |
29 changes: 29 additions & 0 deletions
29
x-pack/plugins/endpoint/public/applications/endpoint/store/policy_details/selectors.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { createSelector } from 'reselect'; | ||
import { PolicyDetailsState } from '../../types'; | ||
|
||
export const selectPolicyDetails = (state: PolicyDetailsState) => state.policyItem; | ||
|
||
export const isOnPolicyDetailsPage = (state: PolicyDetailsState) => { | ||
if (state.location) { | ||
const pathnameParts = state.location.pathname.split('/'); | ||
return pathnameParts[1] === 'policy' && pathnameParts[2]; | ||
} else { | ||
return false; | ||
} | ||
}; | ||
|
||
export const selectPolicyIdFromParams: (state: PolicyDetailsState) => string = createSelector( | ||
(state: PolicyDetailsState) => state.location, | ||
(location: PolicyDetailsState['location']) => { | ||
if (location) { | ||
return location.pathname.split('/')[2]; | ||
} | ||
return ''; | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ | |
*/ | ||
|
||
export * from './policy_list'; | ||
export * from './policy_details'; |
36 changes: 36 additions & 0 deletions
36
x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_details.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { EuiTitle } from '@elastic/eui'; | ||
import { FormattedMessage } from '@kbn/i18n/react'; | ||
import { usePolicyDetailsSelector } from './policy_hooks'; | ||
import { selectPolicyDetails } from '../../store/policy_details/selectors'; | ||
|
||
export const PolicyDetails = React.memo(() => { | ||
const policyItem = usePolicyDetailsSelector(selectPolicyDetails); | ||
|
||
function policyName() { | ||
if (policyItem) { | ||
return <span data-test-subj="policyDetailsName">{policyItem.name}</span>; | ||
} else { | ||
return ( | ||
<span data-test-subj="policyDetailsNotFound"> | ||
<FormattedMessage | ||
id="xpack.endpoint.policyDetails.notFound" | ||
defaultMessage="Policy Not Found" | ||
/> | ||
</span> | ||
); | ||
} | ||
} | ||
|
||
return ( | ||
<EuiTitle size="l"> | ||
<h1 data-test-subj="policyDetailsViewTitle">{policyName()}</h1> | ||
</EuiTitle> | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.