Skip to content

Commit

Permalink
run formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
Lunarequest committed Jul 24, 2024
1 parent 30e0361 commit 268b306
Show file tree
Hide file tree
Showing 19 changed files with 2,908 additions and 2,741 deletions.
374 changes: 191 additions & 183 deletions src/app.tsx

Large diffs are not rendered by default.

50 changes: 25 additions & 25 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,41 +22,41 @@ import cockpit from "cockpit";
const _ = cockpit.gettext;

export const permissions = [
/* 0 */ _("None"),
/* 1 */ _("Execute-only"),
/* 2 */ _("Write-only"),
/* 3 */ _("Write and execute"),
/* 4 */ _("Read-only"),
/* 5 */ _("Read and execute"),
/* 6 */ _("Read and write"),
/* 7 */ _("Read, write and execute"),
/* 0 */ _("None"),
/* 1 */ _("Execute-only"),
/* 2 */ _("Write-only"),
/* 3 */ _("Write and execute"),
/* 4 */ _("Read-only"),
/* 5 */ _("Read and execute"),
/* 6 */ _("Read and write"),
/* 7 */ _("Read, write and execute"),
];

export const inode_types = {
blk: _("Block device"),
chr: _("Character device"),
dir: _("Directory"),
fifo: _("Named pipe"),
lnk: _("Symbolic link"),
reg: _("Regular file"),
sock: _("Socket"),
blk: _("Block device"),
chr: _("Character device"),
dir: _("Directory"),
fifo: _("Named pipe"),
lnk: _("Symbolic link"),
reg: _("Regular file"),
sock: _("Socket"),
};

export function get_permissions(n: number) {
return permissions[n & 0o7];
return permissions[n & 0o7];
}

export function* map_permissions<T>(func: (value: number, label: string) => T) {
for (const [value, label] of permissions.entries()) {
yield func(value, label);
}
for (const [value, label] of permissions.entries()) {
yield func(value, label);
}
}

export function basename(path: string) {
const elements = path.split("/");
if (elements.length === 0) {
return "/";
} else {
return elements[elements.length - 1];
}
const elements = path.split("/");
if (elements.length === 0) {
return "/";
} else {
return elements[elements.length - 1];
}
}
187 changes: 97 additions & 90 deletions src/dialogs/delete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import React, { useState } from "react";

import { Button } from "@patternfly/react-core/dist/esm/components/Button";
import {
Modal,
ModalVariant,
Modal,
ModalVariant,
} from "@patternfly/react-core/dist/esm/components/Modal";

import cockpit from "cockpit";
Expand All @@ -34,101 +34,108 @@ import type { FolderFileInfo } from "../app";
const _ = cockpit.gettext;

