From c28ad893936b045c14296ff5abff1c44e7de97b5 Mon Sep 17 00:00:00 2001 From: Taylor Bantle Date: Wed, 10 Jan 2024 11:59:22 -0800 Subject: [PATCH] Fix diffs --- .../src/diffStats/diffStat.resolver.ts | 3 ++ graphql-server/src/queryFactory/dolt/index.ts | 34 ++++++++----------- .../DiffTableNav/DiffTableStats/TableName.tsx | 6 +++- .../DiffTableStats/index.module.css | 4 +++ web/components/SqlDataTable/WorkingDiff.tsx | 14 ++++++-- 5 files changed, 39 insertions(+), 22 deletions(-) diff --git a/graphql-server/src/diffStats/diffStat.resolver.ts b/graphql-server/src/diffStats/diffStat.resolver.ts index 4be37e2e..853c318a 100644 --- a/graphql-server/src/diffStats/diffStat.resolver.ts +++ b/graphql-server/src/diffStats/diffStat.resolver.ts @@ -50,6 +50,9 @@ export function checkArgs(args: DiffStatArgs): void { ) { throw new Error("refName is required for TwoDot diff with ref keyword"); } + if (args.refName && isRefKeyword(args.refName)) { + throw new Error("refName cannot be a ref keyword"); + } } function isRefKeyword(refName: string): boolean { diff --git a/graphql-server/src/queryFactory/dolt/index.ts b/graphql-server/src/queryFactory/dolt/index.ts index e7c38ed2..dbe56cc8 100644 --- a/graphql-server/src/queryFactory/dolt/index.ts +++ b/graphql-server/src/queryFactory/dolt/index.ts @@ -412,25 +412,21 @@ export class DoltQueryFactory async getOneSidedRowDiff( args: t.TableArgs & { offset: number }, ): Promise<{ rows: t.RawRows; columns: t.RawRows }> { - return this.queryMultiple( - async query => { - const columns = await query(qh.tableColsQueryAsOf, [ - args.tableName, - args.refName, - ]); - const { q, cols } = qh.getRowsQueryAsOf(columns); - const rows = await query(q, [ - args.tableName, - args.refName, - ...cols, - ROW_LIMIT + 1, - args.offset, - ]); - return { rows, columns }; - }, - args.databaseName, - args.refName, - ); + return this.queryMultiple(async query => { + const columns = await query(qh.tableColsQueryAsOf, [ + args.tableName, + args.refName, + ]); + const { q, cols } = qh.getRowsQueryAsOf(columns); + const rows = await query(q, [ + args.tableName, + args.refName, + ...cols, + ROW_LIMIT + 1, + args.offset, + ]); + return { rows, columns }; + }, args.databaseName); } async getRowDiffs(args: t.RowDiffArgs): t.DiffRes { diff --git a/web/components/DiffTableNav/DiffTableStats/TableName.tsx b/web/components/DiffTableNav/DiffTableStats/TableName.tsx index 47a0d2f5..20210f38 100644 --- a/web/components/DiffTableNav/DiffTableStats/TableName.tsx +++ b/web/components/DiffTableNav/DiffTableStats/TableName.tsx @@ -3,6 +3,7 @@ import Link from "@components/links/Link"; import { useDiffContext } from "@contexts/diff"; import { DiffSummaryFragment, TableDiffType } from "@gen/graphql-types"; import { useRouter } from "next/router"; +import css from "./index.module.css"; type TableProps = { diffSummary: DiffSummaryFragment; @@ -28,7 +29,10 @@ function TableLink({ displayedTableName, diffSummary }: TableProps) { if (stayWithinPage) { return ( - setActiveTableName(diffSummary.tableName)}> + setActiveTableName(diffSummary.tableName)} + className={css.tableButton} + > {displayedTableName} ); diff --git a/web/components/DiffTableNav/DiffTableStats/index.module.css b/web/components/DiffTableNav/DiffTableStats/index.module.css index 18d3bcf1..60312705 100644 --- a/web/components/DiffTableNav/DiffTableStats/index.module.css +++ b/web/components/DiffTableNav/DiffTableStats/index.module.css @@ -45,3 +45,7 @@ .noChanges { @apply mx-3 mt-4 mb-8 lg:mb-16; } + +.tableButton { + @apply leading-5; +} diff --git a/web/components/SqlDataTable/WorkingDiff.tsx b/web/components/SqlDataTable/WorkingDiff.tsx index 0ed4c1ed..fe66c28f 100644 --- a/web/components/SqlDataTable/WorkingDiff.tsx +++ b/web/components/SqlDataTable/WorkingDiff.tsx @@ -4,11 +4,12 @@ import ErrorMsg from "@components/ErrorMsg"; import Loader from "@components/Loader"; import NotDoltWrapper from "@components/util/NotDoltWrapper"; import { DiffProvider, useDiffContext } from "@contexts/diff"; +import useSqlParser from "@hooks/useSqlParser"; import { RefParams } from "@lib/params"; import css from "./index.module.css"; type Props = { - params: RefParams; + params: RefParams & { q: string }; }; function Inner() { @@ -28,9 +29,18 @@ export default function WorkingDiff(props: Props) { const fromRefName = "HEAD"; const toRefName = "WORKING"; const params = { ...props.params, toRefName, fromRefName }; + + const { getTableNames } = useSqlParser(); + const tns = getTableNames(params.q); + console.log(tns); + return ( - +