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

EZP-31345 Added language select when user edit sub items #270

Merged

Conversation

lucasOsti
Copy link
Contributor

Question Answer
Tickets https://jira.ez.no/browse/EZP-31345
Bug fix? no
New feature? yes
BC breaks? no
Tests pass? yes
Doc needed? no
License GPL-2.0

Checklist:

  • Coding standards ($ composer fix-cs)
  • Ready for Code Review


useEffect(() => {
const items = [..._refInstantFilter.current.querySelectorAll(`.${props.itemClass}`)];
const itemsMap = items.reduce(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why reduce instead of simply map?

}, []);

useEffect(() => {
window.clearTimeout(filterTimeout);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clearTimeout should go to return function insteaed of here

Suggested change
window.clearTimeout(filterTimeout);
useEffect(() => {
const filterActionTimeout = window.setTimeout(() => {
const results = itemsMap.filter((item) => item.label.includes(filterQuery.toLowerCase()));
itemsMap.forEach((item) => item.element.setAttribute('hidden', true));
results.forEach((item) => item.element.removeAttribute('hidden'));
}, FILTER_TIMEOUT);
return () => {
window.clearTimeout(filterActionTimeout);
}
}, [filterQuery]);

window.clearTimeout(filterTimeout);

const filterActionTimeout = window.setTimeout(() => {
const results = itemsMap.filter((item) => item.label.includes(filterQuery.toLowerCase()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can store filterQuery.toLowerCase() in new variable so that you won't fire toLowerCase with each filter iteration

name="items"
className="form-check-input"
value={item.value}
onChange={(event) => props.handleItemChange(event)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be just onChange={props.handleItemChange}

const languages = this.props.languages.mappings;
const { languageCodes } = this.props.item.content._info.currentVersion;
const label = Translator.trans(/*@Desc("Select language")*/ 'languages.modal.label', {}, 'sub_items');
const languageItems = languageCodes.reduce(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why reduce instead of simply map?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const languageItems = languageCodes.reduce(
const languageItems = languageCodes.map((item) => ({
label: languages[item].name,
value: item,
}));

</div>
</div>
);
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary else

Suggested change
} else {
}
return false;
}
}

* @memberof SubItemsModule
*/
setContentEditLanguagesModalPosition() {
const rightMainMenuNode = document.querySelector(RIGHT_MAIN_MENU_SELECTOR);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could go inside if

Copy link
Member

@dew326 dew326 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review discussed in private, some changes in the architecture are needed

}
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

const _refInstantFilter = useRef(null);
const [filterQuery, setFilterQuery] = useState('');
const [itemsMap, setItemsMap] = useState([]);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

};

InstantFilter.propTypes = {
uniqueId: PropTypes.string,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is not needed anymore. I current implementation there will be only one InstantFilter and it will always be the same value.

InstantFilter.propTypes = {
uniqueId: PropTypes.string,
items: PropTypes.array,
itemClass: PropTypes.string,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this have to be in prop? It can be just regular variable. I don't see a point of overriding this by parent component, or am I missing something.

const LanguageSelector = (props) => {
const className = createCssClassNames({
'ez-extra-actions': true,
'ez-language-selector': true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'ez-language-selector': true,
'c-language-selector': true,

@@ -105,6 +113,31 @@ export default class TableViewComponent extends Component {
);
}

/**
* Set language selector data
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Set language selector data
* Sets language selector data

<input
type="text"
className="ez-instant-filter__input form-control"
placeholder="Type to refine"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need translation

@bogusez
Copy link

bogusez commented Feb 21, 2020

I've got a problem with editing sub-items after cloning this. You can find more info on attached screenshot below.
Screenshot 2020-02-21 at 13 31 04

@lucasOsti lucasOsti force-pushed the EZP-31345-edit-subitems-form-list branch from 8d56eea to 31ff69d Compare February 21, 2020 13:11
@lserwatka lserwatka merged commit 4dda573 into ezsystems:master Feb 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

5 participants