Skip to content
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 5 commits into from
Dec 23, 2022
Merged

Conversation

czgu
Copy link
Collaborator

@czgu czgu commented Dec 23, 2022

Changes:

  • DataDoc.meta is now { "variables": ["name": "foo", "type": "string", "value": "bar", ...] }
  • The old .meta is moved to .meta_variables, which is dynamically computed from .meta
  • Added automatic conversion code
  • Added drag and drop in UI
    image
  • Added meta validation

@czgu czgu requested a review from jczhong84 December 23, 2022 00:09
@czgu czgu marked this pull request as ready for review December 23, 2022 00:09
return "string"


def convert_if_legacy_datadoc_meta_v0(datadoc_meta: Dict) -> DataDocMeta:
Copy link
Collaborator

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?

Comment on lines +156 to +159
if any(
field_name in fields
for field_name in ["public", "archived", "owner_uid", "title"]
):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this check for? why are environment_id and meta not in the list?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

environment_id is not changeable, meta is not used in elasticsearch

type="react-select"
name={`variables.${index}.type`}
options={
TEMPLATED_VAR_SUPPORTED_TYPES as any as string[]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does it need two as here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because typescript doesnt let readonly array be casted as string

interface IDataDocMetaVariableWithId extends IDataDocMetaVariable {
id: string;
}
const templatedVarUniqueIdPrefix = '_tvar';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mean tvar_ to make it like tvar_some_id?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the exact prefix doesn't matter, it only needs to be unique. Changed to tvar_

name: '',
value: '',
type: 'string',
id: uniqueId(templatedVarUniqueIdPrefix),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this means the name could be not unique? Shall we update the Yup and also the backend validation to not allow duplicate names?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it could be not unique while the user is writing the form

@@ -58,6 +59,38 @@ export function openDataDoc(docId: number): ThunkResult<Promise<any>> {
dataDoc,
},
});
} else {
// Even if it is sameOrigin, dervied fields also needs to be updated
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont really get why we need this part for same origin. Wouldn't the !isSameOrigin block be able to update the whole doc with derived fields?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for sameOrigin, we only need to update meta_variables field. All other fields are already updated before the request locally is sent to server

self._meta = new_meta

@property
def meta_variables(self):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you add some comments about why we need it?

onSave={(meta) => {
setTemplatedVariables(meta);
variables={templatedVariables}
onSave={async (newVariables) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why async? is setTemplatedVariables async? dont see await is used

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onSave expects a promise, i could either mark the function as async or return an empty promise

@@ -68,7 +68,9 @@ export class QuerySnippetView extends React.PureComponent<
if (templatedVariables.length) {
renderedQuery = await renderTemplatedQuery(
context,
this.state.templatedQueryForm,
Object.entries(this.state.templatedQueryForm).map(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious why we need to do renderTemplatedQuery when inserting snippet? shouldn't the variables be kept in the query, insert as is?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when inserting the snippets, the user needs to fill out the template form

@czgu czgu merged commit 24652a3 into pinterest:master Dec 23, 2022
rohan-sh1 pushed a commit to CAI-TECHNOLOGIES/cai-ext-db-explorer that referenced this pull request Feb 28, 2023
* temp

* feat: add drag and drop for templated variables

* resolved comments

* make templated variables in the frontend array based

* meta.variables should always be defined
aidenprice pushed a commit to arrowtail-precision/querybook that referenced this pull request Jan 3, 2024
* temp

* feat: add drag and drop for templated variables

* resolved comments

* make templated variables in the frontend array based

* meta.variables should always be defined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants