CSS delayed visibility transition doesn’t trigger JavaScript transitionend event for visibility?

I’m using the technique for delaying visibility transition, combined with opacity. This is working nice:

<body>
  <button>run</button>
  <div class="box"></div>
</body>
.box {
  visibility: hidden;
  opacity: 0;
  /* property name | duration | easing function | delay */
  transition: visibility 0s ease-in-out 3s,
              opacity 3s ease-in-out;
}

.box.show {
  visibility: visible;
  opacity: 1;
  transition-delay: 0s;
}

The problem happens when I listen to the transitionend event. This should log both visibility and opacity properties, but instead only the opacity is logged (pen here):

const button = document.querySelector('button');
const box = document.querySelector('.box');

// When class "show" is added, only "opacity" is logged
// When class "show" is removed, both "opacity" and "visibility" are logged
box.addEventListener('transitionend', e => {
  console.log(e.propertyName);
});

button.addEventListener('click', () => {
  box.classList.toggle('show');
});

Why I need to listen to transitioned? with this event I’am checking the number of transition properties (totalProperties); when all properties are transitioned (tracking with a counter), I know that element actually finished all its transitions:

const totalProperties = window.getComputedStyle(element)['transition-property'].split(',').length;
let counter = 0;

const callback = e => {
  e.stopPropagation();

  if (++counter === totalProperties) {
    counter = 0;
    box.removeEventListener('transitionend', callback);

    console.log('All properties transitioned.');
  }
};

box.addEventListener('transitionend', callback);

Fetching api data and Updating the Page’s state in React

This is the function i use for fetching data

export const findAllBugServer = createAsyncThunk(
    'get/bug',
    async (filter, thunkAPI) => {
        console.log("I was called")
        const res = await axios.get(`${URL}/`, {
            params: {}
        })
        console.log(res.data)
        return res.data;
    }
)

And when the request is fullfiled i update my state:

        [findAllBugServer.fulfilled]: (state, action) => {
            state.allBugs = action.payload;
            // console.log("UUUWWWWUUUU");
        },

In my home page i call:

const {allBugs} = useSelector((store) => store.bug);
const dispatch = useDispatch();
useEffect(() => {
        dispatch(findAllBugServer());
        handleSidenavOpenDashboardPage();
        handleSidenavOpen();
    }, [])

Now all of my fetched data have a field of “status” and “severity”, i want to iterate over all the data and show how many of them has status of “open”, “closed” etc.
How can i do this in React, i tried a certain things which involved using useState() but it threw my code in an infinite loop.
This is my useState:

const [counts, setCounts] = useState({
        open: 0,
        toBeTested: 0,
        inProgress: 0,
        closed: 0,
        minor: 0,
        major: 0,
        critical: 0,
        showStopper: 0
    })

Please tell me how can i update this counts and then display them in components like these:

<DashboardStateCard name={"Open"} count={counts.open} />

Pact V3 JS with GraphQL

I want to use Pact-JS V3 version with GraphQL operations testing. It offers interesting new features, such as multiple provider states, provider state params, etc. The V3 is still in beta so addmitedly not all features are available as of yet. However, I have not found any mention of V3 support for GraphQL operations.

The previous Pact version (V2) had a GraphQLInteraction object which expanded the standard Interaction. That does not seem to work anymore with V3.

So far I searched for an answer or an example here:

Perhaps I missed something. Do you know if this is currently supported? If not, when?

Do you have any example of PactV3 setup with GraphQL?

Number to roman numerals, understanding of the code Javascript

So I am learning Javascript on freeCodeCamp and one of certification projects is building roman numerals convertor. I couldn’t find solution so I looked online and found this code. It works but I don’t realy understand for loop in the end.

     function convertToRoman(num) {
    var roman = {
      M: 1000,
      CM: 900,
      D: 500,
      CD: 400,
      C: 100,
      XC: 90,
      L: 50,
      XL: 40,
      X: 10,
      IX: 9,
      V: 5,
      IV: 4,
      I: 1
    };
    var str = '';
  
    // I don't understand this part
    for (var i of Object.keys(roman)) {
      var q = Math.floor(num / roman[i]);
      num -= q * roman[i];
      str += i.repeat(q);
    }
  
    return str;
  }

