Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • cubicweb/react-admin-cubicweb
1 result
Show changes
Commits on Source (3)
......@@ -18,6 +18,7 @@
SimpleShowLayout,
DataProvider,
} from "react-admin";
import { client } from "@logilab/cwclientlibjs";
import { createDataProvider } from "ra-cubicweb/dist";
import { schema } from "./schema";
......@@ -81,7 +82,10 @@
</Show>
);
const dataProvider = createDataProvider("http://localhost:8080", schema);
const httpClient = new client.CwSimpleHttpClient("http://localhost:8080", true);
const rqlClient = new client.CwRqlClient(httpClient);
const dataProvider = createDataProvider(rqlClient, schema);
dataProvider.getList("toto", {
pagination: { page: 1, perPage: 10 },
sort: { field: "id", order: "ASC" },
......
......@@ -16,6 +16,6 @@
};
export function createDataProvider<S extends Schema>(
endpoint: string,
rqlClient: client.CwRqlClient,
schema: S
): DataProvider {
......@@ -20,5 +20,3 @@
schema: S
): DataProvider {
const httpClient = new client.CwSimpleHttpClient(endpoint, true);
const rqlClient = new client.CwRqlClient(httpClient);
return {
......@@ -24,5 +22,6 @@
return {
getList: async (resource: ETypesNames<S>, { pagination }) => {
getList: async (resource: ETypesNames<S>, { pagination, sort }) => {
const sortAttribute = sort.field === "id" ? "eid" : sort.field;
const attributesNames = ["eid", ...Object.keys(schema.etypes[resource])];
const selection: string[] = [];
const restrictions: string[] = [];
......@@ -26,7 +25,8 @@
const attributesNames = ["eid", ...Object.keys(schema.etypes[resource])];
const selection: string[] = [];
const restrictions: string[] = [];
let sortvariable = null;
attributesNames.forEach((key, idx) => {
const variable = `X${idx}`;
selection.push(variable);
restrictions.push(`X ${key} ${variable}`);
......@@ -29,10 +29,13 @@
attributesNames.forEach((key, idx) => {
const variable = `X${idx}`;
selection.push(variable);
restrictions.push(`X ${key} ${variable}`);
if (key === sortAttribute) {
sortvariable = variable;
}
});
const total = await rqlClient
.queryRows(`Any Count(${selection[0]}) WHERE ${restrictions.join(",")}`)
.then((rows) => rows[0][0]);
return rqlClient
.queryRows(
......@@ -33,10 +36,12 @@
});
const total = await rqlClient
.queryRows(`Any Count(${selection[0]}) WHERE ${restrictions.join(",")}`)
.then((rows) => rows[0][0]);
return rqlClient
.queryRows(
`Any ${selection.join(", ")} LIMIT ${pagination.perPage} OFFSET ${
`Any ${selection.join(", ")} ORDERBY ${sortvariable} ${
sort.order
} LIMIT ${pagination.perPage} OFFSET ${
pagination.page * pagination.perPage
} WHERE ${restrictions.join(", ")}`,
{}
......@@ -79,7 +84,7 @@
[attributesNames[idx]]: attributeValue,
...agg,
}),
{ id: params.id }
{ eid: params.id, id: params.id }
);
// Getting relations
......