-
-
Notifications
You must be signed in to change notification settings - Fork 289
/
SidebarColumn.ts
63 lines (63 loc) · 2.26 KB
/
SidebarColumn.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { EXT_NAME } from '@sqltools/core/constants';
import { ExtensionContext, TreeItemCollapsibleState } from 'vscode';
import { DatabaseInterface } from '@sqltools/core/plugin-api';
import SidebarAbstractItem from './SidebarAbstractItem';
export default class SidebarColumn extends SidebarAbstractItem<null> {
static icons;
public contextValue = 'connection.column';
public value: string;
public get items(): null { return null; }
public addItem(_: never): never {
throw new Error('Cannot add items to table column');
}
public get description() {
let typeSize = '';
if (typeof this.column.size !== 'undefined' && this.column.size !== null) {
typeSize = `(${this.column.size})`;
}
return `${(this.column.type || '').toUpperCase()}${typeSize}`;
}
public get conn() { return this.parent.conn; }
constructor(context: ExtensionContext, public column: DatabaseInterface.TableColumn) {
super(column.columnName, TreeItemCollapsibleState.None);
this.value = column.columnName;
if (!SidebarColumn.icons) {
SidebarColumn.icons = {
default: {
dark: context.asAbsolutePath('icons/column-dark.svg'),
light: context.asAbsolutePath('icons/column-light.svg'),
},
primaryKey: {
dark: context.asAbsolutePath('icons/pk-dark.svg'),
light: context.asAbsolutePath('icons/pk-lightk.svg'),
},
foreignKey: {
dark: context.asAbsolutePath('icons/fk-dark.svg'),
light: context.asAbsolutePath('icons/fk-light.svg'),
},
partitionKey: {
dark: context.asAbsolutePath('icons/partition-key-dark.svg'),
light: context.asAbsolutePath('icons/partition-key-light.svg'),
},
};
}
this.updateIconPath();
this.command = {
title: 'Append to Cursor',
command: `${EXT_NAME}.insertText`,
arguments: [`\${1:${column.columnName}}$0`],
};
}
public updateIconPath() {
this.iconPath = SidebarColumn.icons.default;
if (this.column.isPartitionKey) {
this.iconPath = SidebarColumn.icons.partitionKey;
}
else if (this.column.isPk) {
this.iconPath = SidebarColumn.icons.primaryKey;
}
else if (this.column.isFk) {
this.iconPath = SidebarColumn.icons.foreignKey;
}
}
}