Skip to content

Commit da30ff2

Browse files
chore: hide unactivatable/deactivatble options, alphabetize
1 parent 35afe80 commit da30ff2

File tree

4 files changed

+91
-53
lines changed

4 files changed

+91
-53
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"@inquirer/prompts": "^7.10.1",
1313
"@oclif/core": "^4",
1414
"@oclif/multi-stage-output": "^0.8.29",
15-
"@salesforce/agents": "^0.24.1",
15+
"@salesforce/agents": "^0.24.2",
1616
"@salesforce/core": "^8.26.3",
1717
"@salesforce/kit": "^3.2.4",
1818
"@salesforce/sf-plugins-core": "^12.2.6",

src/agentActivation.ts

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,28 +50,24 @@ export const validateAgent = (agent: BotMetadata): boolean => {
5050
};
5151

5252
export const getAgentChoices = (agents: BotMetadata[], status: 'Active' | 'Inactive'): Array<Choice<AgentValue>> =>
53-
agents.map((agent) => {
54-
let disabled: string | boolean = false;
55-
56-
// For deactivate (status='Inactive'), check if any version is Active (can be deactivated)
57-
// For activate (status='Active'), check if any version is Inactive (can be activated)
58-
const hasAvailableVersion = agent.BotVersions.records.some((version) => version.Status !== status);
59-
if (!hasAvailableVersion) {
60-
disabled = `(Already ${status})`;
61-
}
62-
if (agentIsUnsupported(agent.DeveloperName)) {
63-
disabled = '(Not Supported)';
64-
}
65-
66-
return {
53+
agents
54+
.filter((agent) => {
55+
// Only one version can be active at a time
56+
// For activate (status='Active'): show agents that don't have an active version (all versions are inactive)
57+
// For deactivate (status='Inactive'): show agents that have an active version
58+
const hasActiveVersion = agent.BotVersions.records.some((version) => version.Status === 'Active');
59+
const canPerformOperation = status === 'Active' ? !hasActiveVersion : hasActiveVersion;
60+
// Filter out agents that can't perform the operation or are unsupported
61+
return canPerformOperation && !agentIsUnsupported(agent.DeveloperName);
62+
})
63+
.sort((a, b) => a.DeveloperName.localeCompare(b.DeveloperName))
64+
.map((agent) => ({
6765
name: agent.DeveloperName,
6866
value: {
6967
Id: agent.Id,
7068
DeveloperName: agent.DeveloperName,
7169
},
72-
disabled,
73-
};
74-
});
70+
}));
7571

