Skip to content

Commit

Permalink
Add option to disable rename in renamer (#1113)
Browse files Browse the repository at this point in the history
  • Loading branch information
harshithmohan authored Oct 20, 2024
1 parent a89ba10 commit f836301
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions src/pages/utilities/Renamer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,17 @@ const getStatusColumn = (
},
} as UtilityHeaderType<FileType>);

const Menu = React.memo((
props: { disable: boolean, moveFiles: boolean, toggleMoveFiles: () => void, selectedRows: FileType[] },
) => {
const { disable, moveFiles, selectedRows, toggleMoveFiles } = props;
type MenuProps = {
disable: boolean;
moveFiles: boolean;
renameFiles: boolean;
toggleMoveFiles: () => void;
toggleRenameFiles: () => void;
selectedRows: FileType[];
};

const Menu = React.memo((props: MenuProps) => {
const { disable, moveFiles, renameFiles, selectedRows, toggleMoveFiles, toggleRenameFiles } = props;

const dispatch = useDispatch();

Expand Down Expand Up @@ -250,6 +257,13 @@ const Menu = React.memo((
label="Move Files"
labelRight
/>
<Checkbox
id="rename-files"
isChecked={renameFiles}
onChange={toggleRenameFiles}
label="Rename Files"
labelRight
/>
</div>
);
});
Expand Down Expand Up @@ -282,6 +296,7 @@ const Renamer = () => {
const { isPending: settingsPatchPending, mutate: patchSettings } = usePatchSettingsMutation();

const [moveFiles, toggleMoveFiles] = useToggle(settings.Plugins.Renamer.MoveOnImport);
const [renameFiles, toggleRenameFiles] = useToggle(settings.Plugins.Renamer.RenameOnImport);
const [showSettings, toggleSettings] = useToggle(false);
const [showAddFilesModal, toggleAddFilesModal] = useToggle(false);
const [showConfigModal, toggleConfigModal] = useToggle(false);
Expand Down Expand Up @@ -312,7 +327,7 @@ const Renamer = () => {
await previewRename(
{
move: moveFiles,
rename: true,
rename: renameFiles,
FileIDs: pendingPreviews,
Config: {
RenamerID: renamer.RenamerID,
Expand Down Expand Up @@ -400,7 +415,7 @@ const Renamer = () => {

useEffect(() => {
dispatch(clearRenameResults());
}, [dispatch, moveFiles]);
}, [dispatch, moveFiles, renameFiles]);

useEffect(() => {
if (!renamerConfigsQuery.isSuccess) return;
Expand Down Expand Up @@ -438,7 +453,7 @@ const Renamer = () => {
relocateFiles({
configName: selectedConfig.Name,
move: moveFiles,
rename: true,
rename: renameFiles,
deleteEmptyDirectories: true,
FileIDs: files.map(file => file.ID),
});
Expand All @@ -452,7 +467,9 @@ const Renamer = () => {
<Menu
selectedRows={selectedRows}
moveFiles={moveFiles}
renameFiles={renameFiles}
toggleMoveFiles={toggleMoveFiles}
toggleRenameFiles={toggleRenameFiles}
disable={relocatePending}
/>
<div className="flex gap-x-3">
Expand Down

0 comments on commit f836301

Please sign in to comment.