Skip to content

Commit

Permalink
fix(sandbox): add checkbox for translatable property, regroup setting…
Browse files Browse the repository at this point in the history
…s together
  • Loading branch information
BibiSebi committed Feb 20, 2024
1 parent d24fb14 commit 62ce443
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 13 deletions.
42 changes: 29 additions & 13 deletions packages/container/src/components/FieldPluginContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import { ObjectView } from './ObjectView'
import { UrlView } from './UrlView'
import { usePluginParams } from './usePluginParams'
import { LanguageView } from './LanguageView'
import { TranslatableCheckbox } from './TranslatableCheckbox'

const defaultUrl = 'http://localhost:8080'
const initialStory: StoryData = {
Expand Down Expand Up @@ -111,15 +112,17 @@ const useSandbox = (
const [schema, setSchema] = useState<FieldPluginSchema>({
field_type: 'preview',
options: manifest.options,
translatable: false,
})
const [content, setContent] = useState<unknown>(initialContent)
const [language, setLanguage] = useState<string>('')
const [language, setLanguage] = useState<string>('default')
const [stateChangedCallbackId, setStateChangedCallbackId] = useState<string>()

const stateChangedData = useMemo<StateChangedMessage>(
() => ({
model: content,
schema: schema,
interfaceLanguage: 'en',
action: 'state-changed',
uid,
blockId: undefined,
Expand All @@ -130,6 +133,8 @@ const useSandbox = (
token: null,
isModalOpen,
callbackId: stateChangedCallbackId,
releases: [],
releaseId: undefined,
}),
[
uid,
Expand Down Expand Up @@ -371,13 +376,29 @@ export const FieldPluginContainer: FunctionComponent = () => {
</Accordion>
<Accordion defaultExpanded>
<AccordionSummary>
<Typography variant="h3">Options</Typography>
<Typography variant="h3">Settings</Typography>
</AccordionSummary>
<AccordionDetails>
<SchemaEditor
schema={schema}
setSchema={setSchema}
/>
<Stack
width="xs"
gap={5}
>
<SchemaEditor
schema={schema}
setSchema={setSchema}
/>
<TranslatableCheckbox
isTranslatable={schema.translatable}
setTranslatable={(e) => setSchema({ ...schema, translatable: e })}
/>
<LanguageView
sx={{
alignSelf: 'flex-start',
}}
language={language}
setLanguage={setLanguage}
/>
</Stack>
</AccordionDetails>
</Accordion>
<Accordion defaultExpanded>
Expand All @@ -393,13 +414,6 @@ export const FieldPluginContainer: FunctionComponent = () => {
content={content}
setContent={setContent}
/>
<LanguageView
sx={{
alignSelf: 'flex-start',
}}
language={language}
setLanguage={setLanguage}
/>
</Stack>
</AccordionDetails>
</Accordion>
Expand All @@ -418,6 +432,8 @@ export const FieldPluginContainer: FunctionComponent = () => {
{
content,
isModalOpen,
translatable: schema.translatable,
storyLang: language,
options: recordFromFieldPluginOptions(schema.options),
} satisfies Partial<FieldPluginData<unknown>>
}
Expand Down
21 changes: 21 additions & 0 deletions packages/container/src/components/TranslatableCheckbox.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Checkbox, FormControl, FormLabel } from '@mui/material'
import { FunctionComponent } from 'react'

export const TranslatableCheckbox: FunctionComponent<{
isTranslatable: boolean
setTranslatable: (value: boolean) => void
}> = (props) => {
return (
<FormControl>
<FormLabel htmlFor="translatable-checkbox">Translatable</FormLabel>
<Checkbox
sx={{
alignSelf: 'flex-start',
}}
aria-describedby="translatable-checkbox"
value={props.isTranslatable}
onChange={(e) => props.setTranslatable(e.target.checked)}
/>
</FormControl>
)
}

0 comments on commit 62ce443

Please sign in to comment.