-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat: Implement child render function for DataGrid rows #25476
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
Merged
ling1726
merged 5 commits into
microsoft:master
from
ling1726:feat/datagrid-render-function
Nov 2, 2022
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b40b624
feat: Implement child render function for DataGrid rows
ling1726 f224e58
changefile
ling1726 e7d4c6d
update package.json
ling1726 fe570b5
update unit tests
ling1726 6c20b4f
Merge branch 'master' into feat/datagrid-render-function
ling1726 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-table-350ae095-7533-4307-a31f-6d9cbb178cb8.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "prerelease", | ||
| "comment": "feat: Implement child render function for DataGrid rows", | ||
| "packageName": "@fluentui/react-table", | ||
| "email": "[email protected]", | ||
| "dependentChangeType": "patch" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 11 additions & 3 deletions
14
packages/react-components/react-table/src/components/DataGrid/DataGrid.types.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,23 @@ | ||
| import { TableContextValues, TableProps, TableSlots, TableState } from '../Table/Table.types'; | ||
| import { TableState as HeadlessTableState } from '../../hooks'; | ||
|
|
||
| export type DataGridSlots = TableSlots; | ||
|
|
||
| export type DataGridContextValues = TableContextValues; | ||
| export type DataGridContextValues = TableContextValues & { | ||
| dataGrid: DataGridContextValue; | ||
| }; | ||
|
|
||
| // Use any here since we can't know the user types | ||
| // The user is responsible for narrowing the type downstream | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| export type DataGridContextValue = HeadlessTableState<any>; | ||
|
|
||
| /** | ||
| * DataGrid Props | ||
| */ | ||
| export type DataGridProps = TableProps; | ||
| export type DataGridProps = TableProps & Pick<DataGridContextValue, 'items' | 'columns'>; | ||
|
|
||
| /** | ||
| * State used in rendering DataGrid | ||
| */ | ||
| export type DataGridState = TableState; | ||
| export type DataGridState = TableState & { tableState: HeadlessTableState<unknown> }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 7 additions & 1 deletion
8
packages/react-components/react-table/src/components/DataGrid/renderDataGrid.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,15 @@ | ||
| import * as React from 'react'; | ||
| import type { DataGridContextValues, DataGridState } from './DataGrid.types'; | ||
| import { renderTable_unstable } from '../Table/renderTable'; | ||
| import { DataGridContextProvider } from '../../contexts/dataGridContext'; | ||
|
|
||
| /** | ||
| * Render the final JSX of DataGrid | ||
| */ | ||
| export const renderDataGrid_unstable = (state: DataGridState, contextValues: DataGridContextValues) => { | ||
| return renderTable_unstable(state, contextValues); | ||
| return ( | ||
| <DataGridContextProvider value={contextValues.dataGrid}> | ||
| {renderTable_unstable(state, contextValues)} | ||
| </DataGridContextProvider> | ||
| ); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 9 additions & 3 deletions
12
packages/react-components/react-table/src/components/DataGrid/useDataGridContextValues.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,12 @@ | ||
| import { useTableContextValues_unstable } from '../Table/useTableContextValues'; | ||
| import { DataGridState } from './DataGrid.types'; | ||
| import { DataGridContextValues, DataGridState } from './DataGrid.types'; | ||
|
|
||
| export function useDataGridContextValues_unstable(state: DataGridState) { | ||
| return useTableContextValues_unstable(state); | ||
| export function useDataGridContextValues_unstable(state: DataGridState): DataGridContextValues { | ||
| const tableContextValues = useTableContextValues_unstable(state); | ||
| return { | ||
| ...tableContextValues, | ||
| dataGrid: { | ||
| ...state.tableState, | ||
| }, | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 14 additions & 2 deletions
16
packages/react-components/react-table/src/components/DataGridBody/DataGridBody.types.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 2 additions & 4 deletions
6
...mponents/react-table/src/components/DataGridBody/__snapshots__/DataGridBody.test.tsx.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,10 @@ | ||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
|
||
| exports[`DataGridBody renders a default state 1`] = ` | ||
| exports[`DataGridBody renders items from render function 1`] = ` | ||
| <div> | ||
| <div | ||
| class="fui-DataGridBody fui-TableBody" | ||
| role="rowgroup" | ||
| > | ||
| Default DataGridBody | ||
| </div> | ||
| /> | ||
| </div> | ||
| `; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
packages/react-components/react-table/src/contexts/dataGridContext.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import { createContext, useContextSelector } from '@fluentui/react-context-selector'; | ||
| import type { ContextSelector } from '@fluentui/react-context-selector'; | ||
| import { DataGridContextValue } from '../components/DataGrid/DataGrid.types'; | ||
| import { defaultTableState } from '../hooks'; | ||
|
|
||
| const dataGridContext = createContext<DataGridContextValue | undefined>(undefined); | ||
|
|
||
| const dataGridContextDefaultValue: DataGridContextValue = { | ||
| ...defaultTableState, | ||
| }; | ||
|
|
||
| export const DataGridContextProvider = dataGridContext.Provider; | ||
|
|
||
| export const useDataGridContext_unstable = <T>(selector: ContextSelector<DataGridContextValue, T>) => | ||
| useContextSelector(dataGridContext, (ctx = dataGridContextDefaultValue) => selector(ctx)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, the naming is very confusing.... perhaps
useHeadlessTable?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah I agree, but I'd rather do this later, there are more important thigns that need to be implemented right now before we do a naming pass over everything