Tailoring the interactions between electric and magnetic dipoles in plasmonic and dielectric metasurfaces