Skip to content

Commit

Permalink
feature: remove description on groups view in favor of Chunk Count on
Browse files Browse the repository at this point in the history
group page
  • Loading branch information
cdxker committed Nov 21, 2024
1 parent ddb7efc commit e06f169
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 22 deletions.
3 changes: 2 additions & 1 deletion clients/ts-sdk/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -10698,7 +10698,8 @@
},
"total_pages": {
"type": "integer",
"format": "int32"
"format": "int32",
"minimum": 0
}
}
},
Expand Down
69 changes: 66 additions & 3 deletions frontends/search/src/components/OrgGroupPageView.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { FiTrash } from "solid-icons/fi";
import { isChunkGroupPageDTO, type ChunkGroupDTO } from "../utils/apiTypes";
import {
indirectHasOwnProperty,
isChunkGroupPageDTO,
type ChunkGroupDTO,
} from "../utils/apiTypes";
import {
For,
Setter,
Expand All @@ -20,20 +24,76 @@ export interface GroupUserPageViewProps {
setShowConfirmModal: Setter<boolean>;
}

export type GetChunkGroupCountResponse = {
count: number;
group_id: string;
};

export const GroupUserPageView = (props: GroupUserPageViewProps) => {
const apiHost = import.meta.env.VITE_API_HOST as string;
const datasetAndUserContext = useContext(DatasetAndUserContext);

const $dataset = datasetAndUserContext.currentDataset;
const $user = datasetAndUserContext.user;
const [groups, setGroups] = createSignal<ChunkGroupDTO[]>([]);
const [groupCounts, setGroupCounts] = createSignal<
GetChunkGroupCountResponse[]
>([]);
const [groupPage, setGroupPage] = createSignal(1);
const [groupPageCount, setGroupPageCount] = createSignal(1);
const [deleting, setDeleting] = createSignal(false);
const [loading, setLoading] = createSignal(true);

const serverConfig = useDatasetServerConfig();

createEffect(() => {
const currentDataset = $dataset?.();
if (!currentDataset) return;

const all_counts = groups().map(async (group) => {
const response = await fetch(`${apiHost}/chunk_group/count`, {
method: "POST",
credentials: "include",
body: JSON.stringify({ group_id: group.id }),
headers: {
"X-API-version": "2.0",
"TR-Dataset": currentDataset.dataset.id,
"Content-Type": "application/json",
},
});

if (response.ok) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const data = await response.json();
console.log("data", data);
if (
data !== null &&
typeof data === "object" &&
indirectHasOwnProperty(data, "count") &&
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
typeof data.count === "number" &&
indirectHasOwnProperty(data, "group_id") &&
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
typeof data.group_id === "string"
) {
console.log("Invalid response", data);
return {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
group_id: data.group_id,
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
count: data.count,
} as GetChunkGroupCountResponse;
}
}
});

void Promise.all(all_counts).then((counts) => {
const filteredGroupCounts = counts.filter((c) => c !== undefined);
console.log("setGroupCounts", filteredGroupCounts);
setGroupCounts(filteredGroupCounts);
});
});

createEffect(() => {
const userId = $user?.()?.id;
if (userId === undefined) return;
Expand Down Expand Up @@ -149,7 +209,7 @@ export const GroupUserPageView = (props: GroupUserPageViewProps) => {
scope="col"
class="px-3 py-3.5 text-left text-base font-semibold dark:text-white"
>
Description
Chunk Count
</th>
<th
scope="col"
Expand Down Expand Up @@ -181,7 +241,10 @@ export const GroupUserPageView = (props: GroupUserPageViewProps) => {
</a>
</td>
<td class="whitespace-nowrap text-wrap px-3 py-4 text-sm text-gray-900 dark:text-gray-300">
{group.description}
{
groupCounts().find((c) => c.group_id == group.id)
?.count
}
</td>
<td class="whitespace-nowrap px-3 py-4 text-left text-sm text-gray-900 dark:text-gray-300">
{getLocalTime(group.created_at).toLocaleDateString() +
Expand Down
38 changes: 20 additions & 18 deletions frontends/search/src/components/UploadFile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,20 +138,20 @@ export const UploadFile = () => {
});

const requestBodyTemplate: Omit<RequestBody, "base64_file" | "file_name"> =
{
link: link() === "" ? undefined : link(),
tag_set:
tagSet().split(",").length > 0 ? undefined : tagSet().split(","),
split_delimiters: splitDelimiters(),
target_splits_per_chunk: targetSplitsPerChunk(),
rebalance_chunks: rebalanceChunks(),
use_pdf2md_ocr: useGptChunking(),
group_tracking_id:
groupTrackingId() === "" ? undefined : groupTrackingId(),
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
metadata: metadata(),
time_stamp: timestamp() ? timestamp() + " 00:00:00" : undefined,
};
{
link: link() === "" ? undefined : link(),
tag_set:
tagSet().split(",").length > 0 ? undefined : tagSet().split(","),
split_delimiters: splitDelimiters(),
target_splits_per_chunk: targetSplitsPerChunk(),
rebalance_chunks: rebalanceChunks(),
use_pdf2md_ocr: useGptChunking(),
group_tracking_id:
groupTrackingId() === "" ? undefined : groupTrackingId(),
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
metadata: metadata(),
time_stamp: timestamp() ? timestamp() + " 00:00:00" : undefined,
};

const uploadFilePromises = files().map(async (file) => {
let base64File = await toBase64(file);
Expand Down Expand Up @@ -343,10 +343,11 @@ export const UploadFile = () => {
</Show>
<div class="m-1 mb-1 flex flex-row gap-2">
<button
class={`rounded border-2 border-magenta p-2 px-4 font-semibold ${showFileInput()
class={`rounded border-2 border-magenta p-2 px-4 font-semibold ${
showFileInput()
? "bg-magenta-600 text-white"
: "text-magenta hover:bg-magenta-500 hover:text-white"
}`}
}`}
onClick={() => {
setFiles([]);
setShowFileInput(true);
Expand All @@ -356,10 +357,11 @@ export const UploadFile = () => {
Select Files
</button>
<button
class={`rounded border-2 border-magenta p-2 px-4 font-semibold ${showFolderInput()
class={`rounded border-2 border-magenta p-2 px-4 font-semibold ${
showFolderInput()
? "bg-magenta-600 text-white"
: "text-magenta hover:bg-magenta-500 hover:text-white"
}`}
}`}
onClick={() => {
setFiles([]);
setShowFolderInput(true);
Expand Down

0 comments on commit e06f169

Please sign in to comment.