const ConfirmDeletionDialog = ({
dialogResult,
path,
selected,
setSelected,
dialogResult,
path,
selected,
setSelected,
}: {
dialogResult: DialogResult<void>;
path: string;
selected: FolderFileInfo[];
setSelected: React.Dispatch<React.SetStateAction<FolderFileInfo[]>>;
dialogResult: DialogResult<void>;
path: string;
selected: FolderFileInfo[];
setSelected: React.Dispatch<React.SetStateAction<FolderFileInfo[]>>;
}) => {
const [errorMessage, setErrorMessage] = useState(null);
const [forceDelete, setForceDelete] = useState(false);
const [errorMessage, setErrorMessage] = useState(null);
const [forceDelete, setForceDelete] = useState(false);

let modalTitle;
if (selected.length > 1) {
modalTitle = cockpit.format(
forceDelete ? _("Force delete $0 items") : _("Delete $0 items?"),
selected.length,
);
} else {
const selectedItem = selected[0];
if (selectedItem.type === "reg") {
modalTitle = cockpit.format(
forceDelete ? _("Force delete file $0?") : _("Delete file $0?"),
selectedItem.name,
);
} else if (selectedItem.type === "lnk") {
modalTitle = cockpit.format(
forceDelete ? _("Force delete link $0?") : _("Delete link $0?"),
selectedItem.name,
);
} else if (selectedItem.type === "dir") {
modalTitle = cockpit.format(
forceDelete
? _("Force delete directory $0?")
: _("Delete directory $0?"),
selectedItem.name,
);
} else {
modalTitle = cockpit.format(
forceDelete ? _("Force delete $0") : _("Delete $0?"),
selectedItem.name,
);
}
}
let modalTitle;
if (selected.length > 1) {
modalTitle = cockpit.format(
forceDelete ? _("Force delete $0 items") : _("Delete $0 items?"),
selected.length,
);
} else {
const selectedItem = selected[0];
if (selectedItem.type === "reg") {
modalTitle = cockpit.format(
forceDelete ? _("Force delete file $0?") : _("Delete file $0?"),
selectedItem.name,
);
} else if (selectedItem.type === "lnk") {
modalTitle = cockpit.format(
forceDelete ? _("Force delete link $0?") : _("Delete link $0?"),
selectedItem.name,
);
} else if (selectedItem.type === "dir") {
modalTitle = cockpit.format(
forceDelete
? _("Force delete directory $0?")
: _("Delete directory $0?"),
selectedItem.name,
);
} else {
modalTitle = cockpit.format(
forceDelete ? _("Force delete $0") : _("Delete $0?"),
selectedItem.name,
);
}
}

const deleteItem = () => {
const args = ["rm", "-r"];
// TODO: Make force more sensible https://github.com/cockpit-project/cockpit-files/issues/363
cockpit
.spawn([...args, ...selected.map((f) => path + f.name)], {
err: "message",
superuser: "try",
})
.then(() => {
setSelected([]);
dialogResult.resolve();
})
.catch((err) => {
setErrorMessage(err.message);
setForceDelete(true);
});
};
const deleteItem = () => {
const args = ["rm", "-r"];
// TODO: Make force more sensible https://github.com/cockpit-project/cockpit-files/issues/363
cockpit
.spawn([...args, ...selected.map((f) => path + f.name)], {
err: "message",
superuser: "try",
})
.then(() => {
setSelected([]);
dialogResult.resolve();
})
.catch((err) => {
setErrorMessage(err.message);
setForceDelete(true);
});
};

return (
<Modal
position="top"
title={modalTitle}
titleIconVariant="warning"
variant={ModalVariant.medium}
isOpen
onClose={() => dialogResult.resolve()}
footer={
<>
<Button variant="danger" onClick={deleteItem}>
{_("Delete")}
</Button>
<Button variant="link" onClick={() => dialogResult.resolve()}>
{_("Cancel")}
</Button>
</>
}
>
{errorMessage && (
<InlineNotification type="danger" text={errorMessage} isInline />
)}
</Modal>
);
return (
<Modal
position="top"
title={modalTitle}
titleIconVariant="warning"
variant={ModalVariant.medium}
isOpen
onClose={() => dialogResult.resolve()}
footer={
<>
<Button variant="danger" onClick={deleteItem}>
{_("Delete")}
</Button>
<Button
variant="link"
onClick={() => dialogResult.resolve()}
>
{_("Cancel")}
</Button>
</>
}
>
{errorMessage && (
<InlineNotification
type="danger"
text={errorMessage}
isInline
/>
)}
</Modal>
);
};

export function confirm_delete(
dialogs: Dialogs,
path: string,
selected: FolderFileInfo[],
setSelected: React.Dispatch<React.SetStateAction<FolderFileInfo[]>>,
dialogs: Dialogs,
path: string,
selected: FolderFileInfo[],
setSelected: React.Dispatch<React.SetStateAction<FolderFileInfo[]>>,
) {
dialogs.run(ConfirmDeletionDialog, { path, selected, setSelected });
dialogs.run(ConfirmDeletionDialog, { path, selected, setSelected });
}
Loading

0 comments on commit 268b306

Please sign in to comment.