Push multiple objects into the dataLayer

I have the following javascript function that pushes 1 object made of 5 key values into the dataLayer.

function pollForDatalayer() {
  if (typeof(dataLayer.push) === 'function') {
  // The dataLayer.push function is defined, so you can run it here
    for (var i = 0; i < campaigns.length; i++) {
      var campaign = campaigns[i];
      dataLayer.push({
        'event': 'xxx',
        'event_category': 'xxx',
        'campaignName': campaign.key,
        'experienceName': campaign.split,
        'campaignID': campaign.variant_id
        });
    }
    console.log("Data Layer Found.");
  } else {
     console.log("polling for Data Layer.");
    setTimeout(pollForDatalayer, 5000);  
  }
}
pollForDatalayer();

How do I make sure I can push multiple arrays into the dataLayer?
Right now if I have 2 or more objects information to store into the dataLayer only the last one is being pushed. Not the first one.

example of end result of data pushed into the dataLayer I would like to obtain:

{
    "event": "xxx",
    "event_category": "xxx",
    "campaignName": "TEST-1",
    "experienceName": "xxx",
    "campaignID": xxx,
    "gtm.uniqueEventId": xxx
},
{
    "event": "xxx",
    "event_category": "xxx",
    "campaignName": "TEST-2",
    "experienceName": "xxx",
    "campaignID": xxx,
    "gtm.uniqueEventId": xxx
}

How to Convert Flat JSON Data into Tree JSON Data Dynamically into a Tree Table in sap ui5

I want Tree Json data from flat Array of Object Json Dynamically and it should be binded to XML Tree Table control with model
Here, below is my flat json:

    var data = [{
            "d": {
                results: [{
                    Client: "Full",
                    Kznul: false,
                    Bukrs: "",
                    Butxt: "",
                    Werks: "",
                    Name1: "",
                    Lgort: "",
                    Lgobe: "",
                    Charg: "",
                    Labst: "1366788.000"
                }, {
                    Client: "",
                    Kznul: false,
                    Bukrs: "US10",
                    Butxt: "CHEP USA",
                    Werks: "",
                    Name1: "",
                    Lgort: "",
                    Lgobe: "",
                    Charg: "",
                    Labst: "1366788.000"
                }, {
                    Client: "",
                    Kznul: false,
                    Bukrs: "US10",
                    Butxt: "CHEP USA",
                    Werks: "US01",
                    Name1: "CHEP Service Center Red Bluff",
                    Lgort: "",
                    Lgobe: "",
                    Charg: "",
                    Labst: "1366788.000"
                }, {
                    Client: "",
                    Kznul: false,
                    Bukrs: "US10",
                    Butxt: "CHEP USA",
                    Werks: "USXP",
                    Name1: "CHEP Services - Albany",
                    Lgort: "",
                    Lgobe: "",
                    Charg: "",
                    Labst: "1366788.000"
                }, {
                    Client: "",
                    Kznul: false,
                    Bukrs: "US10",
                    Butxt: "CHEP USA",
                    Werks: "US01",
                    Name1: "CHEP Service Center Red Bluff",
                    Lgort: "1000",
                    Lgobe: "RU Storage",
                    Charg: "",
                    Labst: "1366788.000"
                }, {
                    Client: "",
                    Kznul: false,
                    Bukrs: "US10",
                    Butxt: "CHEP USA",
                    Werks: "US01",
                    Name1: "CHEP Service Center Red Bluff",
                    Lgort: "1000",
                    Lgobe: "RU Storage",
                    Charg: "AI",
                    Labst: "1366788.000"
                }, {
                    Client: "",
                    Kznul: false,
                    Bukrs: "US10",
                    Butxt: "CHEP USA",
                    Werks: "US01",
                    Name1: "CHEP Service Center Red Bluff",
                    Lgort: "1000",
                    Lgobe: "RU Storage",
                    Charg: "VARIANCE",
                    Labst: "1366788.000"
                }, {
                    Client: "",
                    Kznul: false,
                    Bukrs: "US10",
                    Butxt: "CHEP USA",
                    Werks: "US01",
                    Name1: "CHEP Service Center Red Bluff",
                    Lgort: "3000",
                    Lgobe: "Production",
                    Charg: "",
                    Labst: "1366788.000"
                }, {
                    Client: "",
                    Kznul: false,
                    Bukrs: "US10",
                    Butxt: "CHEP USA",
                    Werks: "US01",
                    Name1: "CHEP Service Center Red Bluff",
                    Lgort: "3000",
                    Lgobe: "Production",
                    Charg: "AI",
                    Labst: "1366788.000"
                }, {
                    Client: "",
                    Kznul: false,
                    Bukrs: "US10",
                    Butxt: "CHEP USA",
                    Werks: "USXP",
                    Name1: "CHEP Services - Albanyf",
                    Lgort: "3000",
                    Lgobe: "Production",
                    Charg: "",
                    Labst: "1366788.000"
                }, {
                    Client: "",
                    Kznul: false,
                    Bukrs: "US10",
                    Butxt: "CHEP USA",
                    Werks: "USXP",
                    Name1: "CHEP Services - Albanyf",
                    Lgort: "3000",
                    Lgobe: "Production",
                    Charg: "AI",
                    Labst: "1366788.000"
                }]

            }
        }];
        var oModel = new sap.ui.model.json.JSONModel();
        oModel.setData(data);
        this.getView().setModel(oModel, "TableModel");

