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

[SharedUX][PoC] Move to a package architecture #127419

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@
"@kbn/securitysolution-utils": "link:bazel-bin/packages/kbn-securitysolution-utils",
"@kbn/server-http-tools": "link:bazel-bin/packages/kbn-server-http-tools",
"@kbn/server-route-repository": "link:bazel-bin/packages/kbn-server-route-repository",
"@kbn/sharedux-components": "link:bazel-bin/packages/kbn-sharedux-components",
"@kbn/sharedux-services": "link:bazel-bin/packages/kbn-sharedux-services",
"@kbn/sharedux-storybook": "link:bazel-bin/packages/kbn-sharedux-storybook",
"@kbn/sharedux-utility": "link:bazel-bin/packages/kbn-sharedux-utility",
"@kbn/std": "link:bazel-bin/packages/kbn-std",
"@kbn/timelion-grammar": "link:bazel-bin/packages/kbn-timelion-grammar",
"@kbn/tinymath": "link:bazel-bin/packages/kbn-tinymath",
Expand Down Expand Up @@ -195,6 +199,10 @@
"@turf/helpers": "6.0.1",
"@turf/length": "^6.0.2",
"@types/jsonwebtoken": "^8.5.6",
"@types/kbn__sharedux-components": "link:bazel-bin/packages/kbn-sharedux-components/npm_module_types",
"@types/kbn__sharedux-services": "link:bazel-bin/packages/kbn-sharedux-services/npm_module_types",
"@types/kbn__sharedux-storybook": "link:bazel-bin/packages/kbn-sharedux-storybook/npm_module_types",
"@types/kbn__sharedux-utility": "link:bazel-bin/packages/kbn-sharedux-utility/npm_module_types",
"@types/moment-duration-format": "^2.2.3",
"JSONStream": "1.3.5",
"abort-controller": "^3.0.0",
Expand Down
8 changes: 8 additions & 0 deletions packages/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ filegroup(
"//packages/kbn-securitysolution-utils:build",
"//packages/kbn-server-http-tools:build",
"//packages/kbn-server-route-repository:build",
"//packages/kbn-sharedux-components:build",
"//packages/kbn-sharedux-services:build",
"//packages/kbn-sharedux-storybook:build",
"//packages/kbn-sharedux-utility:build",
"//packages/kbn-spec-to-console:build",
"//packages/kbn-std:build",
"//packages/kbn-storybook:build",
Expand Down Expand Up @@ -138,6 +142,10 @@ filegroup(
"//packages/kbn-securitysolution-utils:build_types",
"//packages/kbn-server-http-tools:build_types",
"//packages/kbn-server-route-repository:build_types",
"//packages/kbn-sharedux-components:build_types",
"//packages/kbn-sharedux-services:build_types",
"//packages/kbn-sharedux-storybook:build_types",
"//packages/kbn-sharedux-utility:build_types",
"//packages/kbn-std:build_types",
"//packages/kbn-storybook:build_types",
"//packages/kbn-telemetry-tools:build_types",
Expand Down
144 changes: 144 additions & 0 deletions packages/kbn-sharedux-components/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
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-sharedux-components"
PKG_REQUIRE_NAME = "@kbn/sharedux-components"

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",
"@npm//@elastic/eui",
"@npm//@emotion/react",
"@npm//@emotion/css",
"@npm//classnames",
"@npm//@storybook/addon-actions",
"//packages/kbn-sharedux-services",
"//packages/kbn-sharedux-storybook",
"//packages/kbn-sharedux-utility",
"//packages/kbn-i18n",
"//packages/kbn-i18n-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",
"@npm//@elastic/eui",
"@npm//@emotion/react",
"@npm//@emotion/css",
"@npm//@storybook/addon-actions",
"@npm//@types/classnames",
"//packages/kbn-sharedux-services:npm_module_types",
"//packages/kbn-sharedux-storybook:npm_module_types",
"//packages/kbn-sharedux-utility:npm_module_types",
"//packages/kbn-i18n:npm_module_types",
"//packages/kbn-i18n-react:npm_module_types",
]

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"],
)
3 changes: 3 additions & 0 deletions packages/kbn-sharedux-components/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @kbn/sharedux-components

Empty package generated by @kbn/generate
13 changes: 13 additions & 0 deletions packages/kbn-sharedux-components/jest.config.js
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-sharedux-components'],
};
8 changes: 8 additions & 0 deletions packages/kbn-sharedux-components/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "@kbn/sharedux-components",
"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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
import React from 'react';

import { EuiLoadingSpinner } from '@elastic/eui';

import { withSuspense } from '../../utility';
import { withSuspense } from '@kbn/sharedux-utility';

