Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Implement basic OnyxDataGrid useTableFeature composable #1852

Open
10 tasks
JoCa96 opened this issue Sep 11, 2024 · 0 comments
Open
10 tasks

Implement basic OnyxDataGrid useTableFeature composable #1852

JoCa96 opened this issue Sep 11, 2024 · 0 comments
Assignees
Labels
dev Requires technical expertise Mob session
Milestone

Comments

@JoCa96
Copy link
Collaborator

JoCa96 commented Sep 11, 2024

Depends on

Description

The composable provides the basic API for implementing table features.

This is done by taking the provided user table data and transform and extend it.
Every feature can perform some transformations and wrap rendered slots.

In the first step, we implement the basic useTableFeature composable.
It should be enough to implement a Sort feature.

Implementation details

The basic useTableFeature composable API should look like this:

// we need to intersect the empty array, so the array entry types are inferred
export const useTableFeatures = <
  T extends TableFeature<any, any, any, any, any, any>[] | [],
  TFeatureName extends symbol = ExtractTFeatureName<T>,
>(
  features: T,
) => {
return {
    /** Takes the column definition and maps all, calls mutation func and maps at the end to RendererCell */
    enrichTableData,
    /** Takes the column definition and creates a RenderHeader for each, adds actions from features */
    enrichHeaders,
    // the combined `watch` for all features
    watcheSources,
  };
}

export type TableEntry = {
  id: string | number;
  [key: PropertyKey]: unknown;
};


export type TableFeature<
  TEntry extends TableEntry,
  TFeatureName extends symbol,
> = {
  /**
   * Unique name and identifier of the table feature
   */
  name: TFeatureName;

  /**
   * An array of reactive states that should trigger a table re-calcualtion
   */
  watch: WatchSource[];

  /**
   * Allows modifying the table state as a whole.
   */
  mutation?: {
    func: (state: EntryState<TEntry>[]) => EntryState<TEntry>[];
  };

  /**
   * Allows the modification of the header columns before render.
   */
  header?: {
    /** actions are shown after the header label, later `listComponent` can be added */
    actions?: { iconComponent: Component, onTrigger?: (event: MouseEvent) => void }[];
  };
};

Reference implementation

Design

https://www.figma.com/design/YfEUBOHk4J4nYrk04geswG/Onyx-Component-Library?node-id=4435-44768&node-type=text&m=dev

Acceptance criteria

  • a basic useTableFeature composable is used to create input for the renderer
  • a withSorting Feature is implemented using the API

Definition of Done

  • example usage added to apps/demo-app/src/views/HomeView.vue
  • covered by tests
    • functional tests (Playwright or unit test)
    • visual tests (Playwright screenshots)
  • follow-up tickets were created if necessary
  • updated version + documentation is deployed
  • Storybook can show the feature
  • Storybook code snippet of new/changed examples are checked that they are generated correctly
  • Namings are aligned with Figma

Approval

  • Storybook
  • Deployed Docs
  • approved by designer @jannick-ux
  • approved by dev
@mj-hof mj-hof added this to the Tables milestone Sep 30, 2024
@mj-hof mj-hof added the dev Requires technical expertise label Sep 30, 2024
@JoCa96 JoCa96 added the 0-refinement All issues that can or need to be estimated in our next refinement label Oct 2, 2024
@JoCa96 JoCa96 self-assigned this Oct 2, 2024
@mj-hof mj-hof removed the 0-refinement All issues that can or need to be estimated in our next refinement label Oct 2, 2024
JoCa96 added a commit that referenced this issue Oct 30, 2024
Relates to #1852 

Implemented basic `useTableFeature` API based on a simple sorting
feature.
The API and the feature set will be extended in future tickets.

---------

Co-authored-by: Lars Rickert <lars.rickert@mail.schwarz>
JoCa96 added a commit that referenced this issue Nov 11, 2024
Relates to #1852 

- Added `features` prop, which exposes the `useDataGridFeature` API to
allow devs to use custom and pre-defined features
- Expose onyx provided data-grid features via a re-export called
`DataGridFeatures`
- Added `DataGridFeatures.useSorting` feature, with support for custom
configuration
- Fixed issue where `OnyxDataGrid` didn't update on sort change: A deep
watcher is necessary, even when a non-shallow ref is used
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
dev Requires technical expertise Mob session
Projects
Status: In Progress
Development

No branches or pull requests

3 participants