Skip to content

feat(client): deleting a file in code editor leaves the file structu… #1159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions packages/client/src/components/common/File/FileExplorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const StyledTreeView = styled(TreeView)(({ theme }) => ({
}));

interface FileExplorerProps {
expandedPaths: string[];
onToggleExpand: (path: string) => void;
/** Type of file opened */
type: 'app' | 'insight';

Expand Down Expand Up @@ -52,6 +54,8 @@ export const FileExplorer = (props: FileExplorerProps) => {
onDragStart = () => null,
onDragEnd = () => null,
onTrashClick = () => null,
expandedPaths,
onToggleExpand,
} = props;

const getAssets = usePixel<
Expand All @@ -70,8 +74,6 @@ export const FileExplorer = (props: FileExplorerProps) => {
);

const initLoadComplete = getAssets.status === 'SUCCESS';

const [expanded, setExpanded] = React.useState<string[]>([]);
const [selected, setSelected] = React.useState<string[]>([]);

/**
Expand All @@ -90,10 +92,6 @@ export const FileExplorer = (props: FileExplorerProps) => {
* Triggered when a item is toggled
* @param expanded - newly expanded values
*/
const handleOnNodeToggle = (expanded: string[]) => {
// set the expanded values
setExpanded(expanded);
};

if (!initLoadComplete) {
return (
Expand All @@ -104,10 +102,15 @@ export const FileExplorer = (props: FileExplorerProps) => {
return (
<StyledTreeView
multiSelect
expanded={expanded}
expanded={expandedPaths}
selected={selected}
onNodeToggle={(e, v) => {
handleOnNodeToggle(v);
onNodeToggle={(e, nodeIds) => {
const lastToggled =
nodeIds.find((id) => !expandedPaths.includes(id)) ||
expandedPaths.find((id) => !nodeIds.includes(id));
if (lastToggled) {
onToggleExpand(lastToggled);
}
}}
onNodeSelect={(e, v) => {
handleOnNodeSelect(v);
Expand Down Expand Up @@ -138,7 +141,7 @@ export const FileExplorer = (props: FileExplorerProps) => {
path={n.path}
isDirectory={n.type === 'directory'}
lastModified={n.lastModified}
expanded={expanded}
expanded={expandedPaths}
selected={selected}
onDragStart={(e, path) => {
onDragStart(e, path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const FileExplorerPanel = (props: FileExplorerPanelProps) => {

const notification = useNotification();

const [expandedPaths, setExpandedPaths] = useState<string[]>([]);
// files to add
const [selectedPath, setSelectedPath] = useState<string>('');
const [fileUploadPath, setFileUploadPath] = useState<string>('');
Expand Down Expand Up @@ -68,6 +69,13 @@ export const FileExplorerPanel = (props: FileExplorerPanelProps) => {
setCounter(counter + 1);
};

const handleToggleExpand = (path: string) => {
setExpandedPaths((prev) =>
prev.includes(path)
? prev.filter((p) => p !== path)
: [...prev, path],
);
};
/**
* Publish the app
*/
Expand Down Expand Up @@ -557,6 +565,8 @@ export const FileExplorerPanel = (props: FileExplorerPanelProps) => {
onDragStart={(e, path) => {
handleOnItemDragStart(e, path);
}}
expandedPaths={expandedPaths}
onToggleExpand={handleToggleExpand}
/>
</Panel>
);
Expand Down