samples/Orders/orders-script/content.js
async function prepareDataSource() {
    const orders = await fetchOrders()
    const ordersByShipCountry = orders.reduce((a, v) => {
        a[v.ShipCountry] = a[v.ShipCountry] || []
        a[v.ShipCountry].push(v)
        return a
    }, {})

    return Object.keys(ordersByShipCountry).map((country) => {
        const ordersInCountry = ordersByShipCountry[country]

        const accumulated = {}

        ordersInCountry.forEach((o) => {
            o.OrderDate = new Date(o.OrderDate);
            const key = o.OrderDate.getFullYear() + '/' + (o.OrderDate.getMonth() + 1);
            accumulated[key] = accumulated[key] || {
                value: 0,
                orderDate: o.OrderDate
            };
            accumulated[key].value++;
        });

        return {
            rows: ordersInCountry,
            country,
            accumulated
        }

    }).slice(0, 2)
}
async function prepareDataSource() {
    const orders = await fetchOrders()
    const ordersByShipCountry = orders.reduce((a, v) => {
        a[v.ShipCountry] = a[v.ShipCountry] || []
        a[v.ShipCountry].push(v)
        return a
    }, {})

    return Object.keys(ordersByShipCountry).map((country) => {
        const ordersInCountry = ordersByShipCountry[country]

        const accumulated = {}

        ordersInCountry.forEach((o) => {
            o.OrderDate = new Date(o.OrderDate);
            const key = o.OrderDate.getFullYear() + '/' + (o.OrderDate.getMonth() + 1);
            accumulated[key] = accumulated[key] || {
                value: 0,
                orderDate: o.OrderDate
            };
            accumulated[key].value++;
        });

        return {
            rows: ordersInCountry,
            country,
            accumulated
        }

    }).slice(0, 2)
}
async function prepareDataSource ( ) { const orders = await fetchOrders ( ) const ordersByShipCountry = orders . reduce ( ( a , v ) => { a [ v . ShipCountry ] = a [ v . ShipCountry ] || [ ] a [ v . ShipCountry ] . push ( v ) return a } , { } ) return Object . keys ( ordersByShipCountry ) . map ( ( country ) => { const ordersInCountry = ordersByShipCountry [ country ] const accumulated = { } ordersInCountry . forEach ( ( o ) => { o . OrderDate = new Date ( o . OrderDate ) ; const key = o . OrderDate . getFullYear ( ) + '/' + ( o . OrderDate . getMonth ( ) + 1 ) ; accumulated [ key ] = accumulated [ key ] || { value : 0 , orderDate : o . OrderDate } ; accumulated [ key ] . value ++ ; } ) ; return { rows : ordersInCountry , country , accumulated } } ) . slice ( 0 , 2 ) }
group the data for report
group the data for report