-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[sharedUX] Move to Package-based Architecture #127546
Merged
Merged
Changes from 3 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
13efeb8
[shared-ux][packages] 1. Create Services Package
clintandrewhall e990d54
Merge branch 'main' into shared_ux/packages/services
kibanamachine dddafc0
Address review feedback
clintandrewhall 2976de7
[shared-ux][packages] 2. Create Storybook Package (#127548)
clintandrewhall aa97305
Merge remote-tracking branch 'upstream/main' into shared_ux/packages/…
clintandrewhall 87a0ea7
Merging
clintandrewhall 26b25e3
Adding docs
clintandrewhall 2cf8743
Merge branch 'main' into shared_ux/packages/services
kibanamachine 645ab34
A few fixes
clintandrewhall 0f7b1cc
Fix TS types
clintandrewhall 70b1661
Merge remote-tracking branch 'upstream' into shared_ux/packages/services
clintandrewhall 7e027c7
Merge remote-tracking branch 'elastic/main' into shared_ux/packages/s…
clintandrewhall 9be7c74
Fix TS types
clintandrewhall d3786b2
Merge branch 'main' into shared_ux/packages/services
clintandrewhall 0bb9bb2
Merge branch 'main' into shared_ux/packages/services
kibanamachine 3494d5e
Fix i18n
clintandrewhall File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
load("@npm//@bazel/typescript:index.bzl", "ts_config") | ||
load("@build_bazel_rules_nodejs//:index.bzl", "js_library") | ||
load("//src/dev/bazel:index.bzl", "jsts_transpiler", "pkg_npm", "pkg_npm_types", "ts_project") | ||
|
||
PKG_DIRNAME = "kbn-shared-ux-services" | ||
PKG_REQUIRE_NAME = "@kbn/shared-ux-services" | ||
|
||
SOURCE_FILES = glob( | ||
[ | ||
"src/**/*.ts", | ||
"src/**/*.tsx", | ||
], | ||
exclude = [ | ||
"**/*.test.*", | ||
], | ||
) | ||
|
||
SRCS = SOURCE_FILES | ||
|
||
filegroup( | ||
name = "srcs", | ||
srcs = SRCS, | ||
) | ||
|
||
NPM_MODULE_EXTRA_FILES = [ | ||
"package.json", | ||
] | ||
|
||
# In this array place runtime dependencies, including other packages and NPM packages | ||
# which must be available for this code to run. | ||
# | ||
# To reference other packages use: | ||
# "//repo/relative/path/to/package" | ||
# eg. "//packages/kbn-utils" | ||
# | ||
# To reference a NPM package use: | ||
# "@npm//name-of-package" | ||
# eg. "@npm//lodash" | ||
RUNTIME_DEPS = [ | ||
"@npm//react", | ||
] | ||
|
||
# In this array place dependencies necessary to build the types, which will include the | ||
# :npm_module_types target of other packages and packages from NPM, including @types/* | ||
# packages. | ||
# | ||
# To reference the types for another package use: | ||
# "//repo/relative/path/to/package:npm_module_types" | ||
# eg. "//packages/kbn-utils:npm_module_types" | ||
# | ||
# References to NPM packages work the same as RUNTIME_DEPS | ||
TYPES_DEPS = [ | ||
"@npm//@types/node", | ||
"@npm//@types/jest", | ||
"@npm//@types/react", | ||
] | ||
|
||
jsts_transpiler( | ||
name = "target_node", | ||
srcs = SRCS, | ||
build_pkg_name = package_name(), | ||
) | ||
|
||
jsts_transpiler( | ||
name = "target_web", | ||
srcs = SRCS, | ||
build_pkg_name = package_name(), | ||
web = True, | ||
) | ||
|
||
ts_config( | ||
name = "tsconfig", | ||
src = "tsconfig.json", | ||
deps = [ | ||
"//:tsconfig.base.json", | ||
"//:tsconfig.bazel.json", | ||
], | ||
) | ||
|
||
ts_project( | ||
name = "tsc_types", | ||
args = ['--pretty'], | ||
srcs = SRCS, | ||
deps = TYPES_DEPS, | ||
declaration = True, | ||
emit_declaration_only = True, | ||
out_dir = "target_types", | ||
root_dir = "src", | ||
tsconfig = ":tsconfig", | ||
) | ||
|
||
js_library( | ||
name = PKG_DIRNAME, | ||
srcs = NPM_MODULE_EXTRA_FILES, | ||
deps = RUNTIME_DEPS + [":target_node", ":target_web"], | ||
package_name = PKG_REQUIRE_NAME, | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
pkg_npm( | ||
name = "npm_module", | ||
deps = [":" + PKG_DIRNAME], | ||
) | ||
|
||
filegroup( | ||
name = "build", | ||
srcs = [":npm_module"], | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
pkg_npm_types( | ||
name = "npm_module_types", | ||
srcs = SRCS, | ||
deps = [":tsc_types"], | ||
package_name = PKG_REQUIRE_NAME, | ||
tsconfig = ":tsconfig", | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
filegroup( | ||
name = "build_types", | ||
srcs = [":npm_module_types"], | ||
visibility = ["//visibility:public"], | ||
) |
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,10 @@ | ||
--- | ||
id: kibSharedUXServices | ||
slug: /kibana-dev-docs/shared-ux/packages/kbn-shared-ux-services | ||
title: Shared UX Services | ||
summary: | ||
date: 2022-03-11 | ||
tags: ['kibana', 'dev', 'sharedUX'] | ||
--- | ||
|
||
> TODO |
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,13 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
module.exports = { | ||
preset: '@kbn/test', | ||
rootDir: '../..', | ||
roots: ['<rootDir>/packages/kbn-shared-ux-services'], | ||
}; |
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,8 @@ | ||
{ | ||
"name": "@kbn/shared-ux-services", | ||
"private": true, | ||
"version": "1.0.0", | ||
"main": "./target_node/index.js", | ||
"browser": "./target_web/index.js", | ||
"license": "SSPL-1.0 OR Elastic License 2.0" | ||
} |
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,61 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import React, { FC, createContext, useContext } from 'react'; | ||
|
||
import type { SharedUxServices } from './types'; | ||
|
||
// The React Context used to provide the services to the SharedUX components. | ||
const SharedUxServicesContext = createContext<SharedUxServices | null>(null); | ||
|
||
/** | ||
* The `React.Context` Provider component for the `SharedUxServices` context. Any | ||
* plugin or environment that consumes SharedUX components needs to wrap their React | ||
* tree with this provider. | ||
* | ||
* Within a plugin, you can use use the Shared UX plugin and retrieve a fully-configured | ||
* context from the `start` contract. | ||
*/ | ||
export const SharedUxServicesProvider: FC<SharedUxServices> = ({ children, ...services }) => ( | ||
<SharedUxServicesContext.Provider value={services}>{children}</SharedUxServicesContext.Provider> | ||
); | ||
|
||
/** | ||
* React hook for accessing pre-wired `SharedUxServices`. | ||
*/ | ||
export function useSharedUxServices() { | ||
const context = useContext(SharedUxServicesContext); | ||
|
||
if (!context) { | ||
throw new Error( | ||
'SharedUxServicesContext missing. Ensure your component or React root is wrapped with SharedUxServicesProvider.' | ||
); | ||
} | ||
|
||
return context; | ||
} | ||
|
||
/** | ||
* React hook for accessing the pre-wired `SharedUxPlatformService`. | ||
*/ | ||
export const usePlatformService = () => useSharedUxServices().platform; | ||
|
||
/** | ||
* React hook for accessing the pre-wired `SharedUxPermissionsService`. | ||
*/ | ||
export const usePermissions = () => useSharedUxServices().permissions; | ||
|
||
/** | ||
* React hook for accessing the pre-wired `SharedUxEditorsService`. | ||
*/ | ||
export const useEditors = () => useSharedUxServices().editors; | ||
|
||
/** | ||
* React hook for accessing the pre-wired `SharedUxDocLinksService`. | ||
*/ | ||
export const useDocLinks = () => useSharedUxServices().docLinks; |
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,31 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export type { ServiceFactory, SharedUxServices, SharedUxServicesContext } from './types'; | ||
export type { | ||
SharedUxDocLinksService, | ||
SharedUxEditorsService, | ||
SharedUxPlatformService, | ||
SharedUxUserPermissionsService, | ||
} from './services'; | ||
|
||
export { | ||
SharedUxServicesProvider, | ||
useDocLinks, | ||
useEditors, | ||
usePermissions, | ||
usePlatformService, | ||
useSharedUxServices, | ||
} from './context'; | ||
|
||
export { | ||
mockServiceFactories, | ||
mockServicesFactory, | ||
stubServiceFactories, | ||
stubServicesFactory, | ||
} from './services'; |
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,14 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
/** | ||
* A service providing links to documentation about various features in Kibana. | ||
*/ | ||
export interface SharedUxDocLinksService { | ||
dataViewsDocLink: string; | ||
} |
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,32 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
/** | ||
* TODO: `DataView` is a class exported by `src/plugins/data_views/public`. Since this service | ||
* is contained in this package-- and packages can only depend on other packages and never on | ||
* plugins-- we have to set this to `unknown`. If and when `DataView` is exported from a | ||
* stateless package, we can remove this. | ||
*/ | ||
type DataView = unknown; | ||
|
||
/** | ||
* A subset of the `DataViewEditorOptions` interface relevant to our service and components. | ||
* | ||
* @see: src/plugins/data_view_editor/public/types.ts | ||
*/ | ||
interface DataViewEditorOptions { | ||
onSave: (dataView: DataView) => void; | ||
} | ||
|
||
/** | ||
* A service providing methods to invoke and interact with various editors provided | ||
* in Kibana. | ||
*/ | ||
export interface SharedUxEditorsService { | ||
openDataViewEditor: (options: DataViewEditorOptions) => () => void; | ||
} |
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,15 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export type { SharedUxDocLinksService } from './doc_links'; | ||
export type { SharedUxEditorsService } from './editors'; | ||
export type { SharedUxUserPermissionsService } from './permissions'; | ||
export type { SharedUxPlatformService } from './platform'; | ||
|
||
export { mockServicesFactory, mockServiceFactories } from './mock'; | ||
export { stubServicesFactory, stubServiceFactories } from './stub'; |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I accidentally left a comment in the PoC PR, so I'll just leave it here 😅
https://github.com/elastic/kibana/pull/127419/files#r826252775
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.
This should really be prioritized imho.