From bfaba2723c9312b127733b2299e8cf650b9d14b5 Mon Sep 17 00:00:00 2001 From: tlartem Date: Sun, 27 Jul 2025 07:39:01 +0300 Subject: [PATCH] =?UTF-8?q?=D1=84=D0=B8=D0=BB=D1=8C=D1=82=D1=80=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TemplateManager/TemplateFilterSidebar.tsx | 3 - .../template/api/templateApiService.ts | 96 ++++- .../template/model/TemplateContext.tsx | 98 ++++- src/page/TemplatesOverviewPage.tsx | 357 +++++++++++++++++- src/widget/template/ui/TemplateCard.tsx | 259 ++++++++++--- 5 files changed, 736 insertions(+), 77 deletions(-) diff --git a/src/component/TemplateManager/TemplateFilterSidebar.tsx b/src/component/TemplateManager/TemplateFilterSidebar.tsx index 5f796f6..d77b179 100644 --- a/src/component/TemplateManager/TemplateFilterSidebar.tsx +++ b/src/component/TemplateManager/TemplateFilterSidebar.tsx @@ -112,7 +112,6 @@ export const TemplateFilterSidebar: React.FC = ({ value={filters.name} onValueChange={value => updateFilters({ name: value })} suggestions={nameSuggestions} - placeholder="Введите название" /> @@ -128,7 +127,6 @@ export const TemplateFilterSidebar: React.FC = ({ value={filters.description} onValueChange={value => updateFilters({ description: value })} suggestions={descriptionSuggestions} - placeholder="Введите описание" /> @@ -187,7 +185,6 @@ export const TemplateFilterSidebar: React.FC = ({ updateAttributeFilter(attribute.id, value) } suggestions={[]} // Пока без автодополнения - placeholder={`Фильтр по ${attribute.name.toLowerCase()}`} /> ))} diff --git a/src/entitiy/template/api/templateApiService.ts b/src/entitiy/template/api/templateApiService.ts index ee9066e..6fbb555 100644 --- a/src/entitiy/template/api/templateApiService.ts +++ b/src/entitiy/template/api/templateApiService.ts @@ -9,7 +9,7 @@ export interface CreateTemplateOutput { } export interface GetTemplatesOutput { - templates: ApiTemplate[] + templates: ApiTemplateWithAttributes[] } export interface GetTemplateOutput { @@ -24,6 +24,10 @@ export interface PatchTemplateInput { name?: string | null description?: string | null elements?: Record | null + attributes?: Array<{ + attribute_id: string + value: string | null + }> | null } export interface PatchTemplateOutput { @@ -126,6 +130,7 @@ export function templateToPatchInput(template: Template): PatchTemplateInput { name: template.name, description: template.description, elements, + // attributes будут добавлены отдельно в TemplateContext при необходимости } } @@ -178,7 +183,7 @@ export async function getTemplatesApi(): Promise { // API получение конкретного шаблона export async function getTemplateApi( - templateId: UUID + templateId: string ): Promise { try { const response = await fetch(`/api/templates/${templateId}`, { @@ -202,18 +207,15 @@ export async function getTemplateApi( // API получение шаблона с атрибутами export async function getTemplateWithAttributesApi( - templateId: UUID + templateId: string ): Promise { try { - const response = await fetch( - `/api/templates/${templateId}/with-attributes`, - { - method: 'GET', - headers: { - 'Content-Type': 'application/json', - }, - } - ) + const response = await fetch(`/api/templates/${templateId}`, { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + }, + }) if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`) @@ -260,3 +262,73 @@ export async function updateTemplate( const patchInput = templateToPatchInput(template) return patchTemplateApi(template.id, patchInput) } + +// Интерфейсы для копирования шаблона +export interface CopyTemplateInput { + template_id: string + new_name: string + new_description?: string | null + new_attributes?: Array<{ + attribute_id: string + value: string | null + }> | null +} + +export interface CopyTemplateOutput { + new_template_id: string +} + +// Интерфейсы для удаления шаблона +export interface DeleteTemplateOutput { + success: boolean + template_id: string +} + +// API копирование шаблона +export async function copyTemplateApi( + input: CopyTemplateInput +): Promise { + try { + const response = await fetch('/api/templates/copy', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(input), + }) + + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`) + } + + const result: CopyTemplateOutput = await response.json() + return result + } catch (error) { + console.error('Ошибка при копировании шаблона:', error) + throw new Error('Ошибка при копировании шаблона на сервере') + } +} + +// API удаление шаблона +export async function deleteTemplateApi( + templateId: string +): Promise { + try { + const response = await fetch(`/api/templates/${templateId}`, { + method: 'DELETE', + headers: { + 'Content-Type': 'application/json', + }, + }) + + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`) + } + + const result: DeleteTemplateOutput = await response.json() + return result + } catch (error) { + console.error('Ошибка при удалении шаблона:', error) + throw new Error('Ошибка при удалении шаблона на сервере') + } +} diff --git a/src/entitiy/template/model/TemplateContext.tsx b/src/entitiy/template/model/TemplateContext.tsx index 36b8546..f9be20a 100644 --- a/src/entitiy/template/model/TemplateContext.tsx +++ b/src/entitiy/template/model/TemplateContext.tsx @@ -1,6 +1,10 @@ import { apiTemplateToTemplate, + apiTemplateWithAttributesToTemplate, + copyTemplateApi, + CopyTemplateInput, createTemplateApi, + deleteTemplateApi, getTemplateApi, getTemplatesApi, patchTemplateApi, @@ -26,8 +30,17 @@ interface TemplateContextType { addTemplate: ( data: Omit ) => Promise