7672
export const getVersionChoices = (
7773
versions: BotVersionMetadata[],

test/agentActivation.test.ts

Lines changed: 70 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,15 @@ describe('agentActivation', () => {
9191
});
9292

9393
describe('getAgentChoices', () => {
94-
it('should enable agent when ANY version is available for activation', () => {
94+
it('should filter out agent when any version is already active (for activation)', () => {
9595
const agents: BotMetadata[] = [
9696
{
9797
Id: 'agent1',
9898
DeveloperName: 'Test_Agent',
9999
BotVersions: {
100100
records: [
101101
{ Status: 'Active', VersionNumber: 1 } as BotVersionMetadata,
102-
{ Status: 'Inactive', VersionNumber: 2 } as BotVersionMetadata, // Can be activated
102+
{ Status: 'Inactive', VersionNumber: 2 } as BotVersionMetadata,
103103
{ Status: 'Inactive', VersionNumber: 3 } as BotVersionMetadata,
104104
],
105105
},
@@ -108,12 +108,10 @@ describe('agentActivation', () => {
108108

109109
const choices = getAgentChoices(agents, 'Active');
110110

111-
expect(choices).to.have.lengthOf(1);
112-
expect(choices[0].disabled).to.equal(false); // Has inactive versions that can be activated
113-
expect(choices[0].value.DeveloperName).to.equal('Test_Agent');
111+
expect(choices).to.have.lengthOf(0); // Filtered out because it already has an active version
114112
});
115113

116-
it('should enable agent when ANY version is available for deactivation', () => {
114+
it('should include agent when it has an active version (for deactivation)', () => {
117115
const agents: BotMetadata[] = [
118116
{
119117
Id: 'agent1',
@@ -131,31 +129,31 @@ describe('agentActivation', () => {
131129
const choices = getAgentChoices(agents, 'Inactive');
132130

133131
expect(choices).to.have.lengthOf(1);
134-
expect(choices[0].disabled).to.equal(false); // Has active version that can be deactivated
132+
expect(choices[0].value.DeveloperName).to.equal('Test_Agent');
135133
});
136134

137-
it('should disable agent when ALL versions are already in target state', () => {
135+
it('should include agent when all versions are inactive (for activation)', () => {
138136
const agents: BotMetadata[] = [
139137
{
140138
Id: 'agent1',
141139
DeveloperName: 'Test_Agent',
142140
BotVersions: {
143141
records: [
144-
{ Status: 'Active', VersionNumber: 1 } as BotVersionMetadata,
145-
{ Status: 'Active', VersionNumber: 2 } as BotVersionMetadata,
146-
{ Status: 'Active', VersionNumber: 3 } as BotVersionMetadata,
142+
{ Status: 'Inactive', VersionNumber: 1 } as BotVersionMetadata,
143+
{ Status: 'Inactive', VersionNumber: 2 } as BotVersionMetadata,
144+
{ Status: 'Inactive', VersionNumber: 3 } as BotVersionMetadata,
147145
],
148146
},
149147
} as BotMetadata,
150148
];
151149

152150
const choices = getAgentChoices(agents, 'Active');
153151

154-
expect(choices).to.have.lengthOf(1);
155-
expect(choices[0].disabled).to.equal('(Already Active)'); // All versions are already active
152+
expect(choices).to.have.lengthOf(1); // All versions are inactive, so can activate one
153+
expect(choices[0].value.DeveloperName).to.equal('Test_Agent');
156154
});
157155

158-
it('should disable agent when ALL versions are inactive for deactivation', () => {
156+
it('should filter out agent when all versions are inactive (for deactivation)', () => {
159157
const agents: BotMetadata[] = [
160158
{
161159
Id: 'agent1',
@@ -171,11 +169,10 @@ describe('agentActivation', () => {
171169

172170
const choices = getAgentChoices(agents, 'Inactive');
173171

174-
expect(choices).to.have.lengthOf(1);
175-
expect(choices[0].disabled).to.equal('(Already Inactive)'); // All versions are already inactive
172+
expect(choices).to.have.lengthOf(0); // All versions are already inactive, nothing to deactivate
176173
});
177174

178-
it('should disable unsupported agents', () => {
175+
it('should filter out unsupported agents', () => {
179176
const agents: BotMetadata[] = [
180177
{
181178
Id: 'agent1',
@@ -188,41 +185,86 @@ describe('agentActivation', () => {
188185

189186
const choices = getAgentChoices(agents, 'Active');
190187

191-
expect(choices).to.have.lengthOf(1);
192-
expect(choices[0].disabled).to.equal('(Not Supported)');
188+
expect(choices).to.have.lengthOf(0); // Unsupported agents are filtered out
193189
});
194190

195-
it('should handle multiple agents with mixed states', () => {
191+
it('should filter out unavailable agents and sort remaining alphabetically', () => {
196192
const agents: BotMetadata[] = [
197193
{
198194
Id: 'agent1',
199-
DeveloperName: 'Agent_All_Active',
195+
DeveloperName: 'Zebra_Agent',
200196
BotVersions: {
201197
records: [
202198
{ Status: 'Active', VersionNumber: 1 } as BotVersionMetadata,
203-
{ Status: 'Active', VersionNumber: 2 } as BotVersionMetadata,
199+
{ Status: 'Inactive', VersionNumber: 2 } as BotVersionMetadata,
204200
],
205201
},
206202
} as BotMetadata,
207203
{
208204
Id: 'agent2',
209-
DeveloperName: 'Agent_Mixed',
205+
DeveloperName: 'Beta_Agent',
210206
BotVersions: {
211207
records: [
212208
{ Status: 'Active', VersionNumber: 1 } as BotVersionMetadata,
213209
{ Status: 'Inactive', VersionNumber: 2 } as BotVersionMetadata,
214210
],
215211
},
216212
} as BotMetadata,
213+
{
214+
Id: 'agent3',
215+
DeveloperName: 'Alpha_Agent',
216+
BotVersions: {
217+
records: [
218+
{ Status: 'Inactive', VersionNumber: 1 } as BotVersionMetadata,
219+
{ Status: 'Inactive', VersionNumber: 2 } as BotVersionMetadata,
220+
],
221+
},
222+
} as BotMetadata,
217223
];
218224

219225
const choices = getAgentChoices(agents, 'Active');
220226

221-
expect(choices).to.have.lengthOf(2);
222-
expect(choices[0].value.DeveloperName).to.equal('Agent_All_Active');
223-
expect(choices[0].disabled).to.equal('(Already Active)');
224-
expect(choices[1].value.DeveloperName).to.equal('Agent_Mixed');
225-
expect(choices[1].disabled).to.equal(false);
227+
expect(choices).to.have.lengthOf(1); // Only Alpha_Agent has no active version (all inactive)
228+
expect(choices[0].value.DeveloperName).to.equal('Alpha_Agent');
229+
});
230+
231+
it('should sort multiple available agents alphabetically', () => {
232+
const agents: BotMetadata[] = [
233+
{
234+
Id: 'agent1',
235+
DeveloperName: 'Zebra_Agent',
236+
BotVersions: {
237+
records: [
238+
{ Status: 'Inactive', VersionNumber: 1 } as BotVersionMetadata,
239+
{ Status: 'Inactive', VersionNumber: 2 } as BotVersionMetadata,
240+
],
241+
},
242+
} as BotMetadata,
243+
{
244+
Id: 'agent2',
245+
DeveloperName: 'Alpha_Agent',
246+
BotVersions: {
247+
records: [
248+
{ Status: 'Inactive', VersionNumber: 1 } as BotVersionMetadata,
249+
{ Status: 'Inactive', VersionNumber: 2 } as BotVersionMetadata,
250+
],
251+
},
252+
} as BotMetadata,
253+
{
254+
Id: 'agent3',
255+
DeveloperName: 'Beta_Agent',
256+
BotVersions: {
257+
records: [{ Status: 'Inactive', VersionNumber: 1 } as BotVersionMetadata],
258+
},
259+
} as BotMetadata,
260+
];
261+
262+
const choices = getAgentChoices(agents, 'Active');
263+
264+
expect(choices).to.have.lengthOf(3);
265+
expect(choices[0].value.DeveloperName).to.equal('Alpha_Agent');
266+
expect(choices[1].value.DeveloperName).to.equal('Beta_Agent');
267+
expect(choices[2].value.DeveloperName).to.equal('Zebra_Agent');
226268
});
227269
});
228270
});

yarn.lock

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1731,14 +1731,14 @@
17311731
resolved "https://registry.yarnpkg.com/@rtsao/scc/-/scc-1.1.0.tgz#927dd2fae9bc3361403ac2c7a00c32ddce9ad7e8"
17321732
integrity sha512-zt6OdqaDoOnJ1ZYsCYGt9YmWzDXl4vQdKTyJev62gFhRGKdx7mcT54V9KIjg+d2wi9EXsPvAPKe7i7WjfVWB8g==
17331733

1734-
"@salesforce/agents@^0.24.1":
1735-
version "0.24.1"
1736-
resolved "https://registry.yarnpkg.com/@salesforce/agents/-/agents-0.24.1.tgz#841e34c7cc2ea6d58a14de67725116dbea5e3180"
1737-
integrity sha512-eU9WRbUwtCsKsv2PhCW8ZXIG2sKS4FFhvKlTFeoCKdEj/rleNseF0Rwn6MI3sIsrP9HfZvhAkh2vbvoPRK/8rQ==
1734+
"@salesforce/agents@^0.24.2":
1735+
version "0.24.2"
1736+
resolved "https://registry.yarnpkg.com/@salesforce/agents/-/agents-0.24.2.tgz#e67a36bf07c6a4d29231f88dd1cf562b125bb768"
1737+
integrity sha512-apYmYxeS3bnqUl32BvqZX2ALu50GUfdLw4iyJjR2jGm2q/kVTSeb/UBq8FhJBCnsPocnhu+Hmmb60bU0NCLwbw==
17381738
dependencies:
1739-
"@salesforce/core" "^8.26.2"
1739+
"@salesforce/core" "^8.26.3"
17401740
"@salesforce/kit" "^3.2.4"
1741-
"@salesforce/source-deploy-retrieve" "^12.31.12"
1741+
"@salesforce/source-deploy-retrieve" "^12.31.14"
17421742
"@salesforce/types" "^1.6.0"
17431743
fast-xml-parser "^5.3.6"
17441744
nock "^13.5.6"
@@ -1882,7 +1882,7 @@
18821882
cli-progress "^3.12.0"
18831883
terminal-link "^3.0.0"
18841884

1885-
"@salesforce/source-deploy-retrieve@^12.31.12", "@salesforce/source-deploy-retrieve@^12.31.14":
1885+
"@salesforce/source-deploy-retrieve@^12.31.14":
18861886
version "12.31.14"
18871887
resolved "https://registry.yarnpkg.com/@salesforce/source-deploy-retrieve/-/source-deploy-retrieve-12.31.14.tgz#6ed0a2fdb9a14d60ed64a2dd8fdc18c16af143a6"
18881888
integrity sha512-tLnTCG6t+d+MN8pGijF6nL4lsqE37FaBINZZvyd+IDAw+7eWffFqIXK/nNyQ1ZARTNeHOs5K/NlNXNBp5+x/YQ==

0 commit comments

Comments
 (0)