kibana
kibana copied to clipboard
Ti plugin reorg
Summary
This PR does a complete restructure of the Threat Intelligence plugin. We can use this draft PR to discuss patterns that we like and ones that we do not.
I'm suggesting to not necessarily looking at the commits themselves as the changes are massive. An easier way might be to pull down the branch and look at the structure and naming and comment on that?
Here an unordered non-exhaustive list of the modifications:
- remove
Indicators
/Indicator
in the folders names and file names - consolidate flyout-related components under
flyout
folder, and removeFlyout
from folder names and file names - consolidate barchart-related components and hooks under
barchart
folder, and removeBarchart
from folder names and file names - consolidate table-related components, contexts and hooks under
table
folder - add missing
index.ts
files and rename allindex.tsx
files toindex.ts
for convention and consistency - move context-related code to
contexts
folders - move translations into
translations.ts
files - move all common, components and container files under
public
folder - rename
lib
folders toutils
- ran Optimize imports command to clean things up
Random notes & questions:
- this new structure introduces a structure with more nested folders. On one hand it creates a structure a bit more feature-oriented, where all the components, hooks, interfaces... related to a feature (the definition of feature isn't clear) are in the same folder. On the other hand, for some people it can make navigating the plugin's code more difficult
- do we want to add
index.ts
files everywhere or just in containers and component folders?
:broken_heart: Build Failed
- Buildkite Build
- Commit: 9031bc25e95886286d70a23060c99a6b38096a6d
- Interpreting CI Failures
- Storybooks Preview
Failed CI Steps
Test Failures
- [job] [logs] FTR Configs #19 / apis management index lifecycle management nodes list should return the list of ES node for each custom attributes
- [job] [logs] FTR Configs #19 / apis management index lifecycle management nodes list should return the list of ES node for each custom attributes
- [job] [logs] Jest Tests #6 / useToolbarOptions() should return correct value for 25 indicators total
- [job] [logs] Jest Tests #6 / useToolbarOptions() should return correct value for 50 indicators total
Metrics [docs]
Module Count
Fewer modules leads to a faster build time
id | before | after | diff |
---|---|---|---|
threatIntelligence |
199 | 221 | +22 |
Async chunks
Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app
id | before | after | diff |
---|---|---|---|
threatIntelligence |
73.1KB | 73.1KB | +65.0B |
Page load bundle
Size of the bundles that are downloaded on every page load. Target size is below 100kb
id | before | after | diff |
---|---|---|---|
threatIntelligence |
28.6KB | 28.6KB | +10.0B |
Unknown metric groups
ESLint disabled in files
id | before | after | diff |
---|---|---|---|
apm |
14 | 13 | -1 |
ESLint disabled line counts
id | before | after | diff |
---|---|---|---|
apm |
81 | 79 | -2 |
securitySolution |
407 | 403 | -4 |
threatIntelligence |
13 | 10 | -3 |
total | -9 |
Total ESLint disabled count
id | before | after | diff |
---|---|---|---|
apm |
95 | 92 | -3 |
securitySolution |
478 | 474 | -4 |
threatIntelligence |
14 | 11 | -3 |
total | -10 |
History
To update your PR or re-run it, just comment with:
@elasticmachine merge upstream
My 5 cents:
- do we need a separate
common
at all? I think having it on the same level withcomponents
,containers
etc. is confusing as everything that is outside of modules is common. I think we can just movemocks
,test
,utils
one level higher, andnavigation
can go into modules. The other option is actually moving everything exceptmodules
insidecommon
, so there are only two pathspublic/common
andpublic/modules
aspublic/common
inside has the same structure as any module potentially. -
barchart
inutils
seems alien after introducingbarchart
insidemodules/indicators
- about deep nesting, I also have mixed feelings about it. It looks logical but I don't like the duality of
components
.component
can mean either a stateless component or a "submodule" now. But I don't have a good solution for that tbh. Another problem I see is that lifting up should be simpler with the deep nesting, but lifting down is probably harder as you don't have good visibility into what is going on deep. Eg. if there is a hook insideindicators/hooks
which is related to the field browser, it is quite hard to grasp that there might also beindicator/components/table/components/field_browser/hooks
.
While writing it I also realized that maybe trying to place "common" things under one umbrella will lead to a pile of smth anyway. And in the end, everything can be part of a bigger logical module. I see the following patterns:
-
components/date_formatter
andutils/dates
could go intomodules/dates
-
mocks/mock_kibana_ui
,containers/security_solution*
,hooks/use_kibana*
,hooks/use_security_context
could go intomodules/kibana_interop
or maybe into two +modules/security_solution_interop
-
components/paywall
andcontainers/enterprise_guard
could go intomodules/enterprise_guard
-
mocks/story_provides
could go into `modules/storybook/story_providers - Stateless components agnostic to modules they are used in probably should be a module itself, eg.
layout
.
I tried to prepare a branch where I moved things around to POC with this approach. Maybe as with many ideas, it looks smart but disastrous in the end, but I'd like to hear your thoughts https://github.com/elastic/kibana/pull/141380
Also we should always remind ourselves about this good advice from react docs https://reactjs.org/docs/faq-structure.html#dont-overthink-it :)
nice job, though I have not went through it all yet. I will!
thanks @maxcold! Super useful to have your branch, it shows me things I didn't think about. It's nice to have other approaches as I find it often difficult to see outside of an idea you have...
Couple of comments:
- why not have a test module. It feels a bit weird to have only 2 top-level folders, and I feel like if we have a
storybook
module then we could have atest
module - if we move the
test
folder inmodules
, then why not getting rid of thatmodules
folder entirely and have all the folders inside at the top level, right underpublic
? (this is how the Security Solution plugin is) - one thing that I'm not a fan of though is that in
modules
, we now have folders that represents sections of the plugin (likeindicators
,timeline
andquery
for example, some other that are just groups of components (likedates
oreui_interop
). The same way cypress is a separate folder, I feel like I would like the idea of having things like tests, mocks, storybook utils or utils in general outisde of the notion of modules - as a specific example I find it weird to have
mock_security_context
underkibana_interop
but it's actually only used in thetest
andstorybook_interop
folders...
I'm not going to spend more time on this for now. I feel like I want the idea to mature in my head a bit, and discussing more all together over time will I'm sure bring more good ideas! :)