[SOLVED] Meteor DataProvider for react-admin

I’ve started to experiment a specific Meteor’s dataprovider (1) for react-admin, for example getList works fine for users, but I’m unable to get it work with another collection !

getList: (resource, params) => {
    const { page, perPage } = params.pagination;
    const { field, order } = params.sort;

    const sort = {};
    let fixField = field === "id" ? "_id" : field;
    sort[fixField] = order === "ASC" ? -1 : 1;
    const skip = (page - 1) * perPage;
    const collection = Meteor.connection._stores[resource]._getCollection();
    const total = collection.find().count();
    const getList = collection
      .find(
        {},
        {
          sort,
          limit: perPage,
          skip
        }
      )
      .fetch();
    return Promise.resolve({
      data: getList.map(resource => ({ ...resource, id: resource._id })),
      total
    });
  },

Admin page is displayed for Users, but can’t find Meteor.connection._stores[contacts], despite I subscribed to the Contacts collection …

<Admin dataProvider={meteorProvider}>
    <Resource name="users" list={UserList} />
    <Resource name="contacts" list={ListGuesser} />
  </Admin>

I just forgot to import Contacts collection in client side … ooops !

When the package will be ready, I’ll publish it and you should be able to find it in this list of available Data Providers.

(1) of course I could put a REST or GraphQL API on Meteor and use the rest / graphql dataprovider but that’s not my objective :wink:

I already improved the code instead of this ugly

Meteor.connection._stores[resource]._getCollection()

I’m using meteor/lai:collection-extensions

import { CollectionExtensions } from "meteor/lai:collection-extensions";

let registered_collections = {};
CollectionExtensions.addExtension(function(name, options) {
  registered_collections[name] = {
    name: name,
    instance: this,
    options: options
  };
});

export function getCollectionByName(collection_name) {
  return registered_collections[collection_name].instance;
}

which allows now to have this nicer code instead :

const collection = getCollectionByName(resource);

Hello @lc3t35 Laurent,

I have also been working on a meteor data Provider for react-admin (method calls only so far, so not reactive). It turned out to be a bigger job than I expected, but only because I was trying to make it a project (eventually). I got it ??working?? with a minimal test data set for react-admin v2.9.7 but the lag before the provider was called was about 15 seconds. Not great, but I figured I would track that down later.

Now that I’ve upgraded to v3.0.1 the delay is about 2 minutes. I can’t be completely certain, but I think the processing which is causing the delay has to do with initialization of the react-admin/redux sub-system: the server comes up quickly, but the client side doesn’t. I only see Meteor.start() being hit after the 2mins have elapsed.

Before I go too far down this path, I wanted to ask: are you experiencing these kind of delays before the UI for react-admin comes up?

1 Like

Hi Fraser (@umbralimi), the current implementation is based on Meteor pub/sub, except for delete. I didn’t notice any delay.

1 Like

Thanks, Laurent (@lc3t35). I was going the same way as you, but as I was intending to use Meteor methods for the writes, I started wholly with them.

Your feedback is very appreciated. I will see where my bottleneck is knowing it shouldn’t be there.

Best of luck to you!