Skip to content

Commit 27413c2

Browse files
author
Craig O'Donnell
authored
remove extra slash in snapshot bucket path (#4590)
1 parent 4192bfe commit 27413c2

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

web/src/features/Dashboard/components/DashboardSnapshotsCard.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { App, SnapshotSettings } from "@types";
1010
import { usePrevious } from "@src/hooks/usePrevious";
1111
import { useCreateSnapshot } from "../api/createSnapshot";
1212
import { useSnapshotSettings } from "../api/getSnapshotSettings";
13+
import { Utilities } from "@src/utilities/utilities";
1314

1415
const DESTINATIONS = [
1516
{
@@ -103,28 +104,28 @@ export const DashboardSnapshotsCard = (props: Props) => {
103104
if (store?.aws) {
104105
return setState({
105106
selectedDestination: find(DESTINATIONS, ["value", "aws"]),
106-
locationStr: `${store?.bucket}${store?.path ? `/${store?.path}` : ""}`,
107+
locationStr: Utilities.snapshotLocationStr(store?.bucket, store?.path),
107108
});
108109
}
109110

110111
if (store?.azure) {
111112
return setState({
112113
selectedDestination: find(DESTINATIONS, ["value", "azure"]),
113-
locationStr: `${store?.bucket}${store?.path ? `/${store?.path}` : ""}`,
114+
locationStr: Utilities.snapshotLocationStr(store?.bucket, store?.path),
114115
});
115116
}
116117

117118
if (store?.gcp) {
118119
return setState({
119120
selectedDestination: find(DESTINATIONS, ["value", "gcp"]),
120-
locationStr: `${store?.bucket}${store?.path ? `/${store?.path}` : ""}`,
121+
locationStr: Utilities.snapshotLocationStr(store?.bucket, store?.path),
121122
});
122123
}
123124

124125
if (store?.other) {
125126
return setState({
126127
selectedDestination: find(DESTINATIONS, ["value", "other"]),
127-
locationStr: `${store?.bucket}${store?.path ? `/${store?.path}` : ""}`,
128+
locationStr: Utilities.snapshotLocationStr(store?.bucket, store?.path),
128129
});
129130
}
130131

web/src/utilities/utilities.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,4 +1032,18 @@ export const Utilities = {
10321032
}
10331033
}
10341034
},
1035+
1036+
snapshotLocationStr(bucket, path) {
1037+
if (!bucket) {
1038+
return "";
1039+
}
1040+
if (!path) {
1041+
return bucket;
1042+
}
1043+
let prefix = path;
1044+
if (prefix && prefix.startsWith("/")) {
1045+
prefix = prefix.slice(1);
1046+
}
1047+
return `${bucket}/${prefix}`;
1048+
},
10351049
};

web/src/utilities/utilities.test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,4 +260,29 @@ describe("Utilities", () => {
260260
expect(Utilities.isInitialAppInstall(app)).toBe(false);
261261
});
262262
});
263+
264+
describe("snapshotLocationStr", () => {
265+
it("should return bucket name if path is empty or undefined", () => {
266+
expect(Utilities.snapshotLocationStr("my-bucket", "")).toBe("my-bucket");
267+
expect(Utilities.snapshotLocationStr("my-bucket", undefined)).toBe(
268+
"my-bucket"
269+
);
270+
});
271+
272+
it("should return bucket name and path if path is not empty", () => {
273+
expect(Utilities.snapshotLocationStr("my-bucket", "my-path")).toBe(
274+
"my-bucket/my-path"
275+
);
276+
});
277+
278+
it("should return bucket name and path if path is not empty and begins with a slash", () => {
279+
expect(Utilities.snapshotLocationStr("my-bucket", "/my-path")).toBe(
280+
"my-bucket/my-path"
281+
);
282+
});
283+
284+
it("should not error if bucket and path are undefined", () => {
285+
expect(Utilities.snapshotLocationStr(undefined, undefined)).toBe("");
286+
});
287+
});
263288
});

0 commit comments

Comments
 (0)