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

implement file type icons #2550

Merged
merged 3 commits into from
Jun 3, 2024
Merged

implement file type icons #2550

merged 3 commits into from
Jun 3, 2024

Conversation

mhsh312
Copy link
Contributor

@mhsh312 mhsh312 commented Oct 31, 2023

Fixes #2542 (needs discussion about icon design)

Changes:

Added File Type Icons.

I have created a new React Component and passed the file extension as a prop. The component returns suitable icon according to the prop. I have not put much thought into choosing the icons (I have used react-icons) as the icon choice can be reviewed and discussed later. For the file types I could not find the icons for, I have set the default case to the old generic FileIcon.

image

I have verified that this pull request:

  • has no linting errors (npm run lint)
  • has no test errors (npm run test)
  • is from a uniquely-named feature branch and is up to date with the develop branch.
  • is descriptively named and links to an issue number, i.e. Fixes #123

Copy link

welcome bot commented Oct 31, 2023

🎉 Thanks for opening this pull request! Please check out our contributing guidelines if you haven't already.

@@ -256,6 +256,7 @@ class FileNode extends React.Component {
const isRoot = this.props.name === 'root';

const { t } = this.props;
const { extension } = parseFileName(this.props.name);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Awesome that we already had a function for this!

import FileIcon from '../../../images/file.svg';

export default function FileTypeIcon({ fileExtension }) {
switch (fileExtension) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a great starting point!

As this evolves we'll figure out what makes sense code-wise. switch definitely works. A dictionary object could work. That is, const icons = { html: IoLogoHtml5, /// etc. }. If we want to use the same icon for more than one extension then if else statements might make sense. Like if (/jsx?/i.test(fileExtension)) { return <IoLogoJavascript /> } to match .js and .jsx.

Copy link
Contributor Author

@mhsh312 mhsh312 Nov 2, 2023

Choose a reason for hiding this comment

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

If we want to use the same icon for more than one extension then if else statements might make sense. Like if (/jsx?/i.test(fileExtension)) { return } to match .js and .jsx.

In javascript, same code can be assigned to multiple cases like this:

 switch (choice) {
  case "1":
  case "2":
    console.log("test1");
    break;
  case "3":
    console.log("test2");
}

So I think switch overall is the best way.

Copy link
Collaborator

@raclim raclim left a comment

Choose a reason for hiding this comment

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

Thanks for your work on this! I think this looks pretty good for now so I'm finally going to merge this in—any added changes can be made in future PRs! One minor additional change I made is adding the focusable' and aria-hiddenproperties toFileTypeIcon` for accessibility purposes.

@raclim raclim merged commit 2f1b66b into processing:develop Jun 3, 2024
1 check passed
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.

Adding unique file type icons for different file types
3 participants