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

Improvement: config registration form settings #3932

Merged
merged 27 commits into from Feb 5, 2022

Conversation

math-GH
Copy link
Contributor

@math-GH math-GH commented Oct 24, 2021

Closes #981

Changes proposed in this pull request:

  • improved UI for set the registration formular

Before:
grafik

After:
Value "1": No registration form, because minimum 1 account exists
grafik

grafik

Value "0": unlimited accounts
grafik

Value "x": set the number
grafik

by default it will give a number of amount of existing accounts + 1, so that the registration form will be enabled

If the set number is bigger than the number of existing account, than the text "form enabled" will be shown.
Else: "form disabled".
The text is calculated "live"
grafik

Pull request checklist:

  • clear commit messages
  • code manually tested

@math-GH
Copy link
Contributor Author

math-GH commented Oct 24, 2021

published as "Draft" PR to collect your feedback.

Open todo:

  • i18n translations. Only en-us is available right now
  • phpcs

@Alkarex
Copy link
Member

Alkarex commented Oct 24, 2021

Looks good :-)

@Alkarex Alkarex added the UI 🎨 User Interfaces label Oct 24, 2021
@math-GH math-GH marked this pull request as ready for review October 25, 2021 21:15
@math-GH
Copy link
Contributor Author

math-GH commented Oct 25, 2021

Ready for review

@Alkarex Alkarex added this to the 1.19.0 milestone Oct 25, 2021
@Alkarex
Copy link
Member

Alkarex commented Oct 25, 2021

Try to run the new make fix-all (not fully production ready yet, as it requires npm install and composer install to be run advance)

@Alkarex
Copy link
Member

Alkarex commented Oct 25, 2021

Hum, it looks there is some old code in there. Maybe an old branch?

@math-GH
Copy link
Contributor Author

math-GH commented Oct 26, 2021

the failed test I will check later

@Alkarex
Copy link
Member

Alkarex commented Oct 26, 2021

It is not only the tests: it looks like some files are based on old versions, e.g. main.js

