Skip to content

Commit

Permalink
fix: ensure queues uri encode name before using in a url
Browse files Browse the repository at this point in the history
  • Loading branch information
ismay committed Aug 29, 2023
1 parent 590e230 commit 840da9b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
23 changes: 16 additions & 7 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2023-08-23T09:22:37.116Z\n"
"PO-Revision-Date: 2023-08-23T09:22:37.116Z\n"
"POT-Creation-Date: 2023-08-29T11:34:50.926Z\n"
"PO-Revision-Date: 2023-08-29T11:34:50.926Z\n"

msgid "Something went wrong"
msgstr "Something went wrong"
Expand All @@ -33,9 +33,6 @@ msgstr "Delete job"
msgid "Delete queue"
msgstr "Delete queue"

msgid "Something went wrong whilst creating your job"
msgstr "Something went wrong whilst creating your job"

msgid "Please select data exchange ids."
msgstr "Please select data exchange ids."

Expand Down Expand Up @@ -132,12 +129,24 @@ msgstr "Jobs in this queue"
msgid "There was a problem fetching the required job type"
msgstr "There was a problem fetching the required job type"

msgid "Something went wrong whilst creating your job"
msgstr "Something went wrong whilst creating your job"

msgid "Save"
msgstr "Save"

msgid "Cancel"
msgstr "Cancel"

msgid "Something went wrong whilst updating your job"
msgstr "Something went wrong whilst updating your job"

msgid "Something went wrong whilst creating your queue"
msgstr "Something went wrong whilst creating your queue"

msgid "Something went wrong whilst updating your queue"
msgstr "Something went wrong whilst updating your queue"

msgid "Job details"
msgstr "Job details"

Expand Down Expand Up @@ -280,8 +289,8 @@ msgstr "System job: {{ name }}"
msgid "Back to all jobs"
msgstr "Back to all jobs"

msgid "New Queue"
msgstr "New Queue"
msgid "New queue"
msgstr "New queue"

msgid ""
"A queue is a collection of jobs that are executed in order, one after "
Expand Down
7 changes: 4 additions & 3 deletions src/hooks/queues/use-queue-by-name.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { useDataQuery } from '@dhis2/app-runtime'

const key = 'queue'
const createQuery = (name) => ({
const createQuery = (encodedName) => ({
[key]: {
resource: `scheduler/queues/${name}`,
resource: `scheduler/queues/${encodedName}`,
params: {
fields: ['cronExpression', 'sequence', 'name'],
},
},
})

const useQueueByName = (name) => {
const fetch = useDataQuery(createQuery(name))
const encodedName = encodeURIComponent(name)
const fetch = useDataQuery(createQuery(encodedName))

// Remove nesting from data
if (fetch.data) {
Expand Down
7 changes: 4 additions & 3 deletions src/hooks/queues/use-submit-queue.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { useDataEngine } from '@dhis2/app-runtime'
import formatError from '../../services/format-error'

const createMutation = (name) => ({
resource: `scheduler/queues/${name}`,
const createMutation = (encodedName) => ({
resource: `scheduler/queues/${encodedName}`,
type: 'create',
data: ({ queue }) => queue,
})

const useSubmitQueue = ({ onSuccess } = {}) => {
const engine = useDataEngine()
const submitQueue = (queue) => {
const mutation = createMutation(queue.name)
const encodedName = encodeURIComponent(queue.name)
const mutation = createMutation(encodedName)
return engine
.mutate(mutation, { variables: { queue } })
.then(() => {
Expand Down
7 changes: 4 additions & 3 deletions src/hooks/queues/use-update-queue.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { useDataEngine } from '@dhis2/app-runtime'
import formatError from '../../services/format-error'

const createMutation = (name) => ({
resource: `scheduler/queues/${name}`,
const createMutation = (encodedInitialName) => ({
resource: `scheduler/queues/${encodedInitialName}`,
type: 'update',
data: ({ queue }) => queue,
})

const useUpdateQueue = ({ onSuccess, initialName } = {}) => {
const engine = useDataEngine()
const updateQueue = (queue) => {
const mutation = createMutation(initialName)
const encodedInitialName = encodeURIComponent(initialName)
const mutation = createMutation(encodedInitialName)
return engine
.mutate(mutation, { variables: { queue } })
.then(() => {
Expand Down

0 comments on commit 840da9b

Please sign in to comment.