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.
[Security Solution] fixes Data Quality dashboard errors when a `baseP…
…ath` is configured (elastic#156233) ## [Security Solution] fixes Data Quality dashboard errors when a `basePath` is configured This PR implements a fix for an [issue](elastic#156231) where the Data Quality dashboard displays errors when a `basePath` is configured, preventing indices from being checked. ### Desk testing - Verify the fix per the reporduction steps in <elastic#156231> - Also verify the page still behaves correctly when Kibana is started with no base path, via: ``` yarn start --no-base-path ``` ### Before / after screenshots **Before:** ![before](https://user-images.githubusercontent.com/4459398/235273609-952fd7e4-0a22-4344-b1e4-48411c6d0e33.png) _Above: Before the fix, errors occur when a `basePath` is configured_ **After:** ![after](https://user-images.githubusercontent.com/4459398/235276257-c62feb05-699a-418c-8da2-b90b6683e5b4.png) _Above: After the fix, errors do NOT occur_ (cherry picked from commit 3389a2b)
- Loading branch information
1 parent
e02d94a
commit 1e56b5c
Showing
27 changed files
with
957 additions
and
182 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
40 changes: 40 additions & 0 deletions
40
...uality_dashboard/impl/data_quality/data_quality_panel/data_quality_context/index.test.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,40 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { renderHook } from '@testing-library/react-hooks'; | ||
import React from 'react'; | ||
|
||
import { DataQualityProvider, useDataQualityContext } from '.'; | ||
|
||
const mockHttpFetch = jest.fn(); | ||
const ContextWrapper: React.FC = ({ children }) => ( | ||
<DataQualityProvider httpFetch={mockHttpFetch}>{children}</DataQualityProvider> | ||
); | ||
|
||
describe('DataQualityContext', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
test('it throws an error when useDataQualityContext hook is used without a DataQualityContext', () => { | ||
const { result } = renderHook(useDataQualityContext); | ||
|
||
expect(result.error).toEqual( | ||
new Error('useDataQualityContext must be used within a DataQualityProvider') | ||
); | ||
}); | ||
|
||
test('it should return the httpFetch function', async () => { | ||
const { result } = renderHook(useDataQualityContext, { wrapper: ContextWrapper }); | ||
const httpFetch = await result.current.httpFetch; | ||
|
||
const path = '/path/to/resource'; | ||
httpFetch(path); | ||
|
||
expect(mockHttpFetch).toBeCalledWith(path); | ||
}); | ||
}); |
39 changes: 39 additions & 0 deletions
39
...ata_quality_dashboard/impl/data_quality/data_quality_panel/data_quality_context/index.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,39 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import type { HttpHandler } from '@kbn/core-http-browser'; | ||
import React, { useMemo } from 'react'; | ||
|
||
interface DataQualityProviderProps { | ||
httpFetch: HttpHandler; | ||
} | ||
|
||
const DataQualityContext = React.createContext<DataQualityProviderProps | undefined>(undefined); | ||
|
||
export const DataQualityProvider: React.FC<DataQualityProviderProps> = ({ | ||
children, | ||
httpFetch, | ||
}) => { | ||
const value = useMemo( | ||
() => ({ | ||
httpFetch, | ||
}), | ||
[httpFetch] | ||
); | ||
|
||
return <DataQualityContext.Provider value={value}>{children}</DataQualityContext.Provider>; | ||
}; | ||
|
||
export const useDataQualityContext = () => { | ||
const context = React.useContext(DataQualityContext); | ||
|
||
if (context == null) { | ||
throw new Error('useDataQualityContext must be used within a DataQualityProvider'); | ||
} | ||
|
||
return context; | ||
}; |
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.