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 inverted validate label check in NcInputField #3980

Merged
merged 4 commits into from
Apr 18, 2023

Conversation

raimund-schluessler
Copy link
Contributor

@raimund-schluessler raimund-schluessler commented Apr 17, 2023

The NcInputField component currently warns about a missing label only if a label is provided and if the label changes during the lifetime of the component (which probably is the reason why no one noticed this yet). This PR fixes the inverted logic and runs the check on component creation as well. This might spawn quite a few warnings in the apps using this component, but I guess that's what this warning is for 🤷

As a side note, I would propose to change from throw new Error to Vue.warn, but that's a matter of taste, I guess.

@raimund-schluessler raimund-schluessler added bug Something isn't working 3. to review Waiting for reviews feature: input-field Covering the InputField, TextField, ... labels Apr 17, 2023
@raimund-schluessler raimund-schluessler added this to the 7.9.1 milestone Apr 17, 2023
Signed-off-by: Raimund Schlüßler <[email protected]>
@raimund-schluessler raimund-schluessler mentioned this pull request Apr 18, 2023
Copy link
Contributor

@ShGKme ShGKme left a comment

Choose a reason for hiding this comment

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

Works fine, tested 🎉

Thank you, interesting hidden problem 😅

Comment about watchs -> computed is non-blocking by me.

Signed-off-by: Raimund Schlüßler <[email protected]>
Copy link
Contributor

@skjnldsv skjnldsv left a comment

Choose a reason for hiding this comment

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

AH, wait

Comment on lines +288 to +290
if (!isValidLabel) {
console.warn('You need to add a label to the NcInputField component. Either use the prop label or use an external one, as per the example in the documentation.')
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Warn in computed = log every time the computed changes. It might not be the desired outcome
I'm not sure this is a good idea 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wouldn't the same happen if we warn in the watcher? The computed changes, the watcher fires, checks the label and warns in case it is not valid!?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hum, good point 🙈
I'm weirded out by this anti pattern though 😁

Copy link
Contributor

Choose a reason for hiding this comment

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

Are we sure the computed is not executed on other occasions? if so, you can merge !

Copy link
Contributor

Choose a reason for hiding this comment

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

The computed is triggered every time label or labelOutside is changed, but of cause the warning will only be fired if one of both is falsy.

Copy link
Contributor Author

@raimund-schluessler raimund-schluessler Apr 18, 2023

Choose a reason for hiding this comment

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

@skjnldsv I don't know whether it's an anti-pattern, but we do the same here for example: https://github.com/nextcloud/nextcloud-vue/blob/master/src/mixins/actionText.js#L87-L93 🙈

The computed is triggered every time label or labelOutside is changed, but of cause the warning will only be fired if one of both is falsy.

I would think so too. If label changes between False, undefined, null, an empty string or anything else evaluating to False, the warning would be triggered again even though it was invalid before already. But that seems a bit theoretic to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's hear what @ShGKme thinks about this approach 🙂

Copy link
Contributor

Choose a reason for hiding this comment

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

@skjnldsv I don't know whether it's an anti-pattern, but we do the samer here for example: master/src/mixins/actionText.js#L87-L93 see_no_evil

looks at blame
sees @skjnldsv
closes tab

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's hear what @ShGKme thinks about this approach 🙂

It's too late, but yes 😅.

It proper works, but it is an anti-pattern, computed should never have side-effects, only computing the value.

In options API there is a place for computed + watch, in Composition - watchEffect.

Copy link
Contributor

@skjnldsv skjnldsv left a comment

Choose a reason for hiding this comment

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

See comments

@Pytal Pytal merged commit 537e85b into master Apr 18, 2023
@Pytal Pytal deleted the fix/noid/inverted-label-logic branch April 18, 2023 16:16
@Pytal Pytal added 4. to release Ready to be released and/or waiting for tests to finish and removed 3. to review Waiting for reviews labels Apr 18, 2023
@AndyScherzinger AndyScherzinger modified the milestones: 7.9.1, 7.10.0 Apr 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4. to release Ready to be released and/or waiting for tests to finish bug Something isn't working feature: input-field Covering the InputField, TextField, ...
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants