Skip to content

Commit 5073bb3

Browse files
authored
Merge pull request #99 from dolthub/taylor/fixes-2
Misc fixes
2 parents 0067668 + dbd6ed7 commit 5073bb3

File tree

12 files changed

+141
-85
lines changed

12 files changed

+141
-85
lines changed

graphql-server/src/diffStats/diffStat.resolver.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ export function checkArgs(args: DiffStatArgs): void {
5050
) {
5151
throw new Error("refName is required for TwoDot diff with ref keyword");
5252
}
53+
if (args.refName && isRefKeyword(args.refName)) {
54+
throw new Error("refName cannot be a ref keyword");
55+
}
5356
}
5457

5558
function isRefKeyword(refName: string): boolean {

graphql-server/src/queryFactory/dolt/index.ts

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -412,25 +412,21 @@ export class DoltQueryFactory
412412
async getOneSidedRowDiff(
413413
args: t.TableArgs & { offset: number },
414414
): Promise<{ rows: t.RawRows; columns: t.RawRows }> {
415-
return this.queryMultiple(
416-
async query => {
417-
const columns = await query(qh.tableColsQueryAsOf, [
418-
args.tableName,
419-
args.refName,
420-
]);
421-
const { q, cols } = qh.getRowsQueryAsOf(columns);
422-
const rows = await query(q, [
423-
args.tableName,
424-
args.refName,
425-
...cols,
426-
ROW_LIMIT + 1,
427-
args.offset,
428-
]);
429-
return { rows, columns };
430-
},
431-
args.databaseName,
432-
args.refName,
433-
);
415+
return this.queryMultiple(async query => {
416+
const columns = await query(qh.tableColsQueryAsOf, [
417+
args.tableName,
418+
args.refName,
419+
]);
420+
const { q, cols } = qh.getRowsQueryAsOf(columns);
421+
const rows = await query(q, [
422+
args.tableName,
423+
args.refName,
424+
...cols,
425+
ROW_LIMIT + 1,
426+
args.offset,
427+
]);
428+
return { rows, columns };
429+
}, args.databaseName);
434430
}
435431

436432
async getRowDiffs(args: t.RowDiffArgs): t.DiffRes {
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import Button from "@components/Button";
2+
import { serializeCellValue } from "@components/pageComponents/FileUploadPage/Steps/Upload/EditableTable/TableGrid/utils";
3+
import {
4+
ColumnForDataTableFragment,
5+
RowForDataTableFragment,
6+
} from "@gen/graphql-types";
7+
import useDelay from "@hooks/useDelay";
8+
import { getBitDisplayValue } from "@lib/dataTable";
9+
import CopyToClipboard from "react-copy-to-clipboard";
10+
import css from "./index.module.css";
11+
12+
type Props = {
13+
row: RowForDataTableFragment;
14+
columns: ColumnForDataTableFragment[];
15+
disabled?: boolean;
16+
};
17+
18+
export default function CopyRowButton({
19+
row,
20+
columns,
21+
disabled,
22+
}: Props): JSX.Element {
23+
const success = useDelay();
24+
const copyVal = getCopyVal(row, columns);
25+
return (
26+
<CopyToClipboard onCopy={success.start} text={copyVal}>
27+
<Button.Link
28+
className={css.button}
29+
data-cy="copy-row-button"
30+
disabled={disabled}
31+
>
32+
{success.active ? "Copied" : "Copy row"}
33+
</Button.Link>
34+
</CopyToClipboard>
35+
);
36+
}
37+
38+
function getCopyVal(
39+
row: RowForDataTableFragment,
40+
columns: ColumnForDataTableFragment[],
41+
): string {
42+
return row.columnValues
43+
.map((c, cidx) => {
44+
const colType = columns[cidx].type;
45+
const value = c.displayValue;
46+
return colType === "bit(1)"
47+
? getBitDisplayValue(value)
48+
: serializeCellValue(value);
49+
})
50+
.join(",");
51+
}

web/components/DataTable/Table/Row.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1+
import CopyRowButton from "@components/CellButtons/CopyRowButton";
2+
import DeleteRowButton from "@components/CellButtons/DeleteRowButton";
3+
import HideRowButton from "@components/CellButtons/HideRowButton";
4+
import CellDropdown from "@components/CellDropdown";
15
import {
26
ColumnForDataTableFragment,
37
RowForDataTableFragment,
48
} from "@gen/graphql-types";
59
import { ColumnStatus } from "@lib/tableTypes";
610
import cx from "classnames";
711
import { useState } from "react";
8-
import DeleteRowButton from "@components/CellButtons/DeleteRowButton";
9-
import HideRowButton from "@components/CellButtons/HideRowButton";
10-
import CellDropdown from "@components/CellDropdown";
1112
import Cell from "./Cell";
1213
import css from "./index.module.css";
1314
import { getDiffTypeClassnameForRow } from "./utils";
@@ -41,6 +42,7 @@ export default function Row(props: Props) {
4142
>
4243
<HideRowButton {...props} />
4344
<DeleteRowButton {...props} />
45+
<CopyRowButton {...props} />
4446
</CellDropdown>
4547
)}
4648
</td>

web/components/DiffTableNav/DiffTableStats/TableName.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Link from "@components/links/Link";
33
import { useDiffContext } from "@contexts/diff";
44
import { DiffSummaryFragment, TableDiffType } from "@gen/graphql-types";
55
import { useRouter } from "next/router";
6+
import css from "./index.module.css";
67

78
type TableProps = {
89
diffSummary: DiffSummaryFragment;
@@ -28,7 +29,10 @@ function TableLink({ displayedTableName, diffSummary }: TableProps) {
2829

2930
if (stayWithinPage) {
3031
return (
31-
<Button.Link onClick={() => setActiveTableName(diffSummary.tableName)}>
32+
<Button.Link
33+
onClick={() => setActiveTableName(diffSummary.tableName)}
34+
className={css.tableButton}
35+
>
3236
{displayedTableName}
3337
</Button.Link>
3438
);

web/components/DiffTableNav/DiffTableStats/index.module.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,7 @@
4545
.noChanges {
4646
@apply mx-3 mt-4 mb-8 lg:mb-16;
4747
}
48+
49+
.tableButton {
50+
@apply leading-5;
51+
}

web/components/SqlDataTable/WorkingDiff.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import ErrorMsg from "@components/ErrorMsg";
44
import Loader from "@components/Loader";
55
import NotDoltWrapper from "@components/util/NotDoltWrapper";
66
import { DiffProvider, useDiffContext } from "@contexts/diff";
7+
import useSqlParser from "@hooks/useSqlParser";
78
import { RefParams } from "@lib/params";
89
import css from "./index.module.css";
910

1011
type Props = {
11-
params: RefParams;
12+
params: RefParams & { q: string };
1213
};
1314

1415
function Inner() {
@@ -28,9 +29,17 @@ export default function WorkingDiff(props: Props) {
2829
const fromRefName = "HEAD";
2930
const toRefName = "WORKING";
3031
const params = { ...props.params, toRefName, fromRefName };
32+
33+
const { getTableNames } = useSqlParser();
34+
const tns = getTableNames(params.q);
35+
3136
return (
3237
<NotDoltWrapper hideNotDolt>
33-
<DiffProvider params={params} stayWithinPage>
38+
<DiffProvider
39+
params={params}
40+
stayWithinPage
41+
initialTableName={tns ? tns[0] : undefined}
42+
>
3443
<Inner />
3544
</DiffProvider>
3645
</NotDoltWrapper>

web/components/pageComponents/DatabasePage/ForReleases/ReleaseList/useTagList.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { useEffect, useState } from "react";
21
import { TagForListFragment, useTagListQuery } from "@gen/graphql-types";
32
import useApolloError from "@hooks/useApolloError";
43
import { handleCaughtApolloError } from "@lib/errors/helpers";
54
import { ApolloErrorType } from "@lib/errors/types";
65
import { DatabaseParams } from "@lib/params";
6+
import { useEffect, useState } from "react";
77

88
type ReturnType = {
99
tags: TagForListFragment[] | undefined;

web/components/pageComponents/DatabasePage/ForTable/EditTableButtons.tsx

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Link from "@components/links/Link";
55
import { useDataTableContext } from "@contexts/dataTable";
66
import { useSqlEditorContext } from "@contexts/sqleditor";
77
import { useTagListQuery } from "@gen/graphql-types";
8+
import useDatabaseDetails from "@hooks/useDatabaseDetails";
89
import useSqlBuilder from "@hooks/useSqlBuilder";
910
import { TableParams } from "@lib/params";
1011
import { table } from "@lib/urls";
@@ -20,17 +21,16 @@ type Props = {
2021
params: TableParams;
2122
};
2223

23-
export default function EditTableButtons(props: Props) {
24+
type InnerProps = Props & {
25+
refIsTag?: boolean;
26+
};
27+
28+
function Inner(props: InnerProps) {
2429
const { executeQuery, setEditorString, toggleSqlEditor } =
2530
useSqlEditorContext();
2631
const { dropTable, insertIntoTable } = useSqlBuilder();
2732
const { columns } = useDataTableContext();
28-
const tagRes = useTagListQuery({
29-
variables: props.params,
30-
});
31-
const refIsTag = !!tagRes.data?.tags.list.find(
32-
t => t.tagName === props.params.refName,
33-
);
33+
3434
const uploadParams = { ...props.params, uploadId: String(Date.now()) };
3535

3636
const onWriteQuery = () => {
@@ -53,26 +53,26 @@ export default function EditTableButtons(props: Props) {
5353
Edit table{" "}
5454
<span className={css.tableName}>{props.params.tableName}</span>
5555
</h2>
56-
{refIsTag && (
56+
{props.refIsTag && (
5757
<ErrorMsg errString="A tag is currently selected. Please change to a branch from the left branch/tag dropdown to edit this database." />
5858
)}
5959
<div className={css.sections}>
6060
<OptionSquare
6161
icon={<AiOutlineCode />}
62-
disabled={refIsTag}
62+
disabled={props.refIsTag}
6363
link={
6464
<Button.Link
6565
onClick={onWriteQuery}
6666
data-cy="sql-query-edit-button"
67-
disabled={refIsTag}
67+
disabled={props.refIsTag}
6868
>
6969
SQL Query
7070
</Button.Link>
7171
}
7272
/>
7373
<OptionSquare
7474
icon={<ImTable2 />}
75-
disabled={refIsTag}
75+
disabled={props.refIsTag}
7676
link={
7777
<DatabaseUploadStageLink
7878
params={{ ...uploadParams, spreadsheet: true }}
@@ -84,7 +84,7 @@ export default function EditTableButtons(props: Props) {
8484
/>
8585
<OptionSquare
8686
icon={<FiUpload />}
87-
disabled={refIsTag}
87+
disabled={props.refIsTag}
8888
link={
8989
<DatabaseUploadStageLink params={uploadParams} stage="upload">
9090
File Upload
@@ -95,7 +95,7 @@ export default function EditTableButtons(props: Props) {
9595
<Button.Link
9696
onClick={onDrop}
9797
className={css.drop}
98-
disabled={refIsTag}
98+
disabled={props.refIsTag}
9999
red
100100
>
101101
<AiOutlineDelete /> Drop Table
@@ -106,3 +106,20 @@ export default function EditTableButtons(props: Props) {
106106
</div>
107107
);
108108
}
109+
110+
function ForDolt(props: Props) {
111+
const tagRes = useTagListQuery({
112+
variables: props.params,
113+
});
114+
const refIsTag = !!tagRes.data?.tags.list.find(
115+
t => t.tagName === props.params.refName,
116+
);
117+
return <Inner {...props} refIsTag={refIsTag} />;
118+
}
119+
120+
export default function EditTableButtons(props: Props) {
121+
const res = useDatabaseDetails();
122+
123+
if (!res.isDolt) return <Inner {...props} />;
124+
return <ForDolt {...props} />;
125+
}

web/components/pageComponents/FileUploadPage/Steps/Upload/EditableTable/TableGrid/index.tsx

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,7 @@ function Inner(props: InnerProps) {
3030

3131
const gridElement = (
3232
<DataGrid
33-
columns={[
34-
indexColumn,
35-
...props.state.columns.map(col => {
36-
return {
37-
...col,
38-
// headerRenderer: HeaderRenderer,
39-
};
40-
}),
41-
]}
33+
columns={[indexColumn, ...props.state.columns]}
4234
topSummaryRows={[{ _id: -1 }]}
4335
rows={props.state.rows}
4436
rowKeyGetter={row => row._id}
@@ -102,30 +94,3 @@ export default function TableGrid(props: Props) {
10294
const { state, setState, gridFunctions: gf } = useGrid(props.columns);
10395
return <Inner {...props} {...{ state, setState, gf }} />;
10496
}
105-
106-
// function HeaderRenderer(props: HeaderRendererProps<Row>) {
107-
// return (
108-
// <ContextMenuTrigger
109-
// id="grid-header-context-menu"
110-
// collect={() => {
111-
// return { column: props.column };
112-
// }}
113-
// >
114-
// <div>{props.column.name}</div>
115-
// </ContextMenuTrigger>
116-
// );
117-
// }
118-
119-
// function RowRenderer(props: RowRendererProps<Row>) {
120-
// return (
121-
// <ContextMenuTrigger
122-
// id="grid-row-context-menu"
123-
// collect={() => {
124-
// return { rowIdx: props.rowIdx };
125-
// }}
126-
// disable={props.rowIdx === 0}
127-
// >
128-
// <GridRow {...props} />
129-
// </ContextMenuTrigger>
130-
// );
131-
// }

0 commit comments

Comments
 (0)