-
Notifications
You must be signed in to change notification settings - Fork 248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add drag and drop for templated variables #1112
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from typing import TypedDict, Union, Literal | ||
|
||
|
||
class DataDocMetaVarConfig(TypedDict): | ||
name: str | ||
value: Union[str, int, float, bool] | ||
type: Literal["boolean", "number", "string"] | ||
|
||
|
||
class DataDocMeta(TypedDict): | ||
variables: list[DataDocMetaVarConfig] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
from typing import Dict, Any | ||
from .doc_types import DataDocMeta, DataDocMetaVarConfig | ||
|
||
|
||
def check_variable_type(val: Any): | ||
if isinstance(val, (int, float)): | ||
return "number" | ||
elif isinstance(val, bool): | ||
return "boolean" | ||
elif isinstance(val, str): | ||
return "string" | ||
|
||
# this shouldn't happen, just in case | ||
return "string" | ||
|
||
|
||
def convert_if_legacy_datadoc_meta_v0(datadoc_meta: Dict) -> DataDocMeta: | ||
"""Converts the old meta format which is only a dictionary of templated variables | ||
to a more general format that has templated vars as array plus other fields | ||
|
||
Old meta: `{ "foo": "bar" }` | ||
New meta: `{ "variables": ["name": "foo", "type": "string", "value": "bar", ...] }` | ||
|
||
If the new meta is passed in, no change would be made. | ||
|
||
Args: | ||
datadoc_meta (Dict): Old/New meta format | ||
|
||
Returns: | ||
DataDocMeta: New meta format | ||
""" | ||
if isinstance(datadoc_meta.get("variables"), list): | ||
return datadoc_meta | ||
|
||
new_meta = {"variables": []} | ||
|
||
for name, value in datadoc_meta.items(): | ||
new_meta["variables"].append( | ||
{"name": name, "value": value, "type": check_variable_type(value)} | ||
) | ||
|
||
return new_meta | ||
|
||
|
||
def convert_if_legacy_datadoc_meta(datadoc_meta: Dict) -> DataDocMeta: | ||
datadoc_meta = convert_if_legacy_datadoc_meta_v0(datadoc_meta) | ||
return datadoc_meta | ||
|
||
|
||
def var_config_to_var_dict(variables: list[DataDocMetaVarConfig]) -> Dict: | ||
var_dict = {} | ||
|
||
for config in variables: | ||
var_dict[config["name"]] = config["value"] | ||
|
||
return var_dict | ||
|
||
|
||
valid_meta_keys = ["variables"] | ||
|
||
|
||
def validate_datadoc_meta(datadoc_meta: DataDocMeta) -> bool: | ||
for key in datadoc_meta.keys(): | ||
if key not in valid_meta_keys: | ||
return False | ||
|
||
if "variables" in datadoc_meta: | ||
variables = datadoc_meta["variables"] | ||
if not isinstance(variables, list): | ||
return False | ||
|
||
for variable_config in variables: | ||
var_type = variable_config["type"] | ||
var_val = variable_config["value"] | ||
|
||
if var_type == "string" and not isinstance(var_val, str): | ||
return False | ||
if var_type == "boolean" and not isinstance(var_val, bool): | ||
return False | ||
if var_type == "number" and not isinstance(var_val, (float, int)): | ||
return False | ||
|
||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,16 +49,18 @@ def create_data_doc( | |
commit=True, | ||
session=None, | ||
): | ||
data_doc = DataDoc( | ||
public=public, | ||
archived=archived, | ||
owner_uid=owner_uid, | ||
environment_id=environment_id, | ||
title=title, | ||
meta=meta, | ||
data_doc = DataDoc.create( | ||
fields={ | ||
"public": public, | ||
"archived": archived, | ||
"owner_uid": owner_uid, | ||
"environment_id": environment_id, | ||
"title": title, | ||
"meta": meta, | ||
}, | ||
commit=False, | ||
session=session, | ||
) | ||
session.add(data_doc) | ||
session.flush() | ||
|
||
for index, cell in enumerate(cells): | ||
data_cell = create_data_cell( | ||
|
@@ -150,7 +152,12 @@ def update_data_doc(id, commit=True, session=None, **fields): | |
|
||
if commit: | ||
session.commit() | ||
update_es_data_doc_by_id(data_doc.id) | ||
|
||
if any( | ||
field_name in fields | ||
for field_name in ["public", "archived", "owner_uid", "title"] | ||
): | ||
Comment on lines
+156
to
+159
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what does this check for? why are There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. environment_id is not changeable, meta is not used in elasticsearch |
||
update_es_data_doc_by_id(data_doc.id) | ||
|
||
# update es queries if doc is switched between public/private | ||
if "public" in fields: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add some comments to have some example of what v0 look like?