Skip to content

Commit 5efdc4b

Browse files
Merge pull request #2059 from mito-ds/modifying-manage-apps
Modifying manage apps
2 parents d95f7d0 + 9f7fecd commit 5efdc4b

File tree

2 files changed

+99
-43
lines changed

2 files changed

+99
-43
lines changed

mito-ai/src/Extensions/AppManager/AppsList.tsx

Lines changed: 61 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import { copyIcon } from '@jupyterlab/ui-components';
99
import { logoutAndClearJWTTokens } from '../AppDeploy/auth';
1010
import { fetchUserApps, GetAppsResponse, AppMetadata, isGetAppsSuccess, AppStatus } from './ListAppsAPI';
1111
import { IAppManagerService } from './ManageAppsPlugin';
12+
import { showAuthenticationPopup } from '../AppDeploy/authPopupUtils';
1213
import '../../../style/AppsList.css';
14+
import '../../../style/button.css';
1315

1416
// Add props interface to receive the appManagerService
1517
interface AppsListProps {
@@ -21,44 +23,40 @@ export const AppsList: React.FC<AppsListProps> = ({ appManagerService }) => {
2123
const [loading, setLoading] = React.useState<boolean>(true);
2224
const [error, setError] = React.useState<string | null>(null);
2325

24-
// Fetch apps on component mount
25-
React.useEffect(() => {
26-
const loadApps = async (): Promise<void> => {
27-
try {
28-
console.log('[AppsList] Starting to load apps...');
29-
setLoading(true);
30-
setError(null);
26+
const refreshApps = async (): Promise<void> => {
27+
try {
28+
console.log('[AppsList] Refreshing apps...');
29+
setLoading(true);
30+
setError(null);
3131

32-
console.log('[AppsList] Calling fetchUserApps...');
33-
const response: GetAppsResponse = await fetchUserApps(appManagerService);
34-
console.log('[AppsList] fetchUserApps response:', response);
32+
const response: GetAppsResponse = await fetchUserApps(appManagerService);
33+
console.log('[AppsList] fetchUserApps response:', response);
3534

36-
if (isGetAppsSuccess(response)) {
37-
setApps(response.apps);
38-
} else {
39-
setError(response.errorMessage || 'Failed to load apps');
40-
setApps([]);
41-
}
42-
} catch (err) {
43-
console.error('[AppsList] Error loading apps:', err);
44-
setError(err instanceof Error ? err.message : 'An unexpected error occurred');
35+
if (isGetAppsSuccess(response)) {
36+
setApps(response.apps);
37+
} else {
38+
setError(response.errorMessage || 'Failed to load apps');
4539
setApps([]);
46-
} finally {
47-
setLoading(false);
4840
}
49-
};
41+
} catch (err) {
42+
console.error('[AppsList] Error loading apps:', err);
43+
setError(err instanceof Error ? err.message : 'An unexpected error occurred');
44+
setApps([]);
45+
} finally {
46+
setLoading(false);
47+
}
48+
}
5049

51-
console.log('[AppsList] Component mounted, calling loadApps...');
52-
void loadApps();
53-
}, [appManagerService]);
50+
React.useEffect(() => {
51+
void refreshApps();
52+
}, []);
5453

55-
const refreshApps = async (): Promise<void> => {
56-
const response = await fetchUserApps(appManagerService);
57-
if (isGetAppsSuccess(response)) {
58-
setApps(response.apps);
59-
setError(null);
60-
} else {
61-
setError(response.errorMessage || 'Failed to refresh apps');
54+
const handleLogin = async (): Promise<void> => {
55+
try {
56+
await showAuthenticationPopup();
57+
await refreshApps();
58+
} catch (err) {
59+
console.warn('[AppsList] Login popup closed or failed:', err);
6260
}
6361
};
6462

@@ -113,9 +111,15 @@ export const AppsList: React.FC<AppsListProps> = ({ appManagerService }) => {
113111
{loading ? 'Loading...' : 'Refresh'}
114112
</button>
115113
<button
116-
onClick={() => {
114+
onClick={async () => {
117115
console.log('Logout clicked');
118-
void logoutAndClearJWTTokens();
116+
try {
117+
await logoutAndClearJWTTokens();
118+
} catch (err) {
119+
console.error('[AppsList] Error during logout:', err);
120+
} finally{
121+
await refreshApps();
122+
}
119123
}}
120124
className="apps-list-button"
121125
title="Logout"
@@ -125,22 +129,37 @@ export const AppsList: React.FC<AppsListProps> = ({ appManagerService }) => {
125129
</div>
126130
</div>
127131

132+
<div className="apps-list-content">
128133
{loading ? (
129134
<div className="apps-list-loading">
130135
Loading apps...
131136
</div>
132137
) : error ? (
133-
<div className="apps-list-error">
134-
Error: {error}
135-
<div className="apps-list-error-actions">
138+
error === 'User not authenticated' ? (
139+
<div className="apps-list-auth-message">
140+
<div className="apps-list-auth-text">User not authenticated</div>
136141
<button
137-
onClick={refreshApps}
138-
className="apps-list-button primary"
142+
onClick={handleLogin}
143+
className="button-base button-purple apps-list-auth-login-button"
139144
>
140-
Try Again
145+
Login
141146
</button>
142147
</div>
143-
</div>
148+
) : (
149+
<div className="apps-list-error">
150+
<>
151+
Error: {error}
152+
<div className="apps-list-error-actions">
153+
<button
154+
onClick={refreshApps}
155+
className="apps-list-button primary"
156+
>
157+
Try Again
158+
</button>
159+
</div>
160+
</>
161+
</div>
162+
)
144163
) : apps.length === 0 ? (
145164
<div className="apps-list-empty">
146165
No apps deployed yet
@@ -189,6 +208,7 @@ export const AppsList: React.FC<AppsListProps> = ({ appManagerService }) => {
189208
))}
190209
</div>
191210
)}
211+
</div>
192212
</div>
193213
);
194214
};

mito-ai/style/AppsList.css

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,28 @@
55

66
/* apps-list.css */
77
.apps-list-container {
8-
padding: 16px;
8+
display: flex;
9+
flex-direction: column;
10+
height: 100%;
911
font-size: 13px;
1012
font-family: var(--jp-ui-font-family);
13+
overflow: hidden;
1114
}
1215

1316
.apps-list-header {
1417
display: flex;
1518
justify-content: space-between;
1619
align-items: center;
17-
margin-bottom: 16px;
20+
padding: 16px;
21+
flex-shrink: 0;
22+
border-bottom: 1px solid var(--jp-border-color2);
23+
}
24+
25+
.apps-list-content {
26+
flex: 1;
27+
overflow-y: auto;
28+
padding: 16px;
29+
min-height: 0;
1830
}
1931

2032
.apps-list-title {
@@ -74,6 +86,30 @@
7486
margin-top: 8px;
7587
}
7688

89+
.apps-list-auth-message {
90+
color: var(--jp-ui-font-color1);
91+
background-color: var(--jp-layout-color0);
92+
border: 1px solid var(--jp-border-color2);
93+
border-radius: 4px;
94+
padding: 24px 16px;
95+
text-align: center;
96+
display: flex;
97+
flex-direction: column;
98+
align-items: center;
99+
gap: 12px;
100+
}
101+
102+
.apps-list-auth-text {
103+
font-size: 14px;
104+
font-weight: bold;
105+
font-family: var(--jp-ui-font-family);
106+
}
107+
108+
.apps-list-auth-login-button {
109+
font-size: 13px;
110+
min-width: 96px;
111+
}
112+
77113
.apps-list-empty {
78114
color: var(--jp-ui-font-color2);
79115
text-align: center;

0 commit comments

Comments
 (0)