Skip to content

Commit 863162f

Browse files
Add decoration provider for decorating treeView items with modified status (#1035)
## Changes ![image](https://github.com/databricks/databricks-vscode/assets/88345179/867554b0-270a-4f6a-b5a1-70ffc56cf70b) ## Tests <!-- How is this tested? -->
1 parent 6f6fd6f commit 863162f

File tree

8 files changed

+124
-10
lines changed

8 files changed

+124
-10
lines changed

packages/databricks-vscode/src/configuration/ui/ClusterComponent.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
import {ConfigurationTreeItem} from "./types";
1111
import {Cluster} from "../../sdk-extensions";
1212
import {onError} from "../../utils/onErrorDecorator";
13-
import {LabelUtils} from "../../ui/bundle-resource-explorer/utils";
13+
import {DecorationUtils} from "../../ui/bundle-resource-explorer/utils";
1414

1515
const TREE_ICON_ID = "CLUSTER";
1616
function getContextValue(key: string) {
@@ -120,13 +120,17 @@ export class ClusterComponent extends BaseComponent {
120120
const url = await cluster.url;
121121
return [
122122
{
123-
label: url
124-
? "Cluster"
125-
: LabelUtils.addModifiedTag("Cluster", "created"),
123+
label: "Cluster",
126124
tooltip: url ? undefined : "Created after deploy",
127125
description: cluster.name,
128126
collapsibleState: TreeItemCollapsibleState.Expanded,
129127
contextValue: url ? `${contextValue}.has-url` : contextValue,
128+
resourceUri: url
129+
? undefined
130+
: DecorationUtils.getModifiedStatusDecoration(
131+
TREE_ICON_ID,
132+
"created"
133+
),
130134
iconPath: icon,
131135
id: TREE_ICON_ID,
132136
url,

packages/databricks-vscode/src/configuration/ui/SyncDestinationComponent.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {ConnectionManager} from "../ConnectionManager";
55
import {BaseComponent} from "./BaseComponent";
66
import {ConfigurationTreeItem} from "./types";
77
import {TreeItemCollapsibleState, ThemeIcon, ThemeColor} from "vscode";
8-
import {LabelUtils} from "../../ui/bundle-resource-explorer/utils";
8+
import {DecorationUtils} from "../../ui/bundle-resource-explorer/utils";
99

1010
const TREE_ICON_ID = "WORKSPACE";
1111
function getContextValue(key: string) {
@@ -101,14 +101,18 @@ export class SyncDestinationComponent extends BaseComponent {
101101

102102
return [
103103
{
104-
label: url
105-
? "Sync"
106-
: LabelUtils.addModifiedTag("Sync", "created"),
104+
label: "Sync",
107105
tooltip: url ? undefined : "Created after deploy",
108106
description: posix.basename(posix.dirname(config)),
109107
collapsibleState: TreeItemCollapsibleState.Expanded,
110108
contextValue: url ? `${contextValue}.has-url` : contextValue,
111109
iconPath: icon,
110+
resourceUri: url
111+
? undefined
112+
: DecorationUtils.getModifiedStatusDecoration(
113+
TREE_ICON_ID,
114+
"created"
115+
),
112116
id: TREE_ICON_ID,
113117
url: url,
114118
},

packages/databricks-vscode/src/extension.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ import {BundleCommands} from "./ui/bundle-resource-explorer/BundleCommands";
6262
import {BundleRunTerminalManager} from "./bundle/run/BundleRunTerminalManager";
6363
import {BundleRunStatusManager} from "./bundle/run/BundleRunStatusManager";
6464
import {BundleProjectManager} from "./bundle/BundleProjectManager";
65+
import {TreeItemDecorationProvider} from "./ui/bundle-resource-explorer/DecorationProvider";
6566
import {BundleInitWizard} from "./bundle/BundleInitWizard";
6667

6768
const customWhenContext = new CustomWhenContext();
@@ -550,10 +551,16 @@ export async function activate(
550551
bundleRunStatusManager,
551552
bundleValidateModel
552553
);
554+
const decorationProvider = new TreeItemDecorationProvider(
555+
bundleResourceExplorerTreeDataProvider,
556+
configurationDataProvider
557+
);
553558
context.subscriptions.push(
554559
bundleResourceExplorerTreeDataProvider,
555560
bundleCommands,
556561
bundleRunTerminalManager,
562+
decorationProvider,
563+
window.registerFileDecorationProvider(decorationProvider),
557564
window.registerTreeDataProvider(
558565
"dabsResourceExplorerView",
559566
bundleResourceExplorerTreeDataProvider
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import {
2+
Event,
3+
FileDecoration,
4+
FileDecorationProvider,
5+
ProviderResult,
6+
Uri,
7+
EventEmitter,
8+
Disposable,
9+
} from "vscode";
10+
import {BundleResourceExplorerTreeDataProvider} from "./BundleResourceExplorerTreeDataProvider";
11+
import {ConfigurationDataProvider} from "../../configuration/ui/ConfigurationDataProvider";
12+
13+
const SCHEME = "databricks-view-item";
14+
export class TreeItemDecorationProvider implements FileDecorationProvider {
15+
private readonly disposables: Disposable[] = [];
16+
private onDidChangeFileDecorationsEmitter: EventEmitter<
17+
Uri | Uri[] | undefined
18+
> = new EventEmitter();
19+
onDidChangeFileDecorations: Event<Uri | Uri[] | undefined> =
20+
this.onDidChangeFileDecorationsEmitter.event;
21+
constructor(
22+
private readonly bundleResourceExplorerTreeDataProvider: BundleResourceExplorerTreeDataProvider,
23+
private readonly configrationViewTreeDataProvider: ConfigurationDataProvider
24+
) {
25+
this.disposables.push(
26+
this.bundleResourceExplorerTreeDataProvider.onDidChangeTreeData(
27+
() => {
28+
this.onDidChangeFileDecorationsEmitter.fire(undefined);
29+
}
30+
),
31+
this.configrationViewTreeDataProvider.onDidChangeTreeData(() => {
32+
this.onDidChangeFileDecorationsEmitter.fire(undefined);
33+
})
34+
);
35+
}
36+
37+
provideFileDecoration(uri: Uri): ProviderResult<FileDecoration> {
38+
if (uri.scheme !== SCHEME) {
39+
return undefined;
40+
}
41+
return uri.query
42+
? (JSON.parse(uri.query) as FileDecoration)
43+
: undefined;
44+
}
45+
46+
dispose() {
47+
this.disposables.forEach((d) => d.dispose());
48+
}
49+
}
50+
51+
export function asDecorationResourceUri(id: string, data: FileDecoration) {
52+
return Uri.from({
53+
scheme: SCHEME,
54+
authority: id,
55+
query: JSON.stringify(data),
56+
});
57+
}

packages/databricks-vscode/src/ui/bundle-resource-explorer/JobTreeNode.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
BundleResourceExplorerTreeNode,
77
} from "./types";
88
import {BundleRunStatusManager} from "../../bundle/run/BundleRunStatusManager";
9-
import {ContextUtils} from "./utils";
9+
import {ContextUtils, DecorationUtils} from "./utils";
1010
import {ConnectionManager} from "../../configuration/ConnectionManager";
1111
import {JobRunStatusTreeNode} from "./JobRunStatusTreeNode";
1212
import {JobRunStatus} from "../../bundle/run/JobRunStatus";
@@ -50,6 +50,10 @@ export class JobTreeNode implements BundleResourceExplorerTreeNode {
5050
hasUrl: this.url !== undefined,
5151
nodeType: this.type,
5252
}),
53+
resourceUri: DecorationUtils.getModifiedStatusDecoration(
54+
this.resourceKey,
55+
this.data.modified_status
56+
),
5357
collapsibleState: isRunning
5458
? TreeItemCollapsibleState.Collapsed
5559
: TreeItemCollapsibleState.Expanded,

packages/databricks-vscode/src/ui/bundle-resource-explorer/PipelineTreeNode.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
BundleResourceExplorerTreeNode,
77
} from "./types";
88
import {BundleRunStatusManager} from "../../bundle/run/BundleRunStatusManager";
9-
import {ContextUtils} from "./utils";
9+
import {ContextUtils, DecorationUtils} from "./utils";
1010
import {ConnectionManager} from "../../configuration/ConnectionManager";
1111
import {PipelineRunStatus} from "../../bundle/run/PipelineRunStatus";
1212
import {TreeItemTreeNode} from "./TreeItemTreeNode";
@@ -48,6 +48,10 @@ export class PipelineTreeNode implements BundleResourceExplorerTreeNode {
4848
hasUrl: this.url !== undefined,
4949
nodeType: this.type,
5050
}),
51+
resourceUri: DecorationUtils.getModifiedStatusDecoration(
52+
this.resourceKey,
53+
this.data.modified_status
54+
),
5155
collapsibleState: isRunning
5256
? TreeItemCollapsibleState.Expanded
5357
: TreeItemCollapsibleState.Collapsed,
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import {BundleResourceModifiedStatus} from "../../../bundle/models/BundleRemoteStateModel";
2+
import {asDecorationResourceUri} from "../DecorationProvider";
3+
import {ThemeColor} from "vscode";
4+
5+
export function getModifiedStatusDecoration(
6+
id: string,
7+
modifiedStatus?: BundleResourceModifiedStatus
8+
) {
9+
switch (modifiedStatus) {
10+
case "created":
11+
return asDecorationResourceUri(id, {
12+
badge: "C",
13+
color: new ThemeColor("gitDecoration.addedResourceForeground"),
14+
tooltip: "Created after deploy",
15+
});
16+
case "deleted":
17+
return asDecorationResourceUri(id, {
18+
badge: "D",
19+
color: new ThemeColor(
20+
"gitDecoration.deletedResourceForeground"
21+
),
22+
tooltip: "Deleted after deploy",
23+
});
24+
case "updated":
25+
return asDecorationResourceUri(id, {
26+
badge: "U",
27+
color: new ThemeColor(
28+
"gitDecoration.modifiedResourceForeground"
29+
),
30+
tooltip: "Updated after deploy",
31+
});
32+
}
33+
}

packages/databricks-vscode/src/ui/bundle-resource-explorer/utils/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export * as JobRunStateUtils from "./JobRunStateUtils";
22
export * as RunStateUtils from "./RunStateUtils";
33
export * as ContextUtils from "./ContextUtils";
44
export * as LabelUtils from "./LabelUtils";
5+
export * as DecorationUtils from "./DecorationUtils";

0 commit comments

Comments
 (0)