Shape and connectivity of groups and clusters: Impact of dynamical state and accretion history