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

Web: encode job name in API requests #2866

Merged
merged 1 commit into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 36 additions & 29 deletions web/src/store/requests/datasets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import { Dataset, DatasetVersions, Datasets } from '../../types/api'
import { genericFetchWrapper } from './index'

export const getDatasets = async (namespace: string, limit = 20, offset = 0) => {
const url = `${API_URL}/namespaces/${encodeURIComponent(
namespace
)}/datasets?limit=${limit}&offset=${offset}`
const encodedNamespace = encodeURIComponent(namespace)
const url = `${API_URL}/namespaces/${encodedNamespace}/datasets?limit=${limit}&offset=${offset}`
return genericFetchWrapper(url, { method: 'GET' }, 'fetchDatasets').then((r: Datasets) => {
return {
datasets: r.datasets.map((d) => ({ ...d, namespace: namespace })),
Expand All @@ -19,66 +18,74 @@ export const getDatasets = async (namespace: string, limit = 20, offset = 0) =>

export const getDatasetVersions = async (
namespace: string,
dataset: string,
datasetName: string,
limit: number,
offset: number
) => {
const url = `${API_URL}/namespaces/${encodeURIComponent(namespace)}/datasets/${encodeURIComponent(
dataset
)}/versions?limit=${limit}&offset=${offset}`
const encodedNamespace = encodeURIComponent(namespace)
const encodedDataset = encodeURIComponent(datasetName)
const url = `${API_URL}/namespaces/${encodedNamespace}/datasets/${encodedDataset}/versions?limit=${limit}&offset=${offset}`
return genericFetchWrapper(url, { method: 'GET' }, 'fetchDatasetVersions').then(
(r: DatasetVersions) => {
return { versions: r.versions, totalCount: r.totalCount }
}
)
}

export const getDataset = async (namespace: string, dataset: string) => {
const url = `${API_URL}/namespaces/${encodeURIComponent(namespace)}/datasets/${encodeURIComponent(
dataset
)}`
export const getDataset = async (namespace: string, datasetName: string) => {
const encodedNamespace = encodeURIComponent(namespace)
const encodedDataset = encodeURIComponent(datasetName)
const url = `${API_URL}/namespaces/${encodedNamespace}/datasets/${encodedDataset}`
return genericFetchWrapper(url, { method: 'GET' }, 'fetchDataset').then((d: Dataset) => d)
}

export const deleteDataset = async (datasetName: string, namespace: string) => {
const url = `${API_URL}/namespaces/${encodeURIComponent(namespace)}/datasets/${datasetName}`
export const deleteDataset = async (namespace: string, datasetName: string) => {
const encodedNamespace = encodeURIComponent(namespace)
const encodedDataset = encodeURIComponent(datasetName)
const url = `${API_URL}/namespaces/${encodedNamespace}/datasets/${encodedDataset}`
return genericFetchWrapper(url, { method: 'DELETE' }, 'deleteDataset')
}

export const deleteDatasetTag = async (namespace: string, datasetName: string, tag: string) => {
const url = `${API_URL}/namespaces/${encodeURIComponent(
namespace
)}/datasets/${datasetName}/tags/${tag}`
const encodedNamespace = encodeURIComponent(namespace)
const encodedDataset = encodeURIComponent(datasetName)
const encodedTag = encodeURIComponent(tag)
const url = `${API_URL}/namespaces/${encodedNamespace}/datasets/${encodedDataset}/tags/${encodedTag}`
return genericFetchWrapper(url, { method: 'DELETE' }, 'deleteDatasetTag')
}

export const addDatasetTag = async (namespace: string, datasetName: string, tag: string) => {
const url = `${API_URL}/namespaces/${encodeURIComponent(
namespace
)}/datasets/${datasetName}/tags/${tag}`
const encodedNamespace = encodeURIComponent(namespace)
const encodedDataset = encodeURIComponent(datasetName)
const encodedTag = encodeURIComponent(tag)
const url = `${API_URL}/namespaces/${encodedNamespace}/datasets/${encodedDataset}/tags/${encodedTag}`
return genericFetchWrapper(url, { method: 'POST' }, 'addDatasetTag')
}

export const deleteDatasetFieldTag = async (
namespace: string,
datasetName: string,
tag: string,
field: string
field: string,
tag: string
) => {
const url = `${API_URL}/namespaces/${encodeURIComponent(
namespace
)}/datasets/${datasetName}/fields/${field}/tags/${tag}`
const encodedNamespace = encodeURIComponent(namespace)
const encodedDataset = encodeURIComponent(datasetName)
const encodedField = encodeURIComponent(field)
const encodedTag = encodeURIComponent(tag)
const url = `${API_URL}/namespaces/${encodedNamespace}/datasets/${encodedDataset}/fields/${encodedField}/tags/${encodedTag}`
return genericFetchWrapper(url, { method: 'DELETE' }, 'deleteDatasetFieldTag')
}

export const addDatasetFieldTag = async (
namespace: string,
datasetName: string,
tag: string,
field: string
field: string,
tag: string
) => {
const url = `${API_URL}/namespaces/${encodeURIComponent(
namespace
)}/datasets/${datasetName}/fields/${field}/tags/${tag}`
const encodedNamespace = encodeURIComponent(namespace)
const encodedDataset = encodeURIComponent(datasetName)
const encodedField = encodeURIComponent(field)
const encodedTag = encodeURIComponent(tag)
const url = `${API_URL}/namespaces/${encodedNamespace}/datasets/${encodedDataset}/fields/${encodedField}/tags/${encodedTag}`
return genericFetchWrapper(url, { method: 'POST' }, 'addDatasetFieldTag')
}
33 changes: 21 additions & 12 deletions web/src/store/requests/jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ import { Jobs } from '../../types/api'
import { genericFetchWrapper } from './index'

export const getJobs = async (namespace: string, limit = 25, offset = 0) => {
const url = `${API_URL}/namespaces/${encodeURIComponent(
namespace
)}/jobs?limit=${limit}&offset=${offset}`
const encodedNamespace = encodeURIComponent(namespace)
const url = `${API_URL}/namespaces/${encodedNamespace}/jobs?limit=${limit}&offset=${offset}`
return genericFetchWrapper(url, { method: 'GET' }, 'fetchJobs').then((r: Jobs) => {
return { totalCount: r.totalCount, jobs: r.jobs.map((j) => ({ ...j, namespace: namespace })) }
})
}

export const deleteJob = async (jobName: string, namespace: string) => {
const url = `${API_URL}/namespaces/${encodeURIComponent(namespace)}/jobs/${jobName}`
export const deleteJob = async (namespace: string, jobName: string) => {
const encodedNamespace = encodeURIComponent(namespace)
const encodedJob = encodeURIComponent(jobName)
const url = `${API_URL}/namespaces/${encodedNamespace}/jobs/${encodedJob}`
return genericFetchWrapper(url, { method: 'DELETE' }, 'deleteJob')
}

Expand All @@ -25,23 +26,31 @@ export const getRuns = async (
limit: number,
offset: number
) => {
const url = `${API_URL}/namespaces/${encodeURIComponent(namespace)}/jobs/${encodeURIComponent(
jobName
)}/runs?limit=${limit}&offset=${offset}`
const encodedNamespace = encodeURIComponent(namespace)
const encodedJob = encodeURIComponent(jobName)
const url = `${API_URL}/namespaces/${encodedNamespace}/jobs/${encodedJob}/runs?limit=${limit}&offset=${offset}`
return genericFetchWrapper(url, { method: 'GET' }, 'fetchRuns')
}

export const getJob = async (namespace: string, job: string) => {
const url = `${API_URL}/namespaces/${encodeURIComponent(namespace)}/jobs/${job}`
export const getJob = async (namespace: string, jobName: string) => {
const encodedNamespace = encodeURIComponent(namespace)
const encodedJob = encodeURIComponent(jobName)
const url = `${API_URL}/namespaces/${encodedNamespace}/jobs/${encodedJob}`
return genericFetchWrapper(url, { method: 'GET' }, 'fetchJob')
}

export const deleteJobTag = async (namespace: string, jobName: string, tag: string) => {
const url = `${API_URL}/namespaces/${encodeURIComponent(namespace)}/jobs/${jobName}/tags/${tag}`
const encodedNamespace = encodeURIComponent(namespace)
const encodedJob = encodeURIComponent(jobName)
const encodedTag = encodeURIComponent(tag)
const url = `${API_URL}/namespaces/${encodedNamespace}/jobs/${encodedJob}/tags/${encodedTag}`
return genericFetchWrapper(url, { method: 'DELETE' }, 'deleteJobTag')
}

export const addJobTag = async (namespace: string, jobName: string, tag: string) => {
const url = `${API_URL}/namespaces/${encodeURIComponent(namespace)}/jobs/${jobName}/tags/${tag}`
const encodedNamespace = encodeURIComponent(namespace)
const encodedJob = encodeURIComponent(jobName)
const encodedTag = encodeURIComponent(tag)
const url = `${API_URL}/namespaces/${encodedNamespace}/jobs/${encodedJob}/tags/${encodedTag}`
return genericFetchWrapper(url, { method: 'POST' }, 'addJobTag')
}
12 changes: 6 additions & 6 deletions web/src/store/sagas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export function* deleteJobSaga() {
while (true) {
try {
const { payload } = yield take(DELETE_JOB)
const job: Job = yield call(deleteJob, payload.jobName, payload.namespace)
const job: Job = yield call(deleteJob, payload.namespace, payload.jobName)
yield put(deleteJobSuccess(job.name))
} catch (e) {
yield put(applicationError('Something went wrong while removing job'))
Expand Down Expand Up @@ -285,7 +285,7 @@ export function* deleteDatasetSaga() {
while (true) {
try {
const { payload } = yield take(DELETE_DATASET)
const dataset: Dataset = yield call(deleteDataset, payload.datasetName, payload.namespace)
const dataset: Dataset = yield call(deleteDataset, payload.namespace, payload.datasetName)
yield put(deleteDatasetSuccess(dataset.name))
} catch (e) {
yield put(applicationError('Something went wrong while removing job'))
Expand Down Expand Up @@ -325,8 +325,8 @@ export function* deleteDatasetFieldTagSaga() {
deleteDatasetFieldTag,
payload.namespace,
payload.datasetName,
payload.tag,
payload.field
payload.field,
payload.tag
)
yield put(
deleteDatasetFieldTagSuccess(
Expand Down Expand Up @@ -374,8 +374,8 @@ export function* addDatasetFieldTagSaga() {
addDatasetFieldTag,
payload.namespace,
payload.datasetName,
payload.tag,
payload.field
payload.field,
payload.tag
)
yield put(
addDatasetFieldTagSuccess(
Expand Down
Loading