My Output should be like this:
Output image of Tree format

same format should be implemented in Tree Table in XML code.

I want Detailed code and explanation for it, Thank you Guys

[JS][React] Creating Custom Avatar Group

I am trying to create a custom avatar. However, nothing is being rendered since by the time that the avatar component is being re-rendered, the count for the avatar is already greater causing it to hide or return null once it is re-rendered.

Scenario: The filter should be done only inside the avatar as I am trying to fetch a data via hook in real situation so doing the filtering in the avatar group component is an unnecessary solution.

Here is my avatar group component:

function AvatarGroup() {
    const avatars = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'];
    const [renderedAvatar, setRenderedAvatar] = useState(0);

    return (
        <Stack direction='row'>
            {
                avatars.map((avatar) => {
                    console.log();

                    return (
                        <AvatarRenderer
                            key={avatar}
                            avatar={avatar}
                            renderedAvatar={renderedAvatar}
                            setRenderedAvatar={setRenderedAvatar}
                        />
                    );
                })
            }
        </Stack>
    );
}

Here is my avatar component:

const AvatarRenderer = memo(({ avatar, renderedAvatar, setRenderedAvatar }) => {
    const doNotRender = ['A', 'C', 'E'];

    useEffect(() => {
        if (!doNotRender.includes(avatar) || renderedAvatar < 5) {
            setRenderedAvatar((prevCount) => prevCount + 1);
        }
    }, [avatar]);

    if (doNotRender.includes(avatar) || renderedAvatar > 4) {
        return null;
    }

    return (
        <Box
            width='24px'
            height='24px'
            backgroundColor='#f3f3f3'
            padding='8px'
            margin='4px'
        >
            { avatar }
        </Box>
    );
});

What I expect here is for it to render:

B, D, F, G, H

And then after fixing this issue, would add a +2 which means there are 2 avatars – I and J.

Main issue is the re-render of the child component Avatar which returns null resulting to no avatar being shown. Any idea of a better approach is appreciated.

Is there a way to record entire call stack (start to end) of methods called during execution of an app using Google Chrome or IntelliJ Idea debuggers?

I’m working on a rather complicated legacy app and the frontend part of it consists of few different applications, all written in either JavaScript or TypeScript with Angular 8+.

They are all designed to be executed at once and communicate with each other, but each of them inside own web browser, where web browsers being invoked on custom hardware with touch screen.

Every app is executed inside different web browser window, kind of like microservices, being used as a different part of a whole frontend interface menu screen.

They communicate through WebSockets, browser’s Window postMessage .etc.

I want to ease myself debugging process, by just saving the entire call stack of a particular app, since the moment of invoking breakpoint and then resuming the app execution.

I know there are call stacks visible in both Google Chrome and IntelliJ Idea Ultimate’s debuggers, but the contents of call stack windows (frames) sometimes changes during execution of an app, when doing step by step debugging checks, thus getting refreshed and be updates with new call stack frames.

What I’d like to achieve is the way, to just record/save the entire call stack log, right after I stumble upon debugging breakpoint and then resuming the app, thus allowing the app to just loosely continue executing without any locks.

I’m aware about possibility to just save whole stack of executions as a .json file using Performance tab inside Google Chrome’s Developer Tools, but there is probably not an option to also save the parameters passed to each method during each call?

Do anyone of you know some better way to achieve my goal, maybe using another debugging tool for web development?

Cheers!

Sendgrid integration to frontend application

I am trying to integrate sendgrid to my website. I was able to integrate the sendgrid and for now I am able to send mails. But I want to be able to edit templates before sending the mail. To describe more, I want to be able to extract templates onto my website and edit them in my compose screen or atleast preview them before being able to send the mails.

Is there a function in sendgrid which can help me do this or is there any other way which I can use to achieve it?

React with node error: process.cwd is not a function

So im getting a strange error:
process.cwd is not a function

