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

Fix bigint interface bugs #20757

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

wasimTQ
Copy link
Contributor

@wasimTQ wasimTQ commented Dec 15, 2023

Scope

What's changed:

  • Can add numbers that are more than javascript safe integer
  • Validates the field for maximum and minimum values when editing through the input field and step up and down. (But atm not possible to validate editing on the raw editor)

Potential Risks / Drawbacks

  • admin/settings/data-model/table/field -> interface tab Adding a maximum or minimum value in a bigInteger field is not possible. It thinks of the field as integer.

Review Notes / Questions

  • I would like to know if that all of the changes that're made doesn't affect other areas.
  • And how we can handle value from raw data editor
  • I think showing an error might be a better approach as well. But I don't know how to trigger an error for that field

Fixes #20287

Copy link

changeset-bot bot commented Dec 15, 2023

🦋 Changeset detected

Latest commit: db5e768

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@directus/app Patch
@directus/api Patch
directus Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@wasimTQ
Copy link
Contributor Author

wasimTQ commented Dec 15, 2023

@br41nslug @paescuj It still is a wip

@wasimTQ
Copy link
Contributor Author

wasimTQ commented Dec 15, 2023

@paescuj I handled min and max. Can you tell me how can I trigger an error for specific field?
And also how can we handle the data inside raw editor. Or should I have the same validation in the raw editor as well?

@wasimTQ
Copy link
Contributor Author

wasimTQ commented Dec 16, 2023

I fixed all the things within the input for bigint calculations. You can check it once to confirm if everything works fine.
I might have missed something. So I'd like your feedback on it

@wasimTQ
Copy link
Contributor Author

wasimTQ commented Dec 16, 2023

I hope the dropdown and radio interfaces has been fixed from these changes.

@wasimTQ
Copy link
Contributor Author

wasimTQ commented Dec 18, 2023

@br41nslug Can you check it out? I think other than slider everything else works perfectly fine

type numeric = number | bigint;

export class SafeInteger {
private _value: numeric;
Copy link
Member

Choose a reason for hiding this comment

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

I dont think we need an underscore in the variable name here

Suggested change
private _value: numeric;
private value: numeric;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did set it private so we can't modify it outside of the class. But can't have a getter with the same name as a variable name.

app/src/__utils__/safe-integer.ts Outdated Show resolved Hide resolved
@@ -87,6 +91,7 @@ const setRawValue = () => {
:disabled="disabled"
language="plaintext"
:placeholder="t('enter_raw_value')"
:is-big-integer="props.field.type === 'bigInteger'"
Copy link
Member

Choose a reason for hiding this comment

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

Let's try to work with BigInts as strings where possible so we limit the amount of "is big int" props added to where they are strictly required. I think we can drop a bunch of the "if big int then" logic if getJSType were to return string for bigInt instead of number.

app/src/components/v-form/v-form.vue Outdated Show resolved Hide resolved
app/src/components/v-input.vue Outdated Show resolved Hide resolved
@wasimTQ
Copy link
Contributor Author

wasimTQ commented Dec 18, 2023

@br41nslug I hope I added the changes you suggested. Can you check it?

@wasimTQ wasimTQ force-pushed the fix-bigint-interface-bugs branch 5 times, most recently from 2f3dfb7 to 5b2104b Compare December 18, 2023 15:23
@wasimTQ
Copy link
Contributor Author

wasimTQ commented Dec 18, 2023

@br41nslug Can you check it one more time and let me know if you're satisfied with the changes I made.

Also it already became a huge PR so I can work on slider in a seperate PR if you like

@br41nslug
Copy link
Member

Will put it on the list for tomorrow :D Yeah the slider should definitely be in a separate PR the goal is to keep PRs as small and to the point as possible

@wasimTQ
Copy link
Contributor Author

wasimTQ commented Dec 19, 2023

@br41nslug Can you review it now please?

Comment on lines 104 to 107
if (safeInt.isInvalid) {
inputRef.value?.focus();
codemirror?.setValue(content.substring(0, content.length - 1));
return;
}
Copy link
Member

Choose a reason for hiding this comment

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

Does this recursively set the value? probably a better approach to emit null if it is invalid.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No this doesn't recursively set values. As It'll be unfocused once the value is invalid.

Comment on lines 150 to 151
<!-- This input is exists just to unfocus the codemirror component -->
<input ref="inputRef" type="radio" :style="{ all: 'unset' }" />
Copy link
Member

Choose a reason for hiding this comment

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

I think we can do without this workaround.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I couldn't find any documentation on blur method first. But looks like it has a method to get the input field.

Comment on lines 48 to 51
if (props.field.type === 'bigInteger') {
return emit('setRawValue', internalValue.value);
}

Copy link
Member

Choose a reason for hiding this comment

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

This should be in the switch statement as getJSType now returns bigInteger

app/src/__utils__/safe-integer.ts Outdated Show resolved Hide resolved
app/src/__utils__/safe-integer.ts Outdated Show resolved Hide resolved
@wasimTQ
Copy link
Contributor Author

wasimTQ commented Dec 20, 2023

@br41nslug Every changes has been made

@wasimTQ

This comment was marked as off-topic.

@paescuj

This comment was marked as off-topic.

@br41nslug

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: 🏗 In progress
Development

Successfully merging this pull request may close these issues.

BigInt interface precision bugs
4 participants