Skip to content

Commit

Permalink
added logic to cover clicking directly on a card. updated tests, upda…
Browse files Browse the repository at this point in the history
…ted copy
  • Loading branch information
Kilian Berres authored and Kilian Berres committed Sep 16, 2024
1 parent f6fb587 commit 8b6d120
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
4 changes: 2 additions & 2 deletions jhub_apps/static/js/index.js

Large diffs are not rendered by default.

17 changes: 14 additions & 3 deletions ui/src/components/app-card/app-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export const AppCard = ({
const [, setIsDeleteOpen] = useRecoilState<boolean>(isDeleteOpen);
const [, setIsStartNotRunningOpen] = useRecoilState(isStartNotRunningOpen);


useEffect(() => {
if (serverStatus) {
setAppStatus(serverStatus);
Expand Down Expand Up @@ -110,6 +111,11 @@ export const AppCard = ({
id: 'start',
title: 'Start',
onClick: () => {
if (isShared) {
// Show error if it's a shared app
setNotification('You don\'t have permission to start this app. Please ask the owner to start it.');
return;
}
setIsStartOpen(true);
setCurrentApp(app!); // Add the non-null assertion operator (!) to ensure that app is not undefined
},
Expand All @@ -120,8 +126,12 @@ export const AppCard = ({
id: 'stop',
title: 'Stop',
onClick: () => {
if (isShared) {
setNotification('You don\'t have permission to stop this app. Please ask the owner to stop it.');
return;
}
setIsStopOpen(true);
setCurrentApp(app!); // Set the current app when Stop is clicked
setCurrentApp(app!);
},
visible: true,
disabled: serverStatus !== 'Running', // Disable stop if the app is not running
Expand All @@ -132,7 +142,7 @@ export const AppCard = ({
onClick: () =>
(window.location.href = `${API_BASE_URL}/edit-app?id=${id}`),
visible: true,
disabled: isShared || id === '' || !isAppCard, // Disable edit for shared apps
disabled: isShared || id === '' || !isAppCard,
},
{
id: 'delete',
Expand All @@ -148,6 +158,7 @@ export const AppCard = ({
];



const getHoverClass = (id: string) => {
const element = document.querySelector(
`#card-content-container-${id}`,
Expand Down Expand Up @@ -195,7 +206,7 @@ export const AppCard = ({
url: app?.url || '',
ready: app?.ready || false,
public: app?.public || false,
shared: false,
shared: app?.shared || isShared || false,
last_activity: new Date(app?.last_activity || ''),
status: 'Ready',
});
Expand Down
4 changes: 2 additions & 2 deletions ui/src/pages/home/home.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ describe('Home', () => {

// Expect the snackbar to display the 403 Forbidden error message
await waitFor(() => {
const snackbar = getByText(/You don't have permission to start this app \(403 Forbidden\)/);
const snackbar = getByText(/You don't have permission to start this app. Please ask the owner to start it./);
expect(snackbar).toBeInTheDocument();
});
});
Expand Down Expand Up @@ -804,7 +804,7 @@ describe('Home', () => {

// Expect the snackbar to display the 403 Forbidden error message
await waitFor(() => {
const snackbar = getByText(/You don't have permission to stop this app \(403 Forbidden\)/);
const snackbar = getByText(/You don't have permission to stop this app. Please ask the owner/);
expect(snackbar).toBeInTheDocument();
});
});
Expand Down
8 changes: 4 additions & 4 deletions ui/src/pages/home/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export const Home = (): React.ReactElement => {
const sharedApp = currentApp?.shared;
if (sharedApp) {
setSubmitting(false);
setSnackbarMessage('You don\'t have permission to start this app (403 Forbidden). Please ask the owner to start it.');
setSnackbarMessage('You don\'t have permission to start this app. Please ask the owner to start it.');
setSnackbarSeverity('error');
setSnackbarOpen(true);
return;
Expand All @@ -179,7 +179,7 @@ export const Home = (): React.ReactElement => {
if (isErrorWithResponse(error)) {
const status = error.response?.status;
if (status === 403) {
setSnackbarMessage('You don\'t have permission to start this app (403 Forbidden). Please ask the owner to start it.');
setSnackbarMessage('You don\'t have permission to start this app. Please ask the owner to start it.');
} else if (status === 404) {
setSnackbarMessage('App not found (404).');
} else if (status === 500) {
Expand Down Expand Up @@ -209,7 +209,7 @@ export const Home = (): React.ReactElement => {
const sharedApp = currentApp?.shared;
if (sharedApp) {
setSubmitting(false);
setSnackbarMessage('You don\'t have permission to stop this app (403 Forbidden). Please ask the owner to stop it.');
setSnackbarMessage('You don\'t have permission to stop this app. Please ask the owner to stop it.');
setSnackbarSeverity('error');
setSnackbarOpen(true);
return;
Expand All @@ -230,7 +230,7 @@ export const Home = (): React.ReactElement => {
if (isErrorWithResponse(error)) {
const status = error.response?.status;
if (status === 403) {
setSnackbarMessage('You don\'t have permission to stop this app (403 Forbidden). Please ask the owner to stop it.');
setSnackbarMessage('You don\'t have permission to stop this app. Please ask the owner to stop it.');
} else if (status === 404) {
setSnackbarMessage('App not found (404).');
} else if (status === 500) {
Expand Down

0 comments on commit 8b6d120

Please sign in to comment.