Skip to content

Commit

Permalink
Be able to drag brim folder (#2178)
Browse files Browse the repository at this point in the history
The brim folder itself should be allowed to live anywhere the user wants in the tree.
Also make the filters and the plus button always visible
  • Loading branch information
jameskerr authored Feb 16, 2022
1 parent a535369 commit fdeee4a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
30 changes: 12 additions & 18 deletions src/js/components/LeftPane/QueriesSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ import TreeModel from "tree-model"
import useResizeObserver from "use-resize-observer"
import DropdownArrow from "../../icons/DropdownArrow"
import MagnifyingGlass from "../../icons/MagnifyingGlass"
import Current from "../../state/Current"
import Modal from "../../state/Modal"
import Queries from "../../state/Queries"
import {isBrimLib} from "../../state/Queries/flows"
import {isChildOf} from "../../state/Queries/flows"
import {Group, Query} from "../../state/Queries/types"
import EmptySection from "../common/EmptySection"
import useCallbackRef from "../hooks/useCallbackRef"
Expand Down Expand Up @@ -166,7 +165,6 @@ function QueriesSection({isOpen, style, resizeProps, toggleProps}) {
const tree = useRef()
const dispatch = useDispatch<AppDispatch>()
const [selectedTag, setSelectedTag] = useState("All Local")
const currentPool = useSelector(Current.getPool)
const queriesRoot = useSelector(Queries.raw)
const remoteQueries = useSelector(RemoteQueries.raw)
const [queries, setQueries] = useState<Group>(queriesRoot)
Expand Down Expand Up @@ -226,7 +224,7 @@ function QueriesSection({isOpen, style, resizeProps, toggleProps}) {
// no reordering while a filter is on
if (selectedTag !== "All Local") return
// no reordering if any one item is part of shipped brim lib
if (dispatch(isBrimLib([...dragIds, parentId]))) return
if (dispatch(isChildOf("brim", [...dragIds, parentId]))) return
dispatch(Queries.moveItems(dragIds, parentId, index))
}

Expand Down Expand Up @@ -259,7 +257,7 @@ function QueriesSection({isOpen, style, resizeProps, toggleProps}) {
data={queries}
getChildren="items"
isOpen="isOpen"
disableDrag={(d) => !!dispatch(isBrimLib([d.id]))}
disableDrag={(d) => !!dispatch(isChildOf("brim", [d.id]))}
disableDrop={(d) => d.id === "brim"}
rowHeight={24}
width={width}
Expand All @@ -284,19 +282,15 @@ function QueriesSection({isOpen, style, resizeProps, toggleProps}) {
<StyledArrow show={isOpen} />
<Title>Queries</Title>
</ClickRegion>
{currentPool && (
<>
<TagsViewSelect
selected={selectedTag}
tags={["Remote", "separator", "All Local", ...tags]}
onSelect={onTagSelect}
/>
<NewActionsDropdown
tree={tree.current}
isRemote={selectedTag === "Remote"}
/>
</>
)}
<TagsViewSelect
selected={selectedTag}
tags={["Remote", "separator", "All Local", ...tags]}
onSelect={onTagSelect}
/>
<NewActionsDropdown
tree={tree.current}
isRemote={selectedTag === "Remote"}
/>
</SectionHeader>
<SectionContents
ref={(r) => {
Expand Down
5 changes: 5 additions & 0 deletions src/js/state/Queries/flows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ export const isBrimLib = (ids: string[]) => (_, getState) => {
]
return intersection(ids, brimIds).length > 0
}

export const isChildOf = (id: string, ids: string[]) => (_, getState) => {
const check = getGroupById(id)(getState())?.items.map((i) => i.id)
return intersection(ids, check).length > 0
}

0 comments on commit fdeee4a

Please sign in to comment.