Skip to content

Commit

Permalink
Fix diffs
Browse files Browse the repository at this point in the history
  • Loading branch information
tbantle22 committed Jan 10, 2024
1 parent 94cd9c9 commit c28ad89
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 22 deletions.
3 changes: 3 additions & 0 deletions graphql-server/src/diffStats/diffStat.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
34 changes: 15 additions & 19 deletions graphql-server/src/queryFactory/dolt/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 5 additions & 1 deletion web/components/DiffTableNav/DiffTableStats/TableName.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,7 +29,10 @@ function TableLink({ displayedTableName, diffSummary }: TableProps) {

if (stayWithinPage) {
return (
<Button.Link onClick={() => setActiveTableName(diffSummary.tableName)}>
<Button.Link
onClick={() => setActiveTableName(diffSummary.tableName)}
className={css.tableButton}
>
{displayedTableName}
</Button.Link>
);
Expand Down
4 changes: 4 additions & 0 deletions web/components/DiffTableNav/DiffTableStats/index.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@
.noChanges {
@apply mx-3 mt-4 mb-8 lg:mb-16;
}

.tableButton {
@apply leading-5;
}
14 changes: 12 additions & 2 deletions web/components/SqlDataTable/WorkingDiff.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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 (
<NotDoltWrapper hideNotDolt>
<DiffProvider params={params} stayWithinPage>
<DiffProvider
params={params}
stayWithinPage
initialTableName={tns ? tns[0] : undefined}
>
<Inner />
</DiffProvider>
</NotDoltWrapper>
Expand Down

0 comments on commit c28ad89

Please sign in to comment.