I'm using react-admin and I have the following resources:
So What I need from here is to add a Images and a videos resource. Something like this:
So as you can see in the image above,Images and Videos SHOULD come from the same endpoint which is called Post.
Now, what I showed you in the image it doesn't actually work. why? Because I don't have an Image or a Videos endpoint. Each time I click on them it will take me to http://localhost:3000/dahboard/Images or http://localhost:3000/dahboard/Videos, which again does not exist. My Posts endpoint does have the content that I need, it has images and it has videos.
What I need
What I need is something to be shown like in the image I posted. Something where I can click on Images or Videos no matter if the endpoint goes directly to http://localhost:3000/dahboard/Post. But I can't seem to find something related in the react-admin documentation.
What I currently Have
<Admin
layout={MyLayout}
theme={theme}
dataProvider={dataProvider}
>
<Resource name="Post" {...posts} icon={ImageIcon} />
<Resource name="Comment" {...comments} icon={ChatIcon} />
<Resource name="User" {...users} icon={PeopleIcon} />
</Admin>
Folder Structure
|-- node_modules
|-- public
|-- src
|---- comments
|---- components
|---- pages
|---- posts
|--- index.js
|--- PostList.js
|--- PostShow.js
|---- users
|--- index.js
|--- UserList.js
|--- UserShow.js
|---- util
|---- videos
|--- index.js
|--- VideoList.js
|--- VideoShow.js
EDIT
This is how I configured my dataProvider, I am using Hasura's data provider for this:
function DashboardPage(props) {
const [dataProvider, setDataProvider] = useState(null);
useEffect(() => {
const buildDataProvider = async () => {
const myClientWithAuth = new ApolloClient({
uri: process.env.NEXT_PUBLIC_HASURA_GRAPHQL_ENDPOINT,
cache: new InMemoryCache(),
headers: {
'x-hasura-admin-secret':
process.env.NEXT_PUBLIC_HASURA_GRAPHQL_API_KEY,
},
});
const dataProvider = await buildHasuraProvider({
client: myClientWithAuth,
getList: (resource, params) => {
const {page, perPage} = params.pagination;
const {field, order} = params.sort;
const query = {
sort: JSON.stringify([field, order]),
range: JSON.stringify([(page - 1) * perPage, page * perPage - 1]),
filter: JSON.stringify(params.filter),
};
const endpoint = resource === 'images' || resource === 'videos'
? 'posts'
: resource;
const url = `${apiUrl}/${endpoint}?${stringify(query)}`;
return httpClient(url).then(({ headers, json }) => ({
data: json,
total: parseInt(headers.get('content-range').split('/').pop(), 10),
}));
}
})
setDataProvider(() => dataProvider);
};
buildDataProvider();
}, []);
if (!dataProvider) return <p>Loading...</p>;
return (
<Admin
layout={MyLayout}
theme={theme}
dataProvider={dataProvider}
>
<Resource name="Post" {...posts} icon={ImageIcon} />
<Resource name="Comment" {...comments} icon={ChatIcon} />
<Resource name="User" {...users} icon={PeopleIcon} />
</Admin>
);