export const LazyDataViewIllustration = React.lazy(() =>
import('../assets/data_view_illustration').then(({ DataViewIllustration }) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
*/
import React from 'react';
import { action } from '@storybook/addon-actions';

import { docLinksServiceFactory } from '../../../services/storybook/doc_links';
import { docLinksServiceFactory } from '@kbn/sharedux-storybook';

import { NoDataViews as NoDataViewsComponent, Props } from './no_data_views.component';
import { NoDataViews } from './no_data_views';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,22 @@ import { ReactWrapper } from 'enzyme';

import { mountWithIntl } from '@kbn/test-jest-helpers';
import { EuiButton } from '@elastic/eui';
import {
SharedUXServicesProvider,
SharedUXServices,
mockServiceFactories,
} from '@kbn/sharedux-services';

import { ServicesProvider, SharedUXServices } from '../../../services';
import { servicesFactory } from '../../../services/mocks';
import { NoDataViews } from './no_data_views';

describe('<NoDataViewsPageTest />', () => {
let services: SharedUXServices;
let mount: (element: JSX.Element) => ReactWrapper;

beforeEach(() => {
services = servicesFactory();
services = mockServiceFactories.servicesFactory();
Copy link
Contributor

Choose a reason for hiding this comment

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

If the module is called somethingServiceFactories, should the method be called services rather than servicesFactory?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The singleton is a collection of all of the factories, and the servicesFactory universal factory for all of them. I think the naming could definitely use some work.

mount = (element: JSX.Element) =>
mountWithIntl(<ServicesProvider {...services}>{element}</ServicesProvider>);
mountWithIntl(<SharedUXServicesProvider {...services}>{element}</SharedUXServicesProvider>);
});

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@
*/

import React, { useCallback, useEffect, useRef } from 'react';

import { DataView } from '../../../../../data_views/public';
import { useEditors, usePermissions } from '../../../services';
import type { SharedUXEditorsService } from '../../../services/editors';
import { useEditors, usePermissions } from '@kbn/sharedux-services';
import type { SharedUXEditorsService } from '@kbn/sharedux-services';

import { NoDataViews as NoDataViewsComponent } from './no_data_views.component';

export interface Props {
onDataViewCreated: (dataView: DataView) => void;
onDataViewCreated: (dataView: unknown) => void;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I want there to be a better type for this. I've asked in the Typescript group.

Copy link
Contributor

Choose a reason for hiding this comment

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

What's wrong with DataView?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@majagrubic DataView is a type from src/plugins/data_views/public. Packages cannot depend on plugins.

dataViewsDocLink: string;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,22 @@
import React from 'react';
import { mount as enzymeMount, ReactWrapper } from 'enzyme';
import { keys } from '@elastic/eui';
import {
SharedUXServicesProvider,
SharedUXServices,
mockServiceFactories,
} from '@kbn/sharedux-services';

import { ServicesProvider, SharedUXServices } from '../../services';
import { servicesFactory } from '../../services/mocks';
import { ExitFullScreenButton } from './exit_full_screen_button';

describe('<ExitFullScreenButton />', () => {
let services: SharedUXServices;
let mount: (element: JSX.Element) => ReactWrapper;

beforeEach(() => {
services = servicesFactory();
services = mockServiceFactories.servicesFactory();
mount = (element: JSX.Element) =>
enzymeMount(<ServicesProvider {...services}>{element}</ServicesProvider>);
enzymeMount(<SharedUXServicesProvider {...services}>{element}</SharedUXServicesProvider>);
});

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import React, { useCallback, useEffect } from 'react';
import { useEuiTheme, keys } from '@elastic/eui';
import { css } from '@emotion/react';

import { usePlatformService } from '@kbn/sharedux-services';

import { ExitFullScreenButton as Component } from './exit_full_screen_button.component';
import { usePlatformService } from '../../services';

/**
* Props for the service-enabled Exit Full Screen button component.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import React from 'react';
import { withSuspense } from './utility';
import { withSuspense } from '@kbn/sharedux-utility';

/**
* The Lazily-loaded `ExitFullScreenButton` component. Consumers should use `React.Suspennse` or the
Expand Down Expand Up @@ -43,7 +43,7 @@ export const SolutionToolbarButton = withSuspense(LazySolutionToolbarButton);
* The Lazily-loaded `NoDataViews` component. Consumers should use `React.Suspennse` or the
* `withSuspense` HOC to load this component.
*/
export const LazyNoDataViewsPage = React.lazy(() =>
export const LazyNoDataViews = React.lazy(() =>
import('./empty_state/no_data_views').then(({ NoDataViews }) => ({
default: NoDataViews,
}))
Expand All @@ -54,4 +54,4 @@ export const LazyNoDataViewsPage = React.lazy(() =>
* be used directly by consumers and will load the `LazyNoDataViewsPage` component lazily with
* a predefined fallback and error boundary.
*/
export const NoDataViewsPage = withSuspense(LazyNoDataViewsPage);
export const NoDataViews = withSuspense(LazyNoDataViews);
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@

import { mount as enzymeMount, ReactWrapper } from 'enzyme';
import React from 'react';
import { ServicesProvider, SharedUXServices } from '../../../../services';
import { servicesFactory } from '../../../../services/mocks';

import {
SharedUXServicesProvider,
SharedUXServices,
mockServiceFactories,
} from '@kbn/sharedux-services';

import { SolutionToolbarButton } from './primary';

Expand All @@ -18,9 +22,9 @@ describe('<SolutionToolbarButton />', () => {
let mount: (element: JSX.Element) => ReactWrapper;

beforeEach(() => {
services = servicesFactory();
services = mockServiceFactories.servicesFactory();
mount = (element: JSX.Element) =>
enzymeMount(<ServicesProvider {...services}>{element}</ServicesProvider>);
enzymeMount(<SharedUXServicesProvider {...services}>{element}</SharedUXServicesProvider>);
});

afterEach(() => {
Expand Down
18 changes: 18 additions & 0 deletions packages/kbn-sharedux-components/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": "../../tsconfig.bazel.json",
"compilerOptions": {
"declaration": true,
"emitDeclarationOnly": true,
"outDir": "target_types",
"rootDir": "src",
"stripInternal": false,
"types": [
"jest",
"node",
"@emotion/react/types/css-prop"
]
},
"include": [
"src/**/*"
]
}
Loading