I am relative new to Javascript so any beginner friendly explination would help. Thank you!

jquery.dataTables.min.js:94 Uncaught RangeError: Maximum call stack size exceeded

Am using jquery ajax bootstrap dataTables,when am trying to download morethan 20k records getting this error in console log” Uncaught RangeError: Maximum call stack size exceeded jquery.dataTables.min.js:94″.Upto 2k records able to download as csv and Excel format. I was tried all stackoverflow solutions with same issue.But not used any solution. Below is my code php codeigniter framework used.

table = $('#example').DataTable({ 
            dom: 'Bfrtip',
            buttons: [
                'copyHtml5',
                'excelHtml5',
                'csvHtml5',
                //'pdfHtml5',
                'pageLength'
            ],
            "pageLength": 25,
            "processing": true, //Feature control the processing indicator.
            "serverSide": true, //Feature control DataTables' server-side processing mode.
            "order": [], //Initial no order.
            "aoColumnDefs": [{ "bSortable": false, "aTargets": [0]}],
            "bInfo": false, //niranjan kumar chowdam added for remove pagination numbers 
            lengthMenu: [
                [ 10, 25, 50, -1 ],
                [ '10 rows', '25 rows', '50 rows', 'Show all' ]
            ],
            // Load data for the table's content from an Ajax source
            "ajax": {
                "url": "http://100.250.90.110:8090/srx/voucher/credit_vouchers_datatable",
                "type": "POST",
                "data": function ( data ) {
                    
                    data.FromDate   = $('#FromDate').val();
                    data.ToDate     = $('#ToDate').val(); 
                }
            },
    
            //Set column definition initialisation properties.
            
        });

How Can I allow Comma In angular Regex?

This is my directive.. I want, user just allow to type number. In the regex here I already allow the comma(,). But here I can’t type comma(,).

import { Directive, HostListener, Input, ElementRef  } from '@angular/core';

@Directive({
  selector: '[appOnlyNumber]'
})
export class OnlyNumberDirective {

  private regex: RegExp = new RegExp(/^[0-9]+(.[0-9]*){0,1}$/g);
  private specialKeys:Array<string> = ['Backspace','ArrowLeft','ArrowRight','Control','Tab'];

  constructor(private elementRef: ElementRef) { }
  /**
   * key board action
   * @param event
   */
  @HostListener('keydown',['$event'])onKeyDown(event:KeyboardEvent){
    if(this.specialKeys.indexOf(event.key)!==-1){
      return;
    }
    const inputValue: string = this.elementRef.nativeElement.value.concat(event.key);
    if(inputValue && !String(inputValue).match(this.regex)){
      event.preventDefault();
    }
    return;
  }

  /**
   * Copy Paste action
   * @param event
   */
  @HostListener('paste',['$event'])onPaste(event){
    const clipboardData = (event.originalEvent || event).clipboardData.getData('text/plain');
    if(clipboardData){
      const regEx = new RegExp('/^[0-9]+(.[0-9]*){0,1}$/g');
      if(!regEx.test(clipboardData)){
        event.preventDefault();
      }
    }
    return;
  }
  
}

How Can I allow comma here? Is there any problem in Regex?

adding fields dynamically and using the entered values on the dynamically entered fields

I am creating an UI, where I am entering some useful information. I use a form tag to set it up.
I have the basic form created and it can be seen as below
Basic form

Since I have made use of form, when I click the Add project details, it directly hits the endpoint assigned (We are usigng springboot+thymeleaf)

Desirable Result:
When I click on Add Project details I should get text fields as shown below :

Basic Project

A student can create multiple projects, so each time Add project details is clicked, a new div with Id, projectname, grade has to be created.

