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/CellButtons/CopyRowButton.tsx b/web/components/CellButtons/CopyRowButton.tsx new file mode 100644 index 00000000..ff15106f --- /dev/null +++ b/web/components/CellButtons/CopyRowButton.tsx @@ -0,0 +1,51 @@ +import Button from "@components/Button"; +import { serializeCellValue } from "@components/pageComponents/FileUploadPage/Steps/Upload/EditableTable/TableGrid/utils"; +import { + ColumnForDataTableFragment, + RowForDataTableFragment, +} from "@gen/graphql-types"; +import useDelay from "@hooks/useDelay"; +import { getBitDisplayValue } from "@lib/dataTable"; +import CopyToClipboard from "react-copy-to-clipboard"; +import css from "./index.module.css"; + +type Props = { + row: RowForDataTableFragment; + columns: ColumnForDataTableFragment[]; + disabled?: boolean; +}; + +export default function CopyRowButton({ + row, + columns, + disabled, +}: Props): JSX.Element { + const success = useDelay(); + const copyVal = getCopyVal(row, columns); + return ( + + + {success.active ? "Copied" : "Copy row"} + + + ); +} + +function getCopyVal( + row: RowForDataTableFragment, + columns: ColumnForDataTableFragment[], +): string { + return row.columnValues + .map((c, cidx) => { + const colType = columns[cidx].type; + const value = c.displayValue; + return colType === "bit(1)" + ? getBitDisplayValue(value) + : serializeCellValue(value); + }) + .join(","); +} diff --git a/web/components/DataTable/Table/Row.tsx b/web/components/DataTable/Table/Row.tsx index 654898cf..d86fae80 100644 --- a/web/components/DataTable/Table/Row.tsx +++ b/web/components/DataTable/Table/Row.tsx @@ -1,3 +1,7 @@ +import CopyRowButton from "@components/CellButtons/CopyRowButton"; +import DeleteRowButton from "@components/CellButtons/DeleteRowButton"; +import HideRowButton from "@components/CellButtons/HideRowButton"; +import CellDropdown from "@components/CellDropdown"; import { ColumnForDataTableFragment, RowForDataTableFragment, @@ -5,9 +9,6 @@ import { import { ColumnStatus } from "@lib/tableTypes"; import cx from "classnames"; import { useState } from "react"; -import DeleteRowButton from "@components/CellButtons/DeleteRowButton"; -import HideRowButton from "@components/CellButtons/HideRowButton"; -import CellDropdown from "@components/CellDropdown"; import Cell from "./Cell"; import css from "./index.module.css"; import { getDiffTypeClassnameForRow } from "./utils"; @@ -41,6 +42,7 @@ export default function Row(props: Props) { > + )} 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..2073087e 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,17 @@ 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); + return ( - + diff --git a/web/components/pageComponents/DatabasePage/ForReleases/ReleaseList/useTagList.ts b/web/components/pageComponents/DatabasePage/ForReleases/ReleaseList/useTagList.ts index 7f0961c8..95448452 100644 --- a/web/components/pageComponents/DatabasePage/ForReleases/ReleaseList/useTagList.ts +++ b/web/components/pageComponents/DatabasePage/ForReleases/ReleaseList/useTagList.ts @@ -1,9 +1,9 @@ -import { useEffect, useState } from "react"; import { TagForListFragment, useTagListQuery } from "@gen/graphql-types"; import useApolloError from "@hooks/useApolloError"; import { handleCaughtApolloError } from "@lib/errors/helpers"; import { ApolloErrorType } from "@lib/errors/types"; import { DatabaseParams } from "@lib/params"; +import { useEffect, useState } from "react"; type ReturnType = { tags: TagForListFragment[] | undefined; diff --git a/web/components/pageComponents/DatabasePage/ForTable/EditTableButtons.tsx b/web/components/pageComponents/DatabasePage/ForTable/EditTableButtons.tsx index 968c8cdc..2f8e770e 100644 --- a/web/components/pageComponents/DatabasePage/ForTable/EditTableButtons.tsx +++ b/web/components/pageComponents/DatabasePage/ForTable/EditTableButtons.tsx @@ -5,6 +5,7 @@ import Link from "@components/links/Link"; import { useDataTableContext } from "@contexts/dataTable"; import { useSqlEditorContext } from "@contexts/sqleditor"; import { useTagListQuery } from "@gen/graphql-types"; +import useDatabaseDetails from "@hooks/useDatabaseDetails"; import useSqlBuilder from "@hooks/useSqlBuilder"; import { TableParams } from "@lib/params"; import { table } from "@lib/urls"; @@ -20,17 +21,16 @@ type Props = { params: TableParams; }; -export default function EditTableButtons(props: Props) { +type InnerProps = Props & { + refIsTag?: boolean; +}; + +function Inner(props: InnerProps) { const { executeQuery, setEditorString, toggleSqlEditor } = useSqlEditorContext(); const { dropTable, insertIntoTable } = useSqlBuilder(); const { columns } = useDataTableContext(); - const tagRes = useTagListQuery({ - variables: props.params, - }); - const refIsTag = !!tagRes.data?.tags.list.find( - t => t.tagName === props.params.refName, - ); + const uploadParams = { ...props.params, uploadId: String(Date.now()) }; const onWriteQuery = () => { @@ -53,18 +53,18 @@ export default function EditTableButtons(props: Props) { Edit table{" "} {props.params.tableName} - {refIsTag && ( + {props.refIsTag && ( )}
} - disabled={refIsTag} + disabled={props.refIsTag} link={ SQL Query @@ -72,7 +72,7 @@ export default function EditTableButtons(props: Props) { /> } - disabled={refIsTag} + disabled={props.refIsTag} link={ } - disabled={refIsTag} + disabled={props.refIsTag} link={ File Upload @@ -95,7 +95,7 @@ export default function EditTableButtons(props: Props) { Drop Table @@ -106,3 +106,20 @@ export default function EditTableButtons(props: Props) {
); } + +function ForDolt(props: Props) { + const tagRes = useTagListQuery({ + variables: props.params, + }); + const refIsTag = !!tagRes.data?.tags.list.find( + t => t.tagName === props.params.refName, + ); + return ; +} + +export default function EditTableButtons(props: Props) { + const res = useDatabaseDetails(); + + if (!res.isDolt) return ; + return ; +} diff --git a/web/components/pageComponents/FileUploadPage/Steps/Upload/EditableTable/TableGrid/index.tsx b/web/components/pageComponents/FileUploadPage/Steps/Upload/EditableTable/TableGrid/index.tsx index 85893ff9..286f36bd 100644 --- a/web/components/pageComponents/FileUploadPage/Steps/Upload/EditableTable/TableGrid/index.tsx +++ b/web/components/pageComponents/FileUploadPage/Steps/Upload/EditableTable/TableGrid/index.tsx @@ -30,15 +30,7 @@ function Inner(props: InnerProps) { const gridElement = ( { - return { - ...col, - // headerRenderer: HeaderRenderer, - }; - }), - ]} + columns={[indexColumn, ...props.state.columns]} topSummaryRows={[{ _id: -1 }]} rows={props.state.rows} rowKeyGetter={row => row._id} @@ -102,30 +94,3 @@ export default function TableGrid(props: Props) { const { state, setState, gridFunctions: gf } = useGrid(props.columns); return ; } - -// function HeaderRenderer(props: HeaderRendererProps) { -// return ( -// { -// return { column: props.column }; -// }} -// > -//
{props.column.name}
-//
-// ); -// } - -// function RowRenderer(props: RowRendererProps) { -// return ( -// { -// return { rowIdx: props.rowIdx }; -// }} -// disable={props.rowIdx === 0} -// > -// -// -// ); -// } diff --git a/web/components/pageComponents/FileUploadPage/Steps/Upload/EditableTable/TableGrid/utils.ts b/web/components/pageComponents/FileUploadPage/Steps/Upload/EditableTable/TableGrid/utils.ts index 9f0f313c..7b63479f 100644 --- a/web/components/pageComponents/FileUploadPage/Steps/Upload/EditableTable/TableGrid/utils.ts +++ b/web/components/pageComponents/FileUploadPage/Steps/Upload/EditableTable/TableGrid/utils.ts @@ -82,7 +82,7 @@ export function filterOutEmptyRowsAndCols(rows: string[][]): string[][] { return filteredEmptyCols; } -function serializeCellValue(value: string): string { +export function serializeCellValue(value: string): string { const formattedValue = value.replace(/"/g, '""'); return formattedValue.includes(",") || formattedValue.includes('"') || diff --git a/web/lib/refetchQueries.ts b/web/lib/refetchQueries.ts index 3d9aabde..11d61524 100644 --- a/web/lib/refetchQueries.ts +++ b/web/lib/refetchQueries.ts @@ -54,15 +54,20 @@ export const refetchResetChangesQueries = ( toRefName: "WORKING", }; return [ - ...(isDolt ? [{ query: gen.GetStatusDocument, variables }] : []), - { - query: gen.DiffStatDocument, - variables: diffVariables, - }, - { - query: gen.DiffSummariesDocument, - variables: diffVariables, - }, + ...(isDolt + ? [ + { query: gen.GetStatusDocument, variables }, + { + query: gen.DiffStatDocument, + variables: diffVariables, + }, + { + query: gen.DiffSummariesDocument, + variables: diffVariables, + }, + ] + : []), + { query: gen.TableNamesDocument, variables: { ...variables, filterSystemTables: true },