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 Boards.uniqueTitle not working as expected #4400 #4401

Merged
merged 1 commit into from Mar 6, 2022
Merged

fix Boards.uniqueTitle not working as expected #4400 #4401

merged 1 commit into from Mar 6, 2022

Conversation

Ben0it-T
Copy link
Contributor

@Ben0it-T Ben0it-T commented Mar 6, 2022

fix #4400

@xet7 xet7 merged commit f8b60de into wekan:master Mar 6, 2022
@Ben0it-T
Copy link
Contributor Author

Ben0it-T commented Mar 6, 2022

Pervert side effect !!
I understand why this was changed.
If you import a board this will had an unnecessary [1] !
Sorry.
Fell free to revert.
Need to dig a little more... or make two functions, one for import, one for duplicate board

wekan-import-01

@Ben0it-T
Copy link
Contributor Author

Ben0it-T commented Mar 7, 2022

Adding a "first check" seems to bring something better

Boards.uniqueTitle = title => {
  const m = title.match(
    new RegExp('^(?<title>.*?)\\s*(\\[(?<num>\\d+)]\\s*$|\\s*$)'),
  );
  const base = escapeForRegex(m.groups.title);
  boards = Boards.find({ title: new RegExp(`^${base}\\s*(\\[(?<num>\\d+)]\\s*$|\\s*$)`) });
  if (boards.count() > 0) {
    let num = 0;
    Boards.find({ title: new RegExp(`^${base}\\s*\\[\\d+]\\s*$`) }).forEach(
      board => {
        const m = board.title.match(
          new RegExp('^(?<title>.*?)\\s*\\[(?<num>\\d+)]\\s*$'),
        );
        if (m) {
          const n = parseInt(m.groups.num, 10);
          num = num < n ? n : num;
        }
      },
    );
    return `${m.groups.title} [${num + 1}]`;
  }
  return title;
};

wekan-uniqueTitle-01

I will redo some tests tomorrow. Then I'll send a PR

@Ben0it-T Ben0it-T deleted the fix-Boards.uniqueTitle branch March 8, 2022 21:09
@Ben0it-T Ben0it-T restored the fix-Boards.uniqueTitle branch March 8, 2022 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Boards.uniqueTitle not working as expected
2 participants