-
Notifications
You must be signed in to change notification settings - Fork 67
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
[useTree]: hook #1880
[useTree]: hook #1880
Conversation
Generated by: track-bundle-size
new sizes (raw)To set the sizes as a new baseline, you can copy/paste next content to the {
"version": "5.7.1",
"timestamp": "2024-04-03",
"sizes": {
"templateApp": {
"css": 284412,
"js": 814992
},
"@epam/app": {
"css": 1591977,
"js": 5249310
},
"@epam/draft-rte": {
"css": 9762,
"js": 45308
},
"@epam/electric": {
"css": 2289,
"js": 2299
},
"@epam/promo": {
"css": 40368,
"js": 16101
},
"@epam/uui-extra": {
"css": 0,
"js": 213
},
"@epam/loveship": {
"css": 49451,
"js": 54148
},
"@epam/uui-components": {
"css": 22214,
"js": 257005
},
"@epam/uui-core": {
"css": 0,
"js": 334039
},
"@epam/uui-db": {
"css": 0,
"js": 43327
},
"@epam/uui-docs": {
"css": 3189,
"js": 200715
},
"@epam/uui-editor": {
"css": 12625,
"js": 164792
},
"@epam/uui-timeline": {
"css": 2251,
"js": 46073
},
"@epam/uui": {
"css": 272887,
"js": 322954
}
}
} Generated by: generate-components-api Total amount of exported types/props without JSDoc comments
New missing commentsNOTE: It's either a new exported types/props without JSDoc, or it's an existing code from which you deleted the JSDoc comments.
|
|
||
const view = dataSource.useView(value, onValueChange, {}); | ||
const { listProps, visibleRows } = useDataRows({ |
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.
Let's try to adjust useDataRows output and DataTable's props to be compatible, and more convenient.
My proposal:
const { rowsCount, rows, totalCount } = useDataRows(); // to use separately
// to pass-thru to the table:
const rowProps = useDataRows();
<DataTable { ...rowsProps } />
DataTable needs a minimal adjustments to allow rows
prop, as alternative to getVisibleRows.
I also believe that rows
is better than visibleRows
, as 'visible' doesn't add any clarification in this case.
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.
I agree on rows
. It can be aligned without any problem.
There is a problem with the pass-through
approach.
interface DataRowsResult<TItem, TId> {
rows: DataRowProps<TItem, TId>[];
getSelectedRows: : ({ topIndex, visibleCount }?: VirtualListRange) => DataRowProps<TItem, TId>[];
getSelectedRowsCount: : () => number;
getById: (id: TId, index: number) => DataRowProps<TItem, TId>;
clearAllChecked: () => void;
listProps: DataSourceListProps;
selectAll: {
value: boolean;
onValueChange: (isChecked: boolean) => void;
indeterminate: boolean;
isDisabled?: undefined;
} | {
value: boolean;
onValueChange: () => void;
isDisabled: boolean;
indeterminate: boolean;
},
}
This is a return type of useDataRows
hook. Sometimes, all the properties, returned from this hook, are required. And not all of them should be passed to the DataTable
. If listProps is spread too, it will turn into a mess. Don't you think that the best idea is to leave it as a separate property, which collects all the stats about the datasource.
Otherwise, we'll face the further issue:
const {
getSelectedRows,
getSelectedRowsCount,
getById,
clearAllChecked,
selectAll,
...tableProps,
} = useDataRows(props);
<DataTable { ...tableProps } />;
To pass necessary data to a DataTable it will be required to destruct all the other props, which looks weird.
It seems to me, it is much better to extract only rows and listProps:
const { rows, listProps } = useDataRows(props);
<DataTable rows={ rows } { ...listProps } />;
@jakobz, WDYT about it?
@@ -58,6 +59,33 @@ export function prop<TObject, TKey extends keyof TObject>(name: TKey): ILensImpl | |||
}; | |||
} | |||
|
|||
export function get<TItem, TId>(id: TId): ILensImpl<ItemsMap<TId, TItem>, TItem> { |
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.
Let's:
- generalize this Lens to support any Map-like object. We can re-use the trick we used to abstract Map in Tree via IMap interface. This approach allows to support a native Map, as well as other Map-like objects. Including immutable Maps like I.Map - they can implement constructor as no-op.
- we need a better name for both ILensImpl and LensBuilder method. I suggest
mapItem
, but let's discuss - probably there'll be a better ideas.
@@ -0,0 +1,96 @@ | |||
export type OnUpdate<TId, TItem> = (newItemsMap: ItemsMap<TId, TItem>) => void; | |||
|
|||
interface ModificationOptions { |
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.
We can be more explicit in this API - just tell callee how we got these items:
interface ModificationOptions {
/** Where new/updated items came from:
* api - received them from the recent api call
* edit - received from dataRow.onValueChange callback
*/
source: 'api' | 'edit';
}
Users can then decide what to do in each case:
setItems((updatedItems, options) => {
let items = new Map(myState.items);
if (options.source === 'api') {
items = new Map([...updatedItems, ...items]) // items from state take precedence, to not override edited items
} else {
items = new Map([...items, ...updatedItem]) // items from state take precedence, to not override edited items
}
})
- Removed isPartialLoad - Moved TreeStats into useDataRows - Added error on tree type change between rerenders - Fixed itemsMap update on loadAll - Fixed itemsMap update on new props in DataSource.
Use tree simpler temp order handling
…ure/use-tree-hook # Conflicts: # app/src/sandbox/editableTable/ProjectTableDemo.tsx
…ure/use-tree-hook
…ure/use-tree-hook
uui-core/src/data/processing/views/tree/treeStructure/helpers/PatchHelper.ts
Outdated
Show resolved
Hide resolved
Released in 5.8.0 ver. |
Summary
New features
access to loaded data
some rows should be uploaded additionally
multiple trees/views
implemented by users, if they don't want to use our trees,
but want to render rows
API Updates
Deprecation
options and access selected rows via IDataSourceView.getVisibleRows().