logidze icon indicating copy to clipboard operation
logidze copied to clipboard

Filter by changed attrs

Open dixpac opened this issue 8 months ago • 2 comments

I have logidze on a model. That model tracks every attribute change. I have a page that is visible to the user and on that page I want to show only versions where value column changed.

Here is the simplified example json:

{
  "h": [
    {
      "c": {
        "id": 202,
        "value": "",
        "aasm_state": "new",
        "created_at": "2024-06-22T12:08:26.450706",
        "updated_at": "2024-06-22T12:08:26.450706",
      },
      "m": {
        "_r": "gid://lab/User/19"
      },
      "v": 1,
      "ts": 1719058106451
    },
    {
      "c": {
        "id": 202,
        "value": 1,
        "aasm_state": "new",
        "created_at": "2024-06-22 12:08:26.450706",
        "updated_at": "2024-06-22 12:08:32.315247",
      },
      "m": {
        "_r": "gid://lab/User/19"
      },
      "v": 2,
      "ts": 1719058112315
    },
    {
      "c": {
        "aasm_state": "entered"
      },
      "m": {
        "_r": "gid://lab/User/19"
      },
      "v": 3,
      "ts": 1719058112339
    },
    {
      "c": {
        "id": 202,
        "value": 2,
        "aasm_state": "entered",
        "created_at": "2024-06-22 12:08:26.450706",
        "updated_at": "2024-06-22 12:08:34.300976",
      "m": {
        "_r": "gid://lab/User/19"
      },
      "v": 4,
      "ts": 1719058114301
    }
  ],
  "v": 4
}

If i take enumerator approach:

  def value_history
    logidze_versions(reverse: true, include_self: true).select { |version| version.changes["value"] }
  end

Issue here is with the version 3, running changes["value"] on a version 3 will show changes for the value (from the v1 if I'm seeing this correctly)

Basically I need to get all the records where value changed. How would you recommend implementing this?

dixpac avatar Jun 22 '24 12:06 dixpac