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

Datatable filter broken #2597

Open
sschuchlenz opened this issue Jul 6, 2020 · 10 comments
Open

Datatable filter broken #2597

sschuchlenz opened this issue Jul 6, 2020 · 10 comments
Labels
filtering next release Needed for next Vulcan release

Comments

@sschuchlenz
Copy link

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)

@eric-burel
Copy link
Contributor

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!

@sschuchlenz
Copy link
Author

  • 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

@eric-burel
Copy link
Contributor

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.

@sschuchlenz
Copy link
Author

I've checked, the sort is there in the variables, but filters is missing completely

@sschuchlenz
Copy link
Author

sschuchlenz commented Jul 8, 2020

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,
      },
    },
  }}
/>

@sschuchlenz sschuchlenz changed the title Datatable filter on userId broken Datatable filter broken Jul 8, 2020
@eric-burel eric-burel added the next release Needed for next Vulcan release label Jul 8, 2020
@sschuchlenz
Copy link
Author

@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!)

@eric-burel
Copy link
Contributor

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).

@yairtal
Copy link
Contributor

yairtal commented Jul 8, 2020

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.

@eric-burel
Copy link
Contributor

Ok I'll try to check that too then

@yairtal
Copy link
Contributor

yairtal commented Jul 8, 2020

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
filtering next release Needed for next Vulcan release
Projects
None yet
Development

No branches or pull requests

3 participants