NOTE: just a plain student can be created without any projects, but one student can have multiple projects too. I am failing in adding the UI components there. Each time I click add project details, it redirects to form submission and does not open the required div into the page.
Please provide me some guidelines here.

<!DOCTYPE html>
<html xmlns:th="https://www.thymeleaf.org">

<head>

    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- Include Bootstrap 5 -->
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
    </link>

    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
        integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p"
        crossorigin="anonymous"></script>


    <!-- Include https://datatables.net/ -->
    <link href="https://cdn.datatables.net/1.11.5/css/jquery.dataTables.min.css" rel="stylesheet">
    </link>
    <script type="text/javascript" language="javascript" src="https://code.jquery.com/jquery-3.5.1.js"></script>
    <script type="text/javascript" language="javascript"
        src="https://cdn.datatables.net/1.11.5/js/jquery.dataTables.min.js"></script>

    <!-- drag select for list of worklogs -->
    <style>
        .noselect {
            user-select: none;
        }

        .ds-selected {
            outline: 1px solid black;
            outline-offset: 0px;
            color: rgb(0, 0, 0);
            font-weight: bold;
        }
    </style>
</head>

<body>
    <div th:fragment="inputdata">
        <div class="container-md">
            <a>Student and Project Details</a>
            <div class="row justify-content-md-end">
                <form>
                    <div class="row">
                        <div class="col-2">
                            <a>Enter unique studentId</a>
                        </div>
                        <div class="col-3">
                            <input type="text" class="form-control" name="studentid" id="studentid" placeholder="studentid"
                                required="required">
                        </div>
                    </div>                 
                    <div class="row">
                        <div class="col-2">
                            <a>Enter Name</a>
                        </div>
                        <div class="col-3">
                            <input type="text" class="form-control" name="name" id="name" placeholder="name"
                                required="required">
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-2">
                            <a>birth date</a>
                        </div>
                        <div class="col-3">
                            <input type="date" class="form-control" name="birthdate" id="birthdate"
                                placeholder="birthdate" required="required">
                        </div>
                    </div>
                   
                    <div class="row">
                        <div class="row-2">
                            <button class="btn btn-primary"> Add project details </button>
                        </div>
                    </div>

                    <div class="row" id= "flexibleDiv">
                        <div class="col-2">
                            <label >Project </label>
                        </div>
                        <div class="col-2">
                            <input type="text" class="form-control" name="id" id="id"
                            placeholder="id" required="required">
                        </div>

                        <div class="col-2">
                            <input type="text" class="form-control" name="name" id="name"
                            placeholder="name" required="required">
                        </div>

                        <div class="col-2">
                            <input type="text" class="form-control" name="grade" id="grade"
                            placeholder="grade" required="required">
                        </div>
                    </div>

                    <br>
                    <br>
                    <br>
                    <div class="row">
                        <div class="row-2">
                            <input type="submit" id="submitButton" class="btn btn-primary btn-sml" value="Enter to DB">
                        </div>
                    </div>
                </form>
            </div>
        </div>
        <script>
        </script>
    </div>
</body>

</html>

How to connect my data table with pagination component

