mirror of
https://github.com/supabase/supabase.git
synced 2026-06-04 11:51:55 +08:00
chore(studio): swap react-query to object syntax (#39842)
* chore(studio): swap react-query to object syntax * Fix small issues found * Fix realtime settings * Nit --------- Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
This commit is contained in:
@@ -37,57 +37,55 @@ export const useExecuteSqlMutation = ({
|
||||
const { mutate: sendEvent } = useSendEventMutation()
|
||||
const { data: org } = useSelectedOrganizationQuery()
|
||||
|
||||
return useMutation<ExecuteSqlData, QueryResponseError, ExecuteSqlVariables>(
|
||||
(args) => executeSql(args),
|
||||
{
|
||||
async onSuccess(data, variables, context) {
|
||||
const { contextualInvalidation, sql, projectRef } = variables
|
||||
return useMutation<ExecuteSqlData, QueryResponseError, ExecuteSqlVariables>({
|
||||
mutationFn: (args) => executeSql(args),
|
||||
async onSuccess(data, variables, context) {
|
||||
const { contextualInvalidation, sql, projectRef } = variables
|
||||
|
||||
// Track all table-related events from SQL execution
|
||||
try {
|
||||
const tableEvents = sqlEventParser.getTableEvents(sql)
|
||||
tableEvents.forEach((event) => {
|
||||
if (projectRef) {
|
||||
sendEvent({
|
||||
action: event.type,
|
||||
properties: {
|
||||
method: 'sql_editor',
|
||||
schema_name: event.schema,
|
||||
table_name: event.tableName,
|
||||
},
|
||||
groups: {
|
||||
project: projectRef,
|
||||
...(org?.slug && { organization: org.slug }),
|
||||
},
|
||||
})
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('Failed to parse SQL for telemetry:', error)
|
||||
}
|
||||
// Track all table-related events from SQL execution
|
||||
try {
|
||||
const tableEvents = sqlEventParser.getTableEvents(sql)
|
||||
tableEvents.forEach((event) => {
|
||||
if (projectRef) {
|
||||
sendEvent({
|
||||
action: event.type,
|
||||
properties: {
|
||||
method: 'sql_editor',
|
||||
schema_name: event.schema,
|
||||
table_name: event.tableName,
|
||||
},
|
||||
groups: {
|
||||
project: projectRef,
|
||||
...(org?.slug && { organization: org.slug }),
|
||||
},
|
||||
})
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('Failed to parse SQL for telemetry:', error)
|
||||
}
|
||||
|
||||
// [Joshen] Default to false for now, only used for SQL editor to dynamically invalidate
|
||||
const sqlLower = sql.toLowerCase()
|
||||
const isMutationSQL =
|
||||
sqlLower.includes('create ') || sqlLower.includes('alter ') || sqlLower.includes('drop ')
|
||||
if (contextualInvalidation && projectRef && isMutationSQL) {
|
||||
const databaseRelatedKeys = queryClient
|
||||
.getQueryCache()
|
||||
.findAll(['projects', projectRef])
|
||||
.map((x) => x.queryKey)
|
||||
.filter((x) => !INVALIDATION_KEYS_IGNORE.some((a) => x.includes(a)))
|
||||
await Promise.all(databaseRelatedKeys.map((key) => queryClient.invalidateQueries(key)))
|
||||
}
|
||||
await onSuccess?.(data, variables, context)
|
||||
},
|
||||
async onError(data, variables, context) {
|
||||
if (onError === undefined) {
|
||||
toast.error(`Failed to execute SQL: ${data.message}`)
|
||||
} else {
|
||||
onError(data, variables, context)
|
||||
}
|
||||
},
|
||||
...options,
|
||||
}
|
||||
)
|
||||
// [Joshen] Default to false for now, only used for SQL editor to dynamically invalidate
|
||||
const sqlLower = sql.toLowerCase()
|
||||
const isMutationSQL =
|
||||
sqlLower.includes('create ') || sqlLower.includes('alter ') || sqlLower.includes('drop ')
|
||||
if (contextualInvalidation && projectRef && isMutationSQL) {
|
||||
const databaseRelatedKeys = queryClient
|
||||
.getQueryCache()
|
||||
.findAll(['projects', projectRef])
|
||||
.map((x) => x.queryKey)
|
||||
.filter((x) => !INVALIDATION_KEYS_IGNORE.some((a) => x.includes(a)))
|
||||
await Promise.all(databaseRelatedKeys.map((key) => queryClient.invalidateQueries(key)))
|
||||
}
|
||||
await onSuccess?.(data, variables, context)
|
||||
},
|
||||
async onError(data, variables, context) {
|
||||
if (onError === undefined) {
|
||||
toast.error(`Failed to execute SQL: ${data.message}`)
|
||||
} else {
|
||||
onError(data, variables, context)
|
||||
}
|
||||
},
|
||||
...options,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user