Skip to content

Commit bc56e60

Browse files
authored
[kibana_react] Extract <FieldButton /> and <FieldIcon/> to a package (#115377)
1 parent bbc50bc commit bc56e60

File tree

40 files changed

+236
-22
lines changed

40 files changed

+236
-22
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
/examples/partial_results_example/ @elastic/kibana-app-services
6262
/packages/elastic-datemath/ @elastic/kibana-app-services
6363
/packages/kbn-interpreter/ @elastic/kibana-app-services
64+
/packages/kbn-react-field/ @elastic/kibana-app-services
6465
/src/plugins/bfetch/ @elastic/kibana-app-services
6566
/src/plugins/data/ @elastic/kibana-app-services
6667
/src/plugins/data_views/ @elastic/kibana-app-services

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@
139139
"@kbn/logging": "link:bazel-bin/packages/kbn-logging",
140140
"@kbn/mapbox-gl": "link:bazel-bin/packages/kbn-mapbox-gl",
141141
"@kbn/monaco": "link:bazel-bin/packages/kbn-monaco",
142+
"@kbn/react-field": "link:bazel-bin/packages/kbn-react-field",
142143
"@kbn/rule-data-utils": "link:bazel-bin/packages/kbn-rule-data-utils",
143144
"@kbn/securitysolution-autocomplete": "link:bazel-bin/packages/kbn-securitysolution-autocomplete",
144145
"@kbn/securitysolution-es-utils": "link:bazel-bin/packages/kbn-securitysolution-es-utils",

packages/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ filegroup(
3636
"//packages/kbn-optimizer:build",
3737
"//packages/kbn-plugin-generator:build",
3838
"//packages/kbn-plugin-helpers:build",
39+
"//packages/kbn-react-field:build",
3940
"//packages/kbn-rule-data-utils:build",
4041
"//packages/kbn-securitysolution-autocomplete:build",
4142
"//packages/kbn-securitysolution-list-constants:build",

packages/kbn-optimizer/limits.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ pageLoadAssetSize:
104104
dataViews: 41532
105105
expressions: 140958
106106
fieldFormats: 65209
107-
kibanaReact: 84422
107+
kibanaReact: 74422
108108
share: 71239
109109
uiActions: 35121
110110
dataEnhanced: 24980

packages/kbn-optimizer/src/worker/webpack.config.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ const IS_CODE_COVERAGE = !!process.env.CODE_COVERAGE;
2828
const ISTANBUL_PRESET_PATH = require.resolve('@kbn/babel-preset/istanbul_preset');
2929
const BABEL_PRESET_PATH = require.resolve('@kbn/babel-preset/webpack_preset');
3030

31+
const nodeModulesButNotKbnPackages = (path: string) => {
32+
if (!path.includes('node_modules')) {
33+
return false;
34+
}
35+
36+
return !path.includes(`node_modules${Path.sep}@kbn${Path.sep}`);
37+
};
38+
3139
export function getWebpackConfig(bundle: Bundle, bundleRefs: BundleRefs, worker: WorkerConfig) {
3240
const ENTRY_CREATOR = require.resolve('./entry_point_creator');
3341

@@ -138,7 +146,7 @@ export function getWebpackConfig(bundle: Bundle, bundleRefs: BundleRefs, worker:
138146
},
139147
{
140148
test: /\.scss$/,
141-
exclude: /node_modules/,
149+
exclude: nodeModulesButNotKbnPackages,
142150
oneOf: [
143151
...worker.themeTags.map((theme) => ({
144152
resourceQuery: `?${theme}`,
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
load("@npm//@bazel/typescript:index.bzl", "ts_config", "ts_project")
2+
load("@build_bazel_rules_nodejs//:index.bzl", "js_library", "pkg_npm")
3+
load("//src/dev/bazel:index.bzl", "jsts_transpiler")
4+
5+
PKG_BASE_NAME = "kbn-react-field"
6+
PKG_REQUIRE_NAME = "@kbn/react-field"
7+
8+
SOURCE_FILES = glob(
9+
[
10+
"src/**/*.ts",
11+
"src/**/*.tsx",
12+
"src/**/*.scss",
13+
"src/**/*.svg",
14+
],
15+
exclude = [
16+
"**/*.test.*",
17+
"**/__fixtures__/**",
18+
"**/__snapshots__/**",
19+
],
20+
)
21+
22+
SRCS = SOURCE_FILES
23+
24+
filegroup(
25+
name = "srcs",
26+
srcs = SRCS,
27+
)
28+
29+
NPM_MODULE_EXTRA_FILES = [
30+
"package.json",
31+
"README.md",
32+
"field_button/package.json",
33+
"field_icon/package.json",
34+
]
35+
36+
RUNTIME_DEPS = [
37+
"@npm//prop-types",
38+
"@npm//react",
39+
"@npm//classnames",
40+
"@npm//@elastic/eui",
41+
"//packages/kbn-i18n",
42+
]
43+
44+
TYPES_DEPS = [
45+
"//packages/kbn-babel-preset",
46+
"//packages/kbn-i18n",
47+
"@npm//tslib",
48+
"@npm//@types/jest",
49+
"@npm//@types/prop-types",
50+
"@npm//@types/classnames",
51+
"@npm//@types/react",
52+
"@npm//@elastic/eui",
53+
"@npm//resize-observer-polyfill",
54+
]
55+
56+
jsts_transpiler(
57+
name = "target_webpack",
58+
srcs = SRCS,
59+
build_pkg_name = package_name(),
60+
web = True,
61+
additional_args = [
62+
"--copy-files",
63+
"--quiet"
64+
],
65+
)
66+
67+
jsts_transpiler(
68+
name = "target_node",
69+
srcs = SRCS,
70+
build_pkg_name = package_name(),
71+
additional_args = [
72+
"--copy-files",
73+
"--quiet"
74+
],
75+
)
76+
77+
ts_config(
78+
name = "tsconfig",
79+
src = "tsconfig.json",
80+
deps = [
81+
"//:tsconfig.base.json",
82+
"//:tsconfig.bazel.json",
83+
],
84+
)
85+
86+
ts_project(
87+
name = "tsc_types",
88+
args = ['--pretty'],
89+
srcs = SRCS,
90+
deps = TYPES_DEPS,
91+
declaration = True,
92+
declaration_map = True,
93+
emit_declaration_only = True,
94+
out_dir = "target_types",
95+
source_map = True,
96+
root_dir = "src",
97+
tsconfig = ":tsconfig",
98+
)
99+
100+
js_library(
101+
name = PKG_BASE_NAME,
102+
srcs = NPM_MODULE_EXTRA_FILES,
103+
deps = RUNTIME_DEPS + [":target_node", ":target_webpack", ":tsc_types"],
104+
package_name = PKG_REQUIRE_NAME,
105+
visibility = ["//visibility:public"],
106+
)
107+
108+
pkg_npm(
109+
name = "npm_module",
110+
deps = [
111+
":%s" % PKG_BASE_NAME,
112+
]
113+
)
114+
115+
filegroup(
116+
name = "build",
117+
srcs = [
118+
":npm_module",
119+
],
120+
visibility = ["//visibility:public"],
121+
)

packages/kbn-react-field/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Shareable field type related React components
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"main": "../target_node/field_button/index.js",
3+
"browser": "../target_webpack/field_button/index.js",
4+
"types": "../target_types/field_button/index.d.ts"
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"main": "../target_node/field_icon/index.js",
3+
"browser": "../target_webpack/field_icon/index.js",
4+
"types": "../target_types/field_icon/index.d.ts"
5+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
module.exports = {
10+
preset: '@kbn/test',
11+
rootDir: '../..',
12+
roots: ['<rootDir>/packages/kbn-react-field'],
13+
};

0 commit comments

Comments
 (0)