Skip to content

Commit

Permalink
BASIRA #273 - Fixing an issue with copying artwork titles
Browse files Browse the repository at this point in the history
  • Loading branch information
dleadbetter committed Dec 10, 2024
1 parent 11986e4 commit 0ec454a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
4 changes: 3 additions & 1 deletion client/src/pages/admin/Artwork.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// @flow

import React, { useCallback, useState } from 'react';
import React, { useCallback, useEffect, useState } from 'react';
import { BooleanIcon, EditModal, EmbeddedList } from '@performant-software/semantic-components';
import { Card, Form, Header } from 'semantic-ui-react';
import _ from 'underscore';
import ArtworkTitleModal from '../../components/ArtworkTitleModal';
import ArtworkTitle from '../../transforms/ArtworkTitle';
import ArtworksService from '../../services/Artworks';
import AttachmentModal from '../../components/AttachmentModal';
import Authorization from '../../utils/Authorization';
Expand Down Expand Up @@ -182,6 +183,7 @@ const Artwork = (props: Props) => {
required: ['title']
}
}}
onCopy={ArtworkTitle.toCopy.bind(this)}
onDelete={props.onDeleteChildAssociation.bind(this, 'artwork_titles')}
onDrag={(dragIndex, hoverIndex) => {
const items = [...props.item.artwork_titles];
Expand Down
27 changes: 27 additions & 0 deletions client/src/transforms/ArtworkTitle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// @flow

import type { ArtworkTitle as ArtworkTitleType } from '../types/ArtworkTitle';
import _ from 'underscore';
import uuid from 'react-uuid';

class ArtworkTitle {
/**
* Returns a copy of the passed artwork_title with any ID values removed. This function also generates a new
* UUID value.
*
* @param title
*
* @returns {*&{qualifications: *}}
*/
toCopy(title: ArtworkTitleType) {
return {
..._.omit(title, 'id', 'uid'),
qualifications: _.map(title.qualifications, (qualification) => ({
..._.omit(qualification, 'id', 'uid', '_destroy', 'qualifiable_id'),
uid: uuid()
}))
};
}
}

export default new ArtworkTitle();

0 comments on commit 0ec454a

Please sign in to comment.