Skip to content
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

[DataGrid] Core api refactoring #130

Merged
merged 5 commits into from
Jul 30, 2020
Merged

Conversation

dtassone
Copy link
Member

No description provided.

@dtassone
Copy link
Member Author

Regression to look at: Sorting issue on click on header

Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regression to look at: Sorting issue on click on header

This sounds like a great opportunity for a new test case :).

@@ -34,7 +34,7 @@ const getGridOptions: () => GridOptionsProp = () => {
action('onSelectionChange', {
depth: 1,
})(params),
onSortedColumns: (params) => action('onSortedColumns')(params),
onColumnsSorted: (params) => action('onColumnsSorted')(params),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Suggested change
onColumnsSorted: (params) => action('onColumnsSorted')(params),
onColumnsSort: (params) => action('onSortedColumns')(params),

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The past it to represent that the action occurs after the sorting has taken place.
The before event is onColumnsSortingChange

Copy link
Member

@oliviertassinari oliviertassinari Jul 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh OK, I didn't spot the difference, I thought they were two events for two different states, I didn't realize it was the same state but events raised at different point in time 😇.

What do you think about using two closed names?

  • onColumnsSortingChange
  • onColumnsSortingChanged

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ATM we have

  • onColumnsSortingChange
  • onColumnsSorted

The 2 names suggested are too similar, it can be confusing I think.

How about we follow the c# convention.
https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/names-of-type-members

✔️ DO give events names with a concept of before and after, using the present and past tenses.
For example, a close event that is raised before a window is closed would be called Closing, and one that is raised after the window is closed would be called Closed.

So in our case, we could do

  • onColumnsSortingChanging or onColumnsSortedChanging, onColumnsSortChanging, onSortChanging
  • onColumnsSortingChanged or onColumnsSortedChanged, onColumnsSortChanged, onSortChanged

Should we introduce the concept all around? So for pages it would be:

  • onPageChanging & onPageChanged

What if we don't have or see the need for before / after notion in a particular event?
Should we just do it?

How about click?
onCellClick => onCellClicking, onCellClicked 🤔

Copy link
Member

@oliviertassinari oliviertassinari Jul 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c# convention

I think that we can take inspiration from the outside as long as it doesn't conflict with the convention that React has. React should always take precedence. React doesn't leave us much choice for the controlled name, it should end with "change".

For the post action, name, do we even need it? Do we have a practical use case. As far as I can push the reflection, I see two cases:

  • The data is sorted client-side, there are no delays, onColumnsSorted has no use cases.
  • The data is sorted server-side, the user already controls when the data is loaded and hence sorted, grouped, filtered, etc.

Copy link
Member

@oliviertassinari oliviertassinari Jul 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keeping only onSortingChange simple and nice what do you think?

I love the direction. The next elements I wonder about are:

Copy link
Member Author

@dtassone dtassone Jul 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming sortedColumns === sortModel what about we have ColumnSortedParams === SortModel?

the idea is to provide all the necessary arguments for the user to do everything it needs without looking to add other props, like in CellParams

What about the uncontrolled and controlled APIs?

Interesting point. I suggest we start with what we have now and we open an RFC for controlled/uncontrolled. And we can always gather feedbacks first and reassess the need of defaultX prop

Shouldn't we rename onSortingChange(ColumnSortedParams) to onSortModelChange(SortModel) to account

for the controlled callback?
Sure, happy with that, if we keep the prop sortModel

I was thinking of renaming the prop options.sortModel with options.sortBy what do you think?
So onSortingChange & sortBy: SortModel or onSortModelChange & sortModel: SortModel?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

taking the later, it's more standard for now.
We can rename later when we clarify a bit more our conventions

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking of renaming the prop options.sortModel with options.sortBy what do you think?

👍 I think that sortBy is more descriptive than sortModel. We better understand what the option aims to achieve, it sounds better. Should we open an issue to keep track of the idea?

the idea is to provide all the necessary arguments for the user to do everything it needs without looking to add other props, like in CellParams

No objection here, the reason I have asked is that in order to make the controllable API efficient, for instance https://next--material-ui.netlify.app/components/tree-view/#ControlledTreeView.tsx, you need to be able to wire things:

  const [expanded, setExpanded] = React.useState([]);

  const handleToggle = (event, nodeIds) => {
    setExpanded(nodeIds);
  };

  return (
    <TreeView
      expanded={expanded}
      defaultSelected={[]}
      onNodeToggle={handleToggle}

P.S. Notice the onX and handleX naming convention. Notice on how we always expose event. Notice that if you control the component and remove the event feedback loop, nothing happens. What sortModel implements is the uncontrolled behavior with the handle change optional behavior (something an uncontrolled input supports but that we didn't in useControlled.js)

If you want to keep it, I would propose to have the state (sortModel or sortBy once renamed) as the first argument, and the helping values as a second argument, under an object.

Interesting point. I suggest we start with what we have now and we open an RFC for controlled/uncontrolled. And we can always gather feedbacks first and reassess the need of defaultX prop

Yeah, an RFC sounds like the way to go, we are already off-topic on the pull request!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes to open an issue with the sortBy.


const getEventParams = React.useCallback(
(event: any) => {
if (event.target == null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we throw if target is null rather than silencing the problem?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well I don't think it can happen. If it does and we throw it can break the app 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you don't think that it can happen, I think that throwing will help us. No matter what happen, we will win.

  • If it throw, we would have learn something new about how the logic behaves. Help make better design decisions later on, or even spot bugs.
  • If it doesn't throw. We would have reduced the combinatory of the logic, reducing the number of cases we need to consider, which mean a simpler logic.

packages/grid/x-grid-modules/src/models/gridOptions.tsx Outdated Show resolved Hide resolved
packages/storybook/src/stories/grid-sorting.stories.tsx Outdated Show resolved Hide resolved
packages/grid/x-grid-modules/src/models/api/coreApi.ts Outdated Show resolved Hide resolved
const [rows, setRows] = React.useState<RowsProp>([]);
const onColumnsSortingChange = (params) => {
sortServerRows(params).then((newRows) => {
setRows(newRows);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsafe

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's treat this one separately.
Should we manage concurrency in demos? maybe an RFC, or doc feedback
There is no server here so I don't think there is any point...

Maybe we should do a demo with a real api? 🤔

Copy link
Member

@oliviertassinari oliviertassinari Jul 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

concurrency in demos?

I think that the question is either or not developers can trust our demos, to behave bug-free, when they copy and paste them, making minor changes, and stress testing them.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it will be as we have a fixed timeout so, latest result will always be the correct one

## Server-side sorting

XGrid supports both client and server-side pagination. By default, sorting works on the client-side. To switch it to server-side,
set the property `sortingMode` to `server` as string or you can use our `FeatureModeConstant`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO, we don't need to export not document FeatureModeConstant it feels like using a string will be simpler, but no strong preference.

@@ -244,7 +251,21 @@ export const SortingWithFormatter = () => {
</div>
);
};
export const SortModelOptionsMultiple = () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export const SortModelOptionsMultiple = () => {
export function SortModelOptionsMultiple() {

@@ -317,3 +339,110 @@ export const SortedEventsApi = () => {
</React.Fragment>
);
};
export const SortedEventsOptions = () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export const SortedEventsOptions = () => {
export function SortedEventsOptions() {

@oliviertassinari oliviertassinari changed the title Core api refactoring [DataGrid] Core api refactoring Jul 29, 2020
@oliviertassinari oliviertassinari added the component: data grid This is the name of the generic UI component, not the React module! label Jul 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: data grid This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants