Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async init() {
const targetEl = document.getElementById(this.target);
const res = await fetchUtils.fetchJson(this.schemaPath);
try {
const schema: Schema = res.json;
const gen: Generator = new Generator({
schema,
defaultRowClick: this.defaultRowClick,
});
const resComps = schema.admin.resources.map((r: Resource) => gen.generateResourceComp(r));
const LayoutComp = generateLayoutComp(schema);
const AdminApp = () => (
);
ReactDOM.render(, targetEl);
} catch (error) {
// TODO: Handle this error
console.error(error);
}
import React from 'react';
import ReactDOM from 'react-dom';
import { App } from './App';
import reportWebVitals from './reportWebVitals';
import { fetchUtils } from 'ra-core';
import { Resource, Schema } from './types/schema';
import { generateResourceComp } from './core/generators/resources';
const rootEl = document.getElementById('root');
const schemaPath = rootEl?.getAttribute("schema");
fetchUtils.fetchJson(schemaPath).then(res => {
const schema: Schema = res.json;
const resComponents = schema.resources.map((r: Resource) => generateResourceComp(schema, r));
ReactDOM.render(
,
rootEl,
);
})
// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
getManyReference: (resource: any, params: any) => {
const { page, perPage } = params.pagination;
const { field, order } = params.sort;
const query = {
...fetchUtils.flattenObject(params.filter),
[params.target]: params.id,
_sort: field,
_order: order,
_start: (page - 1) * perPage,
_end: page * perPage,
};
const url = `${apiUrl}/${params.target}/${params.id}/${resource}?${stringify(query)}`;
return fetchUtils.fetchJson(url).then(({ headers, json }) => {
if (!headers.has('x-total-count')) {
throw new Error(
'The X-Total-Count header is missing in the HTTP Response. The jsonServer Data Provider expects responses for lists of resources to contain this header with the total number of results to build the pagination. If you are using CORS, did you declare X-Total-Count in the Access-Control-Expose-Headers header?'
);
}
return {
data: json,
total: parseInt(
headers.get('x-total-count')!.split('/').pop() || '',
10
),
};
});
}
}