function init_maxNumbersOfAccountsStatus() {
const input = document.getElementById('max-registrations-input');
if (input) {
input.addEventListener('click', function() { onchange_maxNumbersOfAccounts(this); });
Copy link
Member

@Frenzie Frenzie Oct 26, 2021

Choose a reason for hiding this comment

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

There's no need to use anonymous functions for this kind of usage.

Suggested change
input.addEventListener('click', function() { onchange_maxNumbersOfAccounts(this); });
input.addEventListener('click', onchange_maxNumbersOfAccounts);

And then something like:

// I think we use ev rather than e or event? Not 100% sure otoh.
function onchange_maxNumbersOfAccounts(ev) {
  const elem = ev.target;

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 use the function also for
onchange_maxNumbersOfAccounts(input);
any suggestion to fix it?

Copy link
Member

Choose a reason for hiding this comment

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

Did you mean to write onchange_selectInputChanger? The same way,

function onchange_selectInputChanger(ev) {
  const elem = ev.target

Another thing is the name btw, but I'll comment about that on another line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ev.target does not work for input while calling onchange_maxNumbersOfAccounts(input);

Copy link
Member

@Frenzie Frenzie Oct 26, 2021

Choose a reason for hiding this comment

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

I think something like an init event might be a touch more elegant, but let's leave it like this then. Any performance/memory related to anonymous functions is completely irrelevant here.

	input.dispatchEvent(new Event('change', {
		bubbles: true,
		cancelable: true,
	}));

I would like the event listener and/or the function name to be less deceptive about what's going on, however. ;-) change is probably the right event to use here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks, it helped me a lot. That are the small little things I cannot google it, I need it told from an expert :)

Copy link
Member

Choose a reason for hiding this comment

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

The tl;dr is that if you add a lot of event listeners your page's memory usage can balloon, especially combined with anonymous functions. If you ever see a page that's just doing something like document.addEventListener('click', … and then checking if ev.target === some element, that's why. (Or perhaps not on the document, but in any case on the parent container div/form/whatever instead of the individual checkboxes.) While that's definitely not an issue here, one thing I've learned as a maintainer is that letting through something seemingly innocuous will suddenly be copied by someone else several years later as an example to follow, almost guaranteed. :-) Besides the memory usage, all the bubbling through all of the elements that have an event listener attached can also take much longer overall when you have a lot of them.

It's particularly when you're adding anonymous functions programmatically, like here in a for loop, that it can become problematic. For one-offs it probably doesn't make an appreciable difference, at least in memory usage, although it can affect performance in slightly unexpected ways (e.g., a regularly declared function might be JIT-compiled better than an anonymous one, at least in the past).

I'm not sure if what I steered this towards is necessarily the best way to approach this particular problem; you could also write something like, at its simplest:

const elem = ev.target || ev;

I just happen to find it more elegant to use the event listener itself instead of hacking the function to take either an event or an element. Another, probably clearer and better approach would be some indirection, i.e., a function that always takes an element (your original function) and a second non-anonymous function for the event listener that simply calls the first function with ev.target.

So much for tl;dr… but in any case, I hope that explains why adding anonymous functions in a for loop triggered my radar. I don't like pages that waste a lot of memory. ;-)

@math-GH math-GH marked this pull request as draft October 26, 2021 10:43
@math-GH math-GH marked this pull request as ready for review October 26, 2021 10:43
}
}

function onchange_selectInputChanger(elem) {
Copy link
Member

Choose a reason for hiding this comment

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

I would name this something more generic, otherwise it's very easy to get at best strange and at worst misleading function names like we see here. However, the function name is correct that you should probably be listening for change, not for click.

Suggested change
function onchange_selectInputChanger(elem) {
function updateSelectInput(elem) {

@math-GH
Copy link
Contributor Author

math-GH commented Oct 26, 2021

@Alkarex : I do not understand why main.js makes such problems. I thought that I used the newest version from edge branch

@math-GH
Copy link
Contributor Author

math-GH commented Oct 26, 2021

I updated main.js from edge manually. Now it works and passed the checks

@Alkarex Alkarex modified the milestones: 1.19.0, 1.20.0 Oct 29, 2021
@Alkarex
Copy link
Member

Alkarex commented Oct 29, 2021

Let's make a stable release 1.19 before we land this PR in the following 1.20 work (due in particular to new translation strings)

@math-GH
Copy link
Contributor Author

math-GH commented Feb 5, 2022

Cannot find the root of this test issue

Run composer run-script translations && git diff --exit-code
> cli/manipulate.translation.php -a format
PHP Parse error:  syntax error, unexpected single-quoted string "option", expecting ")" in /home/runner/work/FreshRSS/FreshRSS/cli/i18n/I18nFile.php(66) : eval()'d code on line 174
Script cli/manipulate.translation.php -a format handling the translations event returned with error code 255
Error: Process completed with exit code 255.

@aledeg Could you please check?

app/i18n/cz/admin.php Outdated Show resolved Hide resolved
Alkarex added a commit to Alkarex/FreshRSS that referenced this pull request Feb 5, 2022
@Alkarex Alkarex mentioned this pull request Feb 5, 2022
Alkarex added a commit that referenced this pull request Feb 5, 2022
app/i18n/fr/admin.php Outdated Show resolved Hide resolved
@Alkarex Alkarex merged commit ba1259b into FreshRSS:edge Feb 5, 2022
@math-GH math-GH deleted the improve-conf-reg-form-settings branch February 5, 2022 12:53
Alkarex added a commit to Alkarex/FreshRSS that referenced this pull request Apr 13, 2022
Regression from FreshRSS#3932
The data-leave-validation mechanism would always say that max-registrations-input has changed when navigating to another page
<div class="group-controls">
<?php $number = count(listUsers()); ?>
<input type="number" id="max-registrations-input" name="" value="<?= FreshRSS_Context::$system_conf->limits['max_registrations'] > 1 ? FreshRSS_Context::$system_conf->limits['max_registrations'] : $number + 1; ?>" min="2"
data-leave-validation="<?= FreshRSS_Context::$system_conf->limits['max_registrations'] ?>" data-number="<?= $number ?>"/>
Copy link
Member

Choose a reason for hiding this comment

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

Regression fixed in #4312

Alkarex added a commit that referenced this pull request Apr 18, 2022
Regression from #3932
The data-leave-validation mechanism would always say that max-registrations-input has changed when navigating to another page
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[bug] account limit for account creation is not working
3 participants