If you already have the panel off, you're 75% there! You just need to undo two 10mm head nuts disconnect the microswitch, and open (unfold) the plastic connector on the linkage rod. When you put it back together, the place the metal linkage rod in the plastic connector with just enough tension to NOT open the latch, and pinch the connector closed- you may need to use a pliers to fully seat the clip.
The black part that fell off was likely a piece of the plastic that covers the rotating clip inside the latch. The other way these usually fail is that the spring inside simply comes disconnected and won't latch closed.