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

[Observability] [Cases] Cases in the observability app #101487

Merged
merged 160 commits into from
Jun 10, 2021
Merged
Show file tree
Hide file tree
Changes from 154 commits
Commits
Show all changes
160 commits
Select commit Hold shift + click to select a range
7f1a7dd
Adding feature flag for auth
jonathan-buttner Mar 9, 2021
164582d
Hiding SOs and adding consumer field
jonathan-buttner Mar 9, 2021
7eaf41e
First pass at adding security changes
jonathan-buttner Mar 9, 2021
f8e62c6
Consumer as the app's plugin ID
cnasikas Mar 10, 2021
09589c3
Create addConsumerToSO migration helper
cnasikas Mar 10, 2021
eb75eb0
Fix mapping's SO consumer
cnasikas Mar 10, 2021
a930f03
Add test for CasesActions
cnasikas Mar 10, 2021
d6f3b09
Declare hidden types on SO client
cnasikas Mar 10, 2021
b82e686
Restructure integration tests
cnasikas Mar 10, 2021
4d05175
Init spaces_only integration tests
cnasikas Mar 10, 2021
75d72ae
Implementing the cases security string
jonathan-buttner Mar 10, 2021
e65838b
Merge branch 'master' of github.com:elastic/kibana into cases-rbac-poc
jonathan-buttner Mar 10, 2021
1fd66af
Adding security plugin tests for cases
jonathan-buttner Mar 10, 2021
4560d42
Rough concept for authorization class
jonathan-buttner Mar 10, 2021
ef9b3b2
Adding comments
jonathan-buttner Mar 10, 2021
b22a032
Fix merge
cnasikas Mar 11, 2021
ddc2280
Get requiredPrivileges for classes
cnasikas Mar 11, 2021
9d008d8
Check privillages
cnasikas Mar 11, 2021
7bb23dd
Ensure that all classes are available
cnasikas Mar 11, 2021
65d4c6b
Success if hasAllRequested is true
cnasikas Mar 11, 2021
59e4045
Failure if hasAllRequested is false
cnasikas Mar 11, 2021
4092733
Adding schema updates for feature plugin
jonathan-buttner Mar 11, 2021
311e3f4
Seperate basic from trial
cnasikas Mar 16, 2021
f2a50d3
Enable SIR on integration tests
cnasikas Mar 16, 2021
00d89ca
Starting the plumbing for authorization in plugin
jonathan-buttner Mar 16, 2021
40cfcce
Merge branch 'master' into cases-rbac-poc
cnasikas Mar 17, 2021
644a7ac
Unit tests working
jonathan-buttner Mar 17, 2021
9bb1b86
Merge branch 'cases-rbac-poc-plugin-changes' into cases-rbac-poc
jonathan-buttner Mar 17, 2021
12d6e2e
Move find route logic to case client
cnasikas Mar 17, 2021
84d9167
Create integration test helper functions
cnasikas Mar 17, 2021
4bed458
Adding auth to create call
jonathan-buttner Mar 17, 2021
ecb3135
Create getClassFilter helper
cnasikas Mar 18, 2021
fe1d8c8
Add class attribute to find request
cnasikas Mar 18, 2021
22e7752
Create getFindAuthorizationFilter
cnasikas Mar 18, 2021
96f81a4
Ensure savedObject is authorized in find method
cnasikas Mar 18, 2021
e3ae097
Merge branch 'master' into cases-rbac-poc
cnasikas Mar 22, 2021
06d7c64
Include fields for authorization
cnasikas Mar 22, 2021
2ca4134
Combine authorization filter with cases & subcases filter
cnasikas Mar 22, 2021
17110b1
Fix isAuthorized flag
cnasikas Mar 22, 2021
bc06264
Fix merge issue
cnasikas Mar 22, 2021
a04e0d7
Create/delete spaces & users before and after tests
cnasikas Mar 22, 2021
7fe4e40
Add more user and roles
cnasikas Mar 22, 2021
2847861
[Cases] Convert filters from strings to KueryNode (#95288)
cnasikas Mar 24, 2021
a2e1da8
[Cases] RBAC: Rename class to scope (#95535)
cnasikas Mar 26, 2021
9263d7d
Merge branch 'master' into cases-rbac-poc
cnasikas Mar 26, 2021
afff0cc
Merge branch 'master' into cases-rbac-poc
cnasikas Apr 1, 2021
7cf9172
[Cases][RBAC] Rename scope to owner (#96035)
cnasikas Apr 1, 2021
0a95e55
[Cases] RBAC: Create & Find integration tests (#95511)
cnasikas Apr 2, 2021
1a895e5
Merge branch 'master' of github.com:elastic/kibana into cases-rbac-poc
jonathan-buttner Apr 5, 2021
9ffc3db
Merge branch 'master' of github.com:elastic/kibana into cases-rbac-poc
jonathan-buttner Apr 6, 2021
4f3c37e
[Cases] Cases client enchantment (#95923)
cnasikas Apr 6, 2021
36781db
[Cases] Authorization and Client Audit Logger (#95477)
jonathan-buttner Apr 6, 2021
73a4bfc
[Cases] Migrate sub cases routes to a client (#96461)
jonathan-buttner Apr 8, 2021
ae918cc
Merge branch 'master' into cases-rbac-poc
cnasikas Apr 12, 2021
e59602c
Merge branch 'cases-rbac-poc' of github.com:elastic/kibana into cases…
cnasikas Apr 12, 2021
34f2d86
[Cases] RBAC: Migrate routes' unit tests to integration tests (#96374)
cnasikas Apr 14, 2021
613e859
[Cases] Move remaining HTTP functionality to client (#96507)
jonathan-buttner Apr 14, 2021
676173e
[Cases] Refactoring authorization (#97483)
jonathan-buttner Apr 20, 2021
6cdfa84
[Cases] Add authorization to configuration & cases routes (#97228)
cnasikas Apr 26, 2021
7b21b7a
Merge branch 'master' of github.com:elastic/kibana into cases-rbac-poc
jonathan-buttner Apr 27, 2021
103388e
[Cases] Attachments RBAC (#97756)
jonathan-buttner Apr 30, 2021
18e75d9
[Cases] Add RBAC to remaining Cases APIs (#98762)
jonathan-buttner May 4, 2021
d99d9f8
Merge branch 'master' of github.com:elastic/kibana into cases-rbac-poc
jonathan-buttner May 4, 2021
b121662
Fixing some type errors
jonathan-buttner May 4, 2021
42162e3
Merge branch 'master' of github.com:elastic/kibana into cases-rbac-poc
jonathan-buttner May 6, 2021
298ba34
Merge branch 'master' of github.com:elastic/kibana into cases-rbac-poc
jonathan-buttner May 6, 2021
c0fb868
Merge branch 'master' of github.com:elastic/kibana into cases-rbac-poc
jonathan-buttner May 7, 2021
21d173d
Merge branch 'master' of github.com:elastic/kibana into cases-rbac-poc
jonathan-buttner May 10, 2021
b910889
[Cases] Add space only tests (#99409)
jonathan-buttner May 10, 2021
78dfac4
Merge branch 'master' of github.com:elastic/kibana into cases-rbac-poc
jonathan-buttner May 10, 2021
bf583a8
Merge branch 'master' of github.com:elastic/kibana into cases-rbac-poc
jonathan-buttner May 11, 2021
3fd893f
[Cases] Add security only tests (#99679)
jonathan-buttner May 11, 2021
86568ed
Adding sub feature
jonathan-buttner May 12, 2021
952e2a3
[Cases] Cleaning up the services and TODOs (#99723)
jonathan-buttner May 14, 2021
e26de43
Integration tests for cases privs and fixes (#100038)
jonathan-buttner May 14, 2021
2d8601b
[Cases] RBAC on UI (#99478)
cnasikas May 14, 2021
570cddb
Merge branch 'master' of github.com:elastic/kibana into cases-rbac-poc
jonathan-buttner May 14, 2021
3c7670b
Fixing case ids by alert id route call
jonathan-buttner May 14, 2021
dafb4fe
[Cases] Fixing UI feature permissions and adding UI tests (#100074)
jonathan-buttner May 14, 2021
b7c5ebd
Merge branch 'master' of github.com:elastic/kibana into cases-rbac-poc
jonathan-buttner May 14, 2021
698e8e2
Fixing type error
jonathan-buttner May 14, 2021
22abf1f
Merge branch 'master' into cases-rbac-poc
kibanamachine May 17, 2021
71225eb
Adding some comments
jonathan-buttner May 17, 2021
f7a816b
Validate cases features
cnasikas May 18, 2021
2ed0a99
Merge branch 'master' into cases-rbac-poc
cnasikas May 18, 2021
fd39b25
Fix new schema
cnasikas May 18, 2021
84141fc
Merge branch 'master' into cases_obs
stephmilovic May 18, 2021
e3d3e8c
Cases routing
stephmilovic May 18, 2021
a193138
Merge branch 'master' into cases-rbac-poc
kibanamachine May 18, 2021
eb7fdd7
Adding cases feature
jonathan-buttner May 18, 2021
ce68009
wip
stephmilovic May 18, 2021
77b5a54
Merge pull request #3 from jonathan-buttner/obs-cases-feature
stephmilovic May 18, 2021
722649e
i made a case
stephmilovic May 18, 2021
85e3de7
cases in obs
stephmilovic May 19, 2021
1c7b613
add back in user permissions
stephmilovic May 20, 2021
1f9059c
Merge branch 'master' into cases-rbac-poc
kibanamachine May 20, 2021
2085a3b
Merge branch 'master' into cases-rbac-poc
kibanamachine May 24, 2021
ccd7e79
Merge branch 'master' into cases_obs
stephmilovic May 24, 2021
66c1d43
Adding owner param for the status stats
jonathan-buttner May 24, 2021
018dcb5
Merge branch 'master' into cases-rbac-poc
kibanamachine May 24, 2021
34b16c5
Fix get case status tests
cnasikas May 25, 2021
fb7e7a9
in middle of removing alerts stuff
stephmilovic May 25, 2021
9f9f936
Merge branch 'cases-rbac-poc' into cases_obs
stephmilovic May 25, 2021
882d97c
removed alerting and fixing types
stephmilovic May 25, 2021
fe20f5c
fix submitCase when no alerting
stephmilovic May 25, 2021
5345d40
fix up breadcrumbs
stephmilovic May 25, 2021
8c2cc61
Fix jest
stephmilovic May 25, 2021
528c9be
Fix types
stephmilovic May 25, 2021
bd694ca
change key for message storage
stephmilovic May 25, 2021
9ba1243
Adjusting permissions text and fixing status
jonathan-buttner May 25, 2021
9ef3ab4
may it please CI
stephmilovic May 25, 2021
5df7d33
arrys rbac changes
stephmilovic May 26, 2021
315a6e4
Address PR feedback
jonathan-buttner May 26, 2021
02ad6a4
Adding top level feature back
jonathan-buttner May 26, 2021
e8c3532
Merge branch 'master' into cases-rbac-poc
kibanamachine May 26, 2021
fd54706
fix type
stephmilovic May 27, 2021
8881899
Fixing feature privileges
jonathan-buttner May 27, 2021
dd62656
Merge branch 'master' of github.com:elastic/kibana into cases-rbac-poc
jonathan-buttner May 27, 2021
acf550b
Renaming
jonathan-buttner May 27, 2021
148623e
Removing uneeded else
jonathan-buttner May 27, 2021
7acf83a
Fixing tests and adding cases merge tests
jonathan-buttner May 27, 2021
b03fa4c
Merge branch 'master' into cases-rbac-poc
kibanamachine May 28, 2021
445c846
[Cases][Security Solution] Basic license security solution API tests …
jonathan-buttner Jun 1, 2021
c08ac43
Merge branch 'master' of github.com:elastic/kibana into cases-rbac-poc
jonathan-buttner Jun 1, 2021
bee51fd
midst of nathans pr changes
stephmilovic Jun 1, 2021
359df83
merge conflicts and EuiPage to ObsPage on cases
stephmilovic Jun 1, 2021
bf02730
redirect after delete
stephmilovic Jun 1, 2021
c0f2105
does not exist page
stephmilovic Jun 2, 2021
9266b17
fix tests
stephmilovic Jun 2, 2021
1edb767
fix types
stephmilovic Jun 2, 2021
373cd68
Merge branch 'master' into cases-rbac-poc
kibanamachine Jun 2, 2021
8f2cb30
fix jest
stephmilovic Jun 3, 2021
6a66a6c
Merge branch 'cases-rbac-poc' into cases_obs
stephmilovic Jun 3, 2021
d59dbad
renaming to unsecuredSavedObjectsClient (#101215)
jonathan-buttner Jun 3, 2021
7ef02f4
Merge branch 'master' into cases-rbac-poc
kibanamachine Jun 3, 2021
739fd6f
[Cases] RBAC Refactoring audit logging (#100952)
jonathan-buttner Jun 3, 2021
9d87078
fixing links
stephmilovic Jun 3, 2021
28152b8
Merge branch 'cases-rbac-poc' into cases_obs
stephmilovic Jun 3, 2021
e66eb40
[Cases] Cleaning up RBAC integration tests (#101324)
jonathan-buttner Jun 4, 2021
5bd080b
Merge branch 'master' into cases-rbac-poc
kibanamachine Jun 4, 2021
56e0f0d
Merge branch 'master' into cases-rbac-poc
kibanamachine Jun 7, 2021
1211f7f
Merge branch 'cases-rbac-poc' into cases_obs
kibanamachine Jun 7, 2021
7534f28
merge w masteR
stephmilovic Jun 7, 2021
6611765
remove testing links
stephmilovic Jun 7, 2021
c27aa29
add comments
stephmilovic Jun 7, 2021
831dedb
pr changes and remove unnecessary vars
stephmilovic Jun 7, 2021
511f3f7
pr changes and WIP func tests
stephmilovic Jun 9, 2021
58a4ecf
add es archiver
stephmilovic Jun 9, 2021
109a5da
Getting cases to show up in the nav
jonathan-buttner Jun 9, 2021
66f2645
finish func tests
stephmilovic Jun 9, 2021
f93a6ac
Merge branch 'cases_obs' of github.com:stephmilovic/kibana into cases…
stephmilovic Jun 9, 2021
edbd419
a fixing
stephmilovic Jun 9, 2021
0f34792
more pr updates
stephmilovic Jun 9, 2021
09e9ca0
fix telemetry
stephmilovic Jun 9, 2021
1014700
fix a few types and test
stephmilovic Jun 9, 2021
ac8d66d
Merge branch 'master' into cases_obs
stephmilovic Jun 10, 2021
7d7a10a
fix es archiver path
stephmilovic Jun 10, 2021
e318131
fix type
stephmilovic Jun 10, 2021
8522fc6
few more pr changes
stephmilovic Jun 10, 2021
d715573
fix
stephmilovic Jun 10, 2021
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 @@ -148,6 +148,7 @@ export const applicationUsageSchema = {
maps: commonSchema,
ml: commonSchema,
monitoring: commonSchema,
'observability-cases': commonSchema,
'observability-overview': commonSchema,
osquery: commonSchema,
security_account: commonSchema,
Expand Down
131 changes: 131 additions & 0 deletions src/plugins/telemetry/schema/oss_plugins.json
Original file line number Diff line number Diff line change
Expand Up @@ -3970,6 +3970,137 @@
}
}
},
"observability-cases": {
"properties": {
"appId": {
"type": "keyword",
"_meta": {
"description": "The application being tracked"
}
},
"viewId": {
"type": "keyword",
"_meta": {
"description": "Always `main`"
}
},
"clicks_total": {
"type": "long",
"_meta": {
"description": "General number of clicks in the application since we started counting them"
}
},
"clicks_7_days": {
"type": "long",
"_meta": {
"description": "General number of clicks in the application over the last 7 days"
}
},
"clicks_30_days": {
"type": "long",
"_meta": {
"description": "General number of clicks in the application over the last 30 days"
}
},
"clicks_90_days": {
"type": "long",
"_meta": {
"description": "General number of clicks in the application over the last 90 days"
}
},
"minutes_on_screen_total": {
"type": "float",
"_meta": {
"description": "Minutes the application is active and on-screen since we started counting them."
}
},
"minutes_on_screen_7_days": {
"type": "float",
"_meta": {
"description": "Minutes the application is active and on-screen over the last 7 days"
}
},
"minutes_on_screen_30_days": {
"type": "float",
"_meta": {
"description": "Minutes the application is active and on-screen over the last 30 days"
}
},
"minutes_on_screen_90_days": {
"type": "float",
"_meta": {
"description": "Minutes the application is active and on-screen over the last 90 days"
}
},
"views": {
"type": "array",
"items": {
"properties": {
"appId": {
"type": "keyword",
"_meta": {
"description": "The application being tracked"
}
},
"viewId": {
"type": "keyword",
"_meta": {
"description": "The application view being tracked"
}
},
"clicks_total": {
"type": "long",
"_meta": {
"description": "General number of clicks in the application sub view since we started counting them"
}
},
"clicks_7_days": {
"type": "long",
"_meta": {
"description": "General number of clicks in the active application sub view over the last 7 days"
}
},
"clicks_30_days": {
"type": "long",
"_meta": {
"description": "General number of clicks in the active application sub view over the last 30 days"
}
},
"clicks_90_days": {
"type": "long",
"_meta": {
"description": "General number of clicks in the active application sub view over the last 90 days"
}
},
"minutes_on_screen_total": {
"type": "float",
"_meta": {
"description": "Minutes the application sub view is active and on-screen since we started counting them."
}
},
"minutes_on_screen_7_days": {
"type": "float",
"_meta": {
"description": "Minutes the application is active and on-screen active application sub view over the last 7 days"
}
},
"minutes_on_screen_30_days": {
"type": "float",
"_meta": {
"description": "Minutes the application is active and on-screen active application sub view over the last 30 days"
}
},
"minutes_on_screen_90_days": {
"type": "float",
"_meta": {
"description": "Minutes the application is active and on-screen active application sub view over the last 90 days"
}
}
}
}
}
}
},
"observability-overview": {
"properties": {
"appId": {
Expand Down
3 changes: 3 additions & 0 deletions test/functional/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ export default async function ({ readConfigFile }) {
pathname: '/app/home',
hash: '/',
},
observabilityCases: {
pathname: '/app/observability/cases',
},
},
junit: {
reportName: 'Chrome UI Functional Tests',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ interface AllCasesGenericProps {
caseDetailsNavigation?: CasesNavigation<CaseDetailsHrefSchema, 'configurable'>; // if not passed, case name is not displayed as a link (Formerly dependant on isSelectorView)
configureCasesNavigation?: CasesNavigation; // if not passed, header with nav is not displayed (Formerly dependant on isSelectorView)
createCaseNavigation: CasesNavigation;
disableAlerts?: boolean;
hiddenStatuses?: CaseStatusWithAllStatus[];
isSelectorView?: boolean;
onRowClick?: (theCase?: Case | SubCase) => void;
showTitle?: boolean;
updateCase?: (newCase: Case) => void;
userCanCrud: boolean;
}
Expand All @@ -75,9 +77,11 @@ export const AllCasesGeneric = React.memo<AllCasesGenericProps>(
caseDetailsNavigation,
configureCasesNavigation,
createCaseNavigation,
disableAlerts,
hiddenStatuses = [],
isSelectorView,
onRowClick,
showTitle,
updateCase,
userCanCrud,
}) => {
Expand Down Expand Up @@ -190,6 +194,7 @@ export const AllCasesGeneric = React.memo<AllCasesGenericProps>(

const columns = useCasesColumns({
caseDetailsNavigation,
disableAlerts,
dispatchUpdateCaseProperty,
filterStatus: filterOptions.status,
handleIsLoading,
Expand Down Expand Up @@ -271,6 +276,7 @@ export const AllCasesGeneric = React.memo<AllCasesGenericProps>(
createCaseNavigation={createCaseNavigation}
configureCasesNavigation={configureCasesNavigation}
refresh={refresh}
showTitle={showTitle}
userCanCrud={userCanCrud}
/>
)}
Expand Down
24 changes: 15 additions & 9 deletions x-pack/plugins/cases/public/components/all_cases/columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const renderStringField = (field: string, dataTestSubj: string) =>

export interface GetCasesColumn {
caseDetailsNavigation?: CasesNavigation<CaseDetailsHrefSchema, 'configurable'>;
disableAlerts?: boolean;
dispatchUpdateCaseProperty: (u: UpdateCase) => void;
filterStatus: string;
handleIsLoading: (a: boolean) => void;
Expand All @@ -64,6 +65,7 @@ export interface GetCasesColumn {
}
export const useCasesColumns = ({
caseDetailsNavigation,
disableAlerts = false,
dispatchUpdateCaseProperty,
filterStatus,
handleIsLoading,
Expand Down Expand Up @@ -203,15 +205,19 @@ export const useCasesColumns = ({
},
truncateText: true,
},
{
align: RIGHT_ALIGNMENT,
field: 'totalAlerts',
name: ALERTS,
render: (totalAlerts: Case['totalAlerts']) =>
totalAlerts != null
? renderStringField(`${totalAlerts}`, `case-table-column-alertsCount`)
: getEmptyTagValue(),
},
...(!disableAlerts
? [
{
align: RIGHT_ALIGNMENT,
field: 'totalAlerts',
name: ALERTS,
render: (totalAlerts: Case['totalAlerts']) =>
totalAlerts != null
? renderStringField(`${totalAlerts}`, `case-table-column-alertsCount`)
: getEmptyTagValue(),
},
]
: []),
{
align: RIGHT_ALIGNMENT,
field: 'totalComment',
Expand Down
4 changes: 3 additions & 1 deletion x-pack/plugins/cases/public/components/all_cases/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ interface OwnProps {
configureCasesNavigation: CasesNavigation;
createCaseNavigation: CasesNavigation;
refresh: number;
showTitle?: boolean;
userCanCrud: boolean;
}

Expand All @@ -40,9 +41,10 @@ export const CasesTableHeader: FunctionComponent<Props> = ({
configureCasesNavigation,
createCaseNavigation,
refresh,
showTitle = true,
userCanCrud,
}) => (
<CaseHeaderPage title={i18n.PAGE_TITLE}>
<CaseHeaderPage title={showTitle ? i18n.PAGE_TITLE : ''}>
<EuiFlexGroup
alignItems="center"
gutterSize="m"
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/cases/public/components/all_cases/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export interface AllCasesProps extends Owner {
caseDetailsNavigation: CasesNavigation<CaseDetailsHrefSchema, 'configurable'>; // if not passed, case name is not displayed as a link (Formerly dependant on isSelector)
configureCasesNavigation: CasesNavigation; // if not passed, header with nav is not displayed (Formerly dependant on isSelector)
createCaseNavigation: CasesNavigation;
disableAlerts?: boolean;
showTitle?: boolean;
userCanCrud: boolean;
}

Expand Down
7 changes: 6 additions & 1 deletion x-pack/plugins/cases/public/components/callout/callout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ const CallOutComponent = ({
]);

return showCallOut ? (
<EuiCallOut title={title} color={type} iconType="gear" data-test-subj={`case-callout-${id}`}>
<EuiCallOut
title={title}
color={type}
iconType="gear"
data-test-subj={`case-callout-${id} another-one`}
>
{!isEmpty(messages) && (
<EuiDescriptionList data-test-subj={`callout-messages-${id}`} listItems={messages} />
)}
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/cases/public/components/callout/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import md5 from 'md5';
import * as i18n from './translations';
import { ErrorMessage } from './types';

export const savedObjectReadOnlyErrorMessage: ErrorMessage = {
export const permissionsReadOnlyErrorMessage: ErrorMessage = {
id: 'read-only-privileges-error',
title: i18n.READ_ONLY_FEATURE_TITLE,
description: <>{i18n.READ_ONLY_FEATURE_MSG}</>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ jest.mock('react-router-dom', () => {
}),
};
});

const defaultProps = {
allCasesNavigation: {
href: 'all-cases-href',
onClick: () => {},
},
caseData: basicCase,
currentExternalIncident: null,
};
describe('CaseView actions', () => {
const handleOnDeleteConfirm = jest.fn();
const handleToggleModal = jest.fn();
Expand All @@ -49,7 +56,7 @@ describe('CaseView actions', () => {
it('clicking trash toggles modal', () => {
const wrapper = mount(
<TestProviders>
<Actions caseData={basicCase} currentExternalIncident={null} />
<Actions {...defaultProps} />
</TestProviders>
);

Expand All @@ -67,7 +74,7 @@ describe('CaseView actions', () => {
}));
const wrapper = mount(
<TestProviders>
<Actions caseData={basicCase} currentExternalIncident={null} />
<Actions {...defaultProps} />
</TestProviders>
);

Expand All @@ -82,7 +89,7 @@ describe('CaseView actions', () => {
const wrapper = mount(
<TestProviders>
<Actions
caseData={basicCase}
{...defaultProps}
currentExternalIncident={{
...basicPush,
firstPushIndex: 5,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,27 @@

import { isEmpty } from 'lodash/fp';
import React, { useMemo } from 'react';
import { useHistory } from 'react-router-dom';
import * as i18n from '../case_view/translations';
import { useDeleteCases } from '../../containers/use_delete_cases';
import { ConfirmDeleteCaseModal } from '../confirm_delete_case';
import { PropertyActions } from '../property_actions';
import { Case } from '../../containers/types';
import { Case } from '../../../common';
import { CaseService } from '../../containers/use_get_case_user_actions';
import { CasesNavigation } from '../links';

interface CaseViewActions {
allCasesNavigation: CasesNavigation;
caseData: Case;
currentExternalIncident: CaseService | null;
disabled?: boolean;
}

const ActionsComponent: React.FC<CaseViewActions> = ({
allCasesNavigation,
caseData,
currentExternalIncident,
disabled = false,
}) => {
const history = useHistory();
// Delete case
const {
handleToggleModal,
Expand Down Expand Up @@ -57,7 +58,7 @@ const ActionsComponent: React.FC<CaseViewActions> = ({
);

if (isDeleted) {
history.push('/');
allCasesNavigation.onClick(({ preventDefault: () => null } as unknown) as MouseEvent);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we need to pass preventDefault?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's in the type, @michaelolo24 do you remember why we're requiring to pass MouseEvent?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MouseEvent was added because TS was was complaining about the conflict of event object typed differently based on MouseEvent vs KeyboardEvent, etc... If I remember correctly. The preventDefault is added just to meet those requirements. I'm guessing this is to disable the click?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, its not doing anything here but satisfying the type

Copy link
Member

@cnasikas cnasikas Jun 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stephmilovic @michaelolo24 You can change the type of onClick: (arg: T) => void; to onClick: (arg?: T) => void; (arg is optional) and avoid passing { preventDefault: () => null }.

Copy link
Contributor Author

@stephmilovic stephmilovic Jun 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that creates a lot of type errors such as:

x-pack/plugins/security_solution/public/overview/components/recent_cases/index.tsx:46:7 - error TS2322: Type '({ detailName, subCaseId, search }: AllCasesNavProps) => void' is not assignable to type '(arg?: CaseDetailsHrefSchema | undefined) => void'.
  Types of parameters '__0' and 'arg' are incompatible.
    Type 'CaseDetailsHrefSchema | undefined' is not assignable to type 'AllCasesNavProps'.
      Type 'undefined' is not assignable to type 'AllCasesNavProps'.

46       onClick: ({ detailName, subCaseId, search }: AllCasesNavProps) => {
         ~~~~~~~

  x-pack/plugins/cases/target/types/public/components/links/index.d.ts:5:5
    5     onClick: (arg?: T) => void;
          ~~~~~~~
    The expected type comes from property 'onClick' which is declared here on type 'CasesNavigation<CaseDetailsHrefSchema, "configurable">'

How about this, I'll allow to pass null like:

export interface CasesNavigation<T = React.MouseEvent | MouseEvent | null, K = null> {
  href: K extends 'configurable' ? (arg: T) => string : string;
  onClick: (arg: T) => void;
}

and just pass null if we do not have a MouseEvent

return null;
}
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ describe('CaseActionBar', () => {
const onRefresh = jest.fn();
const onUpdateField = jest.fn();
const defaultProps = {
allCasesNavigation: {
href: 'all-cases-href',
onClick: () => {},
},
caseData: basicCase,
isAlerting: true,
isLoading: false,
onRefresh,
onUpdateField,
Expand Down
Loading