Skip to content

Commit

Permalink
fix: cannot set transforms
Browse files Browse the repository at this point in the history
  • Loading branch information
nextchamp-saqib committed Feb 18, 2024
1 parent c789596 commit 371235e
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 25 deletions.
39 changes: 21 additions & 18 deletions frontend/src/query/resources/useQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default function useQuery(name) {
sourceSchema: {},
})

const run = createTaskRunner()
const queue = createTaskRunner()
state.doc = computed(() => resource.doc)

const setLoading = (value) => (state.loading = value)
Expand Down Expand Up @@ -52,11 +52,11 @@ export default function useQuery(name) {

state.updateTitle = (title) => {
setLoading(true)
return run(() => resource.setValue.submit({ title }).finally(() => setLoading(false)))
return queue(() => resource.setValue.submit({ title }).finally(() => setLoading(false)))
}
state.changeDataSource = (data_source) => {
setLoading(true)
return run(() => resource.setValue.submit({ data_source }).then(() => setLoading(false)))
return queue(() => resource.setValue.submit({ data_source }).then(() => setLoading(false)))
}

const autoExecuteEnabled = settingsStore().settings.auto_execute_query
Expand All @@ -66,7 +66,7 @@ export default function useQuery(name) {

setLoading(true)
return new Promise((resolve) =>
run(() =>
queue(() =>
resource.setValue
.submit({ json: JSON.stringify(newQuery, null, 2) })
.then(() => autoExecuteEnabled && state.execute())
Expand All @@ -80,7 +80,7 @@ export default function useQuery(name) {
if (!state.doc?.data_source) return
setLoading(true)
state.executing = true
await run(() => resource.run.submit().catch(() => {}))
await queue(() => resource.run.submit().catch(() => {}))
await state.results.reload()
state.executing = false
setLoading(false)
Expand All @@ -89,37 +89,40 @@ export default function useQuery(name) {
state.updateTransforms = debounce(async (transforms) => {
if (!transforms) return
setLoading(true)
return run(() =>
resource.setValue
.submit({ transforms, status: 'Pending Execution' })
.then(() => autoExecuteEnabled && state.execute())
const updateTransform = () => resource.setValue.submit({ transforms })
const updateStatus = () => resource.set_status.submit({ status: 'Pending Execution' })
const autoExecute = () => autoExecuteEnabled && state.execute()
return queue(() =>
updateTransform()
.then(updateStatus)
.then(autoExecute)
.finally(() => setLoading(false))
)
}, 500)

state.duplicate = async () => {
state.duplicating = true
await run(() => resource.duplicate.submit())
await queue(() => resource.duplicate.submit())
state.duplicating = false
return resource.duplicate.data.message
}

state.delete = async () => {
state.deleting = true
await run(() => resource.delete.submit())
await queue(() => resource.delete.submit())
state.deleting = false
}

state.store = () => {
setLoading(true)
return run(() => resource.store.submit().finally(() => setLoading(false)))
return queue(() => resource.store.submit().finally(() => setLoading(false)))
}
state.unstore = () => {
setLoading(true)
return run(() => resource.unstore.submit().finally(() => setLoading(false)))
return queue(() => resource.unstore.submit().finally(() => setLoading(false)))
}
state.switchQueryBuilder = () => {
return run(() => {
return queue(() => {
return resource.switch_query_type.submit().then(() => {
window.location.reload()
})
Expand Down Expand Up @@ -160,7 +163,7 @@ export default function useQuery(name) {
state.convertToNative = async () => {
if (state.doc.is_native_query) return
setLoading(true)
return run(() => {
return queue(() => {
return resource.setValue
.submit({ is_native_query: 1, is_assisted_query: 0, is_script_query: 0 })
.finally(() => setLoading(false))
Expand All @@ -171,7 +174,7 @@ export default function useQuery(name) {
state.executeSQL = debounce((sql) => {
if (!sql || sql === state.doc.sql) return state.execute()
setLoading(true)
return run(() =>
return queue(() =>
resource.setValue
.submit({ sql })
.then(() => state.execute())
Expand All @@ -183,13 +186,13 @@ export default function useQuery(name) {
state.updateScript = debounce((script) => {
if (script === state.doc.script) return
setLoading(true)
return run(() => resource.setValue.submit({ script }).finally(() => setLoading(false)))
return queue(() => resource.setValue.submit({ script }).finally(() => setLoading(false)))
}, 500)

state.updateScriptVariables = debounce((script_variables) => {
if (variables === state.doc.variables) return
setLoading(true)
return run(() => resource.setValue.submit({ variables }).finally(() => setLoading(false)))
return queue(() => resource.setValue.submit({ variables }).finally(() => setLoading(false)))
}, 500)

state.downloadResults = () => {
Expand Down
1 change: 1 addition & 0 deletions frontend/src/query/useQueryResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const API_METHODS = {
unstore: 'unstore',
convert: 'convert',
setLimit: 'set_limit',
set_status: 'set_status',
duplicate: 'duplicate',
reset: 'reset_and_save',
fetchTables: 'fetch_tables',
Expand Down
6 changes: 0 additions & 6 deletions insights/insights/doctype/insights_query/insights_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ def after_insert(self):

def before_save(self):
self.variant_controller.before_save()
self.handle_transform_change()

def handle_transform_change(self):
if self.has_value_changed("transforms"):
self.update_query_results()
self.status = Status.PENDING.value

def on_update(self):
self.link_chart()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@


class InsightsQueryClient:
@frappe.whitelist()
def set_status(self, status):
# since status is auto set based on the sql, we need some way to override it
self.db_set("status", status)

@frappe.whitelist()
def duplicate(self):
new_query = frappe.copy_doc(self)
Expand Down
2 changes: 1 addition & 1 deletion insights/insights/doctype/insights_query/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def update_sql(query):
if query.sql == sql:
return
query.sql = sql
query.update_query_results([])
query.update_query_results()
query.status = Status.PENDING.value if sql else Status.SUCCESS.value


Expand Down

0 comments on commit 371235e

Please sign in to comment.