Skip to content

Conversation

mysiar
Copy link
Member

@mysiar mysiar commented Oct 12, 2017

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
License MIT

@dunglas
Copy link
Member

dunglas commented Oct 12, 2017

It will double the work and the maintenance with api-platform/admin...

@mysiar
Copy link
Member Author

mysiar commented Oct 12, 2017

I needed it so created due to some custom endpoints that api-platform/admin couldn't serve

… List buttons display, resources for each endpoint, resource import list
@mysiar mysiar requested a review from mauchede October 25, 2017 04:48
@mysiar mysiar force-pushed the admin-on-rest branch 2 times, most recently from 741dc48 to 904a27d Compare October 25, 2017 13:57
@mysiar mysiar self-assigned this Oct 25, 2017
@mysiar
Copy link
Member Author

mysiar commented Oct 25, 2017

@mauchede please review this PR

this.createDir(dir, false);
}

// for (let dir of [`${dir}/components/${lc}`]) {

Choose a reason for hiding this comment

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

It could be removed.

@@ -0,0 +1 @@
import {{{lc}}} from './resources/{{{lc}}}';

Choose a reason for hiding this comment

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

How can we use resource-import.js? When I tried your PR, I created an Admin node and I used directly my resource:

import React from 'react';
import { Admin } from 'admin-on-rest';
import { hydraClient } from '@api-platform/admin';
import gallery from './admin/resources/gallery';

export default (props) => {
  return (
      <Admin restClient={hydraClient({entrypoint: 'http://127.0.0.1:8000'})}>
        {gallery}
      </Admin>
  );
};

It worked fine, but if I tried to use resource-import.js:

import React from 'react';
import { Admin } from 'admin-on-rest';
import { hydraClient } from '@api-platform/admin';
import { gallery } from './admin/resource-import';

export default (props) => {
  return (
      <Admin restClient={hydraClient({entrypoint: 'http://127.0.0.1:8000'})}>
        {gallery}
      </Admin>
  );
};

It did not work because resource-import did not export resources. In that case, we have two solutions:

  1. Export each resource in resource-import with the following syntax:
export { default as gallery } from './resources/gallery';
  1. Export only an array of resources:
export default [
  gallery
];

IMO, this solution will be better for DX because we just have to use this array in Admin rendering:

import React from 'react';
import { Admin } from 'admin-on-rest';
import { hydraClient } from '@api-platform/admin';
import resources from './admin/resource-import';

export default (props) => {
  return (
      <Admin restClient={hydraClient({entrypoint: 'http://127.0.0.1:8000'})}>
        {resources}
      </Admin>
  );
};

Copy link
Member Author

@mysiar mysiar Oct 30, 2017

Choose a reason for hiding this comment

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

I like the idea 2 but how to get in template the export of the array ?

right now I fixed it with idea 1

@mysiar
Copy link
Member Author

mysiar commented Oct 30, 2017

there is another solution to get all imports at once

import  * as resources from "resource-import";
...
  <Admin
     ...
   >
     {Object.keys(resources).map( (key) => resources[key] )}
  </Admin>

@mauchede WDYT ?

@mauchede
Copy link

It seems good!

@mysiar mysiar merged commit d79022c into api-platform:master Oct 30, 2017
@mysiar mysiar deleted the admin-on-rest branch October 30, 2017 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants