Skip to content

Commit

Permalink
address comment
Browse files Browse the repository at this point in the history
  • Loading branch information
devketanpro committed Nov 10, 2023
1 parent 8283e2f commit c076993
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]) {
if (isInitialMount && translations[multilingualConfig.defaultLanguage] == null) {
translations[multilingualConfig.defaultLanguage] = get(
this.props.item,
this.props.field,
Expand Down

0 comments on commit c076993

Please sign in to comment.