Skip to content

Commit

Permalink
fix filter sort order
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustav-Eikaas committed Nov 20, 2023
1 parent 39b3453 commit 6c71da5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/filter/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@equinor/workspace-filter",
"version": "3.0.0",
"version": "3.0.1",
"type": "module",
"sideEffects": false,
"license": "MIT",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ const QuickFilterReady = ({ groups }: QuickFilterReadyProps) => {
</StyledSearchLine>
</StyledCompactFilterWrapper>
{isFilterExpanded && (
<FilterView isFetching={query.isFetching} groups={groups.filter((s) => visibleFilterGroups.includes(s.name))} />
<FilterView
isFetching={query.isFetching}
groups={visibleFilterGroups.map((x) => groups.find((s) => s.name === x)).filter(Boolean) as IFilterGroup[]}
/>
)}
</StyledWrapper>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Icon, Checkbox, Popover } from '@equinor/eds-core-react';
import { tokens } from '@equinor/eds-tokens';
import { useState, useRef } from 'react';
import { ReactSortable } from 'react-sortablejs';
import { SortObject } from '../../types/sortObject';
import { StyledButton, StyledItemWrapper, StyledPopoverList } from './toggleHideFilterPopover.styles';

interface ShowHideFilterButtonProps {
Expand All @@ -19,18 +18,19 @@ export const ToggleHideFilterPopover = ({
const [isOpen, setIsOpen] = useState(false);
const ref = useRef<HTMLDivElement>(null);

const [list, setList] = useState<SortObject<string>[]>(allFilters.map((s) => ({ id: s, item: s })));
const listRef = useRef(allFilters.map((s) => ({ id: s, item: s })));

const handleChange = (val: string) => {
if (visibleFilters.includes(val)) {
setVisibleFilters(visibleFilters.filter((s) => s !== val));
setVisibleFilters([...visibleFilters.filter((s) => s !== val)]);
} else {
setVisibleFilters([...visibleFilters, val]);
}
};
const DraggableHandleSelector = 'globalDraggableHandle';

const updateList = () => setVisibleFilters(list.map((s) => s.item).filter((s) => visibleFilters.includes(s)));
const updateList = () =>
setVisibleFilters(listRef.current.map((s) => s.item).filter((s) => visibleFilters.includes(s)));

return (
<>
Expand All @@ -51,11 +51,13 @@ export const ToggleHideFilterPopover = ({
<ReactSortable
animation={200}
handle={`.${DraggableHandleSelector}`}
list={list}
setList={setList}
list={listRef.current}
setList={(e) => {
listRef.current = e;
}}
onEnd={updateList}
>
{list.map(({ item }) => (
{listRef.current.map(({ item }) => (
<StyledItemWrapper className={DraggableHandleSelector} key={item}>
<Checkbox
size={2}
Expand Down

0 comments on commit 6c71da5

Please sign in to comment.