Skip to content

Commit

Permalink
Update App Launcher Keep Alive based on new design (nebari-dev#233)
Browse files Browse the repository at this point in the history
* Add keep alive switch to app form.

* Update form switches for consistency.

* Fix positioning issue on tooltip.
  • Loading branch information
jbouder authored Apr 12, 2024
1 parent 0ffeaa5 commit 4c77288
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 28 deletions.
52 changes: 26 additions & 26 deletions jhub_apps/static/js/index.js

Large diffs are not rendered by default.

66 changes: 64 additions & 2 deletions ui/src/components/app-form/app-form.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import InfoRoundedIcon from '@mui/icons-material/InfoRounded';
import {
Box,
Button,
FormControl,
FormControlLabel,
Expand All @@ -7,6 +9,8 @@ import {
Select,
Switch,
TextField,
Tooltip,
Typography,
} from '@mui/material';
import {
AppFrameworkProps,
Expand Down Expand Up @@ -59,6 +63,7 @@ export const AppForm = ({ id }: AppFormProps): React.ReactElement => {
defaultImage,
);
const [isPublic, setIsPublic] = useState(false);
const [keepAlive, setKeepAlive] = useState(false);
// Get the app data if we're editing an existing app
const { data: formData, error: formError } = useQuery<
AppQueryGetProps,
Expand Down Expand Up @@ -123,6 +128,7 @@ export const AppForm = ({ id }: AppFormProps): React.ReactElement => {
custom_command: '',
profile: '',
is_public: false,
keep_alive: false,
},
});
const currentFramework = watch('framework');
Expand Down Expand Up @@ -152,6 +158,7 @@ export const AppForm = ({ id }: AppFormProps): React.ReactElement => {
custom_command,
profile,
is_public: isPublic,
keep_alive: keepAlive,
};
setCurrentFormInput(payload);
navigate(`/server-types${id ? `?id=${id}` : ''}`);
Expand All @@ -171,6 +178,7 @@ export const AppForm = ({ id }: AppFormProps): React.ReactElement => {
custom_command: custom_command || '',
profile: profile || '',
public: isPublic,
keep_alive: keepAlive,
},
};

Expand Down Expand Up @@ -268,6 +276,7 @@ export const AppForm = ({ id }: AppFormProps): React.ReactElement => {
: undefined,
});
setIsPublic(formData.user_options.public);
setKeepAlive(formData.user_options.keep_alive);
setCurrentImage(formData.user_options.thumbnail);
}
}, [
Expand Down Expand Up @@ -295,6 +304,7 @@ export const AppForm = ({ id }: AppFormProps): React.ReactElement => {
profile: currentFormInput.profile || '',
});
setIsPublic(currentFormInput.is_public);
setKeepAlive(currentFormInput.keep_alive);
setCurrentImage(currentFormInput.thumbnail);
}
}, [currentFormInput, reset, setCurrentImage, setCurrentServerName]);
Expand Down Expand Up @@ -463,6 +473,56 @@ export const AppForm = ({ id }: AppFormProps): React.ReactElement => {
</FormControl>
)}
/>
<Box
sx={{
display: 'flex',
flexDirection: 'row',
}}
>
<Tooltip
placement="bottom-start"
title={
<Typography sx={{ fontSize: '10px', fontWeight: 600 }}>
Keep alive prevents the app from being suspended even when not
in active use. Your app will be instantly available, but it will
consume resources until manually stopped.
</Typography>
}
>
<InfoRoundedIcon
fontSize="small"
sx={{
position: 'relative',
top: '9px',
left: '2px',
color: '#0F10158F',
}}
/>
</Tooltip>
<Controller
name="keep_alive"
control={control}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
render={({ field: { ref: _, value, onChange, ...field } }) => (
<FormControl sx={{ flexDirection: 'row' }}>
<FormControlLabel
control={
<Switch
{...field}
id="keep_alive"
checked={keepAlive}
onChange={() => {
setKeepAlive(!keepAlive);
}}
/>
}
label="Keep app alive"
labelPlacement="start"
/>
</FormControl>
)}
/>
</Box>
</div>
<hr />
<div className="form-section">
Expand All @@ -472,7 +532,7 @@ export const AppForm = ({ id }: AppFormProps): React.ReactElement => {
control={control}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
render={({ field: { ref: _, value, onChange, ...field } }) => (
<FormControl>
<FormControl sx={{ flexDirection: 'row' }}>
<FormControlLabel
control={
<Switch
Expand All @@ -484,7 +544,9 @@ export const AppForm = ({ id }: AppFormProps): React.ReactElement => {
}}
/>
}
label="Allow Public Access"
label="Allow public access"
labelPlacement="start"
sx={{ marginLeft: '10px' }}
/>
</FormControl>
)}
Expand Down
6 changes: 6 additions & 0 deletions ui/src/data/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export const app: AppQueryGetProps = {
profile: '',
env: null,
public: false,
keep_alive: false,
},
progress_url: '',
state: {},
Expand Down Expand Up @@ -112,6 +113,7 @@ export const serverApps = {
filepath: '/shared/users/panel_basic.py',
env: null,
public: true,
keep_alive: false,
},
},
{
Expand All @@ -134,6 +136,7 @@ export const serverApps = {
profile: 'small0',
env: { key: 'value' },
public: false,
keep_alive: true,
},
},
{
Expand All @@ -156,6 +159,7 @@ export const serverApps = {
profile: 'small0',
env: null,
public: false,
keep_alive: false,
},
},
{
Expand All @@ -177,6 +181,7 @@ export const serverApps = {
profile: 'small0',
env: null,
public: false,
keep_alive: false,
},
},
],
Expand All @@ -201,6 +206,7 @@ export const serverApps = {
profile: 'small0',
env: null,
public: false,
keep_alive: false,
username: 'Test User',
},
},
Expand Down
1 change: 1 addition & 0 deletions ui/src/pages/server-types/server-types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export const ServerTypes = (): React.ReactElement => {
custom_command: currentFormInput?.custom_command || '',
profile: currentFormInput?.profile || '',
public: currentFormInput?.is_public || false,
keep_alive: currentFormInput?.keep_alive || false,
},
};
setSubmitting(true);
Expand Down
1 change: 1 addition & 0 deletions ui/src/types/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface UserOptions {
conda_env: string;
profile: string;
public: boolean;
keep_alive: boolean;
env: any; // eslint-disable-line @typescript-eslint/no-explicit-any
}

Expand Down
1 change: 1 addition & 0 deletions ui/src/types/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface AppFormInput {
filepath?: string;
framework: string;
is_public: boolean;
keep_alive: boolean;
jhub_app: boolean;
profile?: string;
thumbnail?: string;
Expand Down

0 comments on commit 4c77288

Please sign in to comment.