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

fix: use json+patch for PATCH requests #1593

Merged
merged 2 commits into from
Nov 7, 2023
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
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
Loading