-
Notifications
You must be signed in to change notification settings - Fork 0
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
Enhancement/search bar flint #3
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { useContext, createContext, createElement } from 'react'; | ||
import { createNotifications } from '../../../../../../../src/plugins/opensearch_dashboards_react/public'; | ||
import { | ||
DashboardsObservabilityContext, | ||
OpenSearchDashboardsServices, | ||
ObservabilityDashboardsReactContextValue, | ||
DashboardsObservabilityServices, | ||
} from './types'; | ||
import { useMemo } from 'react'; | ||
import React from 'react'; | ||
|
||
const defaultObservabilityContextValue = { | ||
services: {} as DashboardsObservabilityServices, | ||
notifications: createNotifications({}), | ||
}; | ||
|
||
export const observabilityContext = createContext< | ||
ObservabilityDashboardsReactContextValue<DashboardsObservabilityServices> | ||
>(defaultObservabilityContextValue); | ||
|
||
export const useDashboardsObservability = (): ObservabilityDashboardsReactContextValue< | ||
DashboardsObservabilityServices | ||
> => useContext(observabilityContext); | ||
|
||
export const createDashboardsObservabilityContext = <Services extends OpenSearchDashboardsServices>( | ||
services: Services | ||
): DashboardsObservabilityContext<Services> => { | ||
// common context | ||
const value = { | ||
services, | ||
notifications: createNotifications(services), | ||
}; | ||
|
||
const Provider: React.FC<{ services?: Services; children: React.ReactDOM }> = ({ | ||
services: additionalServices = {}, | ||
children, | ||
}) => { | ||
const oldValue = useDashboardsObservability(); | ||
const { value: mergedValue } = useMemo( | ||
() => | ||
createDashboardsObservabilityContext({ | ||
...services, | ||
...oldValue.services, | ||
...additionalServices, | ||
}), | ||
[services, oldValue, additionalServices] | ||
Check warning on line 51 in public/components/event_analytics/explorer/context/context.tsx GitHub Actions / Lint
|
||
); | ||
return createElement(observabilityContext.Provider as React.ComponentType<any>, { | ||
value: mergedValue, | ||
children, | ||
}); | ||
}; | ||
|
||
return { | ||
value, | ||
Provider, | ||
Consumer: (observabilityContext.Consumer as unknown) as React.Consumer< | ||
ObservabilityDashboardsReactContextValue<Services> | ||
>, | ||
}; | ||
}; | ||
|
||
export const { | ||
Provider: DashboardsObservabilityContextProvider, | ||
} = createDashboardsObservabilityContext({}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React from 'react'; | ||
import { CoreStart } from '../../../../../../../src/core/public'; | ||
import { OpenSearchDashboardsReactNotifications } from '../../../../../../../src/plugins/opensearch_dashboards_react/public'; | ||
import PPLService from '../../../../services/requests/ppl'; | ||
import DSLService from '../../../../services/requests/dsl'; | ||
import { QueryManager } from '../../../../../common/query_manager'; | ||
|
||
export type OpenSearchDashboardsServices = Partial<CoreStart>; | ||
export type DashboardsObservabilityServices = OpenSearchDashboardsServices & { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
pplService: PPLService; | ||
dslService: DSLService; | ||
queryManager: QueryManager; | ||
}; | ||
|
||
export interface ObservabilityDashboardsReactContextValue< | ||
Services extends OpenSearchDashboardsServices | ||
> { | ||
Comment on lines
+20
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why a separate generic |
||
readonly services: Services; | ||
readonly notifications: OpenSearchDashboardsReactNotifications; | ||
} | ||
|
||
export interface DashboardsObservabilityContext<T extends OpenSearchDashboardsServices> { | ||
value: ObservabilityDashboardsReactContextValue<T>; | ||
Provider: React.FC<{ services?: T; children: React.ReactDOM }>; | ||
Consumer: React.Consumer<ObservabilityDashboardsReactContextValue<T>>; | ||
} |
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Services
is a generic type that extendsOpenSearchDashboardsServices
, how does it ensure that Observability specific services likepplService
are passed in?