fix: resolved nav header secret path issues

This commit is contained in:
Akhil Mohan
2023-10-27 12:16:37 +05:30
parent 508ed7f7d6
commit 15504346cd
2 changed files with 7 additions and 15 deletions
@@ -131,7 +131,7 @@ export default function NavHeader({
{isFolderMode && {isFolderMode &&
secretPathSegments?.map((folderName, index) => { secretPathSegments?.map((folderName, index) => {
const query = { ...router.query }; const query = { ...router.query };
query.secretPath = secretPathSegments.slice(0, index + 1); query.secretPath = `/${secretPathSegments.slice(0, index + 1).join("/")}`;
return ( return (
<div <div
@@ -111,23 +111,15 @@ export const SecretOverviewPage = () => {
try { try {
// create folder if not existing // create folder if not existing
if (secretPath !== "/") { if (secretPath !== "/") {
// /hello/world -> ["", "hello","world"] // /hello/world -> [hello","world"]
const path = secretPath.split("/"); const pathSegment = secretPath.split("/").filter(Boolean);
// if its empty string on join use and OR gate to convert to / const parentPath = `/${pathSegment.slice(0, -1).join("/")}`;
// /hello const folderName = pathSegment.at(-1);
const directory = if (folderName && parentPath) {
path
.slice(0, -1)
.reduce(
(prev, curr, index, arr) => prev + (index + 1 === arr.length ? curr : `/${curr}`),
""
) || "/";
const folderName = path.at(-1); // world
if (folderName && directory) {
await createFolder({ await createFolder({
workspaceId, workspaceId,
environment: env, environment: env,
directory, directory: parentPath,
folderName folderName
}); });
} }