Is there a way to connect my data table with Tailwind Pagination?
I would like to use javascript/typescript but I don’t know if it’s possible to connect your pagination (which is in my case component) with data table that I already have.

  <table class="min-w-full z-0  divide-y divide-gray-200">
        <thead class="bg-white">
            <tr class="bg-[#18618e] cursor-pointer border border-slate-800 md:border-none block md:table-row absolute -top-full md:top-auto -left-full md:left-auto md:relative">
                <th class="px-4 py-3.5 text-left text-lg font-semibold text-white">
                    Device Name
                </th>
                <th class="px-4 py-3.5 text-left text-lg font-semibold text-white">Type
                </th>
                <th class="w-28"></th>
            </tr>
        </thead>
        <tbody class="block md:table-row-group bg-white">
            <tr class="border-b-2 block md:table-row" repeat.for="device of agentDevices | filter:searchTerm1">
                <td if.bind="device.deviceType == 0" load="../agent-device-opc/${device.deviceId}"
                    class="p-2 cursor-pointer block md:table-cell">
                    <span class="ml-1 cursor-pointer" innerhtml.bind="device.deviceName | searchbold:searchTerm1">
                    </span>
                </td>
                <td if.bind="device.deviceType == 1" load="../agent-device-plc/${device.deviceId}"
                    class="p-2 cursor-pointer block md:table-cell">
                    <span class="cursor-pointer">
                        ${device.deviceName}
                    </span>
                </td>
                <td class="p-2 block md:table-cell">
                    <span class="inline-block md:hidden font-bold">Type:</span>
                    <a if.bind="device.deviceType == 0" ref="type" class="">
                        <img class="h-6 w-auto" src="images/OpcUaLogo.png" alt="SiemensLogo"
                            style="max-width:fit-content" />
                    </a>
                    <a if.bind="device.deviceType == 1" ref="type" class="h-8 w-auto">
                        <img class="h-8 w-auto" src="images/siemensLogo.png" alt="SiemensLogo"
                            style="max-width:fit-content" />
                    </a>
                </td>
                <td class="p-2 text-left block md:table-cell">
                    <span class="inline-block w-1/3 md:hidden font-bold"></span>
                    <div class="gap-3 text-right mr-10 md:space-x-3 space-x-4 mt-4">
                        <button click.delegate="showDeleteGroupModal(device)" data-bs-toggle="modal"
                            aria-hidden="true" type="button" class="">
                            <img src="/images/delete.svg" class="h-5 w-5">
                        </button>
                    </div>
                </td>
            </tr>
        </tbody>
    </table>
</div>
<pagination></pagination>

Unable to add dynamic style in styled component. I am getting type error

Here I am adding dynamic style to my custom styled components.

    <A
      href={link || undefined}
      style={{ pointerEvents: `${disabled ? 'none' : 'all'}` }}
    >

When I use simply style={{ pointerEvents: 'none' }} it is working fine. But trying to make dynamic, then I am getting the following error:

[!] (plugin rpt2) Error: C:/Users/src/Wizard/Wizard-v2/WizardStep.tsx(232,16): semantic error TS2769: No overload matches this call.
Overload 1 of 2, ‘(props: Pick<Pick<Pick<DetailedHTMLProps<AnchorHTMLAttributes, HTMLAnchorElement>, “slot” | … 262 more … | “referrerPolicy”> & { …; }, “slot” | … 263 more … | “referrerPolicy”> &
Partial<…>, “slot” | … 263 more … | “referrerPolicy”> & { …; } & { …; }): ReactElement<…>’, gave the following error.
Type ‘string’ is not assignable to type ‘”fill” | “stroke” | “none” | “auto” | “inherit” | “initial” | “all” | “-moz-initial” | “revert” | “unset” | “painted” | “visible” | “visibleFill” | “visiblePainted” | “visibleStroke”
| undefined’.
Overload 2 of 2, ‘(props: StyledComponentPropsWithAs<“a”, any, {}, never>): ReactElement<StyledComponentPropsWithAs<“a”, any, {}, never>, string | … 1 more … | (new (props: any) => Component<…>)>’, gave the following error.
Type ‘string’ is not assignable to type ‘”fill” | “stroke” | “none” | “auto” | “inherit” | “initial” | “all” | “-moz-initial” | “revert” | “unset” | “painted” | “visible” | “visibleFill” | “visiblePainted” | “visibleStroke”
| undefined’.

What’s wrong in this?

React: How to catch contenteditable on history save?

I have this contentEditable div. I want to know how to catch the event when the element saves its html content. By doing undo it does not undoing 1 by 1 character each press. It actually saves the content history periodically.

For instance if I type Hello world fastly, when I undo it, it will undo the whole Hello world.

If I type Hello world then pause for 5 seconds, then type another John Smith fastly. If I press undo it will undo John Smith first, then it will undo Hello World after that.

