-
Notifications
You must be signed in to change notification settings - Fork 0
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
Tevon/add query params #22
Merged
Merged
Changes from 2 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
2 changes: 2 additions & 0 deletions
2
backend/prisma/migrations/20240329222220_add_query_parameters/migration.sql
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,2 @@ | ||
-- AlterTable | ||
ALTER TABLE "query" ADD COLUMN "parameters" JSONB; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,9 @@ import Loading from "@/app/loading"; | |
import { ErrorDisplay } from "@/components/error-display"; | ||
import QueryEditor from "@/components/query/query-editor"; | ||
import { QueryHeader } from "@/components/query/query-header"; | ||
import QueryParameters, { | ||
Parameter, | ||
} from "@/components/query/query-parameters"; | ||
import Table from "@/components/table/table"; | ||
import { | ||
useUpdateUserQuery, | ||
|
@@ -26,19 +29,23 @@ const Page: React.FC<UserQueryPageProps> = ({ params: { userQueryId } }) => { | |
isLoading: isLoadingUserQuery, | ||
error: userQueryError, | ||
} = useUserQuery(userQueryId); | ||
const [parameters, setParameters] = useState<Parameter[]>([]); | ||
const [savedParameters, setSavedParameters] = useState<Parameter[]>([]); | ||
|
||
useEffect(() => { | ||
setSqlQuery(userQuery?.sql || ""); | ||
}, [userQuery, setSqlQuery]); | ||
setParameters(userQuery?.parameters || []); | ||
}, [userQuery, setSqlQuery, setParameters]); | ||
|
||
const { | ||
data: results, | ||
isLoading: isLoadingResults, | ||
error: resultsError, | ||
} = useUserQueryResults(userQueryId, userQuery?.sql); | ||
} = useUserQueryResults(userQueryId, userQuery?.sql, savedParameters); | ||
|
||
const handleSaveQuery = () => { | ||
updateUserQueryTrigger({ sql: sqlQuery }); | ||
setSavedParameters(parameters); | ||
updateUserQueryTrigger({ sql: sqlQuery, parameters: parameters }); | ||
}; | ||
|
||
const { trigger: updateUserQueryTrigger, isMutating: isUpdatingUserQuery } = | ||
|
@@ -71,6 +78,7 @@ const Page: React.FC<UserQueryPageProps> = ({ params: { userQueryId } }) => { | |
return ( | ||
<div className="flex flex-col h-full"> | ||
<QueryHeader query={userQuery} /> | ||
<QueryParameters parameters={parameters} setParameters={setParameters} /> | ||
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. Would be good to merge master into this branch to see how this component interacts with the Pipelin/SQL tabs |
||
<QueryEditor value={sqlQuery} onChange={setSqlQuery} /> | ||
<div className="flex flex-row items-center"> | ||
<Button | ||
|
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,170 @@ | ||
import React from "react"; | ||
import { Parameter } from "./query-parameters"; | ||
import { | ||
Button, | ||
ControlGroup, | ||
FormGroup, | ||
InputGroup, | ||
Popover, | ||
SegmentedControl, | ||
} from "@blueprintjs/core"; | ||
import { Label } from "recharts"; | ||
import { on } from "events"; | ||
|
||
interface QueryParameterProps { | ||
parameter: Parameter; | ||
index: number; | ||
removeParameter: (index: number) => void; | ||
saveParameter: (parameter: Partial<Parameter>) => void; | ||
onValueChange: (index: number, value: any) => void; | ||
} | ||
|
||
const QueryParameter: React.FC<QueryParameterProps> = (props) => { | ||
const { parameter, saveParameter, onValueChange, index, removeParameter } = | ||
props; | ||
|
||
const [popoverOpen, setPopoverOpen] = React.useState(false); | ||
const [fieldValues, setFieldValues] = React.useState({ | ||
name: parameter.name, | ||
description: parameter.description, | ||
type: parameter.type, | ||
defaultValue: parameter.defaultValue, | ||
}); | ||
|
||
const handleFieldChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
setFieldValues({ | ||
...fieldValues, | ||
[e.target.name]: e.target.value, | ||
}); | ||
}; | ||
|
||
const handleConfirm = () => { | ||
saveParameter(fieldValues); | ||
setPopoverOpen(false); | ||
}; | ||
|
||
const getRightElement = () => { | ||
return ( | ||
<Popover | ||
isOpen={popoverOpen} | ||
onInteraction={(nextOpenState) => setPopoverOpen(nextOpenState)} | ||
content={ | ||
<div style={{ padding: "10px" }}> | ||
<h5>Edit Parameter</h5> | ||
<SegmentedControl | ||
defaultValue="text" | ||
options={[ | ||
{ | ||
label: "Text", | ||
value: "text", | ||
}, | ||
{ | ||
label: "Date", | ||
value: "date", | ||
}, | ||
{ | ||
label: "Number", | ||
value: "number", | ||
}, | ||
]} | ||
onValueChange={(value) => { | ||
setFieldValues({ | ||
...fieldValues, | ||
type: value, | ||
}); | ||
}} | ||
/> | ||
<FormGroup label="Name" labelFor="name"> | ||
<InputGroup | ||
id="name" | ||
name="name" | ||
placeholder="Name" | ||
value={fieldValues.name} | ||
onChange={handleFieldChange} | ||
/> | ||
</FormGroup> | ||
<FormGroup label="Description" labelFor="description"> | ||
<InputGroup | ||
id="description" | ||
name="description" | ||
placeholder="Description" | ||
value={fieldValues.description} | ||
onChange={handleFieldChange} | ||
/> | ||
</FormGroup> | ||
<FormGroup label="Default Value" labelFor="defaultValue"> | ||
<InputGroup | ||
id="defaultValue" | ||
name="defaultValue" | ||
type={fieldValues.type} | ||
placeholder="Default Value" | ||
value={fieldValues.defaultValue} | ||
onChange={handleFieldChange} | ||
/> | ||
</FormGroup> | ||
<div | ||
style={{ | ||
display: "flex", | ||
justifyContent: "flex-end", | ||
marginTop: "10px", | ||
}} | ||
> | ||
<Button | ||
style={{ marginRight: "5px" }} | ||
onClick={() => { | ||
setPopoverOpen(false); | ||
setFieldValues({ | ||
name: "", | ||
description: "", | ||
type: "", | ||
defaultValue: "", | ||
}); | ||
}} | ||
> | ||
Cancel | ||
</Button> | ||
<Button intent="primary" onClick={handleConfirm}> | ||
Confirm | ||
</Button> | ||
</div> | ||
</div> | ||
} | ||
> | ||
<Button | ||
icon="settings" | ||
minimal={true} | ||
onClick={() => setPopoverOpen(true)} | ||
/> | ||
</Popover> | ||
); | ||
}; | ||
return ( | ||
<div className=""> | ||
<FormGroup | ||
label={ | ||
<div className="flex items-center"> | ||
<span className="mr-2">{parameter.name}</span> | ||
<Button | ||
icon="cross" | ||
minimal={true} | ||
small={true} | ||
className="ml-auto" | ||
onClick={() => removeParameter(index)} | ||
/> | ||
</div> | ||
} | ||
helperText={parameter.description ? parameter.description : undefined} | ||
> | ||
<InputGroup | ||
small | ||
value={parameter.value || parameter.defaultValue} | ||
type={parameter.type} | ||
onValueChange={(value) => onValueChange(index, value)} | ||
rightElement={getRightElement()} | ||
/> | ||
</FormGroup> | ||
</div> | ||
); | ||
}; | ||
|
||
export default QueryParameter; |
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,80 @@ | ||
import React from "react"; | ||
import { Button, EditableText, FormGroup } from "@blueprintjs/core"; | ||
import { Select } from "@blueprintjs/select"; | ||
import * as _ from "lodash"; | ||
import QueryParameter from "./query-parameter"; | ||
|
||
export interface Parameter { | ||
name: string; | ||
description: string; | ||
type: string; | ||
defaultValue: string; | ||
value: any; | ||
} | ||
|
||
interface QueryParametersProps { | ||
parameters: Parameter[]; | ||
setParameters: (parameters: Parameter[]) => void; | ||
} | ||
|
||
const QueryParameters: React.FC<QueryParametersProps> = (props) => { | ||
const { parameters, setParameters } = props; | ||
|
||
const saveParameter = (index: number, parameter: Partial<Parameter>) => { | ||
const newParameters = _.cloneDeep(parameters); | ||
newParameters[index] = { | ||
...newParameters[index], | ||
...parameter, | ||
}; | ||
setParameters(newParameters); | ||
}; | ||
|
||
const removeParameter = (index: number) => { | ||
const newParameters = _.cloneDeep(parameters); | ||
newParameters.splice(index, 1); | ||
setParameters(newParameters); | ||
}; | ||
|
||
const setValue = (index: number, value: any) => { | ||
const newParameters = _.cloneDeep(parameters); | ||
newParameters[index].value = value; | ||
setParameters(newParameters); | ||
}; | ||
|
||
const addParameter = () => { | ||
setParameters([ | ||
...parameters, | ||
{ | ||
type: "string", | ||
defaultValue: "", | ||
value: null, | ||
name: "new_parameter", | ||
description: "", | ||
}, | ||
]); | ||
}; | ||
|
||
console.log(parameters); | ||
tevonsb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return ( | ||
<div className="my-2 grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 gap-2"> | ||
{_.map(parameters, (p, index) => { | ||
return ( | ||
<div key={index} className="col-span-1 items-center"> | ||
<QueryParameter | ||
parameter={p} | ||
index={index} | ||
saveParameter={(param) => saveParameter(index, param)} | ||
removeParameter={(index) => removeParameter(index)} | ||
onValueChange={setValue} | ||
/> | ||
</div> | ||
); | ||
})} | ||
<div className="col-span-1 flex justify-center items-center"> | ||
<Button icon="plus" onClick={addParameter} fill></Button> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default QueryParameters; |
Oops, something went wrong.
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.
rm