Skip to content

Commit

Permalink
Clean up query assets
Browse files Browse the repository at this point in the history
  • Loading branch information
jochenklar committed Oct 26, 2024
1 parent dd0936e commit d92f801
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 84 deletions.
58 changes: 23 additions & 35 deletions daiquiri/query/assets/js/api/QueryApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,6 @@ class QueryApi extends BaseApi {
return this.get('/query/api/dropdowns/')
}

static fetchQueues() {
return this.get('/query/api/queues/')
}

static fetchQueryLanguages() {
return this.get('/query/api/querylanguages/')
}

static fetchDownloads() {
return this.get('/query/api/downloads/')
}
Expand All @@ -35,10 +27,6 @@ class QueryApi extends BaseApi {
return this.get('/query/api/downloadformats/')
}

static fetchPhases() {
return this.get('/query/api/phases/')
}

static fetchJobs(params) {
return this.get(`/query/api/jobs/?${encodeParams(params)}`)
}
Expand All @@ -47,32 +35,12 @@ class QueryApi extends BaseApi {
return this.get('/query/api/jobs/index/')
}

static fetchJob(id) {
return this.get(`/query/api/jobs/${id}/`)
}

static fetchJobColumns(id, params) {
return this.get(`/query/api/jobs/${id}/columns/?${encodeParams(params)}`)
}

static fetchJobRows(id, params) {
return this.get(`/query/api/jobs/${id}/rows/?${encodeParams(params)}`)
}

static fetchUserSchema(params) {
static fetchJobsTables(params) {
return this.get(`/query/api/jobs/tables/?${encodeParams(params)}`)
}

static fetchUserExamples() {
return this.get('/query/api/examples/user/')
}

static fetchUserSchemas() {
return this.get('/query/api/schemas/user/')
}

static fetchUserFunctions() {
return this.get('/query/api/functions/user/')
static fetchJob(id) {
return this.get(`/query/api/jobs/${id}/`)
}

static submitJob(values, formKey = null) {
Expand Down Expand Up @@ -104,6 +72,14 @@ class QueryApi extends BaseApi {
return this.delete(`/query/api/jobs/${id}/`)
}

static fetchJobColumns(id, params) {
return this.get(`/query/api/jobs/${id}/columns/?${encodeParams(params)}`)
}

static fetchJobRows(id, params) {
return this.get(`/query/api/jobs/${id}/rows/?${encodeParams(params)}`)
}

static submitDownloadJob(id, downloadKey, data) {
return this.post(`/query/api/jobs/${id}/download/${downloadKey}/`, data)
}
Expand All @@ -118,6 +94,18 @@ class QueryApi extends BaseApi {
})
}

static fetchUserExamples() {
return this.get('/query/api/examples/user/')
}

static fetchQueues() {
return this.get('/query/api/queues/')
}

static fetchQueryLanguages() {
return this.get('/query/api/querylanguages/')
}

}

export default QueryApi
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { isEmpty } from 'lodash'
import Tooltip from 'daiquiri/core/assets/js/components/Tooltip'

import { useUserSchemasQuery } from 'daiquiri/metadata/assets/js/hooks/queries'
import { useUserSchemaQuery } from 'daiquiri/query/assets/js/hooks/queries'
import { useJobsTablesQuery } from 'daiquiri/query/assets/js/hooks/queries'

