Skip to content

Commit d1069ed

Browse files
authored
fix loading of objects at a path when url is shared opened elsewhere (#2944)
- fix loading of objects at a path when url is shared and opened elsewhere - fix bug when a path is created and objects are uploaded it is not refreshed
1 parent 6d81a1b commit d1069ed

File tree

3 files changed

+34
-14
lines changed

3 files changed

+34
-14
lines changed

portal-ui/src/common/utils.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,20 +434,35 @@ export const representationNumber = (number: number | undefined) => {
434434
return `${returnValue}${unit}`;
435435
};
436436

437+
/** Ref https://developer.mozilla.org/en-US/docs/Glossary/Base64 */
438+
439+
const base64ToBytes = (base64: any): Uint8Array => {
440+
const binString: any = atob(base64);
441+
// @ts-ignore
442+
return Uint8Array.from(binString, (m) => m.codePointAt(0));
443+
};
444+
445+
const bytesToBase64 = (bytes: any) => {
446+
const binString = Array.from(bytes, (x: any) => String.fromCodePoint(x)).join(
447+
""
448+
);
449+
return btoa(binString);
450+
};
451+
437452
export const encodeURLString = (name: string | null) => {
438453
if (!name) {
439454
return "";
440455
}
441456
try {
442-
return btoa(unescape(encodeURIComponent(name)));
457+
return bytesToBase64(new TextEncoder().encode(name));
443458
} catch (err) {
444459
return "";
445460
}
446461
};
447462

448463
export const decodeURLString = (text: string) => {
449464
try {
450-
return decodeURIComponent(escape(window.atob(text)));
465+
return new TextDecoder().decode(base64ToBytes(text));
451466
} catch (err) {
452467
return text;
453468
}

portal-ui/src/screens/Console/Buckets/BucketDetails/BrowserHandler.tsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -291,18 +291,6 @@ const BrowserHandler = () => {
291291
[bucketName, rewindEnabled, showDeleted, dispatch, onMessageCallBack]
292292
);
293293

294-
useEffect(() => {
295-
// when a bucket param changes, (i.e /browser/:bucketName), re-init e.g with KBar, this should not apply for resources prefixes.
296-
const permitItems = permissionItems(bucketName, "", allowResources || []);
297-
298-
if (bucketName && (!permitItems || permitItems.length === 0)) {
299-
dispatch(resetMessages());
300-
dispatch(setLoadingRecords(true));
301-
dispatch(setLoadingObjects(true));
302-
initWSRequest("", new Date());
303-
}
304-
}, [bucketName, dispatch, initWSRequest, allowResources]);
305-
306294
useEffect(() => {
307295
return () => {
308296
const request: WebsocketRequest = {
@@ -480,6 +468,18 @@ const BrowserHandler = () => {
480468
}
481469
}, [bucketName, loadingLocking, dispatch, displayListObjects]);
482470

471+
useEffect(() => {
472+
// when a bucket param changes, (i.e /browser/:bucketName), re-init e.g with KBar, this should not apply for resources prefixes.
473+
const permitItems = permissionItems(bucketName, "", allowResources || []);
474+
475+
if (bucketName && (!permitItems || permitItems.length === 0)) {
476+
dispatch(resetMessages());
477+
dispatch(setLoadingRecords(true));
478+
dispatch(setLoadingObjects(true));
479+
initWSRequest("", new Date());
480+
}
481+
}, [bucketName, dispatch, initWSRequest, allowResources]);
482+
483483
return (
484484
<Fragment>
485485
{!anonymousMode && <OBHeader bucketName={bucketName} />}

portal-ui/src/screens/Console/Buckets/ListBuckets/Objects/ListObjects/CreatePathModal.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,14 @@ const CreatePathModal = ({
103103
.filter((splitItem) => splitItem.trim() !== "")
104104
.join("/");
105105

106+
if (folderPath.slice(0, 1) === "/") {
107+
folderPath = folderPath.slice(1); //trim '/'
108+
}
109+
106110
const newPath = `/browser/${bucketName}/${encodeURLString(
107111
`${folderPath}${cleanPathURL}/`
108112
)}`;
113+
109114
navigate(newPath);
110115
onClose();
111116
};

0 commit comments

Comments
 (0)