Skip to content

Conversation

@BacLuc
Copy link
Contributor

@BacLuc BacLuc commented Aug 2, 2025

frontend: extract method toWorkbook in useMaterialViewHelper.js

That we can test it in isolation.


frontend: trim sheetNames to 31 chars in useMaterialViewHelper.js

And replace the last 3 chars with random alphanumeric characters
on collision.

This also fixes the "duplicate sheet" error if 2 periods have the same name.

Closes: #7184

BacLuc added 2 commits August 2, 2025 21:07
And replace the last 3 chars with random alphanumeric characters
on collision.

This also fixes the "duplicate sheet" error if 2 periods have the same name.
@BacLuc BacLuc requested a review from a team August 2, 2025 19:57
@BacLuc BacLuc changed the title Sheet name length fix xls sheet name length Aug 2, 2025

const workbook = toWorkbook(sheets)

expect(workbook.SheetNames).toEqual([sheetName.slice(0, 31)])
Copy link
Contributor

Choose a reason for hiding this comment

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

you are plus ou moin testing that slice does what it does, so maybe use 'a'.repeat(31)?

expect(workbook.SheetNames).toEqual([sheetName.slice(0, 31)])
})

it('does not overwrite sheets when shortening them makes them not unique anymore', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I tripped over this test name because I assumed overwrite means changing the sheet name, but you mean it doesn't replace the first one with the same (resulting) name. Maybe "does not drop sheets ..."?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not dropping, its replacing the pointer in the map. I would call that overwriting, but i am open for better formulations.

@BacLuc BacLuc requested a review from a team August 3, 2025 16:08
const validSheetName = sheetName.replaceAll(/[?*[\]/\\:]/g, '')
let slicedSheetName = validSheetName.slice(0, 31)
if (workbook.SheetNames.includes(slicedSheetName)) {
slicedSheetName = validSheetName.slice(0, 28) + randomString(3)
Copy link
Member

Choose a reason for hiding this comment

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

Why are you using a random string here?
Wouldn't a simple increment be more understandable?

Like:

MeinLangerPeriodeNam001
MeinLangerPeriodeNam002
...

@BacLuc
Copy link
Contributor Author

BacLuc commented Aug 3, 2025

I considered 4 possible fixes:

  1. Just show an error message to the user. He should shorten the period name himself.
  2. Shorten the string, if (would be less often) a collision happens, an error is in the console. Maybe improve that by showing an error to the user.
  3. Shorten the string and increment on collision. You can increment further for the next collision (and the code gets even more complicated), but it gets even worse when you have more than 9 collisions. Then you need a character less which may lead to even more collisions.
  4. Shorten the string and use random characters: Solves not all cases like 3, but the code is a lot simpler. And the user will eventually, if he really cares, find out that he has the same name (or shortened same name) of the periods.

We can pick our poison. I picked number 4.

@BacLuc BacLuc added this pull request to the merge queue Aug 11, 2025
Merged via the queue into ecamp:devel with commit 9165722 Aug 11, 2025
30 checks passed
@BacLuc BacLuc deleted the sheet-name-length branch August 11, 2025 19:33
This was referenced Aug 11, 2025
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.

Error: Sheet name cannot exceed 31 chars

3 participants