My question is, how can I know when the history is saved? And what is the content for each history save?

How to render edit button with click event for dataTable in vuejs

I am trying to render dynamic buttons for dataTable rows in vuejs. Buttons are displaying for each row, but the problem is, @click event is not working there. My codes are:

$('#users').DataTable({
    data: response.data,
    columns: [
         { data: 'id' },
         { data: 'role_id' },
         { data: 'name' },
         { data: 'email' },
         {
            data: null,
            className: "dt-center editor-edit",
            render: function (data, type, row, meta) {
                 return '<input type="button"'+ @click=toggleModal()+'" class="name" id=n-"' + 
                 meta.row + '" value="Name"/>;
            },
            orderable: false
          }
     ]
})

delete a component using splice isn’t working properly

I have a bunch of components that are mapped and rendered. Those objects have unique keys(or indexes). I use the index to splice the or delete a component for the UI (which actually deletes an object from a local data, that re-renders the mapped components omitting the spliced object’s component).

But whenever I delete an object even with a correct index, It deletes component from last. Cross-checking the object have deleted correctly and upon refresh, it shows correct components. But initially, it deletes the last component.

Object:

{
    Red: {
      Name: "R",
      List: [
        ["4", "6"],
        ["3", "4"],
        ["1", "2"],
        ["7", "10"]
      ]
    }
  }

UI:

enter image description here

Eg: Upon clicking Delete on the 2nd item (i.e 3 and 4 in the UI), which has an index of 1. The corresponding object is deleted (verified by console logging) but, initially, the UI deletes the last component.

Partial Code:

const App = () => {
  const [data, setData] = useState({
    Red: {
      Name: "R",
      List: [
        ["4", "6"],
        ["3", "4"],
        ["1", "2"],
        ["7", "10"]
      ]
    }
  });

  const deleteNewRange = (key) => {
    console.log(key);
    let obj = { ...data };
    data.Red.List.splice(key, 1);
    obj = {
      ...data,
      Red: {
        ...data.Red,
        Name: data.Name,
        List: [...data.Red.List]
      }
    };
    setData(obj);
  };

  return (
    <>
      <Form>
        {data.Red.List.map((range, index) => (
          <div key={index}>
            <Form.Item name={"startRange" + index}>
              <InputNumber />
            </Form.Item>
            <p>To</p>
            <Form.Item name={"endRange" + index}>
              <InputNumber/>
            </Form.Item>
              <div>
                Add
              </div>
              <div onClick={() => deleteNewRange(index)}>
                Delete
              </div>
            </div>
        ))}
      </Form>
      <Button type="primary" htmlType="submit">
        Save
      </Button>
    </>
  );
};

Link to more code and other functions and object conversion: https://codesandbox.io/s/basic-antd-4-16-9-forked-dq9ngr?file=/index.js

Identify points in each quadrant of a canvas

How do you divide a canvas into four quadrants and then identify points drawn at random in each quadrant?

Here is my not so futile attempt:

var myCanvas = document.getElementById("showCanvas");
var myContext = myCanvas.getContext("2d");

var xAxis = [];
var yAxis = [];

for (var i = 0; i < 4; i++) {
  var x = Math.floor(Math.random() * 600);
  var y = Math.floor(Math.random() * 350);
  var r = 5;
  xAxis.push(x);
  yAxis.push(y);
  myContext.arc(x, y, r, 0, 2 * Math.PI, true);
  myContext.closePath();
  myContext.fill();
}

var startingPoint = xAxis[0] + ", " + yAxis[0];
var endingPoint = xAxis[3] + ", " + yAxis[3];
var horizontalSlash = myCanvas.width / 2;
var verticalSlash = myCanvas.height / 2;
var remainder = horizontalSlash % verticalSlash;

And the result should show up in these tags:

<h3>The starting point of the line is: <label id="sumPoints">e.g. top, right</label></h3>
<h3>The end point of the line is: <label id="sumPoints">e.g. bottom, left</label></h3>