Skip to content

Commit

Permalink
Add export win button and link behind a user feature group
Browse files Browse the repository at this point in the history
  • Loading branch information
paulgain committed Mar 1, 2024
1 parent 8464c63 commit b6e6f1a
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 6 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,
}
}
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', () => {
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', () => {
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 "Add export win" link', () => {
cy.setUserFeatureGroups(['export-wins'])
cy.visit(urls.exportPipeline.index())
cy.get('[data-test="export-wins"]').should('exist')
})

it('should hide the "Add export win" button', () => {
cy.setUserFeatureGroups([])
cy.visit(urls.exportPipeline.index())
cy.get('[data-test="export-wins"]').should('not.exist')
})
})
})

0 comments on commit b6e6f1a

Please sign in to comment.