Skip to content

Commit

Permalink
Merge pull request #6566 from uktrade/feature/add-export-win-button
Browse files Browse the repository at this point in the history
Show both 'Add export win' button and 'Export wins' link
  • Loading branch information
paulgain authored Mar 1, 2024
2 parents d37c6d1 + 8c8d692 commit 8a5fc6e
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 11 deletions.
13 changes: 13 additions & 0 deletions src/client/components/CompanyLocalHeader/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ const CompanyLocalHeader = ({
flashMessages,
company,
csrfToken,
hasExportWinFeatureGroup,
}) =>
company && (
<>
Expand Down Expand Up @@ -188,6 +189,18 @@ const CompanyLocalHeader = ({
>
Add export project
</Button>
{hasExportWinFeatureGroup && (
<Button
as={StyledButtonLink}
data-test="header-add-export-win"
href={`${urls.companies.exportWins.create()}?step=officer_details&company=${company.id}`}
aria-label={`Add export win`}
buttonColour={GREY_3}
buttonTextColour={TEXT_COLOUR}
>
Add export win
</Button>
)}
</StyledButtonContainer>
</GridCol>
</GridRow>
Expand Down
1 change: 1 addition & 0 deletions src/client/components/CompanyLocalHeader/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export const state2props = (state) => state[ID]

export const companyState2Props = (state) => ({
csrfToken: state.csrfToken,
hasExportWinFeatureGroup: state.activeFeatureGroups?.includes('export-wins'),
})
38 changes: 32 additions & 6 deletions src/client/modules/ExportPipeline/ExportList/index.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import { useHistory } from 'react-router-dom'
import { HEADING_SIZES, FONT_SIZE, MEDIA_QUERIES } from '@govuk-react/constants'
import { UnorderedList, ListItem, H2 } from 'govuk-react'
import { UnorderedList, ListItem, H2, Link } from 'govuk-react'
import styled from 'styled-components'
import { connect } from 'react-redux'
import PropTypes from 'prop-types'
Expand All @@ -13,6 +13,7 @@ import { MID_GREY } from '../../../utils/colours'
import ListItemRenderer from './ItemRenderer'
import Task from '../../../components/Task'
import ExportSelect from './ExportSelect'
import urls from '../../../../lib/urls'
import ExportDate from './ExportDate'
import List from './List'

Expand Down Expand Up @@ -68,8 +69,18 @@ const HeaderContainer = styled('div')({
marginTop: 30,
})

const LinkContainer = styled('div')({
display: 'flex',
flexDirection: 'column',
padding: 5,
alignItems: 'end',
gap: 10,
})

const StyledButtonLink = styled(ButtonLink)({
marginBottom: 0,
border: 0,
padding: 0,
})

const ListContainer = styled('div')({
Expand All @@ -83,6 +94,7 @@ const ExportList = ({
maxItemsToPaginate,
payload,
filters,
hasExportWinFeatureGroup,
}) => {
const history = useHistory()
const maxItems = Math.min(count, maxItemsToPaginate)
Expand Down Expand Up @@ -168,11 +180,24 @@ const ExportList = ({
</StyledResultCount>{' '}
Exports
</StyledHeader>
{filters.areActive && (
<StyledButtonLink onClick={onClearAll} data-test="clear-filters">
Remove all filters
</StyledButtonLink>
)}
<LinkContainer>
{filters.areActive && (
<StyledButtonLink
onClick={onClearAll}
data-test="clear-filters"
>
Remove all filters
</StyledButtonLink>
)}
{hasExportWinFeatureGroup && (
<Link
href={urls.companies.exportWins.index()}
data-test="export-wins"
>
Export wins
</Link>
)}
</LinkContainer>
</HeaderContainer>
</>
)}
Expand Down Expand Up @@ -239,6 +264,7 @@ ExportList.propTypes = {
results: PropTypes.array,
itemsPerPage: PropTypes.number,
maxItemsToPaginate: PropTypes.number,
hasExportWinFeatureGroup: PropTypes.bool,
}

export default connect(state2props)(ExportList)
3 changes: 3 additions & 0 deletions src/client/modules/ExportPipeline/ExportList/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const areFiltersActive = (queryParams) => {
export const state2props = ({ router, ...state }) => {
const queryParams = getQueryParamsFromLocation(router.location)
const { sectorOptions, countryOptions, ownerOptions } = state[ID]
const hasExportWinFeatureGroup =
state.activeFeatureGroups?.includes('export-wins')
return {
...state[ID],
payload: {
Expand Down Expand Up @@ -55,5 +57,6 @@ export const state2props = ({ router, ...state }) => {
options: SORT_OPTIONS,
},
},
hasExportWinFeatureGroup,
}
}
2 changes: 1 addition & 1 deletion src/client/modules/ExportWins/Status/WinsWonTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const WinsWonTable = ({ exportWins }) => (
<Table.Cell>{currencyGBP(total_expected_export_value)}</Table.Cell>
<NoWrapCell>{formatMediumDate(date)}</NoWrapCell>
<NoWrapCell>
{formatMediumDate(customer_response?.created_on)}
{formatMediumDate(customer_response.responded_on)}
</NoWrapCell>
<NoWrapCell>
<Link
Expand Down
6 changes: 3 additions & 3 deletions test/component/cypress/specs/ExportWins/Table.cy.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const exportWinToRow = (exportWin) => [
exportWin.country.name,
currencyGBP(exportWin.total_expected_export_value),
formatMediumDate(exportWin.date),
formatMediumDate(exportWin.customer_response.created_on),
formatMediumDate(exportWin.customer_response.responded_on),
'View details',
]

Expand All @@ -31,7 +31,7 @@ describe('Export wins table', () => {
total_expected_export_value: 1111111,
date: '1111-11-11',
customer_response: {
created_on: '1212-12-12',
responded_on: '1212-12-12',
},
},
{
Expand All @@ -45,7 +45,7 @@ describe('Export wins table', () => {
total_expected_export_value: 222222,
date: '0101-01-01',
customer_response: {
created_on: '0202-02-02',
responded_on: '0202-02-02',
},
},
exportWinsFaker(),
Expand Down
2 changes: 1 addition & 1 deletion test/functional/cypress/fakers/export-wins.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ export const exportWinsFaker = () => ({
}),
date: faker.date.anytime().toISOString(),
customer_response: {
created_on: faker.date.anytime().toISOString(),
responded_on: faker.date.anytime().toISOString(),
},
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import qs from 'qs'

import { exportListFaker } from '../../fakers/export'
import urls from '../../../../../src/lib/urls'

describe('Export win user feature groups', () => {
const company = '/companies/00009ae3-1912-e411-8a2b-e4115bead28a/overview'

context('Company page"', () => {
it('should show the "Add export win" button when the feature is active', () => {
cy.setUserFeatureGroups(['export-wins'])
cy.visit(company)
cy.get('[data-test="header-add-export-win"]').should('exist')
})
it('should hide the "Add export win" button when the feature is inactive', () => {
cy.setUserFeatureGroups([])
cy.visit(company)
cy.get('[data-test="header-add-export-win"]').should('not.exist')
})
})

context('Dashboard"', () => {
const exports = exportListFaker(3)
const endpoint = '/api-proxy/v4/export'
const queryParams = qs.stringify({
limit: 10,
page: 1,
offset: 0,
archived: false,
sortby: 'created_on:desc',
})

beforeEach(() => {
cy.intercept('GET', `${endpoint}?${queryParams}`, {
body: {
count: exports.length,
results: exports,
},
}).as('apiReqList')
cy.intercept('GET', '/api-proxy/v4/export/owner', [])
})

it('should show the "Export wins" link when the feature is active', () => {
cy.setUserFeatureGroups(['export-wins'])
cy.visit(urls.exportPipeline.index())
cy.get('[data-test="export-wins"]').should('exist')
})

it('should hide the "Export wins" link when the feature is inactive', () => {
cy.setUserFeatureGroups([])
cy.visit(urls.exportPipeline.index())
cy.get('[data-test="export-wins"]').should('not.exist')
})
})
})

0 comments on commit 8a5fc6e

Please sign in to comment.