Skip to content

Commit

Permalink
Generate plugin ids from class instance instead of uuid4
Browse files Browse the repository at this point in the history
  • Loading branch information
HansKallekleiv committed May 19, 2022
1 parent 30070b2 commit ea63e67
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions webviz_config/_plugin_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import warnings
import sys
import urllib
from uuid import uuid4
from typing import List, Optional, Type, Union, Dict

import bleach
Expand Down Expand Up @@ -92,6 +91,10 @@ def layout(self):
# All paths in the returned ASSETS list should be absolute.
ASSETS: list = []

# Counter for instances of the same plugin.
# Used to create unique ids of DOM elements
CLASS_INSTANCE_COUNTER: int = 0

def __init__(self, screenshot_filename: str = "webviz-screenshot.png") -> None:
"""If a plugin/subclass defines its own `__init__` function
(which they usually do), they should remember to call
Expand All @@ -100,8 +103,10 @@ def __init__(self, screenshot_filename: str = "webviz-screenshot.png") -> None:
```
in its own `__init__` function in order to also run the parent `__init__`.
"""

self._plugin_uuid = uuid4()
self.__class__.CLASS_INSTANCE_COUNTER += 1
self._plugin_uuid = (
f"{type(self).__name__}-{self.__class__.CLASS_INSTANCE_COUNTER}"
)
self._screenshot_filename = screenshot_filename
self._add_download_button = False

Expand Down

0 comments on commit ea63e67

Please sign in to comment.