Vulcan
Vulcan copied to clipboard
Datatable filter broken
I tried to integrate a data table which should present the current elements from a Links collection filtered by the actual user:
<Components.Datatable
collectionName='Links'
showSearch={false}
showEdit={true}
showNew={true}
columns={['userId', 'title', 'url']}
initialState={{
sort: {
createdAt: 'desc',
},
filters: {
userId: {
_eq: 'fdslkfjskj',
},
},
}}
/>
The output shows all the elements present in the Links collection, filters is ingnored completely (also tried with garbage values)
Thanks for opening an issue, a few more question:
- does it happen only with userId?
- what is the resulting query? Check your browser devtools under the network tab, you can filter by url on /graphql
- what is your schema, especially for the userId field?
- if possible, can you check with getting documents using "withMulti" instead?
We need those info to reproduce, and to tell if the issue happens in the frontend, during filtering, if you schema is right etc. etc. Thanks!
- does it happen only with userId?
No, it also happens when I filter on other fields like title (tried with _eq as well as ne)
- what is the resulting query? Check your browser devtools under the network tab, you can filter by url on /graphql
query: "query links($input: MultiLinkInput) {↵ links(input: $input) {↵ results {↵ ...FullLinks↵ __typename↵ }↵ totalCount↵ __typename↵ }↵}↵↵fragment FullLinks on Link {↵ _id↵ createdAt↵ userId↵ title↵ url↵ user {↵ _id↵ username↵ createdAt↵ isAdmin↵ locale↵ profile↵ services↵ displayName↵ email↵ emailHash↵ avatarUrl↵ slug↵ twitterUsername↵ pageUrl↵ pagePath↵ editUrl↵ logo↵ biography↵ soc_instagram↵ soc_twitter↵ soc_facebook↵ soc_tiktok↵ soc_snapchat↵ soc_linkedin↵ soc_xing↵ __typename↵ }↵ __typename↵}↵"
- what is your schema, especially for the userId field?
Here it is:
const schema = {
// default properties
_id: {
type: String,
optional: true,
canRead: ["guests"],
},
createdAt: {
type: Date,
optional: true,
canRead: ["guests"],
onCreate: ({ newDocument, currentUser }) => {
return new Date();
},
},
userId: {
type: String,
optional: true,
canRead: ["guests"],
resolveAs: {
fieldName: "user",
type: "User",
resolver: (link, args, context) => {
return context.Users.findOne(
{ _id: link.userId },
{
fields: context.Users.getViewableFields(
context.currentUser,
context.Users
),
}
);
},
addOriginalField: true,
},
},
title: {
label: "Title",
type: String,
optional: false,
canRead: ["guests"],
canCreate: ["members", "admins"],
canUpdate: ["owners", "admins"],
},
url: {
label: "URL",
type: String,
optional: false,
canRead: ["guests"],
canCreate: ["members", "admins"],
canUpdate: ["owners", "admins"],
},
};
export default schema;
- if possible, can you check with getting documents using "withMulti" instead?
I'll check and get back to you.
We need those info to reproduce, and to tell if the issue happens in the frontend, during filtering, if you schema is right etc. etc. Thanks!
Thank you for your efforts!
KR, Stefan
Do you also have the variables of the graphQL query? That's where you can see the "$input" value and check if your filter is indeed there. If it is not that's part of the issue.
I've checked, the sort is there in the variables, but filters is missing completely
Update on this:
I tried now to circumvent theuserId property so I created a new custom property (named slug) which automatically gets the creating user's username value, thus allowing me to filter on this. This works perfectly when I work with useMulti2 on the frontend display of the data, but the Datatable still shows all results. Code is this:
<Components.Datatable
collection={Links}
options={{
fragmentName: 'FullLinks',
}}
showSearch={false}
showEdit={true}
showNew={true}
columns={['slug', 'title', 'url']}
initialState={{
sort: {
createdAt: 'desc',
},
filters: {
slug: {
_eq: props.currentUser.username,
},
},
}}
/>
@eric-burel is there an ETA yet for the next release? because this is something which really renders Datatable quite useless (and it is an awesome component!)
Tagging @yairtal because he is currently doing awesome work on the datatable.
Things are a bit slowed down during summer, as I have more work to do than I expected (but this seems to become my daily routine...) and then I go on holiday. But this does not sound like a very complex issue to solve, more some migration chores to be done (datatable is still using old withMulti).
Thank you @eric-burel , my main concern is to get the ui-material Datatable to function as close as possible to the one at ui-bootstrap. ui-material is great, but I had no idea the features gap is that big, there is no initialState / filterable fields / input / filter... and it seems to me that terms isn't working either unless it is used by the search query. Maybe we can get @ErikDakoda to release his work on ui-material and we'll build on top of it.
Ok I'll try to check that too then
If you have any specific tasks for me regarding these issues please PM me and I'll be happy to work on it! No vacations on my calendar :) (skies are pretty much closed here)