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

Feature/javascript improvements 2 #649

Draft
wants to merge 10 commits into
base: develop
Choose a base branch
from

Conversation

MikeVanMourik
Copy link
Contributor

Describe your changes

upgrading js to use more modern methods

Type of change

Please check only ONE option.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Upgrade

How was this tested?

ran locally and comparing it with the wiserdemo on the side (as far as i can test on that since not everything on the demo site seems to work)

Checklist before requesting a review

  • I have reviewed and tested my changes
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I selected develop as the base branch and not main, or the pull request is a hotfix that needs to be done directly on main
  • I double checked all my changes and they contain no temporary test code, no code that is commented out and no changes that are not part of this branch
  • I added new unit tests for my changes if applicable

Related pull requests

Link to Asana ticket

https://app.asana.com/0/1204371236183532/1205853947344178/f

Copy link
Contributor

Choose a reason for hiding this comment

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

The kendoSortable component still has several functions that you didn't convert to arrow functions. It also uses Wiser.api().then() and .catch(), which could be converted to using async and await.

$(this).parents("ul, li").each(function () {
var treeView = checkTreeElement.data("kendoTreeView");
checkTreeElement.find(".k-in:contains(" + filterText + ")").each(() => {
$(this).parents("ul, li").each( () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Remember that changing functions to arrow functions also changes how the this keyword works in javascript. You forgot to change the code to handle this, so this code will no longer work now. The code $(this) will now return something else, because it's inside an arrow function.

Before it was an arrow function, this was the HTML element, now it's the class/object that the code is located in. To fix this, you change the function; The each function of jQuery has 2 paramers: index and element, you can use those instead of the this keyword. Like this:

checkTreeElement.find(`.k-in:contains(${filterText})`).each((checkboxIndex, checkboxElement) => {
	$(checkboxElement).parents("ul, li").each((listIndex, listElement) => {
		const treeView = checkTreeElement.data("kendoTreeView");
		treeView.expand($(listElement).parents("li"));
		$(listElement).show();
	});
});

(You also forgot to use a string template here, see my example.)

Comment on lines 48 to 49
$(this).parents("ul, li").each(() => {
$(this).show();
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here with the this keyword.

@@ -123,8 +124,8 @@ Wiser.api({
url: window.dynamicItems.settings.serviceRoot + "/GET_COLUMNS_FOR_LINK_TABLE?linkTypeNumber=" + (options.linkTypeNumber || "") + "&id=" + encodeURIComponent(currentItemId),
Copy link
Contributor

Choose a reason for hiding this comment

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

Please also refactor this string concatenation into a template string.

dataSource: {
transport: {
read: function(readOptions) {
read: (readOptions) => {
startLoader();

Wiser.api({
url: window.dynamicItems.settings.serviceRoot + "/GET_DATA_FOR_FIELD_TABLE?itemId=" + encodeURIComponent("{itemIdEncrypted}") + "&linkTypeNumber=" + (options.linkTypeNumber || "") + "&moduleId=" + options.moduleId + "&entity_type=" + encodeURIComponent((!options.entityTypes ? "" : options.entityTypes.join())),
Copy link
Contributor

Choose a reason for hiding this comment

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

Please also refactor this string concatenation into a template string.

@@ -393,8 +399,8 @@ async function generateGrid(data, model, columns) {
data: JSON.stringify(transportOptions.data)
}).then(function (customQueryResults) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You forgot to change this to an arrow function.

},
cursor: "move",
placeholder: function (element) {
placeholder: (element) => {
return element.clone().addClass("k-state-hover").css("opacity", 0.65);
},
container: "#overviewGrid{propertyIdWithSuffix}",
filter: ">tbody >tr",
change: function (e) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You forgot to change this into an arrow function.

@@ -1,9 +1,9 @@
(function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

You forgot to change this into an arrow function.

@@ -1,15 +1,16 @@
(function () {
Copy link
Contributor

Choose a reason for hiding this comment

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

You forgot to change this into an arrow function.

field.on("click", ".openDetails", function (event) {
var itemId = $(this).closest(".timelineEvent").data("itemid");
field.on("click", ".openDetails", (event) => {
let itemId = $(this).closest(".timelineEvent").data("itemid");
Copy link
Contributor

Choose a reason for hiding this comment

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

The this keyword doesn't work the same anymore in an arrow function. This line should be changed to this:

let itemId = $(event.currentTarget).closest(".timelineEvent").data("itemid");

@MikeVanMourik MikeVanMourik force-pushed the feature/javascript-improvements-2 branch from 984e378 to 135791d Compare October 9, 2024 07:50
@MikeVanMourik
Copy link
Contributor Author

this pull request is a lot of work since im making changes, testing and because of only getting a little bit of time for it also includes rebases, so to make things less confusing ill place this PR into Drafts. ill take it out when its ready for another review round.

@MikeVanMourik MikeVanMourik marked this pull request as draft October 10, 2024 11:42
@MikeVanMourik MikeVanMourik force-pushed the feature/javascript-improvements-2 branch from 135791d to 7aca58b Compare October 25, 2024 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants