Skip to content
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

fix: filter sort order #522

Merged
merged 11 commits into from
Nov 20, 2023
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
2 changes: 1 addition & 1 deletion packages/workspace-fusion/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@equinor/workspace-fusion",
"version": "6.0.1",
"version": "6.0.2",
"type": "module",
"sideEffects": false,
"license": "MIT",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ export function WorkspaceContextProvider<T>(props: WorkspaceContextProviderProps
handleTabChange,
updatePayload,
isCreateSidesheetOpen,
openCreateSidesheet: () => setCreateSidesheetOpen(true),
openCreateSidesheet: () => {
clearSelection();
setCreateSidesheetOpen(true);
},
closeCreateSidesheet: () => setCreateSidesheetOpen(false),
clearSelection,
selectById,
Expand Down
Loading