diff --git a/src/client/dd-hub-react/src/sections/document/view/doc-search-view.tsx b/src/client/dd-hub-react/src/sections/document/view/doc-search-view.tsx index 2136b07..b7261d2 100644 --- a/src/client/dd-hub-react/src/sections/document/view/doc-search-view.tsx +++ b/src/client/dd-hub-react/src/sections/document/view/doc-search-view.tsx @@ -7,8 +7,8 @@ import Typography from '@mui/material/Typography'; import Pagination from '@mui/material/Pagination'; import { DashboardContent } from 'src/layouts/dashboard'; -import { Doc, getDocuments } from 'src/services/document-service'; import { Attribute, getAttributes } from 'src/services/attribute-service'; +import { Doc, getDocumentByAttributes, getDocuments } from 'src/services/document-service'; import { Iconify } from 'src/components/iconify'; @@ -49,7 +49,7 @@ export function DocSearchView() { const [attributes, setAttributes] = useState>({}); useEffect(() => { - console.log(attributes); + getDocumentByAttributes(attributes).then(setDocs); }, [attributes]); function setAttribute(name: string, serilizedValue: string) { diff --git a/src/client/dd-hub-react/src/services/document-service.ts b/src/client/dd-hub-react/src/services/document-service.ts index c3fb2a0..8031a81 100644 --- a/src/client/dd-hub-react/src/services/document-service.ts +++ b/src/client/dd-hub-react/src/services/document-service.ts @@ -24,7 +24,7 @@ const validExtensions: FileFormat[] = [ type DocAttribute = { name: string; - serilizedValue?: string; + serilizedValue: string; } export class Doc { @@ -73,7 +73,8 @@ export class Doc { export type DocQuery = { id?: number | undefined, - name?: string | undefined + name?: string | undefined, + attributes?: Record } export function getDocuments(query: DocQuery | undefined = undefined): Promise { @@ -85,6 +86,11 @@ export function getDocuments(query: DocQuery | undefined = undefined): Promise d.name === query.name); + for (const name in query?.attributes) { + const attr = query.attributes[name]; + documents = documents.filter(d => d.attributes.find(a => a.name === name)?.serilizedValue.toLowerCase().includes(attr.toLowerCase())); + } + return Promise.resolve(documents); } @@ -94,4 +100,8 @@ export function getDocumentById(id: number): Promise { export function getDocumentByName(name: string): Promise { return getDocuments({ name: name }); +} + +export function getDocumentByAttributes(attributes: Record): Promise { + return getDocuments({ attributes: attributes }); } \ No newline at end of file