Skip to content

Commit

Permalink
get rid of componentWillReceiveProps
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-blazhko committed Feb 19, 2025
1 parent c53c557 commit 9e39421
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 29 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Migrate to shared GA workflows. Refs UICIRC-1174.
* *BREAKING* Update stripes-* dependencies to latest version. Refs UICIRC-1176.
* Add seven new item-level tokens to "Pick slip" staff slip. Fixes UICIRC-1169.
* Refactor RulesEditor away from componentWillReceiveProps. Refs UICIRC-431.

## [10.0.1](https://github.com/folio-org/ui-circulation/tree/v10.0.1) (2024-12-04)
[Full Changelog](https://github.com/folio-org/ui-circulation/compare/v10.0.0...v10.0.1)
Expand Down
54 changes: 25 additions & 29 deletions src/settings/lib/RuleEditor/RulesEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ export const escapingForSpecialCharactersWhichCanBreakRegExp = (string = '') =>
class RulesEditor extends React.Component {
constructor(props) {
super(props);

initRulesCMM(Codemirror);
initFoldRules(Codemirror);
this.state = this.getInitialState();
Expand Down Expand Up @@ -232,46 +231,43 @@ class RulesEditor extends React.Component {
this.cm.display.input.textarea.ariaLabel = formatMessage({ id: 'ui-circulation.settings.circulationRules.label' });
}

UNSAFE_componentWillReceiveProps(nextProps) {
const nextState = {};

if (nextProps.typeMapping && !isEqual(nextProps.typeMapping, this.props.typeMapping)) {
nextState.typeMapping = nextProps.typeMapping;
}
componentDidUpdate(prevProps) {
this.clearErrors();
this.cm.refresh();

if (nextProps.policyMapping && !isEqual(nextProps.policyMapping, this.props.policyMapping)) {
nextState.policyMapping = nextProps.policyMapping;
}
const {
errors,
completionLists,
filter,
code,
} = this.props;

if (nextProps.completionLists && !isEqual(nextProps.completionLists, this.props.completionLists)) {
nextState.completionLists = nextProps.completionLists;
if (!isEmpty(errors)) {
errors.forEach(({ line, message }) => this.renderError(line, message));
}

if (!isEmpty(nextState)) {
if (completionLists && !isEqual(completionLists, prevProps.completionLists)) {
this.setState(({ codeMirrorOptions }) => {
const newCodeMirrorOptions = cloneDeep(codeMirrorOptions);

return { codeMirrorOptions: Object.assign(newCodeMirrorOptions.mode, nextState) };
return {
codeMirrorOptions: {
...newCodeMirrorOptions,
mode: {
...newCodeMirrorOptions.mode,
completionLists,
},
},
};
});
}

if (nextProps.code !== this.props.code) {
this.setState(() => ({ code: nextProps.code }));
}

if (nextProps.filter !== this.props.filter) {
this.filterRules(nextProps.filter);
if (code !== prevProps.code) {
this.setState({ code });
}
}

componentDidUpdate() {
this.clearErrors();
this.cm.refresh();

const { errors } = this.props;

if (!isEmpty(errors)) {
errors.forEach(({ line, message }) => this.renderError(line, message));
if (filter !== prevProps.filter) {
this.filterRules(filter);
}
}

Expand Down

0 comments on commit 9e39421

Please sign in to comment.