Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
6bbc1d7
[Translations] New document: Add the context menu entries to create a…
MSchinwaldEl Oct 1, 2025
fcf743c
[Translations] New document: Check parent of already available transl…
MSchinwaldEl Oct 1, 2025
49fa716
[Translations] New document: Fix lint #1678
MSchinwaldEl Oct 1, 2025
6e60dd2
[Translations] New document: Refresh tree and fix lint #1678
MSchinwaldEl Oct 2, 2025
f6193f3
Automatic frontend build
MSchinwaldEl Oct 2, 2025
d92fcd7
[Translations] New document: Avoid unnecessary request #1678
MSchinwaldEl Oct 2, 2025
7280843
Merge remote-tracking branch 'origin/1678-document-editorcontext-menu…
MSchinwaldEl Oct 2, 2025
3d4716f
[Translations] New document: Fix SonarQube #1678
MSchinwaldEl Oct 2, 2025
10f0e6b
Automatic frontend build
MSchinwaldEl Oct 2, 2025
be40ff8
[Translations] New document: Show entries only for translatable doc t…
MSchinwaldEl Oct 6, 2025
f5a8443
Automatic frontend build
MSchinwaldEl Oct 6, 2025
23ae3b9
[Translations] New document: Added some icons for translation menu #1678
MSchinwaldEl Oct 6, 2025
96939ba
Automatic frontend build
MSchinwaldEl Oct 6, 2025
9dd4624
[Translations] New document: Set loading state of parent input nicely…
MSchinwaldEl Oct 8, 2025
513193f
[Translations] New document: Improve labelling with translations #1678
MSchinwaldEl Oct 8, 2025
fbe2ea7
[Translations] New document: Remove unnecessary onChange prop from Ma…
MSchinwaldEl Oct 8, 2025
1164ca7
[Translations] New document: Catch error of DocumentAddMutation #1678
MSchinwaldEl Oct 8, 2025
4b9e8f0
Automatic frontend build
MSchinwaldEl Oct 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 3 additions & 0 deletions assets/js/src/core/assets/icons/blank.inline.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions assets/js/src/core/assets/icons/link-document.inline.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/js/src/core/assets/icons/new-document.inline.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions assets/js/src/core/assets/icons/unlink-document.inline.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
/**
* This source file is available under the terms of the
* Pimcore Open Core License (POCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (https://www.pimcore.com)
* @license Pimcore Open Core License (POCL)
*/