TypeError: process.cwd is not a function
at Object.resolve (http://localhost:3000/static/js/bundle.js:14623:46)
at exportUsersToExcel (http://localhost:3000/static/js/bundle.js:638:35)
at getAllVals (http://localhost:3000/static/js/bundle.js:641:3)
at HTMLUnknownElement.callCallback (http://localhost:3000/static/js/bundle.js:23348:18)
at Object.invokeGuardedCallbackDev (http://localhost:3000/static/js/bundle.js:23392:20)
at invokeGuardedCallback (http://localhost:3000/static/js/bundle.js:23449:35)
at invokeGuardedCallbackAndCatchFirstError (http://localhost:3000/static/js/bundle.js:23463:29)
at executeDispatch (http://localhost:3000/static/js/bundle.js:27607:7)
at processDispatchQueueItemsInOrder (http://localhost:3000/static/js/bundle.js:27633:11)
at processDispatchQueue (http://localhost:3000/static/js/bundle.js:27644:9)

Has anyone else ran into this and knows how to fix? My app compiles successfully and this only happens with an onclick event where it tries to write an xl file. Code seems stable otherwise.

Angular : Set checkbox to null instead of false

I am currently working on a filter system where user can select few parameters to filter an item list. For example a list of dishes and the filters are with checkbox input like vegan, vegetarian, fish only etc (Just for the sake of example it is in checkbox, I am aware this could be a drop down option). I want the checkbox to return null instead of false when the checkbox is unchecked. In my backend, the false gets recieved as that field should be false instead of just not filtering it with that field. So if someone checks

I am using form control so I am setting the initial value to null, So initially its fine but once the user checks and unchecks then the value is changed to false. I tried changing the type of my formcontrol to <true | null> but that doesn’t seem to work either.

How to add space in the bar for each y tick with chartjs?

I have a chartjs the output looks like the first image, I would like it to look like the second image where the y axis line will “cross” the bar and space it out a bit for better visibility, I don’t think we can call this padding or how can I manage to create this effect using chartjs?

enter image description here

enter image description here

This is the code I have that creates the bars like the first image thanks ahead.

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>$DOGI Listings Graph</title>
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
    <style>
        html,
        body {
            height: 100%;
            margin: 0;
            background-color: black;
            color: white;
        }

        canvas {
            width: 100% !important;
            height: 100% !important;
        }
    </style>
</head>

<body style="background-color: black;color: white;">

    <canvas id="myChart"></canvas>

    <script>

        const chartData = [
            { x: 1, y: 34504 }, { x: 2, y: 47831 },
            { x: 3, y: 7050 }, { x: 4, y: 8009 },
            { x: 5, y: 8400 }, { x: 6, y: 1250 },
            { x: 7, y: 2505 }, { x: 8, y: 2001 },
            { x: 9, y: 88 }, { x: 10, y: 650 },
            { x: 11, y: 1350 }, { x: 12, y: 200 },
            { x: 13, y: 12782 }, { x: 14, y: 1000 },
            { x: 15, y: 50 }, { x: 16, y: 500 },
            { x: 17, y: 204 }, { x: 18, y: 15 },
            { x: 19, y: 250 }, { x: 20, y: 1200 },
            { x: 21, y: 200 }, { x: 22, y: 200 },
            { x: 23, y: 100 }, { x: 24, y: 200 },
            { x: 25, y: 450 }
        ]


        async function createGraphData() {
            const ctx = document.getElementById('myChart').getContext('2d');
            const myChart = new Chart(ctx, {
                type: 'bar',
                data: {
                    datasets: [{
                        label: '# of Tokens',
                        data: chartData,
                        backgroundColor: 'rgb(255,165,3,0.8)',
                    }]
                },
                options: {
                    legend: {
                        display: false
                    },
                    scales: {
                        x: {
                            type: 'linear',
                            position: 'bottom',
                            min: 0,
                            max: 25,
                            ticks: {
                                stepSize: 1,
                                color: 'white',
                                autoSkip: false,
                            },

                            title: {
                                display: true,
                                text: 'Price $ (USD)',
                                color: 'white'
                            }
                        },
                        y: {
                            beginAtZero: true,
                            grid: {
                                color: 'rgba(255,255,255,0.1)'
                            },
                            title: {
                                display: true,
                                text: 'Number of Tokens',
                                color: 'white'
                            },

                            ticks: {
                                color: 'white'
                            }
                        }
                    },
                    plugins: {
                        legend: {
                            display: false,
                            labels: {
                                color: 'white'
                            }
                        },
                        title: {
                            display: true,
                            text: 'Chart Title',
                            color: 'white',
                            font: {
                                size: 24
                            }
                        }
                    },
                    maintainAspectRatio: false,
                    responsive: true,
                    barPercentage: 0.7,
                    categoryPercentage: 0.8,
                }
            });
        }

        createGraphData().catch(console.error);

    </script>

</body>

</html>```

Is it possible to add tooltip (mouse over listener) to google heat map data?

I’ve developed an HTML/Javascript page that uses google API to display a map. I have a list of coordinates that I draw on the map using google heat map. My problem is that I want to add a tool-tip so that when end user mouses over a section of coordinates on the heatmap, it pops up and displays the total number of coordinates in that section. The heatmap data is not always connected. For example, there could be a cluster/blob of 2 coordinates on one side of town & a separate cluster of 500 coordinates on other side of town.

Relevant Code:

function createHeatMap(coordinates) {
            var map = new google.maps.Map(document.getElementById('map'), {
                center: { lat: 33.xxxxxx, lng: -84.xxxxxx },
                zoom: 13.4,
                maxZoom: 15,
            });

            var heatmapData = [];

            coordinates.forEach(function (coord) {
                var latLng = new google.maps.LatLng(coord.latitude, coord.longitude);
                heatmapData.push(latLng);
            });

            heatmap = new google.maps.visualization.HeatmapLayer({
                data: heatmapData,
                map: map,
            });
            const gradient = [
                "rgba(0, 255, 255, 0)",
                "rgba(0, 255, 255, 1)",
                "rgba(0, 191, 255, 1)",
                "rgba(0, 127, 255, 1)",
                "rgba(0, 63, 255, 1)",
                "rgba(0, 0, 255, 1)",
                "rgba(0, 0, 223, 1)",
                "rgba(0, 0, 191, 1)",
                "rgba(0, 0, 159, 1)",
                "rgba(0, 0, 127, 1)",
                "rgba(63, 0, 91, 1)",
                "rgba(127, 0, 63, 1)",
                "rgba(191, 0, 31, 1)",
                "rgba(255, 0, 0, 1)",
            ];

            heatmap.set('radius', 20);
            heatmap.set('gradient', gradient);
            heatmap.set('maxIntensity', 2);
            heatmap.set("opacity", 0.35);

            //Add mouse over listener to display # of coordinates 
        }

I’ve tried adding an event listener for ‘mouseover’ to simply display the total number of coordinates (not broken out by cluster), but nothing happens when I mouse over.

google.maps.event.addListener(heatmap, 'mouseover', function (event) {
                var totalCoordinates = heatmapData.length;
                var content = 'Total Coordinates: ' + totalCoordinates;

                infoWindow.setContent(content);
                infoWindow.setPosition(event.latLng);
                infoWindow.open(map);
             });

            google.maps.event.addListener(heatmap, 'mouseout', function () {
                infoWindow.close();
            });

Convert Array of objects to array of arrays and values [duplicate]

I want to convert this:

data= [{id: 1, name: 'james', country: 'US'}, {id: 2, name: 'john', country: 'NG'}]

to this:

newdata =[[1,'james', 'US'], [2,'john', 'NG']] 

I tried pushing the data to a new array but couldn’t give me my desired result:

const newdata = [];

for (let index = 0; index < data.length; index++) {
  newdata.push(data[index].name);
}

but it’s giving me just the names. I understand that this line data[index].name is the cause.

How to register two service worker for two different scopes in the same domain

In my PWA I got two service-worker: one for ‘/’ (root) scope, registered by my code

const registration = await navigator.serviceWorker.register('/service-worker.js', {
        scope: '/',
      });

where I want to manage the fetch events with some cache, and one for ‘firecloud-messaging-push-scope’, registered by firebase library and used to manage push notification with firebase code.

For some reason I cannot register the root service-worker as chrome flag it as redundant. This piss me off cause I cannot intercept fetch event from the firebase scoped service-worker.

How can I overcome this?

enter image description here

enter image description here

I expect to register one sw for root scope and many other for ant nested path of the pwa.

How to get the value of PI [closed]

Context:

I am working on a [specific project] in [programming language]. I need to retrieve the value of pi for [reasons].

Code Attempt:

Here is what I have tried so far:

// Your code here


## What I've Tried:
- I have tried using `Math. PI`, but [mention any issues or concerns].
- I also attempted [another approach], but it didn't work as expected.

Can’t find relevant info on reading general abstract syntax

When using JS in VS Code I get help popups showing an abstract syntax for various commands/functions/etc. For example:

(method) Promise<any>.then<void, never>(onfulfilled?: ((value: any) => void | PromiseLike<void>) | null | undefined, onrejected?: ((reason: any) => PromiseLike<never>) | null | undefined): Promise<...>

I want to be able to read and understand any abstract syntax like this in JS with all the special characters, etc. But I have no idea how exactly to specify my query to Google in order to get a full, general documentation for JS syntax reading. I encountered several terms like “signature”, “syntax diagram”, etc., but I have no luck getting the results from Google.

For example PowerShell has this dedicated chapter explaining in depth how to read its abstract syntax. I am looking for an in-depth JS equivalent.