-
-
Notifications
You must be signed in to change notification settings - Fork 193
[FEAT] A collapse button in the sidebar which when clicked closes all the open folders #2314
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
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2b9eb15
feat: collapse all button in the sidebar which closes all the open di…
devvaannsh 73d2917
chore: add license
devvaannsh 1411a66
refactor: update button styling to make it consistent with rest of UI
devvaannsh 886cc5b
fix: button not appearing when cursor is already over sidebar on site…
devvaannsh 67f945c
fix: collapse and git button overlapping issue
devvaannsh 8a5eb9a
feat: integ tests for collapse folders feature
devvaannsh 4d473fc
fix: remove redundant JS for button visibility and replaced with css
devvaannsh d81239c
fix: integ tests rewrite
devvaannsh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| /* | ||
| * GNU AGPL-3.0 License | ||
| * | ||
| * Copyright (c) 2021 - present core.ai . All rights reserved. | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify it | ||
| * under the terms of the GNU Affero General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, but WITHOUT | ||
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License | ||
| * for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see https://opensource.org/licenses/AGPL-3.0. | ||
| * | ||
| */ | ||
|
|
||
| /* Displays a Collapse button in the sidebar area */ | ||
| /* when the button gets clicked, it closes all the directories recursively that are opened */ | ||
| /* Styling for the button is done in `../../styles/Extn-CollapseFolders.less` */ | ||
| define(function (require, exports, module) { | ||
| const AppInit = require("utils/AppInit"); | ||
| const ProjectManager = require("project/ProjectManager"); | ||
|
|
||
| /** | ||
| * This is the main function that handles the closing of all the directories | ||
| */ | ||
| function handleCollapseBtnClick() { | ||
| // this will give us an array of array's | ||
| // the root level directories will be at index 0, its next level will be at index 1 and so on | ||
| const openNodes = ProjectManager._actionCreator.model.getOpenNodes(); | ||
| if (!openNodes || openNodes.length === 0) { | ||
| return; | ||
| } | ||
|
|
||
| // traversing from the back because the deepest nested directories should be closed first | ||
| // Note: this is an array of all the directories at the deepest level | ||
| for (let i = openNodes.length - 1; i >= 0; i--) { | ||
| // close all the directories | ||
| openNodes[i].forEach(function (folderPath) { | ||
| try { | ||
| // to close each dir | ||
| ProjectManager._actionCreator.setDirectoryOpen(folderPath, false); | ||
| } catch (error) { | ||
| console.error("Failed to close folder:", folderPath, error); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * This function is responsible to create the 'Collapse All' button | ||
| * and append it to the sidebar area on the project-files-header | ||
| */ | ||
| function createCollapseButton() { | ||
| const $projectFilesHeader = $("#project-files-header"); | ||
| // make sure that we were able to get the project-files-header DOM element | ||
| if ($projectFilesHeader.length === 0) { | ||
| return; | ||
| } | ||
|
|
||
| // create the collapse btn | ||
| const $collapseBtn = $(` | ||
| <div id="collapse-folders" class="btn-alt-quiet" title="Collapse All"> | ||
| <i class="fa-solid fa-chevron-down collapse-icon" aria-hidden="true"></i> | ||
| <i class="fa-solid fa-chevron-up collapse-icon" aria-hidden="true"></i> | ||
| </div> | ||
| `); | ||
|
|
||
| $collapseBtn.on("click", handleCollapseBtnClick); | ||
|
|
||
| $projectFilesHeader.append($collapseBtn); // append the btn to the project-files-header | ||
|
|
||
| _setupHoverBehavior($collapseBtn); // hover functionality to show/hide the button | ||
| } | ||
|
|
||
| /** | ||
| * This function is responsible for the hover behavior to show/hide the collapse button | ||
| * we only show the button when the cursor is over the sidebar area | ||
| */ | ||
| function _setupHoverBehavior($collapseBtn) { | ||
| const $sidebar = $("#sidebar"); | ||
| if ($sidebar.length === 0) { | ||
| return; | ||
| } | ||
|
|
||
| // we need this check to see if on site load the mouse is already over the sidebar area or not | ||
| // because if it is, then we need to show the button | ||
| if ($sidebar.is(":hover")) { | ||
| $collapseBtn.addClass("show"); | ||
| } | ||
|
|
||
| $sidebar.on("mouseenter", function () { | ||
| $collapseBtn.addClass("show"); | ||
| }); | ||
|
|
||
| $sidebar.on("mouseleave", function () { | ||
| $collapseBtn.removeClass("show"); | ||
| }); | ||
| } | ||
|
|
||
| AppInit.appReady(function () { | ||
| createCollapseButton(); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| #collapse-folders { | ||
| display: flex; | ||
| flex-direction: column; | ||
| align-items: center; | ||
| justify-content: center; | ||
| padding: 0.2em 0.65em; | ||
| margin-top: 0.1em; | ||
| position: absolute !important; | ||
| right: 0; | ||
| opacity: 0; | ||
| visibility: hidden; | ||
| transition: | ||
| opacity 0.2s ease-in-out, | ||
| visibility 0.2s ease-in-out; | ||
|
|
||
| .collapse-icon { | ||
| font-size: 0.5em; | ||
| line-height: 1; | ||
| } | ||
|
|
||
| &.show { | ||
| opacity: 1; | ||
| visibility: visible; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.