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

Added templating and access requests buttons to the new model create screen #1563

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
80 changes: 61 additions & 19 deletions frontend/src/entry/CreateEntry.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ArrowBack, FileUpload, Lock, LockOpen } from '@mui/icons-material'
import { ArrowBack, FileUpload, FolderCopy, Lock, LockOpen } from '@mui/icons-material'
import ExpandMoreIcon from '@mui/icons-material/ExpandMore'
import LoadingButton from '@mui/lab/LoadingButton'
import {
Expand All @@ -7,12 +7,14 @@ import {
AccordionSummary,
Box,
Button,
Checkbox,
Divider,
FormControlLabel,
Paper,
Radio,
RadioGroup,
Stack,
Switch,
Tooltip,
Typography,
} from '@mui/material'
Expand Down Expand Up @@ -60,6 +62,8 @@ export default function CreateEntry({ createEntryKind, onBackClick }: CreateEntr
const [collaborators, setCollaborators] = useState<CollaboratorEntry[]>(
currentUser ? [{ entity: `${EntityKind.USER}:${currentUser?.dn}`, roles: ['owner'] }] : [],
)
const [ungovernedAccess, setungovernedAccess] = useState<boolean>(false)
const [allowTemplating, setAllowTemplating] = useState<boolean>(true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

boolean and string can be inferred from their defaults so we don't need to declare the types, so we can just do useState(false).

const [errorMessage, setErrorMessage] = useState('')
const [loading, setLoading] = useState(false)

Expand All @@ -86,6 +90,8 @@ export default function CreateEntry({ createEntryKind, onBackClick }: CreateEntr
visibility,
collaborators,
settings: {
ungovernedAccess,
allowTemplating,
mirror: {
sourceModelId,
},
Expand Down Expand Up @@ -130,6 +136,20 @@ export default function CreateEntry({ createEntryKind, onBackClick }: CreateEntr
)
}

const templateLabel = () => {
return (
Copy link
Member

@ARADDCC002 ARADDCC002 Oct 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const templateLabel = useMemo(() => {

<Stack direction='row' justifyContent='center' alignItems='center' spacing={1}>
<FolderCopy />
<Stack sx={{ my: 1 }}>
<Typography fontWeight='bold'>Templating</Typography>
<Typography variant='caption'>
{`Allow this to be used as a template for another ${EntryKindLabel[createEntryKind]}`}
</Typography>
</Stack>
</Stack>
)
}

if (isCurrentUserError) {
return <MessageAlert message={isCurrentUserError.info.message} severity='error' />
}
Expand Down Expand Up @@ -174,24 +194,36 @@ export default function CreateEntry({ createEntryKind, onBackClick }: CreateEntr
<Typography component='h3' variant='h6'>
Access control
</Typography>
<RadioGroup
defaultValue='public'
value={visibility}
onChange={(e) => setVisibility(e.target.value as EntryForm['visibility'])}
>
<FormControlLabel
value='public'
control={<Radio />}
label={publicLabel()}
data-test='publicButtonSelector'
/>
<FormControlLabel
value='private'
control={<Radio />}
label={privateLabel()}
data-test='privateButtonSelector'
/>
</RadioGroup>
<Box sx={{ display: 'flex', flexDirection: 'column', gap: 1 }}>
<RadioGroup
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to use this <Box/> component here

defaultValue='public'
value={visibility}
onChange={(e) => setVisibility(e.target.value as EntryForm['visibility'])}
>
<FormControlLabel
value='public'
control={<Radio />}
label={publicLabel()}
data-test='publicButtonSelector'
/>
<FormControlLabel
value='private'
control={<Radio />}
label={privateLabel()}
data-test='privateButtonSelector'
/>
<FormControlLabel
value='false'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The option to allow for templating should appear at the bottom of the expansion menu under or above the choice to allow for ungoverned access. Although I can see why you'd put it under "Access control", this section is accessing the model card page - easy mistake to make though!

control={
<Checkbox
onChange={(event) => setAllowTemplating(event.target.checked)}
checked={allowTemplating}
/>
}
label={templateLabel()}
/>
</RadioGroup>
</Box>
</>
<Accordion sx={{ borderTop: 'none' }}>
<AccordionSummary
Expand Down Expand Up @@ -224,6 +256,16 @@ export default function CreateEntry({ createEntryKind, onBackClick }: CreateEntr
]}
/>
</Box>
<FormControlLabel
label='Ungoverned access requests'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would put the "allow templating" option here, and I'd suggest adding a sub-heading of "Additional settings", a bit like how the user selector appears under the heading of "Manage access list".

To easily space out different components you can use the MUI <Stack /> component, which works like so:

<Stack spacing={2}>
  <Typography>This is some text!</Typography>
  <Typography>This is some more text!</Typography>
</Stack>

control={
<Switch
onChange={(e) => setungovernedAccess(e.target.checked)}
checked={ungovernedAccess}
size='small'
/>
}
/>
</AccordionDetails>
</Accordion>
<Box sx={{ textAlign: 'right' }}>
Expand Down
2 changes: 2 additions & 0 deletions frontend/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,8 @@ export interface EntryForm {
visibility: EntryVisibilityKeys
collaborators?: CollaboratorEntry[]
settings?: {
ungovernedAccess: boolean
allowTemplating: boolean
mirror?: {
sourceModelId?: string
destinationModelId?: string
Expand Down
Loading