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

Overdue Date / Field differrence #142

Open
bogdancs92 opened this issue Jan 16, 2020 · 3 comments
Open

Overdue Date / Field differrence #142

bogdancs92 opened this issue Jan 16, 2020 · 3 comments

Comments

@bogdancs92
Copy link

Hello,

I'm trying to use the component and I need to define a new operator I think.

Here it is what I want:

  • a field of type date (for example: DUE_DATE)
  • field property : type of diff result (for exemple : days)
  • operator name : overdue of
  • right field : number
  • sql effect <=> SELECT DATEDIFF(days, GETDATE(),DUE_DATE )>RIGHT_FIELD_VALUE AS DateDiff;

Also a operator who does the difference between two fields can help us :) : if I have a difference of more then 20€ between FIELD_A and FIELD_B : sql effect : (FIELD_A - FIELD_B)>RIGHT_VALUE

Thank you for your ideas :)

@bogdancs92
Copy link
Author

Hello,

does the "factory" property for a new widget is used by the master branch?

widgets: {
text: {
type: "text", //see 'types' section
valueSrc: 'value', //'value' or 'field' (only for special 'field' widget)
factory: (props) => <TextWidget {...props} />, //React component

If not, do you have any idea when it will be ?

@ukrbublik
Copy link
Owner

@bogdancs92
factory is used.

Addressing your request for overdue operator, I'll add support for it (or explain how to configure it without code changes, which is possible I guess) at this weekend when I have some free time.

Field difference can be implemented with functions.
My lib supports exactly 1 field on left side. So if converting (FIELD_A - FIELD_B)>RIGHT_VALUE to FIELD_A > FIELD_B + RIGHT_VALUE would work for you, you can add function like difference which takes 2 args - field and number.

@bogdancs92
Copy link
Author

bogdancs92 commented Jan 23, 2020

Hello @ukrbublik and thanks you for your work and your help.

For the momeent I succeeded in doing this :
FIELD_A "bigger than" FIELD_B with "number input" using a new operator with cardinality 2 and overriding some properties :

const differenceOperator = {
label : 'supérieur',
cardinality : 2,
reversedOp : 'difference',
labelForFormat : 'diff',
formatOp : (field, _op, value, _valueSrc, _valueType, opDef) => {
console.log(differenceOperator > ${field} ${opDef.labelForFormat} ${value});
return "";
},
sqlFormatOp : (field, _op, value, _valueSrc, _valueType, opDef) => {
return "(("+field+" - "+value._tail.array[0]+") > "+value._tail.array[1]+")";
},
jsonLogic : (field, _op, value, _valueSrc, _valueType, opDef) => {
return "difference[" + value[1] +"]";
},
valueLabels :['Champ', {label: 'Combien', placeholder: 'Valeur'}],
textSeparators : ["à", 'de'],
factory: (props) => <NumberWidget {...props} />,
};
and using this operator in the number types.

This seems to do what I want (exemple in sql : ((FIELD_A - FIELD_B) > 50)

When I try to do exactly the same thing for the date type (the "overdue operation) it doesn't work because the widget presents 2 fields of type date instead of leaving the first field of the same type field and a numeric field for the second....With this I think a need some help...

image

Thanks

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

No branches or pull requests

2 participants