Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Show the document body and associated chunks in a (new) document show… #49

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: the document body will only be shown (1) on a get request and (2) after ingestion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine - if there's no body it will just be empty. We could show a snippet in the list view, I guess

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