Skip to content

Commit

Permalink
fix: Prevent unintended synchronization of multilingual text fields[S…
Browse files Browse the repository at this point in the history
…DESK-7061] (#1877)

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

* address comment
  • Loading branch information
devketanpro authored Nov 10, 2023
1 parent b610709 commit 44c1a79
Showing 1 changed file with 10 additions and 6 deletions.
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

0 comments on commit 44c1a79

Please sign in to comment.