Skip to content

Commit 7c369df

Browse files
varg1714jenfonro
andauthored
fix(fs): Add skipExisting option to move and copy. (#252)
* fix(fs): Add skipExisting option to move and copy. * fix(fs): Add merge option copy. * fix(fs): Code smell. fix(fs): Code smell. fix(fs): Code smell. * fix(fs): display the name of the tasks of the merge type. * fix: align Copy/Move modal actions with new skip options --------- Co-authored-by: jenfonro <799170122@qq.com>
1 parent d91ec6a commit 7c369df

File tree

5 files changed

+111
-34
lines changed

5 files changed

+111
-34
lines changed

src/components/FolderTree.tsx

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -226,17 +226,27 @@ export const ModalFolderChoose = (props: ModalFolderChooseProps) => {
226226
autoOpen
227227
/>
228228
</ModalBody>
229-
<ModalFooter display="flex" gap="$2">
230-
<Show when={props.footerSlot}>{props.footerSlot}</Show>
231-
<Button onClick={props.onClose} colorScheme="neutral">
232-
{t("global.cancel")}
233-
</Button>
234-
<Button
235-
loading={props.loading}
236-
onClick={() => props.onSubmit?.(value())}
237-
>
238-
{t("global.ok")}
239-
</Button>
229+
<ModalFooter
230+
display="flex"
231+
w="$full"
232+
gap="$4"
233+
alignItems="flex-end"
234+
justifyContent="flex-end"
235+
>
236+
<Show when={props.footerSlot}>
237+
<Box mr="auto">{props.footerSlot}</Box>
238+
</Show>
239+
<HStack spacing="$2">
240+
<Button onClick={props.onClose} colorScheme="neutral">
241+
{t("global.cancel")}
242+
</Button>
243+
<Button
244+
loading={props.loading}
245+
onClick={() => props.onSubmit?.(value())}
246+
>
247+
{t("global.ok")}
248+
</Button>
249+
</HStack>
240250
</ModalFooter>
241251
</ModalContent>
242252
</Modal>

src/lang/en/home.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@
193193
"conflict_policy": {
194194
"cancel_if_exists": "Cancel if file exists",
195195
"overwrite_existing": "Overwrite existing files",
196-
"skip_existing": "Skip existing files"
196+
"skip_existing": "Skip existing files",
197+
"merge": "Only Copy new files and subdirectories"
197198
}
198199
}

src/pages/home/toolbar/CopyMove.tsx

Lines changed: 68 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Checkbox, createDisclosure } from "@hope-ui/solid"
1+
import { Checkbox, createDisclosure, VStack } from "@hope-ui/solid"
22
import { createSignal, onCleanup } from "solid-js"
33
import { ModalFolderChoose } from "~/components"
44
import { useFetch, usePath, useRouter, useT } from "~/hooks"
@@ -12,6 +12,8 @@ export const Copy = () => {
1212
const { pathname } = useRouter()
1313
const { refresh } = usePath()
1414
const [overwrite, setOverwrite] = createSignal(false)
15+
const [skipExisting, setSkipExisting] = createSignal(false)
16+
const [merge, setMerge] = createSignal(false)
1517
const handler = (name: string) => {
1618
if (name === "copy") {
1719
onOpen()
@@ -29,22 +31,51 @@ export const Copy = () => {
2931
onClose={onClose}
3032
loading={loading()}
3133
footerSlot={
32-
<Checkbox
33-
mr="auto"
34-
checked={overwrite()}
35-
onChange={() => {
36-
setOverwrite(!overwrite())
37-
}}
38-
>
39-
{t("home.conflict_policy.overwrite_existing")}
40-
</Checkbox>
34+
<VStack w="$full" spacing="$2">
35+
<Checkbox
36+
mr="auto"
37+
checked={overwrite()}
38+
onChange={() => {
39+
const curOverwrite = !overwrite()
40+
if (curOverwrite) {
41+
setSkipExisting(false)
42+
setMerge(false)
43+
}
44+
setOverwrite(curOverwrite)
45+
}}
46+
>
47+
{t("home.conflict_policy.overwrite_existing")}
48+
</Checkbox>
49+
<Checkbox
50+
mr="auto"
51+
checked={skipExisting()}
52+
onChange={() => {
53+
setSkipExisting(!skipExisting())
54+
}}
55+
disabled={overwrite() || merge()}
56+
>
57+
{t("home.conflict_policy.skip_existing")}
58+
</Checkbox>
59+
<Checkbox
60+
mr="auto"
61+
checked={merge()}
62+
onChange={() => {
63+
setMerge(!merge())
64+
}}
65+
disabled={overwrite() || skipExisting()}
66+
>
67+
{t("home.conflict_policy.merge")}
68+
</Checkbox>
69+
</VStack>
4170
}
4271
onSubmit={async (dst) => {
4372
const resp = await ok(
4473
pathname(),
4574
dst,
4675
selectedObjs().map((obj) => obj.name),
4776
overwrite(),
77+
skipExisting(),
78+
merge(),
4879
)
4980
handleRespWithNotifySuccess(resp, () => {
5081
refresh()
@@ -62,6 +93,7 @@ export const Move = () => {
6293
const { pathname } = useRouter()
6394
const { refresh } = usePath()
6495
const [overwrite, setOverwrite] = createSignal(false)
96+
const [skipExisting, setSkipExisting] = createSignal(false)
6597
const handler = (name: string) => {
6698
if (name === "move") {
6799
onOpen()
@@ -79,22 +111,39 @@ export const Move = () => {
79111
onClose={onClose}
80112
loading={loading()}
81113
footerSlot={
82-
<Checkbox
83-
mr="auto"
84-
checked={overwrite()}
85-
onChange={() => {
86-
setOverwrite(!overwrite())
87-
}}
88-
>
89-
{t("home.conflict_policy.overwrite_existing")}
90-
</Checkbox>
114+
<VStack w="$full" spacing="$2">
115+
<Checkbox
116+
mr="auto"
117+
checked={overwrite()}
118+
onChange={() => {
119+
const curOverwrite = !overwrite()
120+
if (curOverwrite) {
121+
setSkipExisting(false)
122+
}
123+
setOverwrite(curOverwrite)
124+
}}
125+
>
126+
{t("home.conflict_policy.overwrite_existing")}
127+
</Checkbox>
128+
<Checkbox
129+
mr="auto"
130+
checked={skipExisting()}
131+
onChange={() => {
132+
setSkipExisting(!skipExisting())
133+
}}
134+
disabled={overwrite()}
135+
>
136+
{t("home.conflict_policy.skip_existing")}
137+
</Checkbox>
138+
</VStack>
91139
}
92140
onSubmit={async (dst) => {
93141
const resp = await ok(
94142
pathname(),
95143
dst,
96144
selectedObjs().map((obj) => obj.name),
97145
overwrite(),
146+
skipExisting(),
98147
)
99148
handleRespWithNotifySuccess(resp, () => {
100149
refresh()

src/pages/manage/tasks/Copy.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ const Copy = () => {
1010
type="copy"
1111
canRetry
1212
nameAnalyzer={{
13-
regex: /^copy \[(.*\/([^\/]*))]\((.*\/([^\/]*))\) to \[(.+)]\((.+)\)$/,
13+
regex:
14+
/^(?:copy|merge) \[(.*\/([^\/]*))]\((.*\/([^\/]*))\) to \[(.+)]\((.+)\)$/,
1415
title: (matches) => {
1516
if (matches[4] !== "") return matches[4]
1617
return matches[2] === "" ? "/" : matches[2]

src/utils/api.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,15 @@ export const fsMove = (
8383
dst_dir: string,
8484
names: string[],
8585
overwrite: boolean,
86+
skip_existing: boolean,
8687
): PEmptyResp => {
87-
return r.post("/fs/move", { src_dir, dst_dir, names, overwrite })
88+
return r.post("/fs/move", {
89+
src_dir,
90+
dst_dir,
91+
names,
92+
overwrite,
93+
skip_existing,
94+
})
8895
}
8996

9097
export const fsRecursiveMove = (
@@ -100,8 +107,17 @@ export const fsCopy = (
100107
dst_dir: string,
101108
names: string[],
102109
overwrite: boolean,
110+
skip_existing: boolean,
111+
merge: boolean,
103112
): PEmptyResp => {
104-
return r.post("/fs/copy", { src_dir, dst_dir, names, overwrite })
113+
return r.post("/fs/copy", {
114+
src_dir,
115+
dst_dir,
116+
names,
117+
overwrite,
118+
skip_existing,
119+
merge,
120+
})
105121
}
106122

107123
export const fsRemove = (dir: string, names: string[]): PEmptyResp => {

0 commit comments

Comments
 (0)