Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "current"
}
}
],
"@babel/preset-typescript"
]
}
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
root = true

[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist
fixtures
65 changes: 15 additions & 50 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,55 +1,20 @@
{
"extends": "eslint-config-airbnb",
"parser": "@typescript-eslint/parser", // Specifies the ESLint parser
"extends": [
"plugin:@typescript-eslint/recommended", // Uses the recommended rules from the @typescript-eslint/eslint-plugin
"prettier/@typescript-eslint", // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier
"plugin:prettier/recommended" // Enables eslint-plugin-prettier and displays prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
],
"parserOptions": {
"ecmaVersion": 2019, // Allows for the parsing of modern ECMAScript features
"sourceType": "module" // Allows for the use of imports
},
"rules": {
"import/no-dynamic-require": false,
"linebreak-style": 0,
"no-underscore-dangle": "off",
"prefer-destructuring": "off",
"no-unused-vars": [
"warn",
{
"args": "none",
"argsIgnorePattern": "^_.+$|utils"
}
],
"radix": "off",
"no-param-reassign": "off",
"no-plusplus": [
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-use-before-define": [
"error",
{
"allowForLoopAfterthoughts": true
}
],
"import/newline-after-import": "off",
"arrow-parens": "off",
"max-len": [
"warn",
{
"ignoreComments": true,
"ignoreTrailingComments": true,
"ignoreUrls": true,
"tabWidth": 2,
"code": 100
}
],
"eqeqeq": "off",
"consistent-return": "off",
"strict": "off",
"no-prototype-builtins": "off",
"operator-assignment": "off",
"no-useless-constructor": "off",
"no-empty-function": [
"error",
{
"allow": [
"constructors",
"arrowFunctions"
]
}
],
"no-buffer-constructor": "off",
"no-use-before-define": "off",
"arrow-body-style": "off",
"no-mixed-operators": "off"
{ "variables": true, "classes": true, "functions": false }
]
}
}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
*.env
.idea
/dist
/node_modules
/node_modules
.vscode
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lts/Dubnium
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist
fixtures
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
82 changes: 78 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,86 @@ const App = () => (
export default App;
```

**Note**: In case of REST verb "CREATE" consider that the response body is the same as the request body but with the object ID injected .
## Working with relations, and selecting spesific fields

*Quick and less flexible: [Set the relations/fields to eager on server CRUD config side](https://github.com/nestjsx/crud/wiki/Controllers#query)*

Due to how nestjsx/crud works, in order to select only spesific fields, or to join relations, we need to add spesific query params.
but, REACT ADMIN does not provide a way to configure that on his side. (as to date [react-admin#3411](https://github.com/marmelab/react-admin/issues/3411)).
To solve that, we've added a way to embed these configurations in the resource name in JSON string form.
In case you want want to work with relationship/select spesific fields:
```jsx
import createDataProvider, { encodeParamsInResource } from "@fusionworks/ra-data-nest-crud";
<Admin dataProvider={createDataProvider("/api/...")} >
...
<Resource
// without setting a label, you will have the JSON inside the generated label
options={{ label: 'Books' }}
name={
encodeParamsInResource("books",
// passed to @nestjsx/crud-request to generate the url
{
fields: ["id", "name", "year"],
join: [
{
field: "pages",
select: ["number", "words"]
},
{
field: "author",
select: ["id", "name"]
},
{
field: "author.favoriteFood",
select: ["id", "name"]
}
]
})}
list={BooksList}
/>
...
</Admin>

```
case CREATE:
return { data: { ...params.data, id: json.id } };


### Handeling references/Permutations and encodeParamsInResource.
Due to how REACT ADMIN works, each variant of resource, even with same name, but using `encodeParamsInResource`, is seen as a different resource.
Means that if on one of your components you've used reference input/field based on `encodeParamsInResource` with different parameters than the top level resource,
You will need to add "headless" resource with same configurations. (What is it headless? what? [see the tags resource here](https://marmelab.com/react-admin/Resource.html#the-resource-component))

For example:
```jsx
// CategoryEdit or what ever
<ReferenceInput
label="Template"
source="template.id"
reference={encodeParamsInResource('templates', {
join: [
{
field: 'template',
},
],
})}
>
<AutocompleteInput optionText="name" >
</ReferenceInput>

<Admin>
// ...
<Resource name={encodeParamsInResource('templates', {
join: [
{
field: 'template',
},
],
})} />
// ...
</Admin>

```
This is because of backwards compatibility compliance.

**Note**: In case of REST verb "CREATE" and "UPDATE" consider that the data provider will make GET_ONE request hehind the scene to fetch fresh copy of all of the record after the update/create.

## Example
You can find an example of a project that uses ```nestjs``` and ```nestjsx/crud``` on backend and ```admin-ui``` with ```@fusionworks/ra-data-nest-crud``` data provider.
Expand Down
4 changes: 4 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
testPathIgnorePatterns: ["/node_modules/", "/example/"],
verbose: true
};
8 changes: 0 additions & 8 deletions lib/copy_package.js

This file was deleted.

8 changes: 0 additions & 8 deletions lib/copy_readme.js

This file was deleted.

1 change: 0 additions & 1 deletion lib/test.js

This file was deleted.

Loading