From 02c21f5cb015b07b1499a5fc1171a3698a865a17 Mon Sep 17 00:00:00 2001 From: Feiyu Wong Date: Fri, 12 Aug 2022 08:47:06 -0700 Subject: [PATCH] Changed documentation with DataSource to be up to date Summary: Since there were large refactoring's done to `DataSource` during the milestone for side-by-side panels, wanted to update some of the documentation as well so that the information is accurate and up to date. Reviewed By: mweststrate Differential Revision: D38541404 fbshipit-source-id: a6ba472f881fb8cbfa90ff5ac295a0b87c595080 --- .../flipper-plugin/src/data-source/DataSource.tsx | 7 +++++++ docs/extending/flipper-plugin.mdx | 13 +++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/desktop/flipper-plugin/src/data-source/DataSource.tsx b/desktop/flipper-plugin/src/data-source/DataSource.tsx index fbc6df931..9880f4f23 100644 --- a/desktop/flipper-plugin/src/data-source/DataSource.tsx +++ b/desktop/flipper-plugin/src/data-source/DataSource.tsx @@ -438,6 +438,13 @@ export class DataSource { return newView; } + /** + * Returns a new view of the `DataSource` if there doesn't exist a `DataSourceView` with the `viewId` passed in. + * The view will allow different filters and sortings on the `DataSource` which can be helpful in cases + * where multiple tables/views are needed. + * @param viewId id for the `DataSourceView` + * @returns `DataSourceView` that corresponds to the `viewId` + */ public getAdditionalView(viewId: string): DataSourceView { if (viewId in this.additionalViews) { return this.additionalViews[viewId]; diff --git a/docs/extending/flipper-plugin.mdx b/docs/extending/flipper-plugin.mdx index 6730f2a0b..b0bb3f5b7 100644 --- a/docs/extending/flipper-plugin.mdx +++ b/docs/extending/flipper-plugin.mdx @@ -575,10 +575,11 @@ To optimise for this situation, there is a dedicated `createDataSource` abstract `DataSource` is a data collection that is heavily optimized for `append` and `update`, which stores items based on insertion order, but also allows for efficient by-id lookups. -Each `DataSource` exposes a `view` property, which contains a `DataSourceView`. +Each `DataSource` exposes a default `view` property, which contains a `DataSourceView`. A `DataSourceView` is a materialized view that can be sorted, filtered and windowed, and is kept incrementally up to date with the underlying `DataSource`. When using the `DataTable` component, this `view` will be managed by the table automatically, giving plugin users the capability to freely sort, filter, search and tail your datasource. +Alternatively, you could also pass in a different view(like from additionalViews) to the `DataTable` component which allows for different filters, searches, etc. than the default `view`. Valid `options` are: @@ -617,7 +618,11 @@ The maximum number of records that can be stored in this DataSource to constrain ##### view -Returns the currently active view on the data source. Note that be default it is windowed on the impractical `[0, 0)` range. For more details, see [DataSourceView](#datasourceview). +Returns the currently active default view on the data source. Note that be default it is windowed on the impractical `[0, 0)` range. For more details, see [DataSourceView](#datasourceview). + +##### additionalViews + +Holds additional `DataSourceView` on this `DataSource`. It contains key of `viewId: string` and value of `DataSourceView`. The default view in `DataSource` has `DEFAULT_VIEW_ID = '0'`, so all additionalViews cannot use this as the `viewId`. This is a `readonly` array and additional views are appended to the array by calling `getAdditionalView(viewId: string)` with a new `viewId` ##### size @@ -675,9 +680,9 @@ Usage: `shift(amount: number)`. Removes the first `amount` records from the data Usage: `clear()`. Removes all records from this data source. -##### fork +##### getAdditionalView -Usage: `fork(): DataSourceView`. Creates an additional materialized view on this data source with its own sort / filter settings. This feature is not implemented yet so contact Flipper oncall if needed. +Usage: `getAdditionalView(viewId: string)`. Gets an additional `DataSourceView` of the `DataSource` by passing in an identifier `viewId`. If there already exists a `DataSourceView` with the `viewId`, we simply return that view instead. #### DataSourceView