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

Add Saved Queries #7354

Merged
merged 16 commits into from
Mar 14, 2022
Merged

Add Saved Queries #7354

merged 16 commits into from
Mar 14, 2022

Conversation

djhi
Copy link
Collaborator

@djhi djhi commented Mar 7, 2022

No description provided.

@djhi djhi added the RFR Ready For Review label Mar 7, 2022
@djhi djhi added this to the 4.0.0-beta.3 milestone Mar 7, 2022
@vercel vercel bot temporarily deployed to Preview – react-admin March 7, 2022 16:37 Inactive
@WiXSL
Copy link
Contributor

WiXSL commented Mar 8, 2022

Everything seems all right! 👍

docs/FilterList.md Outdated Show resolved Hide resolved
docs/FilteringTutorial.md Outdated Show resolved Hide resolved
docs/SavedQueriesList.md Outdated Show resolved Hide resolved
@@ -1,5 +1,4 @@
import * as React from 'react';
import { styled } from '@mui/material/styles';
Copy link
Member

Choose a reason for hiding this comment

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

when testing the Simple Example, the filterbutton remains "active" after adding a filter from the list. This doesn't happen in next

Copy link
Collaborator Author

@djhi djhi Mar 11, 2022

Choose a reason for hiding this comment

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

Because it remains focused which is actually the correct behavior regarding accessibility

Copy link
Member

Choose a reason for hiding this comment

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

I disagree. The first added filter should receive the focus. If you don't know which element to focus, I suggest to keep the behavior of the previous FilterButton.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The thing is, I haven't done anything to make it behave that way so I don't know what to revert

packages/ra-ui-materialui/src/list/filter/FilterButton.tsx Outdated Show resolved Hide resolved
Copy link
Member

@fzaninotto fzaninotto left a comment

Choose a reason for hiding this comment

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

You have to document the validate method in the store hook

packages/ra-core/src/store/useStore.ts Outdated Show resolved Hide resolved
packages/ra-core/src/store/useStore.ts Outdated Show resolved Hide resolved
packages/ra-core/src/store/useStore.ts Outdated Show resolved Hide resolved
@fzaninotto
Copy link
Member

You still haven't fixed the focus p^roblem on the FilterButton after saving a query

@djhi
Copy link
Collaborator Author

djhi commented Mar 14, 2022

You still haven't fixed the focus problem on the FilterButton after saving a query

Because I haven't find the fix yet

@djhi djhi added WIP Work In Progress and removed RFR Ready For Review labels Mar 14, 2022
docs/FilterList.md Show resolved Hide resolved
@@ -214,32 +214,31 @@ You can place these `<FilterList>` anywhere inside a `<List>`. The most common c

```jsx
import * as React from 'react';
import { Card as MuiCard, CardContent, withStyles } from '@mui/material';
import { Box, Card, CardContent, styled } from '@mui/material';
Copy link
Member

Choose a reason for hiding this comment

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

styled isn't used in this example

docs/useStore.md Outdated
@@ -66,3 +66,18 @@ const ChangeDensity = () => {
);
};
```

The validate function can be used to ensure forward compatibility. It must returns a boolean indicating wether the value is valid or not. It will be called in the following cases:
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
The validate function can be used to ensure forward compatibility. It must returns a boolean indicating wether the value is valid or not. It will be called in the following cases:
The validate function can be used to ensure forward compatibility. It must return a boolean indicating wether the value is valid or not. React-admin calls it in the following cases:

jest.spyOn(console, 'warn').mockImplementation(() => {});
const validate = jest
.fn()
.mockReturnValueOnce(true)
Copy link
Member

Choose a reason for hiding this comment

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

I understand these mocked values correspond to "moments" of validation. I think this deserves a few comments in this test (and the following).


const set = useEventCallback(
(valueParam: T, runtimeDefaultValue: T) => {
(
Copy link
Member

Choose a reason for hiding this comment

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

I think it doesn't make sense to validate the value passed to the setter. We want to detect when a value was set by a different version than the current code. The setter can only be called using the current version of the code.

const [value, setValue] = useState(() => getItem(key, defaultValue));
const setValueCalled = useRef(false);

// Validate the value stored in the store
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand when this triggers - or rather, I'm afraid it may trigger when a validation has already been called otherwise.

useEffect(() => {
if (
// Only if it wasn't changed by the setter yet
!setValueCalled.current &&
Copy link
Member

Choose a reason for hiding this comment

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

Not robust, imagine this scenario:

  1. some code calls set in this tab => the value changes, setValueCalled is true, the hook doesn't trigger
  2. some code calls set in another tab => the value changes, setValueCalled is still true from the past call, the hook doesn't trigger

@@ -87,7 +133,66 @@ export const FilterButton = (props: FilterButtonProps): JSX.Element => {
autoFocus={index === 0}
/>
))}
{savedQueries.map((savedQuery, index) =>
Copy link
Member

Choose a reason for hiding this comment

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

you need to be more defensive here, too

<HelpIcon />
</Tooltip>
)}
{savedQueries.map((savedQuery, index) => (
Copy link
Member

Choose a reason for hiding this comment

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

here, too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WIP Work In Progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants