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

restructured the model mirror page and added a backend check for exis… #1691

Merged
merged 7 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 5 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
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
3 changes: 2 additions & 1 deletion backend/test/services/mirroredModel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ vi.mock('../../src/services/log.js', async () => ({
}))

const modelMocks = vi.hoisted(() => ({
getModelById: vi.fn(() => ({ settings: { mirror: { destinationModelId: '123' } } })),
getModelById: vi.fn(() => ({ settings: { mirror: { destinationModelId: '123' } }, card: { schemaId: 'test' } })),
getModelCardRevisions: vi.fn(() => [{ toJSON: vi.fn(), version: 123 }]),
setLatestImportedModelCard: vi.fn(),
saveImportedModelCard: vi.fn(),
Expand Down Expand Up @@ -237,6 +237,7 @@ describe('services > mirroredModel', () => {
test('exportModel > missing mirrored model ID', async () => {
modelMocks.getModelById.mockReturnValueOnce({
settings: { mirror: { destinationModelId: '' } },
card: { schemaId: 'test' },
})
const response = exportModel({} as UserInterface, 'modelId', true, ['1.2.3'])
await expect(response).rejects.toThrowError(/^The 'Destination Model ID' has not been set on this model./)
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'>
Model Export Agreement
Copy link
Member

Choose a reason for hiding this comment

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

I don't think it's super clear that this section of the page doesn't just contain the agreement but also the ability to actually kick off an export. Users will be looking for how they export a model, rather than where the agreement is. The agreement is just something they need to do before being able to do the actual thing they want which is exporting a model.

</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>
</>
)
}
80 changes: 49 additions & 31 deletions frontend/src/entry/model/mirroredModels/ExportSettings.tsx
Copy link
Member

Choose a reason for hiding this comment

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

I can see why you've moved this to top of the page and and not hidden it by default but I'm not sure whether this will cause confusion with users thinking they need to re-populate this every time they export a model? It still doesn't feel quite right to me how we've combined the model setting required to export a model and the ability to actually do the model export.

Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import ExpandMoreIcon from '@mui/icons-material/ExpandMore'
import { LoadingButton } from '@mui/lab'
import { Accordion, AccordionDetails, AccordionSummary, Box, Stack, TextField, Typography } from '@mui/material'
import {
Accordion,
AccordionDetails,
AccordionSummary,
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 All @@ -19,6 +30,7 @@ export default function ExportSettings({ model }: ExportSettingsProps) {
const [destinationModelId, setDestinationModelId] = useState(model.settings.mirror?.destinationModelId || '')
const [loading, setLoading] = useState(false)
const [errorMessage, setErrorMessage] = useState('')
const [isSettingsOpen, setIsSettingsOpen] = useState(destinationModelId === undefined || destinationModelId === '')

// TODO - Add the ability to filter releases needed for export (This functionality is not available on the backend)
// const [selectedReleases, setSelectedReleases] = useState<ReleaseInterface[]>([])
Expand Down Expand Up @@ -55,25 +67,27 @@ 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 />}>
<Accordion expanded={isSettingsOpen} onChange={() => setIsSettingsOpen(isSettingsOpen ? false : true)}>
<AccordionSummary expandIcon={<ExpandMoreIcon />} sx={{ px: 0 }}>
<Typography variant='h6' component='h1' color='primary' align='center'>
Model Export Settings
</Typography>
</AccordionSummary>
<AccordionDetails>
<Stack spacing={2}>
<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 +96,24 @@ 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' />
</Stack>
</AccordionDetails>
</Accordion>
<ExportModelAgreement modelId={model.id} />
</Stack>
</Box>
</AccordionDetails>
</Accordion>
</Card>
</Container>
</>
)
}
Loading