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

Keep the path as string instead of an array #678

Merged
merged 1 commit into from
Jul 31, 2024

Conversation

jelly
Copy link
Member

@jelly jelly commented Jul 26, 2024

There is no good reason to keep the path as an array of strings, usually we want to just append a file to the path for file operations as most of the code simply joined the path back to a string.

This also makes sure the path is properly formatted as /path/to/thing/ with a leading and trailing /.


@jelly
Copy link
Member Author

jelly commented Jul 29, 2024

testBookmark fails everwhere.

@jelly jelly force-pushed the path-as-str branch 3 times, most recently from 357dbb1 to 1bf739b Compare July 30, 2024 16:57
path = path.slice(path.length - 1);
const PathBreadcrumbs = ({ path }: { path: string }) => {
const path_array = path.split("/");
if (path.endsWith("/") && path_array.length > 1) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Needs a comment, why this is needed :-)

Copy link
Member Author

Choose a reason for hiding this comment

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

Or alternative implementation..

Comment on lines +82 to +83
if (!currentPath.startsWith("/")) {
currentPath = `/${currentPath}`;
Copy link
Member Author

Choose a reason for hiding this comment

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

Needs a test :)

defaultBookmarks.push({ name: _("Home"), loc: user?.home }); // TODO: add trash
if (user?.home) {
// Ensure the home dir has a trailing / like the path
const home_dir = user.home.endsWith('/') ? user.home : `${user.home}/`;
Copy link
Member Author

Choose a reason for hiding this comment

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

Yup, never seen user.home be /home/admin/ it always is /home/admin so that's logical.

@jelly jelly force-pushed the path-as-str branch 2 times, most recently from 73043d9 to e7a7c0d Compare July 31, 2024 09:15
@jelly jelly requested a review from tomasmatus July 31, 2024 09:15
There is no good reason to keep the path as an array of strings, usually
we want to just append a file to the path for file operations as most of
the code simply joined the path back to a string.

This also makes sure the path is properly formatted as /path/to/thing/
with a leading and trailing /.
Comment on lines +82 to +83
if (!currentPath.startsWith("/")) {
currentPath = `/${currentPath}`;
Copy link
Contributor

Choose a reason for hiding this comment

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

These 2 added lines are not executed by any test.

Copy link
Member Author

Choose a reason for hiding this comment

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

Test this in a follow up!

defaultBookmarks.push({ name: _("Home"), loc: user?.home }); // TODO: add trash
if (user?.home) {
// Ensure the home dir has a trailing / like the path
const home_dir = user.home.endsWith('/') ? user.home : `${user.home}/`;
Copy link
Contributor

Choose a reason for hiding this comment

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

This added line is not executed by any test.

}
);
} else if (selected.length > 1) {
menuItems.push(
{
id: "copy-item",
title: _("Copy"),
onClick: () => setClipboard(selected.map(s => path.join("/") + "/" + s.name)),
onClick: () => setClipboard(selected.map(s => path + s.name)),
Copy link
Contributor

Choose a reason for hiding this comment

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

This added line is not executed by any test.

@jelly jelly marked this pull request as ready for review July 31, 2024 09:27
Copy link
Member

@tomasmatus tomasmatus left a comment

Choose a reason for hiding this comment

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

I think this looks good... and so the path.join("/") is no more!

@jelly jelly merged commit 2b616dd into cockpit-project:main Jul 31, 2024
20 checks passed
@jelly jelly deleted the path-as-str branch July 31, 2024 15:29
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.

3 participants