Skip to content

Commit 954aa78

Browse files
authored
MMT-4058: Enabling citation association to collection (#1411)
* MMT-4058: Enabling citation association to collection * MMT-4058: Adding 'name' to query * MMT-4058: Fixing disabled rows issue * MMT-4058: Adding tests, fixing comment/warnings elsewhere * MMT-4058: Removing comment * MMT-4058: PR feedback
1 parent 27d0e81 commit 954aa78

File tree

6 files changed

+378
-20
lines changed

6 files changed

+378
-20
lines changed

static/src/js/components/CollectionAssociationForm/CollectionAssociationForm.jsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -306,18 +306,18 @@ const CollectionAssociationForm = ({ metadata }) => {
306306
// Creates an action cell based on the current concept type
307307
const buildActionsCell = useCallback((cellData, rowData) => {
308308
let disabled = false
309-
let checked = null
309+
let checked = false
310310

311311
const { conceptId: collectionConceptId } = rowData
312-
const { associationDetails } = fetchedDraft
313-
const { collections } = associationDetails || {}
312+
const { collections = {} } = fetchedDraft
313+
const { items } = collections
314314

315315
// Checks if collection is already associated to the record.
316-
if (collections) {
317-
const associatedCollection = collections.filter(
316+
if (items) {
317+
const associatedCollection = items.find(
318318
(item) => item.conceptId === collectionConceptId
319319
)
320-
if (associatedCollection[0]?.conceptId === collectionConceptId) {
320+
if (associatedCollection) {
321321
disabled = true
322322
checked = true
323323
}

static/src/js/components/CollectionAssociationForm/__tests__/__mocks__/CollectionAssociationResults.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ export const mockTool = {
165165
version: '1.2.0'
166166
},
167167
name: 'Collection Association Mock Test',
168+
pageTitle: 'Collection Association Mock Test',
168169
organizations: [
169170
{
170171
roles: [
@@ -180,6 +181,15 @@ export const mockTool = {
180181
quality: null,
181182
revisionId: '1',
182183
revisionDate: '2024-03-21T15:01:58.533Z',
184+
revisions: {
185+
count: 1,
186+
items: {
187+
conceptId: 'T1200000098-MMT_2',
188+
revisionDate: '2024-03-21T15:01:58.533Z',
189+
revisionId: '1',
190+
userId: 'user1'
191+
}
192+
},
183193
relatedUrls: null,
184194
searchAction: null,
185195
supportedBrowsers: null,

static/src/js/components/ManageCollectionAssociation/ManageCollectionAssociation.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ const ManageCollectionAssociation = () => {
217217
})
218218

219219
// Handle refresh, calls getMetadata to get the list of association
220-
// TODO: See if we can get rid of this refresh button.
220+
// TODO: MMT-4089 See if we can get rid of this refresh button.
221221
const handleRefreshPage = () => {
222222
refetch()
223223
}

static/src/js/operations/queries/getCitation.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
import { gql } from '@apollo/client'
22

33
export const GET_CITATION = gql`
4-
query GetCitation ($params: CitationInput) {
4+
query GetCitation ($params: CitationInput, $collectionsParams: CollectionsInput) {
55
citation (params: $params) {
66
abstract
77
citationMetadata
8+
collections (params: $collectionsParams) {
9+
count
10+
items {
11+
conceptId
12+
provider
13+
shortName
14+
title
15+
version
16+
}
17+
}
818
conceptId
919
identifier
1020
identifierType
21+
name,
1122
pageTitle: name
1223
nativeId
1324
providerId

static/src/js/pages/CollectionAssociationFormPage/CollectionAssociationFormPage.jsx

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,33 @@ const CollectionAssociationFormPageHeader = () => {
8282
* <CollectionAssociationFormPage />
8383
* )
8484
*/
85-
const CollectionAssociationFormPage = () => (
86-
<Page
87-
pageType="secondary"
88-
header={<CollectionAssociationFormPageHeader />}
89-
>
90-
<ErrorBoundary>
91-
<Suspense fallback="Loading...">
92-
<CollectionAssociationForm />
93-
</Suspense>
94-
</ErrorBoundary>
95-
</Page>
96-
)
85+
const CollectionAssociationFormPage = () => {
86+
const { conceptId } = useParams()
87+
88+
const derivedConceptType = getConceptTypeByConceptId(conceptId)
89+
90+
const { data } = useSuspenseQuery(conceptTypeQueries[derivedConceptType], {
91+
variables: {
92+
params: {
93+
conceptId
94+
}
95+
}
96+
})
97+
98+
const { [camelCase(derivedConceptType)]: concept } = data
99+
100+
return (
101+
<Page
102+
pageType="secondary"
103+
header={<CollectionAssociationFormPageHeader />}
104+
>
105+
<ErrorBoundary>
106+
<Suspense fallback="Loading...">
107+
<CollectionAssociationForm metadata={concept} />
108+
</Suspense>
109+
</ErrorBoundary>
110+
</Page>
111+
)
112+
}
97113

98114
export default CollectionAssociationFormPage

0 commit comments

Comments
 (0)