1
1
import { commands , window , ExtensionContext } from 'vscode' ;
2
- import { updateStatusBarItems } from '../statusBar' ;
3
- import { COMMANDS , TRACKED_EVENTS } from '../constants' ;
4
- import { getDisplayedHubspotPortalInfo } from '../helpers' ;
5
- import { portalNameInvalid } from '../validation' ;
6
- import { trackEvent } from '../tracking' ;
7
- import { showAutoDismissedStatusBarMessage } from '../messaging' ;
8
2
import {
9
3
getConfig ,
10
4
deleteAccount ,
@@ -15,7 +9,17 @@ import {
15
9
getConfigAccounts ,
16
10
} from '@hubspot/local-dev-lib/config' ;
17
11
import { CLIConfig } from '@hubspot/local-dev-lib/types/Config' ;
18
- import { CLIAccount_DEPRECATED } from '@hubspot/local-dev-lib/types/Accounts' ;
12
+ import {
13
+ CLIAccount ,
14
+ CLIAccount_DEPRECATED ,
15
+ } from '@hubspot/local-dev-lib/types/Accounts' ;
16
+ import { getAccountIdentifier } from '@hubspot/local-dev-lib/config/getAccountIdentifier' ;
17
+ import { updateStatusBarItems } from '../statusBar' ;
18
+ import { COMMANDS , TRACKED_EVENTS } from '../constants' ;
19
+ import { getDisplayedHubspotPortalInfo } from '../helpers' ;
20
+ import { portalNameInvalid } from '../validation' ;
21
+ import { trackEvent } from '../tracking' ;
22
+ import { showAutoDismissedStatusBarMessage } from '../messaging' ;
19
23
20
24
const showRenameAccountPrompt = ( accountToRename : CLIAccount_DEPRECATED ) => {
21
25
window
@@ -24,7 +28,8 @@ const showRenameAccountPrompt = (accountToRename: CLIAccount_DEPRECATED) => {
24
28
} )
25
29
. then ( async ( newName : string | undefined ) => {
26
30
if ( newName ) {
27
- const oldName = accountToRename . name || accountToRename . portalId ;
31
+ const oldName =
32
+ accountToRename . name || getAccountIdentifier ( accountToRename ) ;
28
33
const config : CLIConfig | null = getConfig ( ) ;
29
34
let invalidReason = '' ;
30
35
if ( config ) {
@@ -39,6 +44,7 @@ const showRenameAccountPrompt = (accountToRename: CLIAccount_DEPRECATED) => {
39
44
return ;
40
45
}
41
46
renameAccount ( String ( oldName ) , newName ) ;
47
+ commands . executeCommand ( COMMANDS . ACCOUNTS_REFRESH ) ;
42
48
showAutoDismissedStatusBarMessage (
43
49
`Successfully renamed default account from ${ oldName } to ${ newName } .`
44
50
) ;
@@ -66,7 +72,7 @@ export const registerCommands = (context: ExtensionContext) => {
66
72
typeof defaultAccount === 'string' ||
67
73
typeof defaultAccount === 'number'
68
74
? defaultAccount
69
- : defaultAccount . name || defaultAccount . portalId ;
75
+ : defaultAccount . name || getAccountIdentifier ( defaultAccount ) ;
70
76
console . log ( 'Setting default account to: ' , newDefaultAccount ) ;
71
77
updateDefaultAccount ( newDefaultAccount ) ;
72
78
await trackEvent ( TRACKED_EVENTS . UPDATE_DEFAULT_ACCOUNT ) ;
@@ -85,19 +91,20 @@ export const registerCommands = (context: ExtensionContext) => {
85
91
COMMANDS . CONFIG . SELECT_DEFAULT_ACCOUNT ,
86
92
async ( ) => {
87
93
const defaultAccount = getConfigDefaultAccount ( ) ;
88
- const portals : CLIAccount_DEPRECATED [ ] = getConfigAccounts ( ) || [ ] ;
94
+ const accounts : CLIAccount [ ] = getConfigAccounts ( ) || [ ] ;
89
95
90
- if ( portals && portals . length !== 0 ) {
96
+ if ( accounts && accounts . length !== 0 ) {
91
97
window
92
98
. showQuickPick (
93
- portals . map ( ( p : CLIAccount_DEPRECATED ) => {
99
+ accounts . map ( ( a : CLIAccount ) => {
94
100
return {
95
- label : getDisplayedHubspotPortalInfo ( p ) ,
101
+ label : getDisplayedHubspotPortalInfo ( a ) ,
96
102
description :
97
- defaultAccount === p . portalId || defaultAccount === p . name
103
+ defaultAccount === getAccountIdentifier ( a ) ||
104
+ defaultAccount === a . name
98
105
? '(default)'
99
106
: '' ,
100
- portal : p ,
107
+ account : a ,
101
108
} ;
102
109
} ) ,
103
110
{
@@ -107,7 +114,8 @@ export const registerCommands = (context: ExtensionContext) => {
107
114
. then ( async ( selection ) => {
108
115
if ( selection ) {
109
116
const newDefaultAccount =
110
- selection . portal . name || selection . portal . portalId ;
117
+ selection . account . name ||
118
+ getAccountIdentifier ( selection . account ) ;
111
119
if ( ! newDefaultAccount ) {
112
120
window . showErrorMessage (
113
121
'No account selected; Choose an account to set as default'
@@ -140,9 +148,9 @@ export const registerCommands = (context: ExtensionContext) => {
140
148
commands . registerCommand (
141
149
COMMANDS . CONFIG . DELETE_ACCOUNT ,
142
150
async ( accountToDelete ) => {
143
- const portals : CLIAccount_DEPRECATED [ ] = getConfigAccounts ( ) || [ ] ;
151
+ const accounts : CLIAccount [ ] = getConfigAccounts ( ) || [ ] ;
144
152
const accountIdentifier =
145
- accountToDelete . name || accountToDelete . portalId ;
153
+ accountToDelete . name || getAccountIdentifier ( accountToDelete ) ;
146
154
147
155
await window
148
156
. showInformationMessage (
@@ -152,7 +160,7 @@ export const registerCommands = (context: ExtensionContext) => {
152
160
)
153
161
. then ( async ( answer ) => {
154
162
if ( answer === 'Yes' ) {
155
- if ( portals && portals . length === 1 ) {
163
+ if ( accounts && accounts . length === 1 ) {
156
164
deleteConfigFile ( ) ;
157
165
showAutoDismissedStatusBarMessage (
158
166
`Successfully deleted account ${ accountIdentifier } . The config file has been deleted because there are no more authenticated accounts.`
@@ -165,6 +173,7 @@ export const registerCommands = (context: ExtensionContext) => {
165
173
}
166
174
await trackEvent ( TRACKED_EVENTS . DELETE_ACCOUNT ) ;
167
175
commands . executeCommand ( COMMANDS . REMOTE_FS . HARD_REFRESH ) ;
176
+ commands . executeCommand ( COMMANDS . ACCOUNTS_REFRESH ) ;
168
177
updateStatusBarItems ( ) ;
169
178
}
170
179
} ) ;
0 commit comments