mirror of
https://github.com/docmost/docmost.git
synced 2025-11-14 15:41:16 +10:00
* feat: Move the page to another space - The ability to move a page to another space has been added * feat: Move the page to another space * feat: Move the page to another space - Correction of the visibility attribute of elements that extend beyond the boundaries of the space selection modal window * feat: Move the page to another space - Added removal of query keys when moving pages * feat: Move the page to another space - Fix locales * feat: Move the page to another space * feat: Move the page to another space - Fix docker compose * feat: Move the page to another space * feat: Move the page to another space - Some refactor * feat: Move the page to another space - Attachments update * feat: Move the page to another space - The function of searching for attachments by page ID and updating attachments has been combined * feat: Move the page to another space - Fix variable name * feat: Move the page to another space - Move current space to parameter of component SpaceSelectionModal * refactor ui --------- Co-authored-by: plekhanov <astecom@mail.ru>
89 lines
2.4 KiB
TypeScript
89 lines
2.4 KiB
TypeScript
import { useEffect, useState } from "react";
|
|
import { useDebouncedValue } from "@mantine/hooks";
|
|
import { Avatar, Group, Select, SelectProps, Text } from "@mantine/core";
|
|
import { useGetSpacesQuery } from "@/features/space/queries/space-query.ts";
|
|
import { ISpace } from "../../types/space.types";
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
interface SpaceSelectProps {
|
|
onChange: (value: ISpace) => void;
|
|
value?: string;
|
|
label?: string;
|
|
width?: number;
|
|
opened?: boolean;
|
|
clearable?: boolean;
|
|
}
|
|
|
|
const renderSelectOption: SelectProps["renderOption"] = ({ option }) => (
|
|
<Group gap="sm" wrap="nowrap">
|
|
<Avatar color="initials" variant="filled" name={option.label} size={20} />
|
|
<div>
|
|
<Text size="sm" lineClamp={1}>
|
|
{option.label}
|
|
</Text>
|
|
</div>
|
|
</Group>
|
|
);
|
|
|
|
export function SpaceSelect({
|
|
onChange,
|
|
label,
|
|
value,
|
|
width,
|
|
opened,
|
|
clearable,
|
|
}: SpaceSelectProps) {
|
|
const { t } = useTranslation();
|
|
const [searchValue, setSearchValue] = useState("");
|
|
const [debouncedQuery] = useDebouncedValue(searchValue, 500);
|
|
const { data: spaces, isLoading } = useGetSpacesQuery({
|
|
query: debouncedQuery,
|
|
limit: 50,
|
|
});
|
|
const [data, setData] = useState([]);
|
|
|
|
useEffect(() => {
|
|
if (spaces) {
|
|
const spaceData = spaces?.items
|
|
.filter((space: ISpace) => space.slug !== value)
|
|
.map((space: ISpace) => {
|
|
return {
|
|
label: space.name,
|
|
value: space.slug,
|
|
};
|
|
});
|
|
|
|
const filteredSpaceData = spaceData.filter(
|
|
(space) =>
|
|
!data.find((existingSpace) => existingSpace.value === space.value),
|
|
);
|
|
setData((prevData) => [...prevData, ...filteredSpaceData]);
|
|
}
|
|
}, [spaces]);
|
|
|
|
return (
|
|
<Select
|
|
data={data}
|
|
renderOption={renderSelectOption}
|
|
maxDropdownHeight={300}
|
|
//label={label || 'Select space'}
|
|
placeholder={t("Search for spaces")}
|
|
searchable
|
|
searchValue={searchValue}
|
|
onSearchChange={setSearchValue}
|
|
clearable={clearable}
|
|
variant="filled"
|
|
onChange={(slug) =>
|
|
onChange(spaces.items?.find((item) => item.slug === slug))
|
|
}
|
|
// duct tape
|
|
onClick={(e) => e.stopPropagation()}
|
|
nothingFoundMessage={t("No space found")}
|
|
limit={50}
|
|
checkIconPosition="right"
|
|
comboboxProps={{ width, withinPortal: false }}
|
|
dropdownOpened={opened}
|
|
/>
|
|
);
|
|
}
|