Borvik / ts-datatable

1 stars 6 forks source link

Query Cache #18

Closed Borvik closed 3 years ago

Borvik commented 4 years ago

Support using cached data from the likes of ApolloClient and ApolloCache.

Involves an event that send the new filters, etc, up to the parent component which can use them in the <Query> and pass the data down to data and totalCount.

Is there another way?

andrewprins commented 4 years ago

Might be able to do it with either a render function that is always rendered alongside the regular render function or with a render function that is used to wrap the regular render like one of these examples:

<DataTable
  ...
  getDataRender(filterSearchPaginationArgs, onDataChanged) => {
    return <Query
      query={gql`...`}
      variables={filterSearchPaginationArgs}
      onDataChanged={onDataChanged}
    />
  }
/>

Not sure if you would be able to get loading/error from onDataChanged, but you might also be able to just connect it like this:

<DataTable
   ...
   renderMiddleware(filterSearchPaginationArgs, render) => {
     return <Query
       query={gql`...`}
       variables={filterSearchPaginationArgs}
     >
       {(queryResult) => render(queryResult)}
     </Query>
   }
/>
Borvik commented 4 years ago

So, based on what my investigations neither of those would really work. We can't just use a <Query> tag in a callback - it needs to be rendered within the react tree in order work - not just used in a callback.

I have tested a solution that works.

Borvik commented 3 years ago

Upon reflection - while #23 was necessary and can solve this, there are some scenarios where the solution from that PR doesn't handle as nicely.

Namely, the filter (usually from the query string) is parsed by the datatable, but the query is run outside of it (for components like apollo graphql <Query>). While we could put a skip if not loaded and wait for the table event - it isn't as nice.

May have a way to handle a response to the data event being a React.isValidElement to determine to render the result directly or not.

Borvik commented 3 years ago

Completed with version 1.0.3