Skip to content

Commit

Permalink
restructured the model mirror page and added a backend check for exis…
Browse files Browse the repository at this point in the history
…ting model card before allowing export
  • Loading branch information
ARADDCC002 committed Dec 18, 2024
1 parent adf8a49 commit 10d6251
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 56 deletions.
2 changes: 1 addition & 1 deletion backend/config/default.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ module.exports = {
enabled: false,
},
export: {
enabled: false,
enabled: true,
disclaimer: '## Example Agreement \n I agree that this model is suitable for exporting',
},
},
Expand Down
3 changes: 3 additions & 0 deletions backend/src/services/mirroredModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ export async function exportModel(
if (!model.settings.mirror.destinationModelId) {
throw BadReq(`The 'Destination Model ID' has not been set on this model.`)
}
if (!model.card || !model.card.schemaId) {
throw BadReq('You must select a schema for your model before you can start the export process.')
}
const mirroredModelId = model.settings.mirror.destinationModelId
const auth = await authorisation.model(user, model, ModelAction.Update)
if (!auth.success) {
Expand Down
44 changes: 21 additions & 23 deletions frontend/src/entry/model/mirroredModels/ExportModelAgreement.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LoadingButton } from '@mui/lab'
import { Box, Button, Card, Checkbox, Container, FormControlLabel, Stack, Typography } from '@mui/material'
import { Box, Button, Checkbox, FormControlLabel, Stack, Typography } from '@mui/material'
import { postModelExportToS3 } from 'actions/model'
import { ChangeEvent, FormEvent, useState } from 'react'
import Restricted from 'src/common/Restricted'
Expand Down Expand Up @@ -46,27 +46,25 @@ export default function ExportModelAgreement({ modelId }: ExportModelAgreementPr
}

return (
<Container maxWidth='md'>
<Card sx={{ mx: 'auto', my: 4, p: 4 }}>
<Typography variant='h6' component='h1' color='primary' align='center'>
Model Export Agreement
</Typography>
<Box component='form' onSubmit={handleSubmit}>
<Stack spacing={2} alignItems='start' justifyContent='start'>
<ModelExportAgreementText />
<FormControlLabel
control={<Checkbox checked={checked} onChange={handleChecked} />}
label='I agree to the terms and conditions of this model export agreement'
/>
<Restricted action='exportMirroredModel' fallback={<Button disabled>Submit</Button>}>
<LoadingButton variant='contained' loading={loading} disabled={!checked} type='submit'>
Submit
</LoadingButton>
</Restricted>
<MessageAlert message={errorMessage} severity='error' />
</Stack>
</Box>
</Card>
</Container>
<>
<Typography variant='h6' component='h1' color='primary' align='center'>
Model Export Agreement
</Typography>
<Box component='form' onSubmit={handleSubmit}>
<Stack spacing={2} alignItems='start' justifyContent='start'>
<ModelExportAgreementText />
<FormControlLabel
control={<Checkbox checked={checked} onChange={handleChecked} />}
label='I agree to the terms and conditions of this model export agreement'
/>
<Restricted action='exportMirroredModel' fallback={<Button disabled>Submit</Button>}>
<LoadingButton variant='contained' loading={loading} disabled={!checked} type='submit'>
Submit
</LoadingButton>
</Restricted>
<MessageAlert message={errorMessage} severity='error' />
</Stack>
</Box>
</>
)
}
63 changes: 31 additions & 32 deletions frontend/src/entry/model/mirroredModels/ExportSettings.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import ExpandMoreIcon from '@mui/icons-material/ExpandMore'
import { LoadingButton } from '@mui/lab'
import { Accordion, AccordionDetails, AccordionSummary, Box, Stack, TextField, Typography } from '@mui/material'
import { Box, Card, Container, Divider, Stack, TextField, Typography } from '@mui/material'
import { patchModel } from 'actions/model'
import { ChangeEvent, FormEvent, useState } from 'react'
import LabelledInput from 'src/common/LabelledInput'
Expand Down Expand Up @@ -55,25 +54,23 @@ export default function ExportSettings({ model }: ExportSettingsProps) {

return (
<>
<ExportModelAgreement modelId={model.id} />
<Accordion sx={{ borderTop: 'none' }}>
<AccordionSummary sx={{ pl: 0 }} expandIcon={<ExpandMoreIcon />}>
<Typography component='h3' variant='h6'>
Export Settings
</Typography>
</AccordionSummary>
<AccordionDetails>
<Container maxWidth='md'>
<Card sx={{ mx: 'auto', my: 4, p: 4 }}>
<Box component='form' onSubmit={handleSave}>
<Stack spacing={2} alignItems='flex-start'>
<LabelledInput label={'Destination Model ID'} htmlFor={'destination-model-id'} required>
<TextField
id='destination-model-id'
value={destinationModelId}
onChange={handleDestinationModelId}
size='small'
/>
</LabelledInput>
{/*TODO - Add the ability to filter releases needed for export (This functionality is not available on the backend)
<Stack spacing={3} divider={<Divider flexItem />}>
<>
<Typography variant='h6' component='h1' color='primary' align='center'>
Model Export Settings
</Typography>
<LabelledInput label={'Destination Model ID'} htmlFor={'destination-model-id'} required>
<TextField
id='destination-model-id'
value={destinationModelId}
onChange={handleDestinationModelId}
size='small'
/>
</LabelledInput>
{/*TODO - Add the ability to filter releases needed for export (This functionality is not available on the backend)
<ReleaseSelector
model={model}
selectedReleases={selectedReleases}
Expand All @@ -82,20 +79,22 @@ export default function ExportSettings({ model }: ExportSettingsProps) {
requiredRolesText={requiredRolesText}
/>
*/}
<LoadingButton
sx={{ width: 'fit-content' }}
variant='contained'
data-test='createAccessRequestButton'
loading={loading}
type='submit'
>
Save
</LoadingButton>
<MessageAlert message={errorMessage} severity='error' />
<LoadingButton
sx={{ width: 'fit-content' }}
variant='contained'
data-test='createAccessRequestButton'
loading={loading}
type='submit'
>
Save
</LoadingButton>
<MessageAlert message={errorMessage} severity='error' />
</>
<ExportModelAgreement modelId={model.id} />
</Stack>
</Box>
</AccordionDetails>
</Accordion>
</Card>
</Container>
</>
)
}

0 comments on commit 10d6251

Please sign in to comment.