Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editing an app changes it's display name to unique name #201

Merged
merged 2 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
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,
};
Loading