Skip to content

Commit

Permalink
Merge pull request #527 from Esri/position-manager-change-8-20
Browse files Browse the repository at this point in the history
fix(position-manager): reindex, var name updates, id comparison
  • Loading branch information
Csmith246 authored Aug 20, 2024
2 parents baf4d26 + 52f5e94 commit fddcfef
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion amd/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "templates-common-library",
"version": "0.0.510",
"version": "0.0.529",
"files": [
"/*"
],
Expand Down
2 changes: 1 addition & 1 deletion esm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "templates-common-library",
"version": "0.0.510-esm",
"version": "0.0.529-esm",
"files": [
"/*"
],
Expand Down
21 changes: 11 additions & 10 deletions src/functionality/positionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,24 @@ export function assertWidgetOrdering(
() => {
view.when(() => {
const watchWidgetOrdering = (quadrant: __esri.UIPosition) => {
let leftPosition = view.ui.getComponents(quadrant);
let widgets = view.ui.getComponents(quadrant);
let firstAssertion = true;
watch(
() => config.updateCount,
() => {
const leftPositionNew = view.ui.getComponents(quadrant);
const widgetsNew = view.ui.getComponents(quadrant);

const positionsHaveChanged: boolean =
leftPosition.length !== leftPositionNew.length ||
leftPosition.some((el, i) => {
return el !== leftPositionNew[i];
widgets.length !== widgetsNew.length ||
widgets.some((el, i) => {
return el?.id !== widgetsNew[i]?.id;
});

if (positionsHaveChanged || firstAssertion) {
leftPosition = leftPositionNew;
widgets = widgetsNew;
firstAssertion = false;
setTimeout(() => {
const sortedPositionList = leftPosition
const sortedPositionList = widgets
.map((el) => {
const id =
positionKeyLookup.get(el.id) != null
Expand All @@ -79,9 +79,10 @@ export function assertWidgetOrdering(
.sort((a, b) => {
return a[1]?.index - b[1]?.index;
});
sortedPositionList.forEach((sortedPair) => {
sortedPositionList.forEach((sortedPair, index) => {
const [id, positionLookup] = sortedPair;
const el = leftPosition.find((elem) => elem.id === id);
positionLookup.index = index; // override to directly match sorted list
const el = widgets.find((elem) => elem.id === id);
view.ui.move({ component: el, ...positionLookup } as any);
updateExpandGroup(el, positionLookup);
});
Expand Down Expand Up @@ -153,7 +154,7 @@ function debouncePositionUpdate(
components.forEach((component, index) => {
const position = {
index,
position: component.uiPosition.position
position: component.uiPosition.position,
};
view.ui.move(component.widget, position);
});
Expand Down

0 comments on commit fddcfef

Please sign in to comment.