-
Notifications
You must be signed in to change notification settings - Fork 12
[Document Editor][Context Menu Options][Detail view][Translations] New document #2169
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
Merged
markus-moser
merged 18 commits into
1.x
from
1678-document-editorcontext-menu-optionsdetail-viewtranslations-new-document
Oct 8, 2025
Merged
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 fcf743c
[Translations] New document: Check parent of already available transl…
MSchinwaldEl 49fa716
[Translations] New document: Fix lint #1678
MSchinwaldEl 6e60dd2
[Translations] New document: Refresh tree and fix lint #1678
MSchinwaldEl f6193f3
Automatic frontend build
MSchinwaldEl d92fcd7
[Translations] New document: Avoid unnecessary request #1678
MSchinwaldEl 7280843
Merge remote-tracking branch 'origin/1678-document-editorcontext-menu…
MSchinwaldEl 3d4716f
[Translations] New document: Fix SonarQube #1678
MSchinwaldEl 10f0e6b
Automatic frontend build
MSchinwaldEl be40ff8
[Translations] New document: Show entries only for translatable doc t…
MSchinwaldEl f5a8443
Automatic frontend build
MSchinwaldEl 23ae3b9
[Translations] New document: Added some icons for translation menu #1678
MSchinwaldEl 96939ba
Automatic frontend build
MSchinwaldEl 9dd4624
[Translations] New document: Set loading state of parent input nicely…
MSchinwaldEl 513193f
[Translations] New document: Improve labelling with translations #1678
MSchinwaldEl fbe2ea7
[Translations] New document: Remove unnecessary onChange prop from Ma…
MSchinwaldEl 1164ca7
[Translations] New document: Catch error of DocumentAddMutation #1678
MSchinwaldEl 4b9e8f0
Automatic frontend build
MSchinwaldEl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
207 changes: 207 additions & 0 deletions
207
...ts/js/src/core/modules/document/actions/translations/components/new-translation-modal.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
MSchinwaldEl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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> | ||
) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.