Skip to content

Commit c6ed707

Browse files
committed
Code tidyup
1 parent 6c6c232 commit c6ed707

File tree

5 files changed

+86
-84
lines changed

5 files changed

+86
-84
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,53 @@
11
import React from 'react'
2-
2+
import PropTypes from 'prop-types'
33
import Link from '@govuk-react/link'
44

5-
const CollectionSummaryCardItem = ({ title, links, rows }) => {
6-
return (
7-
<div className="govuk-summary-card govuk-!-margin-top-6">
8-
<div class="govuk-summary-card__title-wrapper">
9-
<h2 class="govuk-summary-card__title">{title}</h2>
10-
<div className="govuk-summary-card__title-actions">
11-
{links &&
12-
links.length > 0 &&
13-
links.map((link, index) => (
14-
<>
15-
<Link href={link.url} onClick={link.onClick} {...link.attrs}>
16-
{link.text}
17-
</Link>
18-
{index < links.length - 1 && ' | '}
19-
</>
20-
))}
21-
</div>
22-
</div>
23-
24-
<div class="govuk-summary-card__content">
25-
<dl class="govuk-summary-list">
26-
{rows.map((row, index) => (
27-
<div className="govuk-summary-list__row" key={index}>
28-
<dt className="govuk-summary-list__key">{row.label}</dt>
29-
<dd className="govuk-summary-list__value">{row.value}</dd>
30-
<dd className="govuk-summary-list__actions"></dd>
31-
</div>
5+
const CollectionSummaryCardItem = ({ title, links, rows }) => (
6+
<div className="govuk-summary-card govuk-!-margin-top-6">
7+
<div class="govuk-summary-card__title-wrapper">
8+
<h2 class="govuk-summary-card__title">{title}</h2>
9+
<div className="govuk-summary-card__title-actions">
10+
{links &&
11+
links.length > 0 &&
12+
links.map((link, index) => (
13+
<>
14+
<Link href={link.url} {...link.attrs}>
15+
{link.text}
16+
</Link>
17+
{index < links.length - 1 && ' | '}
18+
</>
3219
))}
33-
</dl>
3420
</div>
3521
</div>
36-
)
22+
23+
<div class="govuk-summary-card__content">
24+
<dl class="govuk-summary-list">
25+
{rows.map((row, index) => (
26+
<div className="govuk-summary-list__row" key={index}>
27+
<dt className="govuk-summary-list__key">{row.label}</dt>
28+
<dd className="govuk-summary-list__value">{row.value}</dd>
29+
</div>
30+
))}
31+
</dl>
32+
</div>
33+
</div>
34+
)
35+
36+
CollectionSummaryCardItem.propTypes = {
37+
title: PropTypes.string.isRequired,
38+
links: PropTypes.arrayOf(
39+
PropTypes.shape({
40+
url: PropTypes.string.isRequired,
41+
text: PropTypes.string.isRequired,
42+
attrs: PropTypes.object,
43+
})
44+
),
45+
rows: PropTypes.arrayOf(
46+
PropTypes.shape({
47+
label: PropTypes.string,
48+
value: PropTypes.string,
49+
})
50+
).isRequired,
3751
}
3852

3953
export default CollectionSummaryCardItem

src/client/modules/Files/CollectionList/CompanyFilesCollection.jsx

+3-20
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,8 @@ const CompanyFilesCollection = ({
3535
},
3636
}
3737

38-
const collectionSummaryCardItemTemplateDefault = (
39-
item,
40-
titleRenderer,
41-
useReactRouter,
42-
pushAnalytics
43-
) => {
44-
return (
45-
<CollectionSummaryCardItem
46-
{...item}
47-
key={item.id}
48-
titleRenderer={titleRenderer}
49-
useReactRouter={useReactRouter}
50-
onClick={() => {
51-
pushAnalytics({
52-
event: 'filterResultClick',
53-
})
54-
}}
55-
/>
56-
)
38+
const collectionSummaryCardItemTemplateDefault = (item) => {
39+
return <CollectionSummaryCardItem {...item} key={item.id} />
5740
}
5841

5942
return (
@@ -70,7 +53,7 @@ const CompanyFilesCollection = ({
7053
summary="Why can I not add a file?"
7154
data-test="archived-details"
7255
>
73-
Contacts files be added to an archived company.{' '}
56+
Files cannot be added to an archived company.{' '}
7457
<Link href={`/companies/${company.id}/unarchive`}>
7558
Click here to unarchive
7659
</Link>

src/client/modules/Files/CollectionList/constants.js

+5
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@ export const SORT_OPTIONS = [
22
{ value: 'created_on:desc', name: 'Recently created' },
33
{ value: 'created_on:asc', name: 'Oldest' },
44
]
5+
6+
export const DOCUMENT_TYPES = {
7+
SHAREPOINT: 'documents.sharepointdocument',
8+
FILE_UPLOAD: 'documents.document',
9+
}

src/client/modules/Files/CollectionList/reducer.js

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { FILES__LOADED } from '../../../actions'
22

33
const initialState = {
44
results: [],
5-
metadata: {},
65
isComplete: false,
76
}
87

src/client/modules/Files/CollectionList/transformers.js

+34-33
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,47 @@ import {
22
formatDate,
33
DATE_FORMAT_MEDIUM_WITH_TIME,
44
} from '../../../utils/date-utils'
5+
import { DOCUMENT_TYPES } from './constants'
56

6-
export const transformArchivedToApi = (archived) =>
7-
archived?.length === 1 ? archived[0] === 'true' : undefined
8-
9-
export const transformContactToListItem = () => (file) => {
7+
export const transformFileToListItem = () => (file) => {
108
let title = ''
119
const links = []
1210
let summaryRows = []
1311

1412
// Check if document type is SharePoint-related
15-
if (file.document_type === 'documents.sharepointdocument') {
16-
title = 'SharePoint link'
17-
if (file.document.title) {
18-
title += ` - ${file.document.title}`
19-
}
13+
switch (file.document_type) {
14+
case DOCUMENT_TYPES.SHAREPOINT:
15+
title = 'SharePoint link'
16+
if (file.document.title) {
17+
title += ` - ${file.document.title}`
18+
}
2019

21-
// Add links
22-
links.push(
23-
{
24-
text: 'View file (opens in new tab)',
25-
url: file.document.url,
26-
attrs: { target: '_blank', rel: 'noopener noreferrer' },
27-
},
28-
{ text: 'Delete', url: '#' }
29-
)
20+
// Add links
21+
links.push(
22+
{
23+
text: 'View file (opens in new tab)',
24+
url: file.document.url,
25+
attrs: { target: '_blank', rel: 'noopener noreferrer' },
26+
},
27+
{ text: 'Delete', url: '#' }
28+
// TODO: Handle that when delete is clicked you go to the delete flow.
29+
)
3030

31-
// Add summary rows
32-
summaryRows = [
33-
{
34-
label: 'Date added',
35-
value: formatDate(
36-
file.document.created_on,
37-
DATE_FORMAT_MEDIUM_WITH_TIME
38-
),
39-
},
40-
{ label: 'Added by', value: file.created_by.name },
41-
{ label: 'SharePoint url', value: file.document.url },
42-
]
43-
} else {
31+
// Add summary rows
32+
summaryRows = [
33+
{
34+
label: 'Date added',
35+
value: formatDate(
36+
file.document.created_on,
37+
DATE_FORMAT_MEDIUM_WITH_TIME
38+
),
39+
},
40+
{ label: 'Added by', value: file.created_by.name },
41+
{ label: 'SharePoint url', value: file.document.url },
42+
]
43+
case DOCUMENT_TYPES.FILE_UPLOAD:
4444
// TODO: Handle flow for uploaded files.
45+
default:
4546
}
4647

4748
return {
@@ -53,9 +54,9 @@ export const transformContactToListItem = () => (file) => {
5354
}
5455

5556
export const transformResponseToCollection = (
56-
companyId,
57+
file,
5758
{ count, results = [] }
5859
) => ({
5960
count,
60-
results: results.map(transformContactToListItem(companyId)),
61+
results: results.map(transformFileToListItem(file)),
6162
})

0 commit comments

Comments
 (0)