sozsoft-platform/ui/src/components/visualDesigner/DesignerScriptBuilderDialog.tsx

72 lines
2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import ScriptBuilderDialog from '@/components/scriptBuilder/ScriptBuilderDialog'
import { useMemo } from 'react'
import { useLocalization } from '@/utils/hooks/useLocalization'
import { createDesignerScriptDialect } from './designerScriptDialect'
import type { FormEvent } from './types'
export type DesignerScriptBuilderDialogProps = {
isOpen: boolean
value?: string
/** Düzenlenen event: başlıkta ve event yolu seçicilerinde kullanılır. */
eventName: string
eventInfo?: FormEvent
/** Event'in sahibi komponentin adı, yalnızca başlık için. */
componentLabel?: string
/** Kayıt tariflerinin yazacağı Form ref adı. */
sqlRef: string
/** Form Select sonucundaki sütun adları. */
recordFields: string[]
/** Sayfadaki tüm ref adları. */
refNames: string[]
onClose: () => void
onApply: (value: string) => void
}
/**
* Designer event'lerinin script editörü. Ortak Script Builder'ı designer
* lehçesiyle kurar; dialog'un kendisi paylaşılan bileşendir.
*/
function DesignerScriptBuilderDialog({
isOpen,
value,
eventName,
eventInfo,
componentLabel,
sqlRef,
recordFields,
refNames,
onClose,
onApply,
}: DesignerScriptBuilderDialogProps) {
const { translate } = useLocalization()
// Çağıran her render'da yeni diziler üretiyor; lehçe içeriklerine göre
// sabitlenmezse editör yazarken sıfırlanırdı.
const recordFieldKey = recordFields.join('|')
const refNameKey = refNames.join('|')
const dialect = useMemo(
() =>
createDesignerScriptDialect({
componentLabel,
eventInfo,
eventName,
recordFields: recordFieldKey ? recordFieldKey.split('|') : [],
refNames: refNameKey ? refNameKey.split('|') : [],
sqlRef,
translate,
}),
[componentLabel, eventInfo, eventName, recordFieldKey, refNameKey, sqlRef, translate],
)
return (
<ScriptBuilderDialog
dialect={dialect}
isOpen={isOpen}
value={value}
onApply={onApply}
onClose={onClose}
/>
)
}
export default DesignerScriptBuilderDialog