Skip to content
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

fix: Prevent unintended synchronization of multilingual text fields[SDESK-7061] #1877

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions client/components/fields/editor/base/multilingualText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class EditorFieldMultilingualText extends React.Component<IMultilingualTe
constructor(props: IMultilingualTextProps) {
super(props);

this.state = {fields: this.getFieldStates()};
this.state = {fields: this.getFieldStates(true)};
this.onChange = this.onChange.bind(this);
}

Expand All @@ -30,12 +30,16 @@ export class EditorFieldMultilingualText extends React.Component<IMultilingualTe
this.updateFieldState();
}
}
componentDidMount() {
// Update the field state after mounting, indicating it's the initial mount
this.updateFieldState(true);
}

updateFieldState() {
this.setState({fields: this.getFieldStates()});
updateFieldState(isInitialMount: boolean = false) {
this.setState({fields: this.getFieldStates(isInitialMount)});
}

getFieldStates(): IState['fields'] {
getFieldStates(isInitialMount: boolean = false): IState['fields'] {
const multilingualConfig = planningApi.contentProfiles.multilingual.getConfig(this.props.profile?.name);

if (multilingualConfig.isEnabled === false) {
Expand All @@ -50,10 +54,10 @@ export class EditorFieldMultilingualText extends React.Component<IMultilingualTe
return fields;
}, {});

// If the entry for the default language has not been assigned to the item
// If it's the initial mount and the entry for the default language has not been assigned to the item
// then this item may have been created before multilingual functionality
// therefor show the value from the parent field
if (translations[multilingualConfig.defaultLanguage] == null) {
if (isInitialMount && translations[multilingualConfig.defaultLanguage] == null) {
translations[multilingualConfig.defaultLanguage] = get(
this.props.item,
this.props.field,
Expand Down
Loading