Skip to content

Commit

Permalink
Merge pull request #2108 from solliancenet/jdh-user-portal-agents
Browse files Browse the repository at this point in the history
User Portal agent listing improvements
  • Loading branch information
ciprianjichici authored Jan 2, 2025
2 parents 99e778f + f657f40 commit cc4f95b
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 64 deletions.
134 changes: 70 additions & 64 deletions src/ui/UserPortal/components/NavBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -155,73 +155,16 @@ export default {
},
deep: true,
},
},
async created() {
await this.$appStore.getAgents();
this.agentOptions = this.$appStore.agents.map((agent) => ({
label: agent.resource.name,
type: agent.resource.type,
object_id: agent.resource.object_id,
description: agent.resource.description,
my_agent: agent.roles.includes('Owner'),
value: agent,
}));
if (this.agentOptions.length === 0) {
this.emptyAgentsMessage = this.$appConfigStore.noAgentsMessage ?? null;
}
const publicAgentOptions = this.agentOptions.filter((agent) => !agent.my_agent);
const privateAgentOptions = this.agentOptions.filter((agent) => agent.my_agent);
const noAgentOptions = [
{
label: 'None',
value: null,
disabled: true,
type: '',
object_id: '',
description: '',
'$appStore.agents': {
handler() {
this.setAgentOptions();
},
];
this.virtualUser = await this.$appStore.getVirtualUser();
this.agentOptionsGroup.push({
label: '',
items: [
{
label: '--select--',
value: null,
type: '',
object_id: '',
description: '',
},
],
});
if (this.agentOptions.length === 0) {
// Append noAgentOptions to the last entry in the agentOptionsGroup
this.agentOptionsGroup[this.agentOptionsGroup.length - 1].items.push(...noAgentOptions);
return;
}
if (privateAgentOptions.length > 0) {
this.agentOptionsGroup.push({
label: 'My Agents',
items: privateAgentOptions,
});
this.agentOptionsGroup.push({
label: 'Other Agents',
items: publicAgentOptions.length > 0 ? publicAgentOptions : noAgentOptions,
});
} else {
this.agentOptionsGroup[this.agentOptionsGroup.length - 1].items.push(
...(publicAgentOptions.length > 0 ? publicAgentOptions : noAgentOptions),
);
}
deep: true,
},
},
async created() {},
mounted() {
this.updateAgentSelection();
},
Expand Down Expand Up @@ -250,6 +193,69 @@ export default {
await this.$authStore.logout();
},
async setAgentOptions() {
this.agentOptions = this.$appStore.agents.map((agent) => ({
label: agent.resource.name,
type: agent.resource.type,
object_id: agent.resource.object_id,
description: agent.resource.description,
my_agent: agent.roles.includes('Owner'),
value: agent,
}));
if (this.agentOptions.length === 0) {
this.emptyAgentsMessage = this.$appConfigStore.noAgentsMessage ?? null;
}
const publicAgentOptions = this.agentOptions.filter((agent) => !agent.my_agent);
const privateAgentOptions = this.agentOptions.filter((agent) => agent.my_agent);
const noAgentOptions = [
{
label: 'None',
value: null,
disabled: true,
type: '',
object_id: '',
description: '',
},
];
this.virtualUser = await this.$appStore.getVirtualUser();
this.agentOptionsGroup.push({
label: '',
items: [
{
label: '--select--',
value: null,
type: '',
object_id: '',
description: '',
},
],
});
if (this.agentOptions.length === 0) {
// Append noAgentOptions to the last entry in the agentOptionsGroup
this.agentOptionsGroup[this.agentOptionsGroup.length - 1].items.push(...noAgentOptions);
return;
}
if (privateAgentOptions.length > 0) {
this.agentOptionsGroup.push({
label: 'My Agents',
items: privateAgentOptions,
});
this.agentOptionsGroup.push({
label: 'Other Agents',
items: publicAgentOptions.length > 0 ? publicAgentOptions : noAgentOptions,
});
} else {
this.agentOptionsGroup[this.agentOptionsGroup.length - 1].items.push(
...(publicAgentOptions.length > 0 ? publicAgentOptions : noAgentOptions),
);
}
},
// handleCopySession() {
// const chatLink = `${window.location.origin}?chat=${this.currentSession!.id}`;
// navigator.clipboard.writeText(chatLink);
Expand Down
1 change: 1 addition & 0 deletions src/ui/UserPortal/stores/appStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const useAppStore = defineStore('app', {
actions: {
async init(sessionId: string) {
const appConfigStore = useAppConfigStore();
await this.getAgents();

// Watch for changes in autoHideToasts and update sessionStorage
watch(
Expand Down

0 comments on commit cc4f95b

Please sign in to comment.