Closed Bug 1565204 Opened 6 years ago Closed 4 years ago

Inappropriate use of tree API

Categories

(Calendar :: Internal Components, defect)

Lightning 6.2.5.1
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED WONTFIX

People

(Reporter: neil, Unassigned)

Details

If Lightning starts before I can register my XPCOM calendar component it creates a dummy calendar in its place. I currently do some nasty hackery to remove the dummy calendar without deleting it so that I can reregister my calendar. However one side-effect of this is that the widget that displays the list of calendars sometimes gets confused as to which the default calendar is, depending where it was before.

In particular, when removing a calendar, Lightning always selects the next but one (!) calendar, even when the removed calendar was not the default calendar.

    removeCalendar(calendar) {
        let index = this.findIndexById(calendar.id);
        if (index < 0) {
            return;
        }

        this.mCalendarList.splice(index, 1);
        this.tree.rowCountChanged(index, -1);

        if (index == this.rowCount) {
            index--;
        }

        this.tree.view.selection.select(index + 1);

At the very least you should check whether index used to be selected, and only if so then should you reselect that index or failing that the last index. Selecting the next index actually chooses the calendar two after the one removed. This error also defeats the check against the row count, which could cause a newly added calendar to become selected by mistake.

I also noticed that when adding a calendar, Lightning always tells the tree that it was appended.

        const initialSortOrderPos = calendar.getProperty("initialSortOrderPos");
        if (initialSortOrderPos != null && initialSortOrderPos < this.mCalendarList.length) {
            // Insert the calendar at the requested sort order position
            // and then discard the property.
            this.mCalendarList.splice(initialSortOrderPos, 0, calendar);
            calendar.deleteProperty("initialSortOrderPos");
        } else {
            this.mCalendarList.push(calendar);
        }

        this.tree.rowCountChanged(this.mCalendarList.length - 1, 1);

Here you should calculate the initial position as either the predefined position or the current length, and then insert the calendar at that position, and then tell the tree that it was inserted at that position, so that it can update the selection correctly.

Version: unspecified → Lightning 6.2.5.1

... I guess this is moot on trunk due to bug 1561530.

Resolving as WONTFIX per comment#1.

Status: NEW → RESOLVED
Closed: 4 years ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.