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

Add a formula field #3131

Closed
dufoli opened this issue Apr 14, 2019 · 5 comments
Closed

Add a formula field #3131

dufoli opened this issue Apr 14, 2019 · 5 comments
Assignees
Labels
issue: feature request Issue suggesting a new feature severity: low If the issue only affects a very niche base of users and an easily implemented workaround can solve

Comments

@dufoli
Copy link

dufoli commented Apr 14, 2019

It is quite a standard feature on many CRM (saleforce, neolane,...).
It can be very flexible and useful for many things.
A formula field store a formula on metadata but nothing is stored in DB.
The formula is based on record fields and is calculated on the fly when api query this field.
potential use case:
with function:

  • dateonly(mydate)
  • urlized(myTitle)
    -DaysAgo(myDate)
    -If(IsClosed;'Closed', 'Open')
    or just operations:
  • TotalWithTaxes = TotalHt * VAT
  • Cost = Price + shippingFee
  • Surface = width * Height
@soupette soupette added severity: low If the issue only affects a very niche base of users and an easily implemented workaround can solve issue: feature request Issue suggesting a new feature labels Apr 15, 2019
@lauriejim lauriejim changed the title formula field Add a formula field Apr 16, 2019
@Aurelsicoko
Copy link
Member

Yes, yes and yes! I've added it to the public roadmap, it could be awesome to have this new type of field available.

https://portal.productboard.com/strapi/c/58-formula-field

Please upvote the card and give me your insights, I close the issue.

@dufoli
Copy link
Author

dufoli commented Apr 22, 2019

For that, you will need a little language with formula editor and a list of function. You can take look to salesforce editor here:
https://trailhead.salesforce.com/en/content/learn/modules/point_click_business_logic/formula_fields

@mik3lov3st3ch
Copy link

Directus uses some kind of "in-field templating" e.g. for the content of a dropdown like:
{{brand.name}} {{title}}

@TeoGoddet
Copy link

TeoGoddet commented Jan 16, 2021

Could/Should I write an RFC for this ?

Main Tradeoff seems to be about performance and genericity
The more generic possible solution would run on each record in strapi
But a more efficient solution would be to delegate some work to the ORM and DB
if querying 100 of ObjectA.child1.property1, the difference is clear : 1 db request at ORM level but 101 at strapi level

If going on with row by row evaluation :
This calculator look really great : https://github.com/handsontable/formula-parser
It can handle variable name (unfortunately without . and [] inside but that seem a relatively easy change to do) and call a function to resolve variable names (giving us the opportunity to provide the value from the object or do the required queries to find it)
it has a huge list of implemented functions

The other option is to parse the whole formula and try to translate it as much as possible to orm/strapi query language, at least retrieving all the used values a once.

In any case, this repo can be a great inspiration for the jison lexer/parser

Another trade-off is the level of complexity of the allowed excel like code,
should it understand full json path : https://goessner.net/articles/JsonPath/ ?
should it allow traversing relations ?
should it allow same object fields to be used ?

Some point other point of attention:

  • validation of user pseudo code input and the error handling
  • circular reference detection

Maybe I have some time to wirte it in february.
Tagging @Aurelsicoko as the issue is closed, but seems the better place to discuss it

@derrickmehaffy
Copy link
Member

@dufoli please do feel free to write an RFC :) I'm not sure when we will be able to look at it as our "book" is quite full utnil after Q3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue: feature request Issue suggesting a new feature severity: low If the issue only affects a very niche base of users and an easily implemented workaround can solve
Projects
None yet
Development

No branches or pull requests

8 participants