mirror of
https://github.com/elastic/kibana.git
synced 2025-04-25 02:09:32 -04:00
## Summary This is a refactor: * Move `FilesContext`, `FilePicker` and `UploadFile` components to `packages/shared-ux/file` as packages * Renamed `UploadFile` to `FileUpload` for more consistency * Also created `packages/shared-ux/file/types` and added `useBehaviourSubject` to `packages/shared-ux/file/util` (we can consider moving this elsewhere since that function is not necessarily tied to the files domain). * Removed the storybook config from `files` public plugin since there are no more components there ## How to test 👉🏻 `yarn storybook shared_ux` to see the components in a lab environment OR 👉🏻 `yarn start --run-examples` then "Developer examples" > "Files example" to see the components being used in Kibana Look out for any regressions: for example, in the `FileImage` component importing `import bh from 'blurhash'` caused a regression because blurhash does not expose a default export. This was fixed by doing: `import * as bh from 'blurhash`. ## Notes * With this change, we needed to move `FilesClient` interface to packages since it is used by the components. However, we also wanted to keep `FilesClient` interface as it is currently exported from `files` plugin because it exposes methods that only the server of `files` plugin should know about (e.g., the metrics endpoint). I created the `BaseFilesClient` in the packages directory that is extended in the `files` plugin as needed. This is a snapshot of the types as they are provided from the server implementation and will need to be updated/maintained by hand from here on out. * With `BaseFilesClient` in `packages`, we lost the type check between `files` server endpoints and the client methods. To re-establish this link the `CreateRouteDefinition` type helper got a parameter where the client method can be passed in to do checks that the server inputs (query, param and body) as well as outputs (the responses) match what the client expects using the `X extends Y ? X : unknown` capability of TS. See this in action in, for example `src/plugins/files/server/routes/find.ts`. DX will be: if these ever get out of sync, the server values for `query`, `param` or `body` will map to `unknown` causing a type issue when trying to use these values. This can only be fixed by bringing the `FilesClient` types in sync with the server types. * Server endpoints that should match expected `FilesClient` inputs/outputs should use the `CreateRouteDefinition` type helper, but if the endpoint does not need to map to a client method we can always skip using `CreateRouteDefinition`. Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> |
||
---|---|---|
.. | ||
index.ts |