Skip to content

Commit

Permalink
fix: use json+patch for PATCH requests (#1593)
Browse files Browse the repository at this point in the history
  • Loading branch information
edoardo authored Nov 7, 2023
1 parent 73acd1a commit bdb0b9c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
9 changes: 6 additions & 3 deletions src/api/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ export const createCalculationMutation = {
}

export const updateCalculationMutation = {
type: 'update',
type: 'json-patch',
resource: 'expressionDimensionItems',
partial: true,
id: ({ id }) => id,
data: ({ name, expression }) => ({ name, shortName: name, expression }),
data: ({ name, expression }) => [
{ op: 'add', path: '/name', value: name },
{ op: 'add', path: '/shortName', value: name },
{ op: 'add', path: '/expression', value: expression },
],
}

export const deleteCalculationMutation = {
Expand Down
37 changes: 31 additions & 6 deletions src/components/FileMenu/RenameDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,25 @@ import {
labelForFileType,
} from './utils.js'

const formatPayload = (name, description) => {
const payload = [{ op: 'add', path: '/name', value: name }]

if (description) {
payload.push({
op: 'add',
path: '/description',
value: description,
})
}

return payload
}

const getMutation = (type) => ({
resource: endpointFromFileType(type),
id: ({ id }) => id,
type: 'update',
partial: true,
data: ({ name, description }) => ({ name, description }),
type: 'json-patch',
data: ({ name, description }) => formatPayload(name, description),
})

export const RenameDialog = ({ type, object, onClose, onRename, onError }) => {
Expand Down Expand Up @@ -52,7 +65,7 @@ export const RenameDialog = ({ type, object, onClose, onRename, onError }) => {
}

return (
<Modal onClose={onClose}>
<Modal onClose={onClose} dataTest="file-menu-rename-modal">
<style jsx>{modalStyles}</style>
<ModalTitle>
{i18n.t('Rename {{fileType}}', {
Expand All @@ -67,22 +80,34 @@ export const RenameDialog = ({ type, object, onClose, onRename, onError }) => {
required
value={name}
onChange={({ value }) => setName(value)}
dataTest="file-menu-rename-modal-name"
/>
<TextAreaField
label={i18n.t('Description')}
disabled={loading}
value={description}
rows={3}
onChange={({ value }) => setDescription(value)}
dataTest="file-menu-rename-modal-description"
/>
</div>
</ModalContent>
<ModalActions>
<ButtonStrip>
<Button onClick={onClose} disabled={loading} secondary>
<Button
onClick={onClose}
disabled={loading}
secondary
dataTest="file-menu-rename-modal-cancel"
>
{i18n.t('Cancel')}
</Button>
<Button onClick={renameObject} disabled={loading} primary>
<Button
onClick={renameObject}
disabled={loading}
primary
dataTest="file-menu-rename-modal-rename"
>
{i18n.t('Rename')}
</Button>
</ButtonStrip>
Expand Down

0 comments on commit bdb0b9c

Please sign in to comment.