Skip to content

Commit

Permalink
Show the document body and associated chunks in a (new) document show…
Browse files Browse the repository at this point in the history
… view. (#49)
  • Loading branch information
kerinin authored Jan 31, 2024
1 parent b8242d2 commit e880cb7
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dewy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async def lifespan(_app: FastAPI) -> AsyncIterator[State]:
app = FastAPI(lifespan=lifespan, **app_configs)

origins = [
"http://localhost:5173",
"*",
]
app.add_middleware(
CORSMiddleware,
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import SegmentIcon from '@mui/icons-material/Segment';
import { Route } from "react-router-dom";
import { dataProvider } from "./dataProvider";
import { CollectionList, CollectionCreate, CollectionEdit } from "./Collection";
import { DocumentList, DocumentCreate, DocumentEdit } from "./Document";
import { DocumentList, DocumentCreate, DocumentEdit, DocumentShow } from "./Document";
import { ChunkList } from "./Chunk";
import { Search } from "./Search";
import { MyLayout } from "./MyLayout";
Expand All @@ -38,6 +38,7 @@ export const App = () => (
list={DocumentList}
edit={DocumentEdit}
create={DocumentCreate}
show={DocumentShow}
recordRepresentation={(record) => record.url}
icon={ArticleIcon}
/>
Expand Down
23 changes: 23 additions & 0 deletions frontend/src/Document.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import {
List,
Datagrid,
ChipField,
TextField,
ReferenceManyField,
Show,
SimpleShowLayout,
ReferenceField,
BooleanField,
FileField,
TopToolbar,
EditButton,
ShowButton,
FilterButton,
CreateButton,
SearchInput,
Expand All @@ -15,6 +20,7 @@ import {
SimpleForm,
SelectInput,
ReferenceInput,
RichTextField,
FileInput,
required,
TextInput
Expand All @@ -38,6 +44,7 @@ export const DocumentList = () => (
<Datagrid>
<TextField source="url" />
<>
<ShowButton />
<EditButton />
</>
</Datagrid>
Expand All @@ -61,3 +68,19 @@ export const DocumentEdit = () => (
</SimpleForm>
</Edit>
);

export const DocumentShow = () => (
<Show>
<SimpleShowLayout>
<TextField source="url" />
<RichTextField source="text" />
<ReferenceManyField label="Chunk" reference="chunks" target="document_id">
<Datagrid>
<ChipField source="kind"/>
<TextField source="text" sx={{overflow: "hidden", textOverflow: "ellipsis", display: "-webkit-box", WebkitLineClamp: "3", WebkitBoxOrient: "vertical"}}/>
<ShowButton/>
</Datagrid>
</ReferenceManyField>
</SimpleShowLayout>
</Show>
);
17 changes: 17 additions & 0 deletions frontend/src/dataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,23 @@ export const dataProvider = {
const { json } = await httpClient(url, params);
return { data: json };
},
getManyReference: async (resource, params) => {
const { page, perPage } = params.pagination;
const { field, order } = params.sort;
const queryparams = {
[params.target]: params.id,
...params.pagination,
...params.sort,
...params.filter,
};

const url = `${apiUrl}/api/${resource}?${stringify(queryparams)}`;
const { json, headers } = await httpClient(url);
return {
data: json,
pageInfo: {hasNextPage: false, hasPreviousPage: false},
};
},
create: async (resource, params) => {
const { json } = await httpClient(`${apiUrl}/api/${resource}/`, {
method: 'PUT',
Expand Down

0 comments on commit e880cb7

Please sign in to comment.