Skip to content

Conversation

@rafaellehmkuhl
Copy link
Member

@rafaellehmkuhl rafaellehmkuhl commented Jul 24, 2025

New feature

This patch adds the possibility of exporting and importing data-lake variables from the Tools menu.

image

Tests Required to Merge (by dev and/or testers)

  • Create some data-lake variables from the Tools menu
  • Test exporting and importing them
  • Test exporting and importing Cockpit Actions (routine was changed to use a common implementation)
  • Test exporting and importing a DIY widget (routine was changed to use a common implementation)
  • Test exporting and importing a Cockpit Settings (routine was changed to use a common implementation)

Fix #2000

@rafaellehmkuhl rafaellehmkuhl force-pushed the support-batch-importing-exporting-data-lake-variables branch from 8cd35d6 to f254c21 Compare July 24, 2025 19:57
@ES-Alexander ES-Alexander added the docs-needed Change needs to be documented label Jul 25, 2025
@rafaellehmkuhl
Copy link
Member Author

@ES-Alexander @ArturoManzoli could you take a look at this one?

@ArturoManzoli
Copy link
Contributor

ArturoManzoli commented Aug 8, 2025

  • Running on Electron, I downloaded the file and then clicked to delete the camera-zoom data-lake variable. Both zoom and focus variables were automatically deleted (was supposed to be like this?).
  • Rebooted Cockpit and tried to import those from the file.
  • The following error ocurred (no console message tho):
image

File contents:

{
  "variables": [],
  "values": {},
  "transformingFunctions": [
    {
      "name": "Camera Zoom",
      "id": "camera-zoom",
      "type": "number",
      "expression": "const zoom = {{camera-zoom-increase}} - {{camera-zoom-decrease}}\nreturn zoom < 0.05 && zoom > -0.05 ? 0 : Math.max(Math.min(1, zoom), -1)\n",
      "description": "Used to control the camera zoom. The value is the difference between {{camera-zoom-increase}} and {{camera-zoom-decrease}}."
    },
    {
      "name": "Camera Focus",
      "id": "camera-focus",
      "type": "number",
      "expression": "const focus = {{camera-focus-increase}} - {{camera-focus-decrease}}\nreturn focus < 0.05 && focus > -0.05 ? 0 : Math.max(Math.min(1, focus), -1)\n",
      "description": "Used to control the camera focus. The value is the difference between {{camera-focus-increase}} and {{camera-focus-decrease}}."
    }
  ],
  "exportDate": "2025-08-08T19:03:47.120Z",
  "version": "1.0"
}

@rafaellehmkuhl
Copy link
Member Author

rafaellehmkuhl commented Aug 8, 2025

  • Running on Electron, I downloaded the file and then clicked to delete the camera-zoom data-lake variable. Both zoom and focus variables were automatically deleted (was supposed to be like this?).

  • Rebooted Cockpit and tried to import those from the file.

  • The following error ocurred (no console message tho):

Can you check with other than those variables as well? Because the camera variables are automatically added so it may be something specifically to them. I will check nonetheless.

@ArturoManzoli
Copy link
Contributor

It seems to be working, just need some reactivity fix, I think:

  • Created 2 variables, rebooted (after creation the variables didn't show up on the table);
  • After reboot, the variables were there (1);
  • Exported the file with the new variables (3);
  • Deleted the first on the top, then the other (shoryuken). When deleted this last one, both camera and focus disappeard. Rebooted cockpit and zoom and focus were back there on the table;
  • Deleted zoom, and focus was automatically deleted with it. Rebooted and both were indeed gone;
  • With a fresh table, imported the file and the following snackbar showed up (2);
  • No imported variables showed up on the table, but after a reboot the 4 exported/imported were there as in (1).

(1)
image

(2)
image

(3)

{
  "variables": [
    {
      "id": "hadouken",
      "name": "Hadouken",
      "type": "number",
      "description": "Testing variable",
      "persistent": true,
      "persistValue": true,
      "allowUserToChangeValue": true
    }
  ],
  "values": {
    "hadouken": 666
  },
  "transformingFunctions": [
    {
      "name": "Camera Zoom",
      "id": "camera-zoom",
      "type": "number",
      "expression": "const zoom = {{camera-zoom-increase}} - {{camera-zoom-decrease}}\nreturn zoom < 0.05 && zoom > -0.05 ? 0 : Math.max(Math.min(1, zoom), -1)\n",
      "description": "Used to control the camera zoom. The value is the difference between {{camera-zoom-increase}} and {{camera-zoom-decrease}}."
    },
    {
      "name": "Camera Focus",
      "id": "camera-focus",
      "type": "number",
      "expression": "const focus = {{camera-focus-increase}} - {{camera-focus-decrease}}\nreturn focus < 0.05 && focus > -0.05 ? 0 : Math.max(Math.min(1, focus), -1)\n",
      "description": "Used to control the camera focus. The value is the difference between {{camera-focus-increase}} and {{camera-focus-decrease}}."
    },
    {
      "name": "Shoryuken",
      "id": "shoryuken",
      "type": "number",
      "expression": "// Example 1:\n2 * {{ cockpit-memory-usage }} + 100\n\n// Example 2:\nif ({{ cockpit-memory-usage }} > 100) {\n  return 'on'\n}\nreturn 'off'\n\n// Example 3:\nreturn {{ cockpit-memory-usage }} > 100\n",
      "description": "Testing 2"
    }
  ],
  "exportDate": "2025-08-08T19:41:51.376Z",
  "version": "1.0"
}

@rafaellehmkuhl
Copy link
Member Author

It seems to be working, just need some reactivity fix, I think:

  • Created 2 variables, rebooted (after creation the variables didn't show up on the table);
  • After reboot, the variables were there (1);
  • Exported the file with the new variables (3);
  • Deleted the first on the top, then the other (shoryuken). When deleted this last one, both camera and focus disappeard. Rebooted cockpit and zoom and focus were back there on the table;
  • Deleted zoom, and focus was automatically deleted with it. Rebooted and both were indeed gone;
  • With a fresh table, imported the file and the following snackbar showed up (2);
  • No imported variables showed up on the table, but after a reboot the 4 exported/imported were there as in (1).

Interesting!

I will test that in master as well. Seems to me that there's a bug around the delete logic. Thanks!

@rafaellehmkuhl rafaellehmkuhl force-pushed the support-batch-importing-exporting-data-lake-variables branch from f254c21 to de143ce Compare August 22, 2025 16:41
@rafaellehmkuhl rafaellehmkuhl force-pushed the support-batch-importing-exporting-data-lake-variables branch from de143ce to 05e9006 Compare September 4, 2025 15:47
@rafaellehmkuhl rafaellehmkuhl force-pushed the support-batch-importing-exporting-data-lake-variables branch from 05e9006 to 8b24b27 Compare September 5, 2025 08:26
@ArturoManzoli
Copy link
Contributor

@rafaellehmkuhl I was taking a look on this one today, and it seems to still have some issues on refreshing the table data after a import operation.
I exported, deleted and imported, all of that with a reboot between operations. It all worked, although with some error/success snackbar messages.
The main problem is that the imported variables do not show on the table without a Cockpit reboot

@rafaellehmkuhl
Copy link
Member Author

@rafaellehmkuhl I was taking a look on this one today, and it seems to still have some issues on refreshing the table data after a import operation. I exported, deleted and imported, all of that with a reboot between operations. It all worked, although with some error/success snackbar messages. The main problem is that the imported variables do not show on the table without a Cockpit reboot

Yup. I didn't fix that one yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs-needed Change needs to be documented

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow exporting and importing all user-created data lake variables

3 participants