Skip to content

Commit 4ffe5b4

Browse files
committed
feat: cover SOQL Builder UI with a warning message when there is no default org
1 parent fd37e31 commit 4ffe5b4

7 files changed

Lines changed: 65 additions & 7 deletions

File tree

packages/salesforcedx-vscode-soql/src/editor/soqlEditorInstance.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ type MessageType =
7474
| 'text_soql_changed'
7575
| 'run_query'
7676
| 'connection_changed'
77-
| 'run_query_done';
77+
| 'run_query_done'
78+
| 'no_default_org';
7879

7980
export class SOQLEditorInstance {
8081
public subscriptions: vscode.Disposable[] = [];
@@ -115,6 +116,8 @@ export class SOQLEditorInstance {
115116
this.subscriptions.push({ dispose: () => Effect.runFork(Fiber.interrupt(messageFiber)) });
116117

117118
const { onConnectionChanged } = this;
119+
// eslint-disable-next-line @typescript-eslint/no-this-alias
120+
const self = this;
118121
const connectionFiber = getSoqlRuntime().runFork(
119122
Effect.gen(function* () {
120123
const api = yield* (yield* ExtensionProviderService).getServicesApi;
@@ -123,7 +126,9 @@ export class SOQLEditorInstance {
123126
Stream.tap(org => Effect.sync(() => console.log(`Target org changed to ${org.orgId ?? '<NOT SET>'}`))),
124127
Stream.map(org => org.orgId),
125128
Stream.changes,
126-
Stream.runForEach(() => onConnectionChanged())
129+
Stream.runForEach(orgId =>
130+
orgId ? onConnectionChanged() : self.sendMessageToUi('no_default_org')
131+
)
127132
);
128133
})
129134
);
@@ -176,8 +181,16 @@ export class SOQLEditorInstance {
176181

177182
private handleMessageEffect = (event: SoqlEditorEvent) => {
178183
switch (event.type) {
179-
case 'ui_activated':
180-
return this.updateWebview(this.document).pipe(Effect.withSpan('SOQLEditor.ui_activated'));
184+
case 'ui_activated': {
185+
const self = this;
186+
return Effect.gen(function* () {
187+
const isOrgSet = yield* Effect.promise(() => isDefaultOrgSet());
188+
if (!isOrgSet) {
189+
yield* self.sendMessageToUi('no_default_org');
190+
}
191+
yield* self.updateWebview(self.document);
192+
}).pipe(Effect.withSpan('SOQLEditor.ui_activated'));
193+
}
181194

182195
case 'ui_soql_changed': {
183196
const soql = event.payload;

packages/salesforcedx-vscode-soql/src/soql-builder-ui/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
--soql-foreground: #080707;
4141
--soql-white: #ffffff;
4242
--soql-red: #c23934;
43+
--soql-purple: #6a0dad;
4344
--soql-error-background: #fffacd;
4445
}
4546
</style>

packages/salesforcedx-vscode-soql/src/soql-builder-ui/modules/querybuilder/app/app.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,16 @@ main {
5858
.warning-notification__dismiss {
5959
text-align: right;
6060
}
61+
62+
.info-notification {
63+
max-width: var(--soql-media-max-width);
64+
}
65+
66+
.info-notification__message {
67+
background-color: var(--soql-purple);
68+
color: var(--soql-white);
69+
font-size: small;
70+
padding: 1rem;
71+
border-radius: 3px;
72+
margin-bottom: 1rem;
73+
}

packages/salesforcedx-vscode-soql/src/soql-builder-ui/modules/querybuilder/app/app.html

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,17 @@
1717
</header>
1818
<article class="querybuilder-body">
1919
<section class="querybuilder-form">
20-
<template if:false={shouldBlockQueryBuilder}>
20+
<template if:true={showNoDefaultOrgNotification}>
21+
<div class="info-notification">
22+
<div class="info-notification__message">
23+
<!-- TODO: i18n -->
24+
No default org found. Set a default org to use SOQL Builder. Run
25+
"SFDX: Create a Default Scratch Org" or "SFDX: Authorize an Org"
26+
to set one.
27+
</div>
28+
</div>
29+
</template>
30+
<template if:true={showQueryBuilderForm}>
2131
<querybuilder-from
2232
onfrom__object_selected={handleObjectChange}
2333
sobjects={sObjects}
@@ -63,7 +73,7 @@
6373
class={theme}
6474
></querybuilder-limit>
6575
</template>
66-
<template if:true={shouldBlockQueryBuilder}>
76+
<template if:true={showBlockedQueryBuilder}>
6777
<div class="warning-notification">
6878
<div class="warning-notification__message">
6979
<template if:true={showUnsupportedNotification}>

packages/salesforcedx-vscode-soql/src/soql-builder-ui/modules/querybuilder/app/app.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ export default class App extends LightningElement {
5555
public get showSyntaxErrorNotification(): boolean {
5656
return this.hasUnrecoverableError;
5757
}
58+
public get showNoDefaultOrgNotification(): boolean {
59+
return this.hasNoDefaultOrg;
60+
}
61+
public get showBlockedQueryBuilder(): boolean {
62+
return !this.hasNoDefaultOrg && this.shouldBlockQueryBuilder;
63+
}
64+
public get showQueryBuilderForm(): boolean {
65+
return !this.hasNoDefaultOrg && !this.shouldBlockQueryBuilder;
66+
}
67+
public hasNoDefaultOrg = false;
5868
public hasUnsupportedMessage = false;
5969
public hasRecoverableFieldsError = false;
6070
public hasRecoverableFromError = false;
@@ -95,6 +105,10 @@ export default class App extends LightningElement {
95105
this.toolingSDK.queryRunState.subscribe(() => {
96106
this.isQueryRunning = false;
97107
});
108+
109+
this.toolingSDK.noDefaultOrg.subscribe((hasNoDefaultOrg: boolean) => {
110+
this.hasNoDefaultOrg = hasNoDefaultOrg;
111+
});
98112
this.loadSObjectDefinitions();
99113
this.modelService.restoreViewState();
100114
}

packages/salesforcedx-vscode-soql/src/soql-builder-ui/modules/querybuilder/services/message/soqlEditorEvent.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ export enum MessageType {
1212
TEXT_SOQL_CHANGED = 'text_soql_changed',
1313
RUN_SOQL_QUERY = 'run_query',
1414
CONNECTION_CHANGED = 'connection_changed',
15-
RUN_SOQL_QUERY_DONE = 'run_query_done'
15+
RUN_SOQL_QUERY_DONE = 'run_query_done',
16+
NO_DEFAULT_ORG = 'no_default_org'
1617
}
1718

1819
export type SoqlEditorEvent = {

packages/salesforcedx-vscode-soql/src/soql-builder-ui/modules/querybuilder/services/toolingSDK.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export class ToolingSDK {
1919
public queryRunState: Observable<boolean> = new BehaviorSubject<boolean>(
2020
false
2121
);
22+
public noDefaultOrg: Observable<boolean> = new BehaviorSubject<boolean>(false);
2223
private messageService: IMessageService;
2324
private latestSObjectName?: string;
2425

@@ -51,12 +52,17 @@ export class ToolingSDK {
5152
break;
5253
}
5354
case MessageType.CONNECTION_CHANGED: {
55+
this.noDefaultOrg.next(false);
5456
this.loadSObjectDefinitions();
5557
if (this.latestSObjectName) {
5658
this.loadSObjectMetatada(this.latestSObjectName);
5759
}
5860
break;
5961
}
62+
case MessageType.NO_DEFAULT_ORG: {
63+
this.noDefaultOrg.next(true);
64+
break;
65+
}
6066
case MessageType.RUN_SOQL_QUERY_DONE: {
6167
this.queryRunState.next(false);
6268
break;

0 commit comments

Comments
 (0)