1- import * as Common from "@frontend/common" ;
1+ import { Components } from "@frontend/common" ;
2+ import { retrieve } from "@frontend/common/src/apis/admin_api" ;
3+ import {
4+ useBackendAdminClient ,
5+ useChoicesQuery ,
6+ useCreateMutation ,
7+ useRemoveMutation ,
8+ useSchemaQuery ,
9+ useUpdateMutation ,
10+ } from "@frontend/common/src/hooks/useAdminAPI" ;
11+ import {
12+ filterPropertiesByLanguageInJsonSchema ,
13+ filterReadOnlyPropertiesInJsonSchema ,
14+ filterWritablePropertiesInJsonSchema ,
15+ } from "@frontend/common/src/utils" ;
216import { Add , Close , Delete , Edit } from "@mui/icons-material" ;
317import {
418 Box ,
@@ -132,7 +146,7 @@ const fieldPropsToSelectedProps = (props: FieldProps): OutlinedSelectProps & { d
132146} ;
133147
134148const M2MSelect : Field = ErrorBoundary . with (
135- { fallback : Common . Components . ErrorFallback } ,
149+ { fallback : Components . ErrorFallback } ,
136150 Suspense . with ( { fallback : < CircularProgress /> } , ( props ) => {
137151 const selectable = ( props . schema . items as JSONSchema7 ) . oneOf as DescriptedEnum [ ] ;
138152 const selectableListObj : DescriptedEnumObject = selectable . reduce ( ( a , i ) => ( { ...a , [ i . const ] : i } ) , { } as DescriptedEnumObject ) ;
@@ -167,29 +181,26 @@ const MDRendererContainer = styled(Box)(({ theme }) => ({
167181 } ,
168182} ) ) ;
169183
170- const MDEditorField : Field = ErrorBoundary . with (
171- { fallback : Common . Components . ErrorFallback } ,
172- ( { disabled, formData, name, onChange : rawOnChange } ) => {
173- const [ valueState , setValueState ] = React . useState < string | undefined > ( formData ?. toString ( ) || "" ) ;
174- const onChange = ( value ?: string ) => {
175- setValueState ( value ) ;
176- rawOnChange ( value , undefined , name ) ;
177- } ;
178- return (
179- < MUIStyledFieldset >
180- < Typography variant = "subtitle2" component = "legend" children = { name } />
181- < Stack direction = "row" spacing = { 2 } sx = { { width : "100%" , height : "100%" , minHeight : "100%" , maxHeight : "100%" , flexGrow : 1 , py : 2 } } >
182- < Box sx = { { width : "50%" , maxWidth : "50%" } } >
183- < Common . Components . MarkdownEditor disabled = { disabled } name = { name } value = { valueState } onChange = { onChange } extraCommands = { [ ] } />
184- </ Box >
185- < MDRendererContainer >
186- < Common . Components . MDXRenderer text = { valueState || "" } format = "md" />
187- </ MDRendererContainer >
188- </ Stack >
189- </ MUIStyledFieldset >
190- ) ;
191- }
192- ) ;
184+ const MDEditorField : Field = ErrorBoundary . with ( { fallback : Components . ErrorFallback } , ( { disabled, formData, name, onChange : rawOnChange } ) => {
185+ const [ valueState , setValueState ] = React . useState < string | undefined > ( formData ?. toString ( ) || "" ) ;
186+ const onChange = ( value ?: string ) => {
187+ setValueState ( value ) ;
188+ rawOnChange ( value , undefined , name ) ;
189+ } ;
190+ return (
191+ < MUIStyledFieldset >
192+ < Typography variant = "subtitle2" component = "legend" children = { name } />
193+ < Stack direction = "row" spacing = { 2 } sx = { { width : "100%" , height : "100%" , minHeight : "100%" , maxHeight : "100%" , flexGrow : 1 , py : 2 } } >
194+ < Box sx = { { width : "50%" , maxWidth : "50%" } } >
195+ < Components . MarkdownEditor disabled = { disabled } name = { name } value = { valueState } onChange = { onChange } extraCommands = { [ ] } />
196+ </ Box >
197+ < MDRendererContainer >
198+ < Components . MDXRenderer text = { valueState || "" } format = "md" />
199+ </ MDRendererContainer >
200+ </ Stack >
201+ </ MUIStyledFieldset >
202+ ) ;
203+ } ) ;
193204
194205type ReadOnlyValueFieldStateType = {
195206 loading : boolean ;
@@ -234,7 +245,7 @@ const ReadOnlyValueField: React.FC<{
234245 ) }
235246 { fieldState . blob . type . startsWith ( "application/json" ) && fieldState . blobText && (
236247 < Box sx = { { maxWidth : "600px" , overflow : "auto" } } >
237- < Common . Components . LottieDebugPanel data = { JSON . parse ( fieldState . blobText ) } />
248+ < Components . LottieDebugPanel data = { JSON . parse ( fieldState . blobText ) } />
238249 </ Box >
239250 ) }
240251 < a href = { value as string } > 링크</ a >
@@ -251,7 +262,7 @@ type InnerAdminEditorStateType = {
251262} ;
252263
253264const InnerAdminEditor : React . FC < AppResourceIdType & AdminEditorPropsType > = ErrorBoundary . with (
254- { fallback : Common . Components . ErrorFallback } ,
265+ { fallback : Components . ErrorFallback } ,
255266 Suspense . with (
256267 { fallback : < CircularProgress /> } ,
257268 ( {
@@ -275,9 +286,10 @@ const InnerAdminEditor: React.FC<AppResourceIdType & AdminEditorPropsType> = Err
275286 tab : 0 ,
276287 formData : undefined ,
277288 } ) ;
278- const backendAdminClient = Common . Hooks . BackendAdminAPI . useBackendAdminClient ( ) ;
279- const { data : schemaInfo } = Common . Hooks . BackendAdminAPI . useSchemaQuery ( backendAdminClient , app , resource ) ;
280- const { data : choicesData } = Common . Hooks . BackendAdminAPI . useChoicesQuery ( backendAdminClient , app , resource ) ;
289+
290+ const backendAdminClient = useBackendAdminClient ( ) ;
291+ const { data : schemaInfo } = useSchemaQuery ( backendAdminClient , app , resource ) ;
292+ const { data : choicesData } = useChoicesQuery ( backendAdminClient , app , resource ) ;
281293
282294 // Merge choices into schema for FK/M2M fields
283295 React . useMemo ( ( ) => {
@@ -299,9 +311,9 @@ const InnerAdminEditor: React.FC<AppResourceIdType & AdminEditorPropsType> = Err
299311 const selectedLanguage = editorState . tab === 0 ? "ko" : "en" ;
300312 const notSelectedLanguage = editorState . tab === 0 ? "en" : "ko" ;
301313
302- const createMutation = Common . Hooks . BackendAdminAPI . useCreateMutation < Record < string , string > > ( backendAdminClient , app , resource ) ;
303- const modifyMutation = Common . Hooks . BackendAdminAPI . useUpdateMutation < Record < string , string > > ( backendAdminClient , app , resource , id || "" ) ;
304- const deleteMutation = Common . Hooks . BackendAdminAPI . useRemoveMutation ( backendAdminClient , app , resource , id || "undefined" ) ;
314+ const createMutation = useCreateMutation < Record < string , string > > ( backendAdminClient , app , resource ) ;
315+ const modifyMutation = useUpdateMutation < Record < string , string > > ( backendAdminClient , app , resource , id || "" ) ;
316+ const deleteMutation = useRemoveMutation ( backendAdminClient , app , resource , id || "undefined" ) ;
305317 const submitMutation = id ? modifyMutation : createMutation ;
306318
307319 React . useEffect ( ( ) => {
@@ -311,7 +323,7 @@ const InnerAdminEditor: React.FC<AppResourceIdType & AdminEditorPropsType> = Err
311323 return ;
312324 }
313325
314- const initialData = await Common . BackendAdminAPIs . retrieve < Record < string , string > > ( backendAdminClient , app , resource , id ) ( ) ;
326+ const initialData = await retrieve < Record < string , string > > ( backendAdminClient , app , resource , id ) ( ) ;
315327 setFormData ( { ...initialData , ...context } ) ;
316328 } ) ( ) ;
317329 // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -359,13 +371,13 @@ const InnerAdminEditor: React.FC<AppResourceIdType & AdminEditorPropsType> = Err
359371 . reduce ( ( acc , [ key , value ] ) => ( { ...acc , [ key ] : value } ) , { } as RJSFSchema ) ;
360372 }
361373
362- const writableSchema = Common . Utils . filterPropertiesByLanguageInJsonSchema (
363- Common . Utils . filterWritablePropertiesInJsonSchema ( schemaInfo . schema ) ,
374+ const writableSchema = filterPropertiesByLanguageInJsonSchema (
375+ filterWritablePropertiesInJsonSchema ( schemaInfo . schema ) ,
364376 schemaInfo . translation_fields ,
365377 selectedLanguage
366378 ) ;
367- const readOnlySchema = Common . Utils . filterPropertiesByLanguageInJsonSchema (
368- Common . Utils . filterReadOnlyPropertiesInJsonSchema ( schemaInfo . schema ) ,
379+ const readOnlySchema = filterPropertiesByLanguageInJsonSchema (
380+ filterReadOnlyPropertiesInJsonSchema ( schemaInfo . schema ) ,
369381 schemaInfo . translation_fields ,
370382 selectedLanguage
371383 ) ;
0 commit comments