-
Notifications
You must be signed in to change notification settings - Fork 293
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
Fix model display issue in request table view #2787
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e92356c
fix(requests): ensure accurate model display in table view
use-tusk[bot] e3adcba
fix: address review from colegottdank
use-tusk[bot] 2b026a0
fix: Tusk automated feedback for automated check failure
use-tusk[bot] 19271fb
fix(11372792741): auto linting
use-tusk[bot] e6676a8
fix: Tusk automated feedback for automated check failure
use-tusk[bot] a50824c
fix(11372895088): auto linting
use-tusk[bot] dc3cb30
fix: Tusk automated feedback for automated check failure
use-tusk[bot] 2b20134
fix(11373055794): auto linting
use-tusk[bot] 9d79c29
fix: Tusk automated feedback for automated check failure
use-tusk[bot] 0834ec3
fix(11373213846): auto linting
use-tusk[bot] 1c97c25
fix: Tusk automated feedback for automated check failure
use-tusk[bot] 67d71fb
merge main into tusk-2784-fix-model-display-101620241919
use-tusk[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,200 @@ | ||
import React from "react"; | ||
import { | ||
useTable, | ||
useSortBy, | ||
usePagination, | ||
Column, | ||
UsePaginationInstanceProps, | ||
UseSortByInstanceProps, | ||
TableState, | ||
TableInstance, | ||
} from "react-table"; | ||
|
||
interface Request { | ||
request_id: string; | ||
created_at: string; | ||
status: string; | ||
user: string; | ||
cost: string; | ||
model: string | undefined; | ||
request_text: string; | ||
response_text: string; | ||
prompt_tokens: number; | ||
} | ||
|
||
interface RequestsTableProps { | ||
requests: Request[]; | ||
} | ||
|
||
const RequestsTable: React.FC<RequestsTableProps> = ({ requests }) => { | ||
const data = React.useMemo(() => requests, [requests]); | ||
|
||
const columns: Column<Request>[] = React.useMemo( | ||
() => [ | ||
{ | ||
Header: "Created At", | ||
accessor: "created_at", | ||
}, | ||
{ | ||
Header: "Status", | ||
accessor: "status", | ||
}, | ||
{ | ||
Header: "User", | ||
accessor: "user", | ||
}, | ||
{ | ||
Header: "Cost", | ||
accessor: "cost", | ||
}, | ||
{ | ||
Header: "Model", | ||
accessor: "model", | ||
Cell: ({ value }: { value: string | undefined }) => | ||
value || "Unsupported", | ||
}, | ||
{ | ||
Header: "Request", | ||
accessor: "request_text", | ||
}, | ||
{ | ||
Header: "Response", | ||
accessor: "response_text", | ||
}, | ||
{ | ||
Header: "Prompt Tokens", | ||
accessor: "prompt_tokens", | ||
}, | ||
], | ||
[] | ||
); | ||
|
||
const tableInstance = useTable<Request>( | ||
{ | ||
columns, | ||
data, | ||
initialState: { pageIndex: 0 } as Partial<TableState<Request>>, | ||
}, | ||
useSortBy, | ||
usePagination | ||
) as TableInstance<Request> & | ||
UsePaginationInstanceProps<Request> & | ||
UseSortByInstanceProps<Request>; | ||
|
||
const { | ||
getTableProps, | ||
getTableBodyProps, | ||
headerGroups, | ||
prepareRow, | ||
page, | ||
canPreviousPage, | ||
canNextPage, | ||
pageOptions, | ||
pageCount, | ||
gotoPage, | ||
nextPage, | ||
previousPage, | ||
setPageSize, | ||
state: { pageIndex, pageSize }, | ||
} = tableInstance; | ||
|
||
return ( | ||
<div> | ||
<table {...getTableProps()}> | ||
<thead> | ||
{headerGroups.map((headerGroup, index) => ( | ||
<tr | ||
{...headerGroup.getHeaderGroupProps()} | ||
key={`header-group-${index}`} | ||
> | ||
{headerGroup.headers.map((column, columnIndex) => ( | ||
<th | ||
{...column.getHeaderProps(column.getSortByToggleProps())} | ||
key={`header-${columnIndex}`} | ||
> | ||
{column.render("Header")} | ||
<span> | ||
{column.isSorted | ||
? column.isSortedDesc | ||
? " 🔽" | ||
: " 🔼" | ||
: ""} | ||
</span> | ||
</th> | ||
))} | ||
</tr> | ||
))} | ||
</thead> | ||
<tbody {...getTableBodyProps()}> | ||
{page.map((row, rowIndex) => { | ||
prepareRow(row); | ||
return ( | ||
<tr {...row.getRowProps()} key={`row-${rowIndex}`}> | ||
{row.cells.map((cell, cellIndex) => { | ||
return ( | ||
<td {...cell.getCellProps()} key={`cell-${cellIndex}`}> | ||
{cell.render("Cell")} | ||
</td> | ||
); | ||
})} | ||
</tr> | ||
); | ||
})} | ||
</tbody> | ||
</table> | ||
|
||
<div className="pagination"> | ||
<button onClick={() => gotoPage(0)} disabled={!canPreviousPage}> | ||
{"<<"} | ||
</button>{" "} | ||
<button onClick={() => previousPage()} disabled={!canPreviousPage}> | ||
{"<"} | ||
</button>{" "} | ||
<button onClick={() => nextPage()} disabled={!canNextPage}> | ||
{">"} | ||
</button>{" "} | ||
<button onClick={() => gotoPage(pageCount - 1)} disabled={!canNextPage}> | ||
{">>"} | ||
</button>{" "} | ||
<span> | ||
Page{" "} | ||
<strong> | ||
{pageIndex + 1} of {pageOptions.length} | ||
</strong>{" "} | ||
</span> | ||
<span> | ||
| Go to page:{" "} | ||
<input | ||
type="number" | ||
defaultValue={pageIndex + 1} | ||
onChange={(e) => { | ||
const page = e.target.value ? Number(e.target.value) - 1 : 0; | ||
gotoPage(page); | ||
}} | ||
style={{ width: "100px" }} | ||
/> | ||
</span>{" "} | ||
<select | ||
value={pageSize} | ||
onChange={(e) => { | ||
setPageSize(Number(e.target.value)); | ||
}} | ||
> | ||
{[10, 20, 30, 40, 50].map((pageSize) => ( | ||
<option key={pageSize} value={pageSize}> | ||
Show {pageSize} | ||
</option> | ||
))} | ||
</select> | ||
</div> | ||
|
||
<style jsx>{` | ||
.pagination { | ||
padding: 0.5rem; | ||
} | ||
`}</style> | ||
</div> | ||
); | ||
}; | ||
|
||
export default RequestsTable; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { | ||
UseTableInstanceProps, | ||
UsePaginationInstanceProps, | ||
UseSortByInstanceProps, | ||
TableState as ReactTableState, | ||
} from "react-table"; | ||
|
||
declare module "react-table" { | ||
export interface TableInstance<D extends object = {}> | ||
extends UseTableInstanceProps<D>, | ||
UsePaginationInstanceProps<D>, | ||
UseSortByInstanceProps<D> {} | ||
|
||
export type TableState<D extends object = {}> = ReactTableState<D>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not solving the issue. If the model in the images correctly shows in the request drawer, it should also show correctly in the request page. There is another issue here.