const ColumnsDropdown = ({ onDoubleClick }) => {
const { data: schemas } = useUserSchemasQuery()
const { data: userSchema } = useUserSchemaQuery()
const { data: userSchema } = useJobsTablesQuery()

const [columns, setColumns] = useState([])
const [activeItem, setActiveItem] = useState(null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { isEmpty, isUndefined } from 'lodash'
import Schemas from 'daiquiri/metadata/assets/js/components/Schemas'

import { useUserSchemasQuery } from 'daiquiri/metadata/assets/js/hooks/queries'
import { useUserSchemaQuery } from 'daiquiri/query/assets/js/hooks/queries'
import { useJobsTablesQuery } from 'daiquiri/query/assets/js/hooks/queries'

const SchemasDropdown = ({ onDoubleClick }) => {
const { data: schemas } = useUserSchemasQuery()
const { data: userSchema } = useUserSchemaQuery()
const { data: userSchema } = useJobsTablesQuery()

const [activeItem, setActiveItem] = useState(null)

Expand Down
90 changes: 45 additions & 45 deletions daiquiri/query/assets/js/hooks/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export const useStatusQuery = () => {
queryFn: () => QueryApi.fetchStatus().then((response) => {
if (status && (status.hash != response.hash)) {
queryClient.invalidateQueries({ queryKey: ['jobsIndex'] })
queryClient.invalidateQueries({ queryKey: ['jobsTables'] })
queryClient.invalidateQueries({ queryKey: ['job'] })
queryClient.invalidateQueries({ queryKey: ['userSchema'] })
}
return response
}),
Expand All @@ -42,10 +42,10 @@ export const useFormQuery = (formKey) => {
})
}

export const useQueryLanguagesQuery = () => {
export const useDropdownsQuery = () => {
return useQuery({
queryKey: ['queryLanguages'],
queryFn: () => QueryApi.fetchQueryLanguages(),
queryKey: ['drowdowns'],
queryFn: () => QueryApi.fetchDropdowns(),
placeholderData: keepPreviousData
})
}
Expand All @@ -66,22 +66,6 @@ export const useDownloadFormatsQuery = () => {
})
}

export const useQueuesQuery = () => {
return useQuery({
queryKey: ['queues'],
queryFn: () => QueryApi.fetchQueues(),
placeholderData: keepPreviousData
})
}

export const useDropdownsQuery = () => {
return useQuery({
queryKey: ['drowdowns'],
queryFn: () => QueryApi.fetchDropdowns(),
placeholderData: keepPreviousData
})
}

export const useJobsQuery = (params) => {
return useInfiniteQuery({
queryKey: ['jobs', params],
Expand All @@ -100,18 +84,10 @@ export const useJobsIndexQuery = () => {
})
}

export const useUserSchemaQuery = () => {
return useQuery({
queryKey: ['userSchema'],
queryFn: () => QueryApi.fetchUserSchema(),
placeholderData: keepPreviousData
})
}

export const useUserExamplesQuery = () => {
export const useJobsTablesQuery = () => {
return useQuery({
queryKey: ['userExamples'],
queryFn: () => QueryApi.fetchUserExamples(),
queryKey: ['jobsTables'],
queryFn: () => QueryApi.fetchJobsTables(),
placeholderData: keepPreviousData
})
}
Expand Down Expand Up @@ -163,21 +139,11 @@ export const useJobPlotQuery = (job, column) => {
})
}

export const useSimbadQuery = (url, search) => {
return useQuery({
queryKey: ['simbad', search],
queryFn: () => SimbadApi.search(url, search),
placeholderData: keepPreviousData,
enabled: !isEmpty(search)
})
}

export const useVizierQuery = (url, search) => {
export const useUserExamplesQuery = () => {
return useQuery({
queryKey: ['vizier', search],
queryFn: () => VizierApi.search(url, search),
placeholderData: keepPreviousData,
enabled: !isEmpty(search)
queryKey: ['userExamples'],
queryFn: () => QueryApi.fetchUserExamples(),
placeholderData: keepPreviousData
})
}

Expand All @@ -194,3 +160,37 @@ export const useDownloadJobQuery = (job, downloadKey, downloadJobId) => {
}
})
}

export const useQueuesQuery = () => {
return useQuery({
queryKey: ['queues'],
queryFn: () => QueryApi.fetchQueues(),
placeholderData: keepPreviousData
})
}

export const useQueryLanguagesQuery = () => {
return useQuery({
queryKey: ['queryLanguages'],
queryFn: () => QueryApi.fetchQueryLanguages(),
placeholderData: keepPreviousData
})
}

export const useSimbadQuery = (url, search) => {
return useQuery({
queryKey: ['simbad', search],
queryFn: () => SimbadApi.search(url, search),
placeholderData: keepPreviousData,
enabled: !isEmpty(search)
})
}

export const useVizierQuery = (url, search) => {
return useQuery({
queryKey: ['vizier', search],
queryFn: () => VizierApi.search(url, search),
placeholderData: keepPreviousData,
enabled: !isEmpty(search)
})
}

0 comments on commit d92f801

Please sign in to comment.