Skip to content

Commit

Permalink
Fix app edit display name issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
jbouder committed Apr 5, 2024
1 parent 75d6c9c commit b3cd375
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 34 deletions.
48 changes: 24 additions & 24 deletions jhub_apps/static/js/index.js

Large diffs are not rendered by default.

25 changes: 17 additions & 8 deletions ui/src/components/app-form/app-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
currentFile as defaultFile,
currentFormInput as defaultFormInput,
currentImage as defaultImage,
currentServerName as defaultServerName,
currentUser as defaultUser,
} from '../../store';
import './app-form.css';
Expand All @@ -48,7 +49,9 @@ export const AppForm = ({ id }: AppFormProps): React.ReactElement => {
const [currentFormInput, setCurrentFormInput] = useRecoilState<
AppFormInput | undefined
>(defaultFormInput);
const [name, setName] = useState('');
const [currentServerName, setCurrentServerName] = useRecoilState<
string | undefined
>(defaultServerName);
const [currentFile, setCurrentFile] = useRecoilState<File | undefined>(
defaultFile,
);
Expand Down Expand Up @@ -138,7 +141,7 @@ export const AppForm = ({ id }: AppFormProps): React.ReactElement => {
if (profiles && profiles.length > 0) {
const payload: AppFormInput = {
jhub_app: true,
display_name: name || display_name,
display_name: currentServerName || display_name,
description,
framework,
thumbnail,
Expand All @@ -153,10 +156,10 @@ export const AppForm = ({ id }: AppFormProps): React.ReactElement => {
navigate(`/server-types${id ? `?id=${id}` : ''}`);
} else {
const payload = {
servername: name || display_name,
servername: currentServerName || display_name,
user_options: {
jhub_app: true,
name: name || display_name,
name: currentServerName || display_name,
display_name,
description: description || '',
framework,
Expand Down Expand Up @@ -256,7 +259,7 @@ export const AppForm = ({ id }: AppFormProps): React.ReactElement => {
// Populate form with existing app data
useEffect(() => {
if (formData?.name && formData?.user_options) {
setName(formData.name);
setCurrentServerName(formData.name);
reset({
...formData.user_options,
env: formData.user_options.env
Expand All @@ -266,13 +269,19 @@ export const AppForm = ({ id }: AppFormProps): React.ReactElement => {
setIsPublic(formData.user_options.public);
setCurrentImage(formData.user_options.thumbnail);
}
}, [formData?.name, formData?.user_options, reset, setCurrentImage]);
}, [
formData?.name,
formData?.user_options,
reset,
setCurrentImage,
setCurrentServerName,
]);

// Populate form when returning from server-types page
useEffect(() => {
// istanbul ignore next
if (currentFormInput) {
setName(currentFormInput.display_name);
setCurrentServerName(currentFormInput.display_name);
reset({
display_name: currentFormInput.display_name || '',
description: currentFormInput.description || '',
Expand All @@ -288,7 +297,7 @@ export const AppForm = ({ id }: AppFormProps): React.ReactElement => {
setIsPublic(currentFormInput.is_public);
setCurrentImage(currentFormInput.thumbnail);
}
}, [currentFormInput, reset, setCurrentImage]);
}, [currentFormInput, reset, setCurrentImage, setCurrentServerName]);

useEffect(() => {
if (formError) {
Expand Down
8 changes: 6 additions & 2 deletions ui/src/pages/server-types/server-types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
currentFile as defaultFile,
currentFormInput as defaultFormInput,
currentImage as defaultImage,
currentServerName as defaultServerName,
currentUser as defaultUser,
} from '../../store';
import './server-types.css';
Expand All @@ -35,6 +36,9 @@ export const ServerTypes = (): React.ReactElement => {
const [currentFormInput, setCurrentFormInput] = useRecoilState<
AppFormInput | undefined
>(defaultFormInput);
const [currentServerName] = useRecoilState<string | undefined>(
defaultServerName,
);
const [currentFile] = useRecoilState<File | undefined>(defaultFile);
const [currentImage] = useRecoilState<string | undefined>(defaultImage);
const [, setNotification] = useRecoilState<string | undefined>(
Expand Down Expand Up @@ -76,10 +80,10 @@ export const ServerTypes = (): React.ReactElement => {
const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();
const payload = {
servername: currentFormInput?.display_name || '',
servername: currentServerName || '',
user_options: {
jhub_app: true,
name: currentFormInput?.display_name || '',
name: currentServerName || '',
display_name: currentFormInput?.display_name || '',
description: currentFormInput?.description || '',
framework: currentFormInput?.framework || '',
Expand Down
6 changes: 6 additions & 0 deletions ui/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ const currentNotification = atom<string | undefined>({
default: undefined,
});

const currentServerName = atom<string | undefined>({
key: 'currentServerName',
default: undefined,
});

const currentFormInput = atom<AppFormInput | undefined>({
key: 'currentFormInput',
default: undefined,
Expand Down Expand Up @@ -69,6 +74,7 @@ export {
currentNotification,
currentOwnershipValue,
currentSearchValue,
currentServerName,
currentSortValue,
currentUser,
};

0 comments on commit b3cd375

Please sign in to comment.