Skip to content

[#1526] Add ellipsis to sidebar file names #1527

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

Merged
merged 8 commits into from
Aug 6, 2020

Conversation

catarak
Copy link
Member

@catarak catarak commented Jul 30, 2020

Fixes #1526

I have verified that this pull request:

  • has no linting errors (npm run lint)
  • is from a uniquely-named feature branch and has been rebased on top of the latest master. (If I was asked to make more changes, I have made sure to rebase onto master then too)
  • is descriptively named and links to an issue number, i.e. Fixes #123

I went a little overboard and decided to copy Glitch's design on this one—would love some feedback!
Screen Shot 2020-07-30 at 7 02 23 PM

@catarak catarak requested a review from ghalestrilo July 30, 2020 23:05
Copy link
Collaborator

@ghalestrilo ghalestrilo left a comment

Choose a reason for hiding this comment

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

Looks great! I made some suggestions on the code structure, let me know how you feel about them

@@ -10,6 +10,47 @@ import FolderRightIcon from '../../../images/triangle-arrow-right.svg';
import FolderDownIcon from '../../../images/triangle-arrow-down.svg';
import FileIcon from '../../../images/file.svg';

function FileName({ name }) {
const nameArray = name.split('.');
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's a good idea to catch if (!name) return; at the beginning of the function, otherwise .split can explode

Copy link
Member Author

Choose a reason for hiding this comment

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

name is a required string proptype, which means that the component itself will complain if it's used without this prop, so is this necessary?

Copy link
Collaborator

Choose a reason for hiding this comment

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

True, in this case it's kind of pointless

const extension = `.${nameArray[nameArray.length - 1]}`;
const fileName = nameArray.slice(0, -1).join('');
const firstLetter = fileName[0];
const lastLetter = fileName[fileName.length - 1];
Copy link
Collaborator

Choose a reason for hiding this comment

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

ditto

function FileName({ name }) {
const nameArray = name.split('.');
if (nameArray.length > 1) {
const extension = `.${nameArray[nameArray.length - 1]}`;
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can use nameArray.slice(-1) here, if that's more readable

Copy link
Member Author

Choose a reason for hiding this comment

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

I always forget that I can use slice for this 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

I think I'm actually going to change this to nameArray.charAt(nameArray.length - 1) as I think that's the most readable.

Copy link
Member Author

Choose a reason for hiding this comment

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

Wow, so apparently charAt can work in some really wacky ways (see this StackOverflow answer), so......... I'm just going to stick with bracket notation.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Make sure to check/test what happens if you pass an empty string to it!
Javascript doesn't like array[-1]

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nevermind, you're catching this on line 15. My bad!

Comment on lines 21 to 32
return (
<span className="sidebar__file-item-name-text">
<span>{firstLetter}</span>
{fileName.length > 2 &&
<span className="sidebar__file-item-name--ellipsis">{middleText}</span>
}
{fileName.length > 1 &&
<span>{lastLetter}</span>
}
<span>{extension}</span>
</span>
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

If possible, I think FileName should be just this block, and the name logic should go on another function, which returns a string. This will avoid having to duplicate this code below.

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes sense!

);
}
const firstLetter = name[0];
const lastLetter = name[name.length - 1];
Copy link
Collaborator

Choose a reason for hiding this comment

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

ditto

Comment on lines 37 to 47
return (
<span className="sidebar__file-item-name-text">
<span>{firstLetter}</span>
{name.length > 2 &&
<span className="sidebar__file-item-name--ellipsis">{middleText}</span>
}
{name.length > 1 &&
<span>{lastLetter}</span>
}
</span>
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

ditto

catarak added 3 commits August 3, 2020 12:26
- Create function parseFileName to separate a file name into first
  letter, last letter, middle, extension
…js-web-editor into bug/sidebar-name-overflow
@catarak
Copy link
Member Author

catarak commented Aug 3, 2020

Other things I still need to consider for this:

  • How does this sound with a screen reader? Do I need to add an aria-label?
  • How does this for for keyboard-only users? Is there a way to expand the text?

@ghalestrilo
Copy link
Collaborator

Maybe, if there's already a concrete improvement delivered by this PR, you can address these concerns later in another issue/PR.

@catarak
Copy link
Member Author

catarak commented Aug 4, 2020

* How does this sound with a screen reader? Do I need to add an `aria-label`?

I'm pretty sure this is broken by this PR, so I want to fix it.

* How does this for for keyboard-only users? Is there a way to expand the text?

This, however, is something I think could be addressed in a different PR!

@catarak
Copy link
Member Author

catarak commented Aug 6, 2020

Tested this with VoiceOver, file labels are working 😄

@catarak catarak merged commit 873b2b7 into develop Aug 6, 2020
@catarak catarak deleted the bug/sidebar-name-overflow branch August 6, 2020 00:43
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.

File names overflow wrap in Sidebar
2 participants