-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added create Child system functionality * Ran prettier and linting
- Loading branch information
Showing
10 changed files
with
227 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Systems } from '@tapis/tapis-typescript'; | ||
import { apiGenerator, errorDecoder } from 'tapis-api/utils'; | ||
|
||
const createChildSystem = ( | ||
reqPostChildSystem: Systems.ReqPostChildSystem, | ||
parentId: string, | ||
basePath: string, | ||
jwt: string | ||
) => { | ||
const api: Systems.ChildSystemsApi = apiGenerator<Systems.ChildSystemsApi>( | ||
Systems, | ||
Systems.ChildSystemsApi, | ||
basePath, | ||
jwt | ||
); | ||
return errorDecoder<Systems.RespBasic>(() => | ||
api.createChildSystem({ reqPostChildSystem, parentId }) | ||
); | ||
}; | ||
|
||
export default createChildSystem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...ail/_Layout/SystemLayoutToolbar/CreateChildSystemModal/CreateChildSystemModal.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
.modal-settings { | ||
max-height: 38rem; | ||
overflow-y: scroll; | ||
} | ||
|
||
.item { | ||
border: 1px dotted lightgray; | ||
padding: 0.5em 0.5em 0.5em 0.5em; | ||
margin-bottom: 1em; | ||
} | ||
|
||
.array { | ||
border: 1px solid gray; | ||
padding: 0.5em 0.5em 0.5em 0.5em; | ||
margin-bottom: 0.5em; | ||
} |
130 changes: 130 additions & 0 deletions
130
...ystemDetail/_Layout/SystemLayoutToolbar/CreateChildSystemModal/CreateChildSystemModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
import { Button } from 'reactstrap'; | ||
import { GenericModal } from 'tapis-ui/_common'; | ||
import { SubmitWrapper } from 'tapis-ui/_wrappers'; | ||
import { ToolbarModalProps } from '../SystemLayoutToolbar'; | ||
import { Form, Formik } from 'formik'; | ||
import { FormikInput } from 'tapis-ui/_common'; | ||
import { useTapisConfig } from 'tapis-hooks'; | ||
import { useCreateChildSystem } from 'tapis-hooks/systems'; | ||
import { useEffect } from 'react'; | ||
import { useLocation } from 'react-router-dom'; | ||
import styles from './CreateChildSystemModal.module.scss'; | ||
import * as Yup from 'yup'; | ||
|
||
const CreateChildSystemModal: React.FC<ToolbarModalProps> = ({ toggle }) => { | ||
const { isLoading, isSuccess, error, reset, createChildSystem } = | ||
useCreateChildSystem(); | ||
|
||
useEffect(() => { | ||
reset(); | ||
}, [reset]); | ||
|
||
const validationSchema = Yup.object({ | ||
sysname: Yup.string() | ||
.min(1) | ||
.max(80, 'System name should not be longer than 80 characters') | ||
.matches( | ||
/^[a-zA-Z0-9_.-]+$/, | ||
"Must contain only alphanumeric characters and the following: '.', '_', '-'" | ||
) | ||
.required('System name is a required field'), | ||
rootDir: Yup.string() | ||
.min(1) | ||
.max(4096, 'Root Directory should not be longer than 4096 characters'), | ||
effectiveUserId: Yup.string() | ||
.max(60, 'Effective User ID should not be longer than 60 characters') | ||
.required('Effective User ID is a required field'), | ||
parentId: Yup.string().required('Parent ID is a required field'), | ||
}); | ||
|
||
const initialValues = { | ||
sysname: '', | ||
rootDir: '/', | ||
effectiveUserId: useTapisConfig().claims['tapis/username'], | ||
parentId: String(useLocation().pathname.split('/').pop()), | ||
}; | ||
|
||
const onSubmit = ({ | ||
sysname, | ||
rootDir, | ||
effectiveUserId, | ||
parentId, | ||
}: { | ||
sysname: string; | ||
rootDir: string; | ||
effectiveUserId: string; | ||
parentId: string; | ||
}) => { | ||
createChildSystem( | ||
{ | ||
id: sysname, | ||
effectiveUserId, | ||
rootDir, | ||
}, | ||
parentId | ||
); | ||
}; | ||
|
||
return ( | ||
<GenericModal | ||
toggle={toggle} | ||
title="Create New Child System" | ||
body={ | ||
<div className={styles['modal-settings']}> | ||
<Formik | ||
initialValues={initialValues} | ||
validationSchema={validationSchema} | ||
onSubmit={onSubmit} | ||
> | ||
{() => ( | ||
<Form id="newsystem-form"> | ||
<FormikInput | ||
name="sysname" | ||
label="System Name" | ||
required={true} | ||
description={`System Name`} | ||
aria-label="Input" | ||
/> | ||
<FormikInput | ||
name="effectiveUserId" | ||
label="Effective User ID" | ||
required={true} | ||
description={`Effective User ID`} | ||
aria-label="Input" | ||
/> | ||
<FormikInput | ||
name="rootDir" | ||
label="Root Directory" | ||
required={true} | ||
description={`Root Directory`} | ||
aria-label="Input" | ||
/> | ||
</Form> | ||
)} | ||
</Formik> | ||
</div> | ||
} | ||
footer={ | ||
<SubmitWrapper | ||
className={styles['modal-footer']} | ||
isLoading={isLoading} | ||
error={error} | ||
success={isSuccess ? `Successfully created a new child system` : ''} | ||
reverse={true} | ||
> | ||
<Button | ||
form="newsystem-form" | ||
color="primary" | ||
disabled={isLoading || isSuccess} | ||
aria-label="Submit" | ||
type="submit" | ||
> | ||
Create a new child system | ||
</Button> | ||
</SubmitWrapper> | ||
} | ||
/> | ||
); | ||
}; | ||
|
||
export default CreateChildSystemModal; |
3 changes: 3 additions & 0 deletions
3
...apis-app/Systems/SystemDetail/_Layout/SystemLayoutToolbar/CreateChildSystemModal/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import CreateChildSystemModal from './CreateChildSystemModal'; | ||
|
||
export default CreateChildSystemModal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { useMutation, MutateOptions } from 'react-query'; | ||
import { Systems } from '@tapis/tapis-typescript'; | ||
import { createChildSystem } from 'tapis-api/systems'; | ||
import { useTapisConfig } from '../context'; | ||
import QueryKeys from './queryKeys'; | ||
|
||
type createChildSystemParams = { | ||
reqPostChildSystem: Systems.ReqPostChildSystem; | ||
parentId: string; | ||
}; | ||
|
||
const useCreateChildSystem = () => { | ||
const { basePath, accessToken } = useTapisConfig(); | ||
const jwt = accessToken?.access_token || ''; | ||
|
||
const { mutate, isLoading, isError, isSuccess, data, error, reset } = | ||
useMutation<Systems.RespBasic, Error, createChildSystemParams>( | ||
[QueryKeys.createChildSystem, basePath, jwt], | ||
({ reqPostChildSystem, parentId }) => | ||
createChildSystem(reqPostChildSystem, parentId, basePath, jwt) | ||
); | ||
|
||
return { | ||
isLoading, | ||
isError, | ||
isSuccess, | ||
data, | ||
error, | ||
reset, | ||
createChildSystem: ( | ||
reqPostChildSystem: Systems.ReqPostChildSystem, | ||
parentId: string, | ||
options?: MutateOptions<Systems.RespBasic, Error, createChildSystemParams> | ||
) => { | ||
return mutate({ reqPostChildSystem, parentId }, options); | ||
}, | ||
}; | ||
}; | ||
|
||
export default useCreateChildSystem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters