bryntum / support

An issues-only repository for the Bryntum project management component suite which includes powerful Grid, Scheduler, Calendar, Kanban Task Board and Gantt chart components all built in pure JS / CSS / TypeScript
https://www.bryntum.com
54 stars 6 forks source link

`TooltipBase` should use the default `template` if a custom one returns falsy. #9813

Closed ExtAnimal closed 3 months ago

ExtAnimal commented 3 months ago

Forum post

TooltipBase.js needs:

    getTipHtml({ tip, activeTarget }) {
        const
            me              = this,
            {
                client,
                template
            }               = me,
            defaultTemplate = me.constructor.defaultConfig.template,
            recordProp      = me.recordType || `${client.scheduledEventName}Record`,
            timeSpanRecord  = me.resolveTimeSpanRecord(activeTarget);

        // If user has mouseovered a fading away element of a deleted event,
        // an event record will not be found. In this case the tip must hide.
        // Instance of check is to not display while propagating
        if (timeSpanRecord?.startDate instanceof Date) {
            tip.eventRecord = tip.record = timeSpanRecord;

            if (!template) {
                return;
            }

            const
                { startDate, endDate } = timeSpanRecord,
                startText              = client.getFormattedDate(startDate),
                endDateValue           = client.getDisplayEndDate(endDate, startDate),
                endText                = client.getFormattedDate(endDateValue),
                templateData           = {
                    tip,
                    // eventRecord for Scheduler, taskRecord for Gantt
                    [`${recordProp}`] : timeSpanRecord,
                    startDate,
                    endDate,
                    startText,
                    endText,
                    startClockHtml    : me.clockTemplate.template({
                        date : startDate,
                        text : startText,
                        cls  : 'b-sch-tooltip-startdate'
                    }),
                    endClockHtml : timeSpanRecord.isMilestone ? '' : me.clockTemplate.template({
                        date : endDateValue || '',
                        text : endText || '',
                        cls  : 'b-sch-tooltip-enddate'
                    })
                };

            let result = template.call(me, templateData);

            // If a custom template returns falsy, use the class's own template
            if (!result && template !== defaultTemplate) {
                result = defaultTemplate.call(me, templateData);
            }
            return result;
        }
        else {
            tip.hide();
            return '';
        }
    }