Refactor compare index to use helper for data attributes
<!--IssueSummary start-->
<details>
<summary>
Everyone can contribute. [Help move this issue forward](https://handbook.gitlab.com/handbook/marketing/developer-relations/contributor-success/community-contributors-workflows/#contributor-links) while earning points, leveling up and collecting rewards.
</summary>
- [Close this issue](https://contributors.gitlab.com/manage-issue?action=close&projectId=278964&issueIid=321195)
</details>
<!--IssueSummary end-->
The following discussion from !52967 should be addressed:
- [ ] @jivanvl started a [discussion](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/52967#note_506411824):
> **Suggestion (optional)** There's fair amount of data attributes for this app, I think it would be beneficial to move them to a helper a function and call that function here, an example of this pattern can be found at
>
> https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/app/helpers/ee/operations_helper.rb#L16
>
> https://gitlab.com/gitlab-org/gitlab/-/blob/master/app/views/projects/environments/folder.html.haml
issue