Skip to content

Commit 3da9762

Browse files
Merge pull request #570 from dolthub/eric/usability-fixes
Usability fixes
2 parents bfa76ff + e1013e5 commit 3da9762

File tree

19 files changed

+191
-129
lines changed

19 files changed

+191
-129
lines changed

web/jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const customJestConfig = {
1010
rootDir: "./renderer",
1111
setupFilesAfterEnv: ["../jest.setup.ts"],
1212
testRegex: TEST_REGEX,
13+
testEnvironment: "jsdom",
1314
transform: {
1415
"^.+\\.tsx?$": "babel-jest",
1516
},

web/main/background.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,13 +252,26 @@ ipcMain.handle("toggle-left-sidebar", () => {
252252

253253
ipcMain.handle(
254254
"start-dolt-server",
255-
async (_, connectionName: string, port: string, init?: boolean) => {
255+
async (
256+
_,
257+
connectionName: string,
258+
port: string,
259+
databaseName: string,
260+
init?: boolean,
261+
) => {
256262
try {
257-
console.log("start-dolt-server", connectionName, port, init);
263+
console.log(
264+
"start-dolt-server",
265+
connectionName,
266+
port,
267+
databaseName,
268+
init,
269+
);
258270
doltServerProcess = await startServer(
259271
mainWindow,
260272
connectionName,
261273
port,
274+
databaseName,
262275
init,
263276
);
264277
if (!doltServerProcess) {

web/main/doltServer.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@ export async function startServer(
1313
mainWindow: BrowserWindow,
1414
connectionName: string,
1515
port: string,
16+
databaseName: string,
1617
init?: boolean,
1718
): Promise<ChildProcess | null> {
1819
// Set the path for the database folder
1920
// In production, it's in the userData directory
2021
// In development, it's in the build directory since the development userData directory clears its contents every time the app is rerun in dev mode
21-
const dbFolderPath = path.join(getDatabasesPath(), connectionName);
22-
22+
const dbFolderPath = path.join(
23+
getDatabasesPath(),
24+
connectionName,
25+
databaseName,
26+
);
2327
const doltPath = getDoltPaths();
2428

2529
try {

web/renderer/components/CloneDatabaseForm/CloneDetails.tsx

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { Checkbox } from "@dolthub/react-components";
21
import {
32
DatabaseConnectionFragment,
43
DatabaseType,
@@ -13,16 +12,10 @@ import css from "./index.module.css";
1312
import CloneForm from "./CloneForm";
1413

1514
type Props = {
16-
cloneDolt: boolean;
17-
setCloneDolt: (c: boolean) => void;
1815
currentConnection: DatabaseConnectionFragment;
1916
};
2017

21-
export default function CloneDetails({
22-
cloneDolt,
23-
setCloneDolt,
24-
currentConnection,
25-
}: Props) {
18+
export default function CloneDetails({ currentConnection }: Props) {
2619
const { mutateFn: doltClone, ...res } = useMutation({
2720
hook: useDoltCloneMutation,
2821
refetchQueries: [
@@ -92,25 +85,14 @@ export default function CloneDetails({
9285

9386
return (
9487
<div className={css.form}>
95-
<Checkbox
96-
checked={cloneDolt}
97-
onChange={() => {
98-
setCloneDolt(!cloneDolt);
99-
}}
100-
name="clone-dolt-server"
101-
label="Clone a remote Dolt database from DoltHub"
102-
className={css.checkbox}
88+
<CloneForm
89+
onCloneDoltHubDatabase={onCloneDoltHubDatabase}
90+
progress={progress}
91+
loading={loading}
92+
error={err}
93+
setErr={setErr}
94+
disabledForConnection={false}
10395
/>
104-
{cloneDolt && (
105-
<CloneForm
106-
onCloneDoltHubDatabase={onCloneDoltHubDatabase}
107-
progress={progress}
108-
loading={loading}
109-
error={err}
110-
setErr={setErr}
111-
disabledForConnection={false}
112-
/>
113-
)}
11496
</div>
11597
);
11698
}

web/renderer/components/CloneDatabaseForm/CloneForm.tsx

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export default function CloneForm({
4040
disabledForConnection,
4141
owner,
4242
remoteDbName,
43+
newDbName,
4344
disabledForConnectionMessage,
4445
);
4546

@@ -53,7 +54,8 @@ export default function CloneForm({
5354
}}
5455
label="Owner Name"
5556
labelClassName={css.label}
56-
placeholder="e.g. dolthub"
57+
placeholder="e.g. dolthub (required)"
58+
data-cy="owner-name-input"
5759
light
5860
/>
5961
<FormInput
@@ -66,6 +68,7 @@ export default function CloneForm({
6668
label="Remote Database Name"
6769
labelClassName={css.label}
6870
placeholder="e.g. my-database (required)"
71+
data-cy="remote-db-name-input"
6972
light
7073
/>
7174
<FormInput
@@ -77,6 +80,7 @@ export default function CloneForm({
7780
label="New Database Name"
7881
labelClassName={css.label}
7982
placeholder="e.g. my-database (required)"
83+
data-cy="new-db-name-input"
8084
light
8185
/>
8286
<ButtonsWithError error={error} className={css.buttons}>
@@ -108,6 +112,7 @@ export default function CloneForm({
108112
onClick={async e =>
109113
onCloneDoltHubDatabase(e, owner, remoteDbName, newDbName)
110114
}
115+
data-cy="start-clone-button"
111116
>
112117
Start Clone
113118
</Button>
@@ -126,14 +131,25 @@ export default function CloneForm({
126131
function getDisabled(
127132
disabledForConnection: boolean,
128133
owner: string,
129-
database?: string,
134+
remoteDatabaseName: string,
135+
newDatabaseName: string,
130136
disabledForConnectionMessage?: ReactNode,
131137
): DisabledReturnType {
132138
if (disabledForConnection) {
133139
return { disabled: true, message: disabledForConnectionMessage };
134140
}
135-
if (!database) {
136-
return { disabled: true, message: <span>Database name is required.</span> };
141+
if (!remoteDatabaseName) {
142+
return {
143+
disabled: true,
144+
message: <span>Remote database name is required.</span>,
145+
};
146+
}
147+
148+
if (!newDatabaseName) {
149+
return {
150+
disabled: true,
151+
message: <span>New database name is required.</span>,
152+
};
137153
}
138154
if (!owner) {
139155
return { disabled: true, message: <span>Owner name is required.</span> };

web/renderer/components/CloneDatabaseForm/index.module.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.form .checkbox {
1+
.form {
22
svg {
33
@apply -top-1;
44
}

web/renderer/components/CloneDatabaseForm/index.test.tsx

Lines changed: 9 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,14 @@ jest.mock("next/router", () => {
1717
});
1818

1919
describe("tests CloneDatabaseForm", () => {
20-
const defaultProps = {
21-
cloneDolt: false,
22-
setCloneDolt: jest.fn(),
23-
};
24-
2520
beforeEach(() => {
2621
jest.clearAllMocks();
2722
});
2823

2924
it("renders error when no current connection", async () => {
3025
setup(
3126
<MockedProvider mocks={[mocks.currentConnectionNullMock]}>
32-
<CloneDatabaseForm {...defaultProps} />
27+
<CloneDatabaseForm />
3328
</MockedProvider>,
3429
);
3530

@@ -43,7 +38,7 @@ describe("tests CloneDatabaseForm", () => {
4338
it("renders nothing for postgres connections", async () => {
4439
const { container } = setup(
4540
<MockedProvider mocks={[mocks.postgresConnectionMock]}>
46-
<CloneDatabaseForm {...defaultProps} />
41+
<CloneDatabaseForm />
4742
</MockedProvider>,
4843
);
4944

@@ -52,64 +47,10 @@ describe("tests CloneDatabaseForm", () => {
5247
expect(container).toBeEmptyDOMElement();
5348
});
5449

55-
it("renders clone form when cloneDolt is false", async () => {
56-
setup(
57-
<MockedProvider mocks={[mocks.currentConnectionMock]}>
58-
<CloneDatabaseForm {...defaultProps} />
59-
</MockedProvider>,
60-
);
61-
62-
await waitForQueryLoaders();
63-
64-
expect(
65-
screen.getByText("Clone a remote Dolt database from DoltHub"),
66-
).toBeInTheDocument();
67-
expect(screen.getByRole("checkbox")).not.toBeChecked();
68-
expect(screen.queryByText("Owner Name")).not.toBeInTheDocument();
69-
});
70-
71-
it("renders form fields when cloneDolt is true", async () => {
72-
setup(
73-
<MockedProvider mocks={[mocks.currentConnectionMock]}>
74-
<CloneDatabaseForm {...defaultProps} cloneDolt />
75-
</MockedProvider>,
76-
);
77-
78-
await waitForQueryLoaders();
79-
80-
expect(
81-
screen.getByText("Clone a remote Dolt database from DoltHub"),
82-
).toBeInTheDocument();
83-
expect(screen.getByRole("checkbox")).toBeChecked();
84-
expect(screen.getByText("Owner Name")).toBeInTheDocument();
85-
expect(screen.getByText("Remote Database Name")).toBeInTheDocument();
86-
expect(screen.getByText("New Database Name")).toBeInTheDocument();
87-
});
88-
89-
it("toggles checkbox and calls setCloneDolt", async () => {
90-
const mockSetCloneDolt = jest.fn();
91-
const { user } = setup(
92-
<MockedProvider mocks={[mocks.currentConnectionMock]}>
93-
<CloneDatabaseForm
94-
{...defaultProps}
95-
setCloneDolt={mockSetCloneDolt}
96-
cloneDolt={false}
97-
/>
98-
</MockedProvider>,
99-
);
100-
101-
await waitForQueryLoaders();
102-
103-
const checkbox = screen.getByRole("checkbox");
104-
await user.click(checkbox);
105-
106-
expect(mockSetCloneDolt).toHaveBeenCalledWith(true);
107-
});
108-
10950
it("shows disabled submit button when fields are empty", async () => {
11051
setup(
11152
<MockedProvider mocks={[mocks.currentConnectionMock]}>
112-
<CloneDatabaseForm {...defaultProps} cloneDolt />
53+
<CloneDatabaseForm />
11354
</MockedProvider>,
11455
);
11556

@@ -122,7 +63,7 @@ describe("tests CloneDatabaseForm", () => {
12263
it("enables submit button when all fields are filled", async () => {
12364
const { user } = setup(
12465
<MockedProvider mocks={[mocks.currentConnectionMock]}>
125-
<CloneDatabaseForm {...defaultProps} cloneDolt />
66+
<CloneDatabaseForm />
12667
</MockedProvider>,
12768
);
12869

@@ -142,7 +83,7 @@ describe("tests CloneDatabaseForm", () => {
14283
it("auto-fills new database name when remote database name changes", async () => {
14384
const { user } = setup(
14485
<MockedProvider mocks={[mocks.currentConnectionMock]}>
145-
<CloneDatabaseForm {...defaultProps} cloneDolt />
86+
<CloneDatabaseForm />
14687
</MockedProvider>,
14788
);
14889

@@ -162,7 +103,7 @@ describe("tests CloneDatabaseForm", () => {
162103
<MockedProvider
163104
mocks={[mocks.currentConnectionMock, mocks.doltCloneMock]}
164105
>
165-
<CloneDatabaseForm {...defaultProps} cloneDolt />
106+
<CloneDatabaseForm />
166107
</MockedProvider>,
167108
);
168109

@@ -194,7 +135,7 @@ describe("tests CloneDatabaseForm", () => {
194135
it("shows tooltip when button is disabled", async () => {
195136
const { user } = setup(
196137
<MockedProvider mocks={[mocks.currentConnectionMock]}>
197-
<CloneDatabaseForm {...defaultProps} cloneDolt />
138+
<CloneDatabaseForm />
198139
</MockedProvider>,
199140
);
200141

@@ -207,15 +148,15 @@ describe("tests CloneDatabaseForm", () => {
207148

208149
await waitFor(() => {
209150
expect(
210-
screen.getByText("Database name is required."),
151+
screen.getByText("Remote database name is required."),
211152
).toBeInTheDocument();
212153
});
213154
});
214155

215156
it("shows owner required tooltip when only database is filled", async () => {
216157
const { user } = setup(
217158
<MockedProvider mocks={[mocks.currentConnectionMock]}>
218-
<CloneDatabaseForm {...defaultProps} cloneDolt />
159+
<CloneDatabaseForm />
219160
</MockedProvider>,
220161
);
221162

web/renderer/components/CloneDatabaseForm/index.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,15 @@ import { ErrorMsg, QueryHandler } from "@dolthub/react-components";
22
import { useCurrentConnectionQuery } from "@gen/graphql-types";
33
import CloneDetails from "./CloneDetails";
44

5-
type Props = {
6-
cloneDolt: boolean;
7-
setCloneDolt: (c: boolean) => void;
8-
};
9-
10-
export default function CloneDatabaseForm(props: Props) {
5+
export default function CloneDatabaseForm() {
116
const res = useCurrentConnectionQuery();
127

138
return (
149
<QueryHandler
1510
result={res}
1611
render={data =>
1712
data.currentConnection ? (
18-
<CloneDetails {...props} currentConnection={data.currentConnection} />
13+
<CloneDetails currentConnection={data.currentConnection} />
1914
) : (
2015
<ErrorMsg errString="Could not find current connection." />
2116
)

web/renderer/components/CreateDatabase/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export default function CreateDatabase(props: Props) {
5555
<Button.Link
5656
onClick={() => setIsOpen(true)}
5757
className={cx(css.createDB, props.buttonClassName)}
58+
data-cy="add-database-button"
5859
>
5960
{props.showText ? (
6061
<span className={css.text}>Create Database</span>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.radios {
2+
@apply mb-6;
3+
}

0 commit comments

Comments
 (0)