Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(datasource-customizer): add helper to fetch values from selected record in single actions #891

Merged
merged 2 commits into from
Dec 4, 2023

Conversation

romain-gilliotte
Copy link
Contributor

@romain-gilliotte romain-gilliotte commented Nov 26, 2023

This is not much, but it helps when declaring single actions which use data from the selected record.
It's a major eyesore in the codebase I'm currently working in, as the field names are quite long, and this pattern is everywhere!

The templating is so that the output of the function have the proper type

Go from this:

{
    label: 'Street',
    isRequired: true,
    type: 'String',
    defaultValue: async (context) =>
      (await context.getRecord(['company:street'])).company?.street,
}

to this

{
    label: 'Street',
    isRequired: true,
    type: 'String',
    defaultValue: (context) => context.getField('company:street')
}

@@ -93,4 +93,16 @@ describe('ActionContext', () => {
await expect(promise1).rejects.toThrow('bad request');
await expect(promise2).rejects.toThrow('bad request');
});

test('should get individual fields', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a test that is accessing child properties here? I think it's a major part of your contribution, and it should be tested as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. Will do!
@Scra3 would have told me the same 😁

@romain-gilliotte
Copy link
Contributor Author

It's done!

@ghusse
Copy link
Contributor

ghusse commented Dec 4, 2023

Thanks!

@ghusse ghusse merged commit 24d3e50 into ForestAdmin:main Dec 4, 2023
17 of 18 checks passed
forest-bot added a commit that referenced this pull request Dec 4, 2023
## [1.6.67](https://github.com/ForestAdmin/agent-nodejs/compare/example@1.6.66...example@1.6.67) (2023-12-04)

### Features

* **datasource-customizer:** add helper to fetch values from selected record in single actions ([#891](#891)) ([24d3e50](24d3e50))
forest-bot added a commit that referenced this pull request Dec 4, 2023
## [1.36.7](https://github.com/ForestAdmin/agent-nodejs/compare/@forestadmin/agent@1.36.6...@forestadmin/agent@1.36.7) (2023-12-04)

### Features

* **datasource-customizer:** add helper to fetch values from selected record in single actions ([#891](#891)) ([24d3e50](24d3e50))
@forest-bot
Copy link
Member

🎉 This PR is included in version 1.0.51 🎉

The release is available on npm package (@latest dist-tag)

Your semantic-release bot 📦🚀

forest-bot added a commit that referenced this pull request Dec 4, 2023
forest-bot added a commit that referenced this pull request Dec 4, 2023
## [1.0.86](https://github.com/ForestAdmin/agent-nodejs/compare/@forestadmin/datasource-dummy@1.0.85...@forestadmin/datasource-dummy@1.0.86) (2023-12-04)

### Features

* **datasource-customizer:** add helper to fetch values from selected record in single actions ([#891](#891)) ([24d3e50](24d3e50))
@forest-bot
Copy link
Member

🎉 This PR is included in version 1.6.67 🎉

The release is available on example@1.6.67

Your semantic-release bot 📦🚀

forest-bot added a commit that referenced this pull request Dec 4, 2023
## [1.3.50](https://github.com/ForestAdmin/agent-nodejs/compare/@forestadmin/plugin-aws-s3@1.3.49...@forestadmin/plugin-aws-s3@1.3.50) (2023-12-04)

### Features

* **datasource-customizer:** add helper to fetch values from selected record in single actions ([#891](#891)) ([24d3e50](24d3e50))
forest-bot added a commit that referenced this pull request Dec 4, 2023
forest-bot added a commit that referenced this pull request Dec 4, 2023
## [1.0.75](https://github.com/ForestAdmin/agent-nodejs/compare/@forestadmin/plugin-flattener@1.0.74...@forestadmin/plugin-flattener@1.0.75) (2023-12-04)

### Features

* **datasource-customizer:** add helper to fetch values from selected record in single actions ([#891](#891)) ([24d3e50](24d3e50))
@forest-bot
Copy link
Member

🎉 This PR is included in version 1.36.7 🎉

The release is available on npm package (@latest dist-tag)

Your semantic-release bot 📦🚀

@forest-bot
Copy link
Member

🎉 This PR is included in version 1.39.0 🎉

The release is available on npm package (@latest dist-tag)

Your semantic-release bot 📦🚀

@forest-bot
Copy link
Member

🎉 This PR is included in version 1.0.86 🎉

The release is available on npm package (@latest dist-tag)

Your semantic-release bot 📦🚀

@forest-bot
Copy link
Member

🎉 This PR is included in version 1.3.50 🎉

The release is available on npm package (@latest dist-tag)

Your semantic-release bot 📦🚀

@forest-bot
Copy link
Member

🎉 This PR is included in version 1.0.62 🎉

The release is available on npm package (@latest dist-tag)

Your semantic-release bot 📦🚀

@forest-bot
Copy link
Member

🎉 This PR is included in version 1.0.75 🎉

The release is available on npm package (@latest dist-tag)

Your semantic-release bot 📦🚀

forest-bot added a commit that referenced this pull request Dec 12, 2023
## [1.5.31](https://github.com/ForestAdmin/agent-nodejs/compare/@forestadmin/datasource-mongoose@1.5.30...@forestadmin/datasource-mongoose@1.5.31) (2023-12-12)

### Bug Fixes

* **datasource-sql:** don't return function names when default values are not constants ([#872](#872)) ([db5dba9](db5dba9))
* do not generate typing aliases with dashes ([#883](#883)) ([f971b68](f971b68))
* field formValue is sometimes not correctly provided in execute context ([#894](#894)) ([a24aab1](a24aab1))
* **renameAndRemoveField:** allow to rename or remove a relation by improving the TS typing ([#865](#865)) ([1a6a4b4](1a6a4b4))
* **restart:** the agent should only restart when at least one customisation is installed ([#893](#893)) ([d5e3c15](d5e3c15))
* **schema:** throw an error when enum values are corrupted in the schema ([#877](#877)) ([d4488c9](d4488c9))
* **security:** patch axios dependency vulnerabilities ([#884](#884)) ([a693ace](a693ace))
* send details to frontend on unexpected sequelize errors ([#868](#868)) ([f6cb9a5](f6cb9a5))
* skip mssql tables with dots in their names instead of crashing the agent ([#870](#870)) ([97aea61](97aea61))
* **smart-field:** log error on missing parameter dependencies and avoid crash ([#873](#873)) ([e7f80e2](e7f80e2))
* **typing:** avoid ordering issues that causes issue with typing ([#890](#890)) ([1c9628c](1c9628c))
* user receives 403 on newly created segment query ([#889](#889)) ([b2eb86a](b2eb86a))

### Features

* **datasource-customizer:** add helper to fetch values from selected record in single actions ([#891](#891)) ([24d3e50](24d3e50))
* **datasource-customizer:** sort enum values in typings file ([#892](#892)) ([564974d](564974d))
* **forestadmin-client:** add schema hash to startup logs ([#867](#867)) ([d13a671](d13a671))
forest-bot added a commit that referenced this pull request Dec 12, 2023
## [1.5.26](https://github.com/ForestAdmin/agent-nodejs/compare/@forestadmin/datasource-sequelize@1.5.25...@forestadmin/datasource-sequelize@1.5.26) (2023-12-12)

### Bug Fixes

* **datasource-sql:** don't return function names when default values are not constants ([#872](#872)) ([db5dba9](db5dba9))
* do not generate typing aliases with dashes ([#883](#883)) ([f971b68](f971b68))
* field formValue is sometimes not correctly provided in execute context ([#894](#894)) ([a24aab1](a24aab1))
* **restart:** the agent should only restart when at least one customisation is installed ([#893](#893)) ([d5e3c15](d5e3c15))
* **schema:** throw an error when enum values are corrupted in the schema ([#877](#877)) ([d4488c9](d4488c9))
* **security:** patch axios dependency vulnerabilities ([#884](#884)) ([a693ace](a693ace))
* skip mssql tables with dots in their names instead of crashing the agent ([#870](#870)) ([97aea61](97aea61))
* **smart-field:** log error on missing parameter dependencies and avoid crash ([#873](#873)) ([e7f80e2](e7f80e2))
* **typing:** avoid ordering issues that causes issue with typing ([#890](#890)) ([1c9628c](1c9628c))
* user receives 403 on newly created segment query ([#889](#889)) ([b2eb86a](b2eb86a))

### Features

* **datasource-customizer:** add helper to fetch values from selected record in single actions ([#891](#891)) ([24d3e50](24d3e50))
* **datasource-customizer:** sort enum values in typings file ([#892](#892)) ([564974d](564974d))
forest-bot added a commit that referenced this pull request Dec 12, 2023
## [1.7.43](https://github.com/ForestAdmin/agent-nodejs/compare/@forestadmin/datasource-sql@1.7.42...@forestadmin/datasource-sql@1.7.43) (2023-12-12)

### Bug Fixes

* field formValue is sometimes not correctly provided in execute context ([#894](#894)) ([a24aab1](a24aab1))
* **restart:** the agent should only restart when at least one customisation is installed ([#893](#893)) ([d5e3c15](d5e3c15))
* **typing:** avoid ordering issues that causes issue with typing ([#890](#890)) ([1c9628c](1c9628c))

### Features

* **datasource-customizer:** add helper to fetch values from selected record in single actions ([#891](#891)) ([24d3e50](24d3e50))
* **datasource-customizer:** sort enum values in typings file ([#892](#892)) ([564974d](564974d))
forest-bot added a commit that referenced this pull request Dec 12, 2023
## [1.29.1](https://github.com/ForestAdmin/agent-nodejs/compare/@forestadmin/datasource-toolkit@1.29.0...@forestadmin/datasource-toolkit@1.29.1) (2023-12-12)

### Bug Fixes

* **agent:** add body parser options to allow increase body limits ([#854](#854)) ([a4de720](a4de720))
* **authentication:** don't crash if an error occurs when initializing the authentication client ([#862](#862)) ([265b1b4](265b1b4))
* **authentication:** return errors details during authentication instead of generic 500s ([#857](#857)) ([3ec14e6](3ec14e6))
* **charts:** remove option to set zeros instead of null values & do it by default ([#863](#863)) ([5f88663](5f88663))
* **datasource-mongoose:** don't return records for null values of flattened fields when using asModel on object fields ([#853](#853)) ([d4b3f0c](d4b3f0c))
* **datasource-mongoose:** error on a nested field when requesting a child property on a missing value ([#860](#860)) ([6a04be7](6a04be7))
* **datasource-sql:** don't return function names when default values are not constants ([#872](#872)) ([db5dba9](db5dba9))
* do not generate typing aliases with dashes ([#883](#883)) ([f971b68](f971b68))
* field formValue is sometimes not correctly provided in execute context ([#894](#894)) ([a24aab1](a24aab1))
* **renameAndRemoveField:** allow to rename or remove a relation by improving the TS typing ([#865](#865)) ([1a6a4b4](1a6a4b4))
* **restart:** the agent should only restart when at least one customisation is installed ([#893](#893)) ([d5e3c15](d5e3c15))
* **schema:** throw an error when enum values are corrupted in the schema ([#877](#877)) ([d4488c9](d4488c9))
* **security:** patch @babel/traverse dependency vulnerabilities ([#855](#855)) ([505b7fa](505b7fa))
* **security:** patch axios dependency vulnerabilities ([#884](#884)) ([a693ace](a693ace))
* send details to frontend on unexpected sequelize errors ([#868](#868)) ([f6cb9a5](f6cb9a5))
* skip mssql tables with dots in their names instead of crashing the agent ([#870](#870)) ([97aea61](97aea61))
* **smart-field:** log error on missing parameter dependencies and avoid crash ([#873](#873)) ([e7f80e2](e7f80e2))
* support mangoose decimal128 type ([#864](#864)) ([5bbed39](5bbed39))
* **time-based-chart:** don't crash when there is no value and format the data to display "no data" on the front ([#852](#852)) ([3f033eb](3f033eb))
* **typing:** avoid ordering issues that causes issue with typing ([#890](#890)) ([1c9628c](1c9628c))
* user receives 403 on newly created segment query ([#889](#889)) ([b2eb86a](b2eb86a))

### Features

* **charts:** timebasedCharts: add option to display missing points as zeros ([#861](#861)) ([b314d3a](b314d3a))
* **datasource-customizer:** add helper to fetch values from selected record in single actions ([#891](#891)) ([24d3e50](24d3e50))
* **datasource-customizer:** sort enum values in typings file ([#892](#892)) ([564974d](564974d))
* **forestadmin-client:** add schema hash to startup logs ([#867](#867)) ([d13a671](d13a671))
forest-bot added a commit that referenced this pull request Dec 12, 2023
## [1.25.2](https://github.com/ForestAdmin/agent-nodejs/compare/@forestadmin/forestadmin-client@1.25.1...@forestadmin/forestadmin-client@1.25.2) (2023-12-12)

### Bug Fixes

* **datasource-sql:** don't return function names when default values are not constants ([#872](#872)) ([db5dba9](db5dba9))
* field formValue is sometimes not correctly provided in execute context ([#894](#894)) ([a24aab1](a24aab1))
* **restart:** the agent should only restart when at least one customisation is installed ([#893](#893)) ([d5e3c15](d5e3c15))
* **typing:** avoid ordering issues that causes issue with typing ([#890](#890)) ([1c9628c](1c9628c))

### Features

* **datasource-customizer:** add helper to fetch values from selected record in single actions ([#891](#891)) ([24d3e50](24d3e50))
* **datasource-customizer:** sort enum values in typings file ([#892](#892)) ([564974d](564974d))
@forest-bot
Copy link
Member

🎉 This PR is included in version 1.5.31 🎉

The release is available on npm package (@latest dist-tag)

Your semantic-release bot 📦🚀

@forest-bot
Copy link
Member

🎉 This PR is included in version 1.5.26 🎉

The release is available on npm package (@latest dist-tag)

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants