-
Notifications
You must be signed in to change notification settings - Fork 5
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
base: develop
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
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( () => { |
There was a problem hiding this comment.
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.)
$(this).parents("ul, li").each(() => { | ||
$(this).show(); |
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
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())), |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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 () { |
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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");
984e378
to
135791d
Compare
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. |
135791d
to
7aca58b
Compare
Describe your changes
upgrading js to use more modern methods
Type of change
Please check only ONE option.
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
develop
as the base branch and notmain
, or the pull request is a hotfix that needs to be done directly onmain
Related pull requests
Link to Asana ticket
https://app.asana.com/0/1204371236183532/1205853947344178/f