Skip to content

Commit d7fae74

Browse files
authored
Merge pull request #1990 from github/charisk/disable-local-dbs
Turn off support for local dbs and remote root 'remote' node from new db panel
2 parents 8a6b361 + 526c4f3 commit d7fae74

14 files changed

Lines changed: 87 additions & 337 deletions

File tree

extensions/ql-vscode/databases-schema.json

Lines changed: 1 addition & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -48,120 +48,14 @@
4848
},
4949
"required": ["repositoryLists", "owners", "repositories"],
5050
"additionalProperties": false
51-
},
52-
"local": {
53-
"type": "object",
54-
"properties": {
55-
"lists": {
56-
"type": "array",
57-
"items": {
58-
"type": "object",
59-
"properties": {
60-
"name": {
61-
"type": "string"
62-
},
63-
"databases": {
64-
"type": "array",
65-
"items": {
66-
"type": "object",
67-
"properties": {
68-
"name": {
69-
"type": "string",
70-
"minLength": 1
71-
},
72-
"dateAdded": {
73-
"type": "number"
74-
},
75-
"language": {
76-
"type": "string",
77-
"minLength": 1
78-
},
79-
"storagePath": {
80-
"type": "string",
81-
"minLength": 1
82-
}
83-
},
84-
"required": [
85-
"name",
86-
"dateAdded",
87-
"language",
88-
"storagePath"
89-
],
90-
"additionalProperties": false
91-
}
92-
}
93-
},
94-
"required": ["name", "databases"],
95-
"additionalProperties": false
96-
}
97-
},
98-
"databases": {
99-
"type": "array",
100-
"items": {
101-
"type": "object",
102-
"properties": {
103-
"name": {
104-
"type": "string",
105-
"minLength": 1
106-
},
107-
"dateAdded": {
108-
"type": "number"
109-
},
110-
"language": {
111-
"type": "string",
112-
"minLength": 1
113-
},
114-
"storagePath": {
115-
"type": "string",
116-
"minLength": 1
117-
}
118-
},
119-
"required": ["name", "dateAdded", "language", "storagePath"],
120-
"additionalProperties": false
121-
}
122-
}
123-
},
124-
"required": ["lists", "databases"],
125-
"additionalProperties": false
12651
}
12752
},
128-
"required": ["variantAnalysis", "local"],
53+
"required": ["variantAnalysis"],
12954
"additionalProperties": false
13055
},
13156
"selected": {
13257
"type": "object",
13358
"oneOf": [
134-
{
135-
"properties": {
136-
"kind": {
137-
"type": "string",
138-
"enum": ["localUserDefinedList"]
139-
},
140-
"listName": {
141-
"type": "string",
142-
"minLength": 1
143-
}
144-
},
145-
"required": ["kind", "listName"],
146-
"additionalProperties": false
147-
},
148-
{
149-
"properties": {
150-
"kind": {
151-
"type": "string",
152-
"enum": ["localDatabase"]
153-
},
154-
"databaseName": {
155-
"type": "string"
156-
},
157-
"listName": {
158-
"type": "string",
159-
"minLength": 1
160-
}
161-
},
162-
"required": ["kind", "databaseName"],
163-
"additionalProperties": false
164-
},
16559
{
16660
"properties": {
16761
"kind": {

extensions/ql-vscode/src/databases/config/db-config-store.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { pathExists, outputJSON, readJSON, readJSONSync } from "fs-extra";
22
import { join } from "path";
33
import {
4+
clearLocalDbConfig,
45
cloneDbConfig,
56
DbConfig,
7+
initializeLocalDbConfig,
68
removeLocalDb,
79
removeLocalList,
810
removeRemoteList,
@@ -349,6 +351,7 @@ export class DbConfigStore extends DisposableObject {
349351
}
350352

351353
private async writeConfig(config: DbConfig): Promise<void> {
354+
clearLocalDbConfig(config);
352355
await outputJSON(this.configPath, config, {
353356
spaces: 2,
354357
});
@@ -380,6 +383,7 @@ export class DbConfigStore extends DisposableObject {
380383
}
381384

382385
if (newConfig) {
386+
initializeLocalDbConfig(newConfig);
383387
this.configErrors = this.configValidator.validate(newConfig);
384388
}
385389

@@ -414,6 +418,7 @@ export class DbConfigStore extends DisposableObject {
414418
}
415419

416420
if (newConfig) {
421+
initializeLocalDbConfig(newConfig);
417422
this.configErrors = this.configValidator.validate(newConfig);
418423
}
419424

extensions/ql-vscode/src/databases/config/db-config-validator.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { readJsonSync } from "fs-extra";
22
import { resolve } from "path";
33
import Ajv from "ajv";
4-
import { DbConfig } from "./db-config";
4+
import { clearLocalDbConfig, DbConfig } from "./db-config";
55
import { findDuplicateStrings } from "../../text-utils";
66
import {
77
DbConfigValidationError,
@@ -18,6 +18,9 @@ export class DbConfigValidator {
1818

1919
public validate(dbConfig: DbConfig): DbConfigValidationError[] {
2020
const ajv = new Ajv({ allErrors: true });
21+
22+
const localDbs = clearLocalDbConfig(dbConfig);
23+
2124
ajv.validate(this.schema, dbConfig);
2225

2326
if (ajv.errors) {
@@ -27,6 +30,13 @@ export class DbConfigValidator {
2730
}));
2831
}
2932

33+
// Add any local db config back so that we have a config
34+
// object that respects its type and validation can happen
35+
// as normal.
36+
if (localDbs) {
37+
dbConfig.databases.local = localDbs;
38+
}
39+
3040
return [
3141
...this.validateDbListNames(dbConfig),
3242
...this.validateDbNames(dbConfig),

extensions/ql-vscode/src/databases/config/db-config.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,38 @@ export function removeRemoteOwner(
325325
return config;
326326
}
327327

328+
/**
329+
* Removes local db config from a db config object, if one is set.
330+
* We do this because we don't want to expose this feature to users
331+
* yet (since it's only partially implemented), but we also don't want
332+
* to remove all the code we've already implemented.
333+
* @param config The config object to change.
334+
* @returns Any removed local db config.
335+
*/
336+
export function clearLocalDbConfig(
337+
config: DbConfig,
338+
): LocalDbConfig | undefined {
339+
let localDbs = undefined;
340+
341+
if (config && config.databases && config.databases.local) {
342+
localDbs = config.databases.local;
343+
delete (config.databases as any).local;
344+
}
345+
346+
return localDbs;
347+
}
348+
349+
/**
350+
* Initializes the local db config, if the config object contains
351+
* database configuration.
352+
* @param config The config object to change.
353+
*/
354+
export function initializeLocalDbConfig(config: DbConfig): void {
355+
if (config.databases) {
356+
config.databases.local = { lists: [], databases: [] };
357+
}
358+
}
359+
328360
function cloneDbConfigSelectedItem(selected: SelectedDbItem): SelectedDbItem {
329361
switch (selected.kind) {
330362
case SelectedDbItemKind.LocalUserDefinedList:

extensions/ql-vscode/src/databases/db-manager.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
getSelectedDbItem,
2121
mapDbItemToSelectedDbItem,
2222
} from "./db-item-selection";
23-
import { createLocalTree, createRemoteTree } from "./db-tree-creator";
23+
import { createRemoteTree } from "./db-tree-creator";
2424
import { DbConfigValidationError } from "./db-validation-errors";
2525

2626
export class DbManager {
@@ -58,10 +58,8 @@ export class DbManager {
5858

5959
const expandedItems = this.getExpandedItems();
6060

61-
return ValueResult.ok([
62-
createRemoteTree(configResult.value, expandedItems),
63-
createLocalTree(configResult.value, expandedItems),
64-
]);
61+
const remoteTree = createRemoteTree(configResult.value, expandedItems);
62+
return ValueResult.ok(remoteTree.children);
6563
}
6664

6765
public getConfigPath(): string {

extensions/ql-vscode/src/databases/ui/db-panel.ts

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import {
2222
DbListKind,
2323
LocalDatabaseDbItem,
2424
LocalListDbItem,
25-
remoteDbKinds,
2625
RemoteUserDefinedListDbItem,
2726
} from "../db-item";
2827
import { getDbItemName } from "../db-item-naming";
@@ -219,7 +218,7 @@ export class DbPanel extends DisposableObject {
219218
}
220219

221220
private async addNewList(): Promise<void> {
222-
const listKind = await this.getAddNewListKind();
221+
const listKind = DbListKind.Remote;
223222

224223
const listName = await window.showInputBox({
225224
prompt: "Enter a name for the new list",
@@ -237,47 +236,6 @@ export class DbPanel extends DisposableObject {
237236
await this.dbManager.addNewList(listKind, listName);
238237
}
239238

240-
private async getAddNewListKind(): Promise<DbListKind> {
241-
const highlightedItem = await this.getHighlightedDbItem();
242-
if (highlightedItem) {
243-
return remoteDbKinds.includes(highlightedItem.kind)
244-
? DbListKind.Remote
245-
: DbListKind.Local;
246-
} else {
247-
const quickPickItems = [
248-
{
249-
label: "$(cloud) Variant Analysis",
250-
detail: "Add a repository from GitHub",
251-
alwaysShow: true,
252-
kind: DbListKind.Remote,
253-
},
254-
{
255-
label: "$(database) Local",
256-
detail: "Import a database from the cloud or a local file",
257-
alwaysShow: true,
258-
kind: DbListKind.Local,
259-
},
260-
];
261-
const selectedOption = await window.showQuickPick<AddListQuickPickItem>(
262-
quickPickItems,
263-
{
264-
title: "Add a new database",
265-
ignoreFocusOut: true,
266-
},
267-
);
268-
if (!selectedOption) {
269-
// We don't need to display a warning pop-up in this case, since the user just escaped out of the operation.
270-
// We set 'true' to make this a silent exception.
271-
throw new UserCancellationException(
272-
"No database list kind selected",
273-
true,
274-
);
275-
}
276-
277-
return selectedOption.kind;
278-
}
279-
}
280-
281239
private async setSelectedItem(treeViewItem: DbTreeViewItem): Promise<void> {
282240
if (treeViewItem.dbItem === undefined) {
283241
throw new Error(

extensions/ql-vscode/test/unit-tests/databases/config/data/databases.json

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,40 +9,6 @@
99
],
1010
"owners": [],
1111
"repositories": ["owner/repo1", "owner/repo2", "owner/repo3"]
12-
},
13-
"local": {
14-
"lists": [
15-
{
16-
"name": "localList1",
17-
"databases": [
18-
{
19-
"name": "foo/bar",
20-
"dateAdded": 1668096745193,
21-
"language": "go",
22-
"storagePath": "/path/to/database/"
23-
}
24-
]
25-
},
26-
{
27-
"name": "localList2",
28-
"databases": [
29-
{
30-
"name": "foo/baz",
31-
"dateAdded": 1668096760848,
32-
"language": "javascript",
33-
"storagePath": "/path/to/database/"
34-
}
35-
]
36-
}
37-
],
38-
"databases": [
39-
{
40-
"name": "example-db",
41-
"dateAdded": 1668096927267,
42-
"language": "ruby",
43-
"storagePath": "/path/to/database/"
44-
}
45-
]
4612
}
4713
},
4814
"selected": {

extensions/ql-vscode/test/unit-tests/databases/config/data/without-selected/databases.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
"repositoryLists": [],
55
"owners": [],
66
"repositories": []
7-
},
8-
"local": {
9-
"lists": [],
10-
"databases": []
117
}
128
}
139
}

0 commit comments

Comments
 (0)