forked from github/plane
chore: filter member option sorting improvement (#4285)
This commit is contained in:
parent
88165a8fdb
commit
80461e6484
@ -4,7 +4,7 @@ import { observer } from "mobx-react-lite";
|
|||||||
// hooks
|
// hooks
|
||||||
import { Avatar, Loader } from "@plane/ui";
|
import { Avatar, Loader } from "@plane/ui";
|
||||||
import { FilterHeader, FilterOption } from "@/components/issues";
|
import { FilterHeader, FilterOption } from "@/components/issues";
|
||||||
import { useMember } from "@/hooks/store";
|
import { useMember, useUser } from "@/hooks/store";
|
||||||
// components
|
// components
|
||||||
// ui
|
// ui
|
||||||
|
|
||||||
@ -22,19 +22,22 @@ export const FilterLead: React.FC<Props> = observer((props: Props) => {
|
|||||||
const [previewEnabled, setPreviewEnabled] = useState(true);
|
const [previewEnabled, setPreviewEnabled] = useState(true);
|
||||||
// store hooks
|
// store hooks
|
||||||
const { getUserDetails } = useMember();
|
const { getUserDetails } = useMember();
|
||||||
|
const { currentUser } = useUser();
|
||||||
|
|
||||||
const appliedFiltersCount = appliedFilters?.length ?? 0;
|
const appliedFiltersCount = appliedFilters?.length ?? 0;
|
||||||
|
|
||||||
const sortedOptions = useMemo(() => {
|
const sortedOptions = useMemo(() => {
|
||||||
const filteredOptions = (memberIds || []).filter(
|
const filteredOptions = (memberIds || []).filter((memberId) =>
|
||||||
(memberId) => getUserDetails(memberId)?.display_name.toLowerCase().includes(searchQuery.toLowerCase())
|
getUserDetails(memberId)?.display_name.toLowerCase().includes(searchQuery.toLowerCase())
|
||||||
);
|
);
|
||||||
|
|
||||||
return sortBy(filteredOptions, [
|
return sortBy(filteredOptions, [
|
||||||
(memberId) => !(appliedFilters ?? []).includes(memberId),
|
(memberId) => !(appliedFilters ?? []).includes(memberId),
|
||||||
|
(memberId) => memberId !== currentUser?.id,
|
||||||
(memberId) => getUserDetails(memberId)?.display_name.toLowerCase(),
|
(memberId) => getUserDetails(memberId)?.display_name.toLowerCase(),
|
||||||
]);
|
]);
|
||||||
}, [appliedFilters, getUserDetails, memberIds, , searchQuery]);
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [searchQuery]);
|
||||||
|
|
||||||
const handleViewToggle = () => {
|
const handleViewToggle = () => {
|
||||||
if (!sortedOptions) return;
|
if (!sortedOptions) return;
|
||||||
@ -65,7 +68,7 @@ export const FilterLead: React.FC<Props> = observer((props: Props) => {
|
|||||||
isChecked={appliedFilters?.includes(member.id) ? true : false}
|
isChecked={appliedFilters?.includes(member.id) ? true : false}
|
||||||
onClick={() => handleUpdate(member.id)}
|
onClick={() => handleUpdate(member.id)}
|
||||||
icon={<Avatar name={member.display_name} src={member.avatar} showTooltip={false} size="md" />}
|
icon={<Avatar name={member.display_name} src={member.avatar} showTooltip={false} size="md" />}
|
||||||
title={member.display_name}
|
title={currentUser?.id === member.id ? "You" : member?.display_name}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
@ -4,7 +4,7 @@ import { observer } from "mobx-react-lite";
|
|||||||
// hooks
|
// hooks
|
||||||
import { Avatar, Loader } from "@plane/ui";
|
import { Avatar, Loader } from "@plane/ui";
|
||||||
import { FilterHeader, FilterOption } from "@/components/issues";
|
import { FilterHeader, FilterOption } from "@/components/issues";
|
||||||
import { useMember } from "@/hooks/store";
|
import { useMember, useUser } from "@/hooks/store";
|
||||||
// components
|
// components
|
||||||
// ui
|
// ui
|
||||||
|
|
||||||
@ -22,16 +22,18 @@ export const FilterMembers: React.FC<Props> = observer((props: Props) => {
|
|||||||
const [previewEnabled, setPreviewEnabled] = useState(true);
|
const [previewEnabled, setPreviewEnabled] = useState(true);
|
||||||
// store hooks
|
// store hooks
|
||||||
const { getUserDetails } = useMember();
|
const { getUserDetails } = useMember();
|
||||||
|
const { currentUser } = useUser();
|
||||||
|
|
||||||
const appliedFiltersCount = appliedFilters?.length ?? 0;
|
const appliedFiltersCount = appliedFilters?.length ?? 0;
|
||||||
|
|
||||||
const sortedOptions = useMemo(() => {
|
const sortedOptions = useMemo(() => {
|
||||||
const filteredOptions = (memberIds || []).filter(
|
const filteredOptions = (memberIds || []).filter((memberId) =>
|
||||||
(memberId) => getUserDetails(memberId)?.display_name.toLowerCase().includes(searchQuery.toLowerCase())
|
getUserDetails(memberId)?.display_name.toLowerCase().includes(searchQuery.toLowerCase())
|
||||||
);
|
);
|
||||||
|
|
||||||
return sortBy(filteredOptions, [
|
return sortBy(filteredOptions, [
|
||||||
(memberId) => !(appliedFilters ?? []).includes(memberId),
|
(memberId) => !(appliedFilters ?? []).includes(memberId),
|
||||||
|
(memberId) => memberId !== currentUser?.id,
|
||||||
(memberId) => getUserDetails(memberId)?.display_name.toLowerCase(),
|
(memberId) => getUserDetails(memberId)?.display_name.toLowerCase(),
|
||||||
]);
|
]);
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
@ -66,7 +68,7 @@ export const FilterMembers: React.FC<Props> = observer((props: Props) => {
|
|||||||
isChecked={appliedFilters?.includes(member.id) ? true : false}
|
isChecked={appliedFilters?.includes(member.id) ? true : false}
|
||||||
onClick={() => handleUpdate(member.id)}
|
onClick={() => handleUpdate(member.id)}
|
||||||
icon={<Avatar name={member.display_name} src={member.avatar} showTooltip={false} size="md" />}
|
icon={<Avatar name={member.display_name} src={member.avatar} showTooltip={false} size="md" />}
|
||||||
title={member.display_name}
|
title={currentUser?.id === member.id ? "You" : member?.display_name}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
@ -6,7 +6,7 @@ import { Avatar, Loader } from "@plane/ui";
|
|||||||
// components
|
// components
|
||||||
import { FilterHeader, FilterOption } from "@/components/issues";
|
import { FilterHeader, FilterOption } from "@/components/issues";
|
||||||
// hooks
|
// hooks
|
||||||
import { useMember } from "@/hooks/store";
|
import { useMember, useUser } from "@/hooks/store";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
appliedFilters: string[] | null;
|
appliedFilters: string[] | null;
|
||||||
@ -22,6 +22,7 @@ export const FilterCreatedBy: React.FC<Props> = observer((props: Props) => {
|
|||||||
const [previewEnabled, setPreviewEnabled] = useState(true);
|
const [previewEnabled, setPreviewEnabled] = useState(true);
|
||||||
// store hooks
|
// store hooks
|
||||||
const { getUserDetails } = useMember();
|
const { getUserDetails } = useMember();
|
||||||
|
const { currentUser } = useUser();
|
||||||
|
|
||||||
const appliedFiltersCount = appliedFilters?.length ?? 0;
|
const appliedFiltersCount = appliedFilters?.length ?? 0;
|
||||||
|
|
||||||
@ -32,9 +33,11 @@ export const FilterCreatedBy: React.FC<Props> = observer((props: Props) => {
|
|||||||
|
|
||||||
return sortBy(filteredOptions, [
|
return sortBy(filteredOptions, [
|
||||||
(memberId) => !(appliedFilters ?? []).includes(memberId),
|
(memberId) => !(appliedFilters ?? []).includes(memberId),
|
||||||
|
(memberId) => memberId !== currentUser?.id,
|
||||||
(memberId) => getUserDetails(memberId)?.display_name.toLowerCase(),
|
(memberId) => getUserDetails(memberId)?.display_name.toLowerCase(),
|
||||||
]);
|
]);
|
||||||
}, [appliedFilters, getUserDetails, memberIds, searchQuery]);
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [searchQuery]);
|
||||||
|
|
||||||
const handleViewToggle = () => {
|
const handleViewToggle = () => {
|
||||||
if (!sortedOptions) return;
|
if (!sortedOptions) return;
|
||||||
@ -65,7 +68,7 @@ export const FilterCreatedBy: React.FC<Props> = observer((props: Props) => {
|
|||||||
isChecked={appliedFilters?.includes(member.id) ? true : false}
|
isChecked={appliedFilters?.includes(member.id) ? true : false}
|
||||||
onClick={() => handleUpdate(member.id)}
|
onClick={() => handleUpdate(member.id)}
|
||||||
icon={<Avatar name={member.display_name} src={member.avatar} showTooltip={false} size="md" />}
|
icon={<Avatar name={member.display_name} src={member.avatar} showTooltip={false} size="md" />}
|
||||||
title={member.display_name}
|
title={currentUser?.id === member.id ? "You" : member?.display_name}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
@ -4,7 +4,7 @@ import { observer } from "mobx-react-lite";
|
|||||||
// hooks
|
// hooks
|
||||||
import { Avatar, Loader } from "@plane/ui";
|
import { Avatar, Loader } from "@plane/ui";
|
||||||
import { FilterHeader, FilterOption } from "@/components/issues";
|
import { FilterHeader, FilterOption } from "@/components/issues";
|
||||||
import { useMember } from "@/hooks/store";
|
import { useMember, useUser } from "@/hooks/store";
|
||||||
// components
|
// components
|
||||||
// ui
|
// ui
|
||||||
|
|
||||||
@ -22,16 +22,18 @@ export const FilterLead: React.FC<Props> = observer((props: Props) => {
|
|||||||
const [previewEnabled, setPreviewEnabled] = useState(true);
|
const [previewEnabled, setPreviewEnabled] = useState(true);
|
||||||
// store hooks
|
// store hooks
|
||||||
const { getUserDetails } = useMember();
|
const { getUserDetails } = useMember();
|
||||||
|
const { currentUser } = useUser();
|
||||||
|
|
||||||
const appliedFiltersCount = appliedFilters?.length ?? 0;
|
const appliedFiltersCount = appliedFilters?.length ?? 0;
|
||||||
|
|
||||||
const sortedOptions = useMemo(() => {
|
const sortedOptions = useMemo(() => {
|
||||||
const filteredOptions = (memberIds || []).filter(
|
const filteredOptions = (memberIds || []).filter((memberId) =>
|
||||||
(memberId) => getUserDetails(memberId)?.display_name.toLowerCase().includes(searchQuery.toLowerCase())
|
getUserDetails(memberId)?.display_name.toLowerCase().includes(searchQuery.toLowerCase())
|
||||||
);
|
);
|
||||||
|
|
||||||
return sortBy(filteredOptions, [
|
return sortBy(filteredOptions, [
|
||||||
(memberId) => !(appliedFilters ?? []).includes(memberId),
|
(memberId) => !(appliedFilters ?? []).includes(memberId),
|
||||||
|
(memberId) => memberId !== currentUser?.id,
|
||||||
(memberId) => getUserDetails(memberId)?.display_name.toLowerCase(),
|
(memberId) => getUserDetails(memberId)?.display_name.toLowerCase(),
|
||||||
]);
|
]);
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
@ -66,7 +68,7 @@ export const FilterLead: React.FC<Props> = observer((props: Props) => {
|
|||||||
isChecked={appliedFilters?.includes(member.id) ? true : false}
|
isChecked={appliedFilters?.includes(member.id) ? true : false}
|
||||||
onClick={() => handleUpdate(member.id)}
|
onClick={() => handleUpdate(member.id)}
|
||||||
icon={<Avatar name={member.display_name} src={member.avatar} showTooltip={false} size="md" />}
|
icon={<Avatar name={member.display_name} src={member.avatar} showTooltip={false} size="md" />}
|
||||||
title={member.display_name}
|
title={currentUser?.id === member.id ? "You" : member?.display_name}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
@ -4,7 +4,7 @@ import { observer } from "mobx-react-lite";
|
|||||||
// hooks
|
// hooks
|
||||||
import { Avatar, Loader } from "@plane/ui";
|
import { Avatar, Loader } from "@plane/ui";
|
||||||
import { FilterHeader, FilterOption } from "@/components/issues";
|
import { FilterHeader, FilterOption } from "@/components/issues";
|
||||||
import { useMember } from "@/hooks/store";
|
import { useMember, useUser } from "@/hooks/store";
|
||||||
// components
|
// components
|
||||||
// ui
|
// ui
|
||||||
|
|
||||||
@ -22,16 +22,18 @@ export const FilterMembers: React.FC<Props> = observer((props: Props) => {
|
|||||||
const [previewEnabled, setPreviewEnabled] = useState(true);
|
const [previewEnabled, setPreviewEnabled] = useState(true);
|
||||||
// store hooks
|
// store hooks
|
||||||
const { getUserDetails } = useMember();
|
const { getUserDetails } = useMember();
|
||||||
|
const { currentUser } = useUser();
|
||||||
|
|
||||||
const appliedFiltersCount = appliedFilters?.length ?? 0;
|
const appliedFiltersCount = appliedFilters?.length ?? 0;
|
||||||
|
|
||||||
const sortedOptions = useMemo(() => {
|
const sortedOptions = useMemo(() => {
|
||||||
const filteredOptions = (memberIds || []).filter(
|
const filteredOptions = (memberIds || []).filter((memberId) =>
|
||||||
(memberId) => getUserDetails(memberId)?.display_name.toLowerCase().includes(searchQuery.toLowerCase())
|
getUserDetails(memberId)?.display_name.toLowerCase().includes(searchQuery.toLowerCase())
|
||||||
);
|
);
|
||||||
|
|
||||||
return sortBy(filteredOptions, [
|
return sortBy(filteredOptions, [
|
||||||
(memberId) => !(appliedFilters ?? []).includes(memberId),
|
(memberId) => !(appliedFilters ?? []).includes(memberId),
|
||||||
|
(memberId) => memberId !== currentUser?.id,
|
||||||
(memberId) => getUserDetails(memberId)?.display_name.toLowerCase(),
|
(memberId) => getUserDetails(memberId)?.display_name.toLowerCase(),
|
||||||
]);
|
]);
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
@ -66,7 +68,7 @@ export const FilterMembers: React.FC<Props> = observer((props: Props) => {
|
|||||||
isChecked={appliedFilters?.includes(member.id) ? true : false}
|
isChecked={appliedFilters?.includes(member.id) ? true : false}
|
||||||
onClick={() => handleUpdate(member.id)}
|
onClick={() => handleUpdate(member.id)}
|
||||||
icon={<Avatar name={member.display_name} src={member.avatar} showTooltip={false} size="md" />}
|
icon={<Avatar name={member.display_name} src={member.avatar} showTooltip={false} size="md" />}
|
||||||
title={member.display_name}
|
title={currentUser?.id === member.id ? "You" : member?.display_name}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
Loading…
Reference in New Issue
Block a user