import React, { useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { WindowModal } from '@Pimcore/components/modal/window-modal/window-modal'
import { ModalFooter } from '@Pimcore/components/modal/footer/modal-footer'
import { Button } from '@Pimcore/components/button/button'
import { ManyToOneRelation } from '@Pimcore/components/many-to-one-relation/many-to-one-relation'
import type { ManyToOneRelationValue } from '@Pimcore/components/many-to-one-relation/many-to-one-relation'
import { Form } from '@sdk/components'
import { Input } from '@Pimcore/components/input/input'
import { Select } from '@Pimcore/components/select/select'
import { type LanguageOption } from '@Pimcore/modules/document/actions/paste/use-paste'
import { useSettings } from '@Pimcore/modules/app/settings/hooks/use-settings'
import { has, isNil, isString } from 'lodash'
import { useLanguageLookup } from '@Pimcore/modules/translations/hooks/use-language-lookup'
import { useDocumentGetTranslationParentByLanguageQuery } from '@Pimcore/modules/document/document-api-slice-enhanced'
import { type Element } from '@Pimcore/modules/element/element-helper'

export interface NewTranslationModalProps {
isOpen: boolean
useInheritance: boolean
onClose: () => void
onSubmit: (values: NewTranslationFormValues) => Promise<void>
currentDocument: Element | null
}

export interface NewTranslationFormValues {
language: string
parent: ManyToOneRelationValue | null
title: string
navigation: string
key: string
}

export const NewTranslationModal = ({
isOpen,
useInheritance,
onClose,
onSubmit,
currentDocument
}: NewTranslationModalProps): React.JSX.Element => {
const { t } = useTranslation()
const { getDisplayName } = useLanguageLookup()
const settings = useSettings()
const [isSubmitting, setIsSubmitting] = useState(false)
const [selectedLanguage, setSelectedLanguage] = useState<string>('')
const [form] = Form.useForm<NewTranslationFormValues>()

const languageProperty = (!isNil(currentDocument) && has(currentDocument, 'properties') && Array.isArray(currentDocument?.properties))
? currentDocument.properties?.find(prop => prop.key === 'language')
: undefined
const currentDocumentLanguage = isString(languageProperty?.data) ? languageProperty.data : ''

const availableLanguages: LanguageOption[] = (settings.validLanguages ?? [])
.filter((locale: string) => locale !== currentDocumentLanguage)
.map((locale: string) => ({
value: locale,
label: `${getDisplayName(locale)} [${locale}]`
}))

const { data: translationParentData, error: translationParentError, isLoading: isLoadingParent, isFetching: isFetchingParent } = useDocumentGetTranslationParentByLanguageQuery(
{
id: currentDocument?.id ?? 0,
language: selectedLanguage
},
{ skip: selectedLanguage === '' || isNil(currentDocument?.id) }
)

const isParentLoading = isLoadingParent || isFetchingParent

// Auto-preselect parent when translation parent data is available and contains fullPath
useEffect(() => {
if (!isNil(translationParentError)) {
// Reset parent field when there's an error (no translation parent found)
form.setFieldValue('parent', null)
} else if (!isNil(translationParentData?.fullPath) && !isNil(translationParentData?.id)) {
form.setFieldValue('parent', {
id: translationParentData.id,
type: 'document',
fullPath: translationParentData.fullPath
})
}
}, [translationParentData, translationParentError, form])

const handleSubmit = async (): Promise<void> => {
setIsSubmitting(true)
try {
const values = await form.validateFields()
await onSubmit(values)
} finally {
setIsSubmitting(false)
}
}

const handleTitleChange = (e: React.ChangeEvent<HTMLInputElement>): void => {
const value = e.target.value
form.setFieldsValue({
title: value,
navigation: value,
key: value
})
}

const handleLanguageChange = (language: string): void => {
setSelectedLanguage(language)
// Reset parent field when language changes - it will be auto-filled by useEffect if translation parent exists
form.setFieldValue('parent', null)
}

const modalTitle = useInheritance
? t('document.translation.new-document-with-inheritance.modal-title')
: t('document.translation.new-document-blank.modal-title')

return (
<WindowModal
footer={
<ModalFooter>
<Button
onClick={ onClose }
type="default"
>
{t('cancel')}
</Button>
<Button
loading={ isSubmitting }
onClick={ handleSubmit }
type="primary"
>
{t('document.translation.new-document-modal.create')}
</Button>
</ModalFooter>
}
onCancel={ onClose }
open={ isOpen }
size="L"
title={ modalTitle }
>
<Form
form={ form }
initialValues={ {
language: '',
parent: null,
title: '',
navigation: '',
key: ''
} }
layout="vertical"
>
<Form.Item
label={ t('document.translation.new-document-modal.label.language') }
name="language"
rules={ [{ required: true, message: t('form.validation.required') }] }
>
<Select
onChange={ handleLanguageChange }
options={ availableLanguages }
/>
</Form.Item>

<Form.Item
label={ t('document.translation.new-document-modal.label.parent') }
name="parent"
rules={ [{ required: true, message: t('form.validation.required') }] }
>
<ManyToOneRelation
allowToClearRelation
disabled={ isParentLoading }
documentsAllowed
/>
</Form.Item>

<Form.Item
label={ t('add-document-form.label.title') }
name="title"
rules={ [{ required: true, message: t('form.validation.required') }] }
>
<Input onChange={ handleTitleChange } />
</Form.Item>

<Form.Item
label={ t('add-document-form.label.navigation') }
name="navigation"
rules={ [{ required: true, message: t('form.validation.required') }] }
>
<Input />
</Form.Item>

<Form.Item
label={ t('add-document-form.label.key') }
name="key"
rules={ [{ required: true, message: t('form.validation.required') }] }
>
<Input />
</Form.Item>
</Form>
</WindowModal>
)
}
Loading