From 3e8669a5fcb0cdf9241ce5a4344e71c7cd555d77 Mon Sep 17 00:00:00 2001 From: hughcrt Date: Mon, 15 Apr 2024 17:33:24 -0300 Subject: [PATCH] should be good --- .github/workflows/run-tests.yml | 76 ++++++++----------- e2e/logs.spec.ts | 7 +- .../frontend/components/blocks/CopyText.tsx | 3 +- .../components/blocks/RunInputOutput.tsx | 7 +- packages/frontend/pages/logs/index.tsx | 65 ++++++++++------ 5 files changed, 87 insertions(+), 71 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 53ae4da8..c2575508 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -7,42 +7,37 @@ on: jobs: run-tests: - name: "Playwright Tests" runs-on: ubuntu-latest - container: - image: mcr.microsoft.com/playwright:v1.43.0-jammy steps: - uses: actions/checkout@v4 - - name: Install dependencies - run: npm ci - # - name: Cache node modules - # id: cache-npm - # uses: actions/cache@v4 - # env: - # cache-name: cache-node-modules - # with: - # path: ~/.npm - # key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} - # restore-keys: | - # ${{ runner.os }}-build-${{ env.cache-name }}- - # ${{ runner.os }}-build- - # ${{ runner.os }}- + - name: Cache node modules + id: cache-npm + uses: actions/cache@v4 + env: + cache-name: cache-node-modules + with: + path: ~/.npm + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-build-${{ env.cache-name }}- + ${{ runner.os }}-build- + ${{ runner.os }}- - # - name: Cache Playwright binaries - # uses: actions/cache@v4 - # id: playwright-cache - # with: - # path: ~/.cache/ms-playwright - # key: ${{ runner.os }}-playwright-${{ hashFiles('**/package-lock.json') }} - # restore-keys: | - # ${{ runner.os }}-playwright- + - name: Cache Playwright binaries + uses: actions/cache@v4 + id: playwright-cache + with: + path: ~/.cache/ms-playwright + key: ${{ runner.os }}-playwright-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-playwright- - # - name: Install dependencies - # run: npm ci + - name: Install dependencies + run: npm ci - # - name: Install Playwright - # # if: steps.playwright-cache.outputs.cache-hit != 'true' - # run: npx playwright install --with-deps chromium + - name: Install Playwright + # if: steps.playwright-cache.outputs.cache-hit != 'true' + run: npx playwright install --with-deps chromium - name: Start backend env: @@ -65,16 +60,11 @@ jobs: - name: Run tests run: npx playwright test env: - HOME: /root - - # - name: Run tests - # run: npx playwright test - # env: - # BASE_URL: http://0.0.0.0:8080 - # DATABASE_URL: ${{ secrets.DATABASE_URL }} - # - uses: actions/upload-artifact@v4 - # if: ${{ !cancelled() }} - # with: - # name: playwright-report - # path: playwright-report/ - # retention-days: 30 + BASE_URL: http://0.0.0.0:8080 + DATABASE_URL: ${{ secrets.DATABASE_URL }} + - uses: actions/upload-artifact@v4 + if: ${{ !cancelled() }} + with: + name: playwright-report + path: playwright-report/ + retention-days: 30 diff --git a/e2e/logs.spec.ts b/e2e/logs.spec.ts index d651358b..ff8ba9b0 100644 --- a/e2e/logs.spec.ts +++ b/e2e/logs.spec.ts @@ -15,8 +15,11 @@ test("make a log public", async ({ page, context }) => { await page.getByTestId("make-log-public-switch").click() - await page.getByTestId("copy-log-url-button").click() - publicLogUrl = await page.evaluate(() => navigator.clipboard.readText()) + publicLogUrl = await page.evaluate(() => { + const urlParams = new URLSearchParams(window.location.search) + const selected = urlParams.get("selected") + return `${window.location.origin}/logs/${selected}` + }) }) test("unauthenticated user can access public log URL", async ({ browser }) => { diff --git a/packages/frontend/components/blocks/CopyText.tsx b/packages/frontend/components/blocks/CopyText.tsx index 94390844..2e5c68de 100644 --- a/packages/frontend/components/blocks/CopyText.tsx +++ b/packages/frontend/components/blocks/CopyText.tsx @@ -8,7 +8,7 @@ import { } from "@mantine/core" import { IconCheck, IconCopy } from "@tabler/icons-react" -export const SuperCopyButton = ({ value, ...props }) => ( +export const SuperCopyButton = ({ value }) => ( {({ copied, copy }) => ( @@ -16,7 +16,6 @@ export const SuperCopyButton = ({ value, ...props }) => ( color={copied ? "teal" : "gray"} variant="transparent" onClick={copy} - {...props} > {copied ? : } diff --git a/packages/frontend/components/blocks/RunInputOutput.tsx b/packages/frontend/components/blocks/RunInputOutput.tsx index 267a21f1..05bca7a0 100644 --- a/packages/frontend/components/blocks/RunInputOutput.tsx +++ b/packages/frontend/components/blocks/RunInputOutput.tsx @@ -167,8 +167,11 @@ export default function RunInputOutput({ URL to share {run?.isPublic ? "" : "with your team"} {hasAccess(user.role, "logs", "update") && ( diff --git a/packages/frontend/pages/logs/index.tsx b/packages/frontend/pages/logs/index.tsx index cd4fcdc1..58a8343c 100644 --- a/packages/frontend/pages/logs/index.tsx +++ b/packages/frontend/pages/logs/index.tsx @@ -50,9 +50,9 @@ import { formatDateTime } from "@/utils/format" import { fetcher } from "@/utils/fetcher" import { useProject, useOrg, useProjectInfiniteSWR } from "@/utils/dataHooks" import { useDebouncedState, useDidUpdate } from "@mantine/hooks" -import Router from "next/router" import { ProjectContext } from "@/utils/context" import { CheckLogic, deserializeLogic, serializeLogic } from "shared" +import { useRouter } from "next/router" const columns = { llm: [ @@ -135,6 +135,7 @@ const editCheck = (filters, id, params) => { } export default function Logs() { + const router = useRouter() const { projectId } = useContext(ProjectContext) const { project, isLoading: projectLoading } = useProject() const { org } = useOrg() @@ -144,11 +145,11 @@ export default function Logs() { { id: "type", params: { type: "llm" } }, ]) const [showCheckBar, setShowCheckBar] = useState(false) - const [selected, setSelected] = useState(null) + const [selectedId, setSelectedId] = useState(null) const [serializedChecks, setSerializedChecks] = useState("") const [type, setType] = useState<"llm" | "trace" | "thread">("llm") - const [query, setQuery] = useDebouncedState("", 300) + const [query, setQuery] = useDebouncedState(null, 300) const { data: logs, @@ -157,34 +158,54 @@ export default function Logs() { loadMore, } = useProjectInfiniteSWR(`/runs?${serializedChecks}`) + const selectedLog = logs?.filter(({ id }) => id === selectedId)[0] + useDidUpdate(() => { - const serialized = serializeLogic(filters) + let serialized = serializeLogic(filters) if (typeof serialized === "string") { setSerializedChecks(serialized) - Router.replace(`/logs?${serialized}`) + if (selectedId) { + serialized += `&selected=${selectedId}` + } + router.replace(`/logs?${serialized}`) } }, [filters]) useEffect(() => { - // restore filters from query params + // restore filters and selected log from query params try { - const params = window.location.search.replace("?", "") - if (params) { - const type = new URLSearchParams(params).get("type") || "llm" - if (type) setType(type as any) + const urlParams = new URLSearchParams(window.location.search) + + const selectedId = urlParams.get("selected") + setSelectedId(selectedId) + + const type = urlParams.get("type") + if (type === "llm" || type === "trace" || type === "thread") { + setType(type) + } - const search = new URLSearchParams(params).get("search") - if (search) setQuery(search as any) + const search = urlParams.get("search") + setQuery(search) - const filtersData = deserializeLogic(params) - if (filtersData) setChecks(filtersData) + const filtersData = deserializeLogic(urlParams.toString()) + if (filtersData) { + setChecks(filtersData) } } catch (e) { console.error(e) } }, []) + useEffect(() => { + if (selectedId) { + router.push({ + pathname: router.pathname, + query: { ...router.query, selected: selectedId }, + }) + } + }, [selectedId]) + useDidUpdate(() => { // Change type filter and remove filters imcompatible with type const newChecks = editCheck(filters, "type", { type }).filter( @@ -348,22 +369,22 @@ export default function Logs() { setSelected(null)} + title={selectedLog ? formatDateTime(selectedLog.createdAt) : ""} + onClose={() => setSelectedId(null)} > - {selected?.type === "llm" && ( + {selectedLog?.type === "llm" && ( )} - {selected?.type === "thread" && } + {selectedLog?.type === "thread" && } { if (["agent", "chain"].includes(row.type)) { analytics.trackOnce("OpenTrace") - Router.push(`/traces/${row.id}`) + router.push(`/traces/${row.id}`) } else { analytics.trackOnce("OpenRun") - setSelected(row) + setSelectedId(row.id) } }} loading={loading || validating}