From 9b4cf2bde2fae6916cfcf5ca1f38cc36e0a3a46e Mon Sep 17 00:00:00 2001
From: Ivan <8611739+IRBorisov@users.noreply.github.com>
Date: Tue, 11 Mar 2025 22:25:30 +0300
Subject: [PATCH] M: Improve location picker
---
.../components/PickLocation/PickLocation.tsx | 65 +++++++++++++++++++
.../SelectLocationContext.tsx | 8 +--
.../library/components/PickLocation/index.tsx | 1 +
.../library/dialogs/DlgChangeLocation.tsx | 43 ++----------
.../library/dialogs/DlgCloneLibraryItem.tsx | 55 +++-------------
.../pages/CreateItemPage/FormCreateItem.tsx | 55 +++-------------
6 files changed, 95 insertions(+), 132 deletions(-)
create mode 100644 rsconcept/frontend/src/features/library/components/PickLocation/PickLocation.tsx
rename rsconcept/frontend/src/features/library/components/{ => PickLocation}/SelectLocationContext.tsx (81%)
create mode 100644 rsconcept/frontend/src/features/library/components/PickLocation/index.tsx
diff --git a/rsconcept/frontend/src/features/library/components/PickLocation/PickLocation.tsx b/rsconcept/frontend/src/features/library/components/PickLocation/PickLocation.tsx
new file mode 100644
index 00000000..4fdecada
--- /dev/null
+++ b/rsconcept/frontend/src/features/library/components/PickLocation/PickLocation.tsx
@@ -0,0 +1,65 @@
+'use client';
+
+import { type FieldError } from 'react-hook-form';
+import clsx from 'clsx';
+
+import { useAuthSuspense } from '@/features/auth';
+
+import { Label, TextArea } from '@/components/Input';
+import { type Styling } from '@/components/props';
+
+import { LocationHead } from '../../models/library';
+import { combineLocation } from '../../models/libraryAPI';
+import { SelectLocationHead } from '../SelectLocationHead';
+
+import { SelectLocationContext } from './SelectLocationContext';
+
+interface PickLocationProps extends Styling {
+ dropdownHeight?: string;
+ rows?: number;
+
+ value: string;
+ onChange: (newLocation: string) => void;
+ error?: FieldError;
+}
+
+export function PickLocation({
+ dropdownHeight,
+ rows = 3,
+ value,
+ onChange,
+ error,
+ className,
+ ...restProps
+}: PickLocationProps) {
+ const { user } = useAuthSuspense();
+
+ return (
+
+
+
+ onChange(combineLocation(newValue, value.substring(3)))}
+ excluded={!user.is_staff ? [LocationHead.LIBRARY] : []}
+ />
+
+
+
+
+
+ );
+}
diff --git a/rsconcept/frontend/src/features/library/components/SelectLocationContext.tsx b/rsconcept/frontend/src/features/library/components/PickLocation/SelectLocationContext.tsx
similarity index 81%
rename from rsconcept/frontend/src/features/library/components/SelectLocationContext.tsx
rename to rsconcept/frontend/src/features/library/components/PickLocation/SelectLocationContext.tsx
index 0a55ea84..643edb80 100644
--- a/rsconcept/frontend/src/features/library/components/SelectLocationContext.tsx
+++ b/rsconcept/frontend/src/features/library/components/PickLocation/SelectLocationContext.tsx
@@ -8,7 +8,7 @@ import { IconFolderTree } from '@/components/Icons';
import { type Styling } from '@/components/props';
import { prefixes } from '@/utils/constants';
-import { SelectLocation } from './SelectLocation';
+import { SelectLocation } from '../SelectLocation';
interface SelectLocationContextProps extends Styling {
value: string;
@@ -22,7 +22,7 @@ export function SelectLocationContext({
title = 'Проводник...',
onChange,
className,
- dropdownHeight,
+ dropdownHeight = 'h-50',
...restProps
}: SelectLocationContextProps) {
const menu = useDropdown();
@@ -35,14 +35,14 @@ export function SelectLocationContext({
}
return (
-
+
}
onClick={() => menu.toggle()}
/>
-
+
validateLocation(data), { message: errorMsg.invalidLocation })
@@ -30,7 +25,6 @@ export interface DlgChangeLocationProps {
export function DlgChangeLocation() {
const { initial, onChangeLocation } = useDialogsStore(state => state.props as DlgChangeLocationProps);
- const { user } = useAuthSuspense();
const {
handleSubmit,
@@ -56,39 +50,16 @@ export function DlgChangeLocation() {
submitInvalidTooltip={`Допустимы буквы, цифры, подчерк, пробел и "!". Сегмент пути не может начинаться и заканчиваться пробелом. Общая длина (с корнем) не должна превышать ${limits.location_len}`}
canSubmit={isValid && isDirty}
onSubmit={event => void handleSubmit(onSubmit)(event)}
- className='w-140 pb-3 px-6 flex gap-3 h-36'
+ className='w-130 pb-3 px-6 h-36'
>
-
-
- (
- field.onChange(combineLocation(newValue, field.value.substring(3)))}
- excluded={!user.is_staff ? [LocationHead.LIBRARY] : []}
- />
- )}
- />
-
(
-
- )}
- />
- (
-
-
-
-
- (
- field.onChange(combineLocation(newValue, field.value.substring(3)))}
- excluded={!user.is_staff ? [LocationHead.LIBRARY] : []}
- />
- )}
- />
-
-
(
-
- )}
- />
- (
-
+ (
+
+ )}
+ />
diff --git a/rsconcept/frontend/src/features/library/pages/CreateItemPage/FormCreateItem.tsx b/rsconcept/frontend/src/features/library/pages/CreateItemPage/FormCreateItem.tsx
index 72208feb..af98c46a 100644
--- a/rsconcept/frontend/src/features/library/pages/CreateItemPage/FormCreateItem.tsx
+++ b/rsconcept/frontend/src/features/library/pages/CreateItemPage/FormCreateItem.tsx
@@ -5,7 +5,6 @@ import { Controller, useForm, useWatch } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import { urls, useConceptNavigation } from '@/app';
-import { useAuthSuspense } from '@/features/auth';
import { Button, MiniButton, SubmitButton } from '@/components/Control';
import { IconDownload } from '@/components/Icons';
@@ -21,17 +20,14 @@ import {
} from '../../backend/types';
import { useCreateItem } from '../../backend/useCreateItem';
import { IconItemVisibility } from '../../components/IconItemVisibility';
+import { PickLocation } from '../../components/PickLocation';
import { SelectAccessPolicy } from '../../components/SelectAccessPolicy';
import { SelectItemType } from '../../components/SelectItemType';
-import { SelectLocationContext } from '../../components/SelectLocationContext';
-import { SelectLocationHead } from '../../components/SelectLocationHead';
import { LocationHead } from '../../models/library';
-import { combineLocation } from '../../models/libraryAPI';
import { useLibrarySearchStore } from '../../stores/librarySearch';
export function FormCreateItem() {
const router = useConceptNavigation();
- const { user } = useAuthSuspense();
const { createItem, isPending, error: serverError, reset: clearServerError } = useCreateItem();
const searchLocation = useLibrarySearchStore(state => state.location);
@@ -196,6 +192,14 @@ export function FormCreateItem() {
+ (
+
+ )}
+ />
+
-
-
-
- (
- field.onChange(combineLocation(newValue, field.value.substring(3)))}
- excluded={!user.is_staff ? [LocationHead.LIBRARY] : []}
- />
- )}
- />
-
-
(
-
- )}
- />
- (
-
-