Skip to content

Commit

Permalink
add sorting and filtering options to Django-Filer
Browse files Browse the repository at this point in the history
  • Loading branch information
jrief committed Oct 28, 2024
1 parent 06d1eef commit 10190cf
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 14 deletions.
10 changes: 10 additions & 0 deletions client/browser/FinderFileSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,19 @@ export default function FinderFileSelect(props) {
closeDialog();
}
};
const preventDefault = (event) => {
event.preventDefault();
}
window.addEventListener('keydown', handleEscape);

// prevent browser from loading a drag-and-dropped file
window.addEventListener('dragover', preventDefault, false);
window.addEventListener('drop', preventDefault, false);

return () => {
window.removeEventListener('keydown', handleEscape);
window.removeEventListener('dragover', preventDefault);
window.removeEventListener('drop', preventDefault);
}
}, []);

Expand Down
2 changes: 2 additions & 0 deletions client/browser/Menu.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, {useRef} from 'react';
import DropDownMenu from '../finder/DropDownMenu';
import {useSearchRealm} from '../finder/Storage';
import {SortingOptionsItem, FilterByLabel} from '../finder/MenuBar';
import SearchIcon from '../icons/search.svg';
import UploadIcon from '../icons/upload.svg';

Expand Down Expand Up @@ -80,6 +81,7 @@ export default function Menu(props) {
</DropDownMenu>
</div>
</li>
<SortingOptionsItem/>
<li onClick={openUploader} data-tooltip-id="django-finder-tooltip" data-tooltip-content={gettext("Upload file")}>
<UploadIcon/>
</li>
Expand Down
7 changes: 4 additions & 3 deletions client/finder/DropDownMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ export default function DropDownMenu(props) {
ref.current.setAttribute('aria-expanded', 'false');
}
};
window.addEventListener('click', closeSubmenu);
return () => window.removeEventListener('click', closeSubmenu);
const rootNode = ref.current.getRootNode();
rootNode.addEventListener('click', closeSubmenu);
return () => rootNode.removeEventListener('click', closeSubmenu);
}, []);

function toggleSubmenu() {
ref.current.setAttribute('aria-expanded', ref.current.ariaExpanded === 'true' ? 'false': 'true');
ref.current.setAttribute('aria-expanded', ref.current.ariaExpanded === 'true' ? 'false' : 'true');
}

return (
Expand Down
7 changes: 7 additions & 0 deletions client/finder/FolderAdmin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ export function FolderAdmin() {
deselectAll();
}

function refreshColumns() {
Object.entries(columnRefs as React.MutableRefObject<any>).forEach(([folderId, columnRef]) => {
columnRef.current?.fetchInodes();
});
}

function computeBoundingBox(inodes) {
let zoom = 1;
if (inodes.length === 0) {
Expand Down Expand Up @@ -366,6 +372,7 @@ export function FolderAdmin() {
layout={layout}
setLayout={setLayout}
deselectAll={deselectAll}
refreshColumns={refreshColumns}
clipboard={clipboard}
setClipboard={setClipboard}
clearClipboard={clearClipboard}
Expand Down
20 changes: 9 additions & 11 deletions client/finder/MenuBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ const useSorting = () => useCookie('django-finder-sorting', '');
const useFilter = () => useCookie('django-finder-filter', []);


function SortingOptionsItem(props: any) {
export function SortingOptionsItem(props: any) {
const {refreshColumns} = props;
const [sorting, setSorting] = useSorting();

function isActive(value) {
Expand All @@ -45,9 +46,7 @@ function SortingOptionsItem(props: any) {
function changeSorting(value) {
if (value !== sorting) {
setSorting(value);
Object.entries(props.columnRefs as React.MutableRefObject<any>).forEach(([folderId, columnRef]) => {
columnRef.current?.fetchInodes();
});
refreshColumns();
}
}

Expand Down Expand Up @@ -83,8 +82,8 @@ function SortingOptionsItem(props: any) {
}


function FilterByLabel(props: any) {
const {columnRefs, labels} = props;
export function FilterByLabel(props: any) {
const {labels, refreshFilesList} = props;
const [filter, setFilter] = useFilter();

function changeFilter(value) {
Expand All @@ -95,9 +94,7 @@ function FilterByLabel(props: any) {
} else {
setFilter([...filter, value]);
}
Object.entries(columnRefs as React.MutableRefObject<any>).forEach(([folderId, columnRef]) => {
columnRef.current?.fetchInodes();
});
refreshFilesList();
}

return (
Expand Down Expand Up @@ -224,6 +221,7 @@ const MenuBar = forwardRef((props: any, forwardedRef) => {
layout,
setLayout,
deselectAll,
refreshColumns,
clipboard,
setClipboard,
clearClipboard,
Expand Down Expand Up @@ -437,8 +435,8 @@ const MenuBar = forwardRef((props: any, forwardedRef) => {
data-tooltip-id="django-finder-tooltip" data-tooltip-content={gettext("Columns view")}>
<ColumnsIcon/></li>
<li style={{marginLeft: 'auto'}}></li>
{settings.labels && <FilterByLabel columnRefs={columnRefs} labels={settings.labels}/>}
<SortingOptionsItem columnRefs={columnRefs}/>
{settings.labels && <FilterByLabel refreshFilesList={refreshColumns} labels={settings.labels}/>}
<SortingOptionsItem refreshColumns={refreshColumns} />
<li style={{marginRight: 'auto'}}></li>
<li className={numSelectedInodes ? null : "disabled"} onClick={cutInodes}
data-tooltip-id="django-finder-tooltip"
Expand Down
4 changes: 4 additions & 0 deletions client/scss/finder-browser.scss
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ dialog {
padding-bottom: 0.5rem;
margin: 0.25rem 1rem;
@include menubar;

.search-field {
margin-left: -14px;
}
}

> .browser-body {
Expand Down

0 comments on commit 10190cf

Please sign in to comment.