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

Implemented template tab in model settings. May need to looka at han… #1327

Merged
merged 6 commits into from
Jun 19, 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
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default function AccessRequestSettings({ model }: AccessRequestSettingsPr
const updatedModelSettings = {
settings: {
ungovernedAccess: allowUngoverned,
allowTemplating: model.settings.allowTemplating,
},
}

Expand Down
72 changes: 72 additions & 0 deletions frontend/src/entry/model/settings/TemplateSettings.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { LoadingButton } from '@mui/lab'
import { Checkbox, Divider, FormControlLabel, Stack, Typography } from '@mui/material'
import { patchModel } from 'actions/model'
import { useState } from 'react'
import useNotification from 'src/hooks/useNotification'
import MessageAlert from 'src/MessageAlert'
import { EntryInterface } from 'types/types'
import { getErrorMessage } from 'utils/fetcher'

type TemplateSettingsProps = {
model: EntryInterface
}

export default function TemplateSettings({ model }: TemplateSettingsProps) {
const [allowTemplating, setAllowTemplating] = useState(model.settings.allowTemplating)
const [loading, setLoading] = useState(false)
const [errorMessage, setErrorMessage] = useState('')
const sendNotification = useNotification()

async function handleSave() {
setLoading(true)
const updatedModelSettings = {
settings: {
ungovernedAccess: model.settings.ungovernedAccess,
allowTemplating,
},
}

const response = await patchModel(model.id, updatedModelSettings)

if (!response.ok) {
setErrorMessage(await getErrorMessage(response))
} else {
sendNotification({
variant: 'success',
msg: 'Template settings updated',
anchorOrigin: { horizontal: 'center', vertical: 'bottom' },
})
}
setLoading(false)
}

return (
<Stack spacing={2}>
<Typography variant='h6' component='h2'>
Manage Template
</Typography>
<FormControlLabel
label='Allow users to make a template'
control={
<Checkbox
onChange={(event) => setAllowTemplating(event.target.checked)}
checked={allowTemplating}
size='small'
/>
}
/>
<Divider />
<div>
<LoadingButton
variant='contained'
aria-label='Save model template settings'
onClick={handleSave}
loading={loading}
>
Save
</LoadingButton>
<MessageAlert message={errorMessage} severity='error' />
</div>
</Stack>
)
}
12 changes: 11 additions & 1 deletion frontend/src/entry/settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useRouter } from 'next/router'
import { useEffect, useState } from 'react'
import SimpleListItemButton from 'src/common/SimpleListItemButton'
import AccessRequestSettings from 'src/entry/model/settings/AccessRequestSettings'
import TemplateSettings from 'src/entry/model/settings/TemplateSettings'
import EntryAccessPage from 'src/entry/settings/EntryAccessPage'
import EntryDetails from 'src/entry/settings/EntryDetails'
import { EntryInterface, EntryKind, EntryKindKeys } from 'types/types'
Expand All @@ -14,6 +15,7 @@ export const SettingsCategory = {
DANGER: 'danger',
ACCESS_REQUESTS: 'access_requests',
PERMISSIONS: 'permissions',
TEMPLATE: 'template',
} as const

export type SettingsCategoryKeys = (typeof SettingsCategory)[keyof typeof SettingsCategory]
Expand All @@ -28,7 +30,8 @@ function isSettingsCategory(
value === SettingsCategory.DETAILS ||
value === SettingsCategory.PERMISSIONS ||
value === SettingsCategory.ACCESS_REQUESTS ||
value === SettingsCategory.DANGER
value === SettingsCategory.DANGER ||
value === SettingsCategory.TEMPLATE
)
case EntryKind.DATA_CARD:
return value === SettingsCategory.DETAILS || value === SettingsCategory.PERMISSIONS
Expand Down Expand Up @@ -93,6 +96,12 @@ export default function Settings({ entry }: SettingsProps) {
>
Access Requests
</SimpleListItemButton>
<SimpleListItemButton
selected={selectedCategory === SettingsCategory.TEMPLATE}
onClick={() => handleListItemClick(SettingsCategory.TEMPLATE)}
>
Template
</SimpleListItemButton>
<SimpleListItemButton
selected={selectedCategory === SettingsCategory.DANGER}
onClick={() => handleListItemClick(SettingsCategory.DANGER)}
Expand All @@ -106,6 +115,7 @@ export default function Settings({ entry }: SettingsProps) {
{selectedCategory === SettingsCategory.DETAILS && <EntryDetails entry={entry} />}
{selectedCategory === SettingsCategory.PERMISSIONS && <EntryAccessPage entry={entry} />}
{selectedCategory === SettingsCategory.ACCESS_REQUESTS && <AccessRequestSettings model={entry} />}
{selectedCategory === SettingsCategory.TEMPLATE && <TemplateSettings model={entry} />}
{selectedCategory === SettingsCategory.DANGER && (
<Stack spacing={2}>
<Typography variant='h6' component='h2'>
Expand Down
1 change: 1 addition & 0 deletions frontend/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ export interface EntryInterface {
description: string
settings: {
ungovernedAccess: boolean
allowTemplating: boolean
}
card: EntryCardInterface
visibility: EntryVisibilityKeys
Expand Down
1 change: 1 addition & 0 deletions frontend/utils/test/testModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export const testV2Model: EntryInterface = {
],
settings: {
ungovernedAccess: false,
allowTemplating: false,
},
teamId: 'test-team',
card: testModelCard,
Expand Down
Loading