Skip to content

Commit

Permalink
fix: requested changes for directory selection
Browse files Browse the repository at this point in the history
  • Loading branch information
0tuedon authored and Emmanuel-Develops committed Sep 22, 2023
1 parent 1dec0aa commit a1fd67d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
38 changes: 32 additions & 6 deletions src/components/sideBarContentEdit/SelectDirectory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ const SelectDirectoryOption = ({
className="select-option"
role="button"
key={dir.slug}
onClick={() => setPath(dir.value)}
onClick={() => setPath(dir.slug)}
color="gray.800"
_hover={{ bg: "blue.600", color: "gray.100" }}
fontSize="14px"
px={[2, 4, 6, 9]}
py={1}
>
{dir.slug}
{dir.value}
</Text>
))}
{!isDirLoading && options.length < 1 && (
Expand Down Expand Up @@ -163,10 +163,24 @@ const SelectDirectory = ({
onClose();
customPath && confirmOnOpen();
};
const customPathStructure = (val: string) => {
let arrayVal = val ? val.split("/") : "".split("");
let pathStructure: IDir = { value: "", slug: "" };
for (let index = 0; index < arrayVal.length; index++) {
if (index === 0) {
pathStructure.value = arrayVal[index];
pathStructure.slug = arrayVal[index];
pathStructure.nestDir = [customPathStructure(arrayVal[index + 1])];
}
}

return pathStructure;
};

const handleConfirmationPath = (val: string) => {
updateData(val.replace(/[/]$/, "")); // replace the / at the end of the string with nothing
confirmOnClose();
options.push(customPathStructure(val));
setCustomPath("");
if (inputRef.current === null) return;
inputRef.current.value = "";
Expand Down Expand Up @@ -252,15 +266,27 @@ const SelectDirectory = ({
{/* Select Path */}
{(customPath || path) && (
<Button
whiteSpace={"normal"}
fontSize={"12px"}
colorScheme={"orange"}
pl="24px"
overflow={"hidden"}
onClick={() => handleChangeDirPath(customPath || path)}
>
{customPath ? "Use:" : "Select"} &nbsp;
<Text as="span" fontWeight={400}>
{" "}
<Text as="span" fontWeight={600}>
{customPath ? "Use:" : "Select"} &nbsp;
</Text>
<Text
maxWidth={"90%"}
overflow={"hidden"}
textOverflow={"ellipsis"}
whiteSpace={"nowrap"}
as="span"
fontWeight={400}
>
{" "}
&quot;{customPath || path}&quot;{" "}
&quot;{(customPath || path).replace(/[A-Z0-9-]+\//gi, "../")}
&quot;{" "}
</Text>
</Button>
)}
Expand Down
2 changes: 1 addition & 1 deletion src/components/sideBarContentEdit/SidebarContentEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function extractDirFormat(input: Record<string, any> = {}): IDir[] {
value: key,
nestDir: Object.keys(child).map((ck: string) => ({
value: ck,
slug: ck,
slug: `${key}/${ck}`,
nestDir: extractDirFormat(child[ck]),
})),
};
Expand Down

0 comments on commit a1fd67d

Please sign in to comment.