Skip to content

Commit

Permalink
Web: encode job name in API requests
Browse files Browse the repository at this point in the history
Signed-off-by: Martynov Maxim <martinov_m_s_@mail.ru>
  • Loading branch information
dolfinus committed Aug 5, 2024
1 parent 94ec22e commit a3b65bc
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 44 deletions.
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')
}
28 changes: 19 additions & 9 deletions web/src/store/requests/jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ export const getJobs = async (namespace: string, limit = 25, offset = 0) => {
})
}

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 +27,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

0 comments on commit a3b65bc

Please sign in to comment.