-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathutilities.ts
More file actions
34 lines (30 loc) · 1.28 KB
/
utilities.ts
File metadata and controls
34 lines (30 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import type { BrowsableFilesSourcePlugin } from "@/api/remoteFiles";
import type { SelectionItem } from "../SelectionDialog/selectionTypes";
export const isSubPath = (originPath: string, destinationPath: string) => {
return subPathCondition(ensureTrailingSlash(originPath), ensureTrailingSlash(destinationPath));
};
// we need "/" at the end to avoid a use case, when we have 2 folders with similar name
// namely, "folder_example" starts with "folder"
function ensureTrailingSlash(path: string) {
return path.endsWith("/") ? path : path + "/";
}
function subPathCondition(originPath: string, destinationPath: string) {
return originPath !== destinationPath && destinationPath.startsWith(originPath);
}
export function fileSourcePluginToItem(plugin: BrowsableFilesSourcePlugin): SelectionItem {
const result = {
id: plugin.id,
label: plugin.label,
details: plugin.doc || "",
isLeaf: false,
url: plugin.uri_root,
entry: plugin,
};
return result;
}
/**
* Normalize SelectionDialog's Model.finalize() return value (single item or array) into an array.
*/
export function selectionToArray(selection: SelectionItem | SelectionItem[]): SelectionItem[] {
return Array.isArray(selection) ? selection : selection ? [selection] : [];
}