Skip to content

Commit 9e5e29e

Browse files
author
Sarah Allen
committed
Be clear about what actions are doing. Set href on anchor.
1 parent 45d5779 commit 9e5e29e

File tree

5 files changed

+20
-22
lines changed

5 files changed

+20
-22
lines changed

packages/lib-classifier/src/components/Classifier/components/FieldGuide/components/FieldGuide/components/FieldGuideItems/FieldGuideItemAnchor.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,24 @@ function storeMapper(stores) {
3838
@inject(storeMapper)
3939
@observer
4040
class FieldGuideItemAnchor extends React.Component {
41-
onClick (event, item) {
41+
onClick (event, itemIndex) {
4242
const { setActiveItemIndex } = this.props
4343
event.preventDefault()
44-
setActiveItemIndex(item)
44+
setActiveItemIndex(itemIndex)
4545
}
4646

4747
render () {
48-
const { className, icons, item } = this.props
48+
const { className, icons, item, itemIndex } = this.props
4949
const label = <AnchorLabel icons={icons} item={item} />
5050

5151
return (
5252
<Anchor
5353
a11yTitle={counterpart('FieldGuideItemAnchor.ariaTitle', { title: item.title })}
5454
className={className}
5555
color='dark-5'
56-
href=''
56+
href={`#field-guide-item-${itemIndex}`}
5757
label={label}
58-
onClick={(event) => this.onClick(event, item)}
58+
onClick={(event) => this.onClick(event, itemIndex)}
5959
/>
6060
)
6161
}

packages/lib-classifier/src/components/Classifier/components/FieldGuide/components/FieldGuide/components/FieldGuideItems/FieldGuideItemAnchor.spec.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ const item = {
1515
icon: medium.id,
1616
content: 'lorem ipsum'
1717
}
18+
const itemIndex = 0
1819

1920
describe('Component > FieldGuideItemAnchor', function () {
2021
it('should render without crashing', function () {
2122
const wrapper = shallow(
2223
<FieldGuideItemAnchor.wrappedComponent
2324
icons={attachedMedia}
2425
item={item}
26+
itemIndex={itemIndex}
2527
setActiveItemIndex={() => {}}
2628
/>)
2729
expect(wrapper).to.be.ok
@@ -32,6 +34,7 @@ describe('Component > FieldGuideItemAnchor', function () {
3234
<FieldGuideItemAnchor.wrappedComponent
3335
icons={attachedMedia}
3436
item={item}
37+
itemIndex={itemIndex}
3538
setActiveItemIndex={() => { }}
3639
/>)
3740
expect(wrapper.props().label.type).to.equal(AnchorLabel)
@@ -43,11 +46,12 @@ describe('Component > FieldGuideItemAnchor', function () {
4346
<FieldGuideItemAnchor.wrappedComponent
4447
icons={attachedMedia}
4548
item={item}
49+
itemIndex={itemIndex}
4650
setActiveItemIndex={setActiveItemIndexSpy}
4751
/>)
4852

4953
wrapper.simulate('click', { preventDefault: () => {} })
50-
expect(setActiveItemIndexSpy).to.have.been.calledOnceWith(item)
54+
expect(setActiveItemIndexSpy).to.have.been.calledOnceWith(itemIndex)
5155
})
5256

5357
describe('Component > AnchorLabel', function () {

packages/lib-classifier/src/components/Classifier/components/FieldGuide/components/FieldGuide/components/FieldGuideItems/FieldGuideItems.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default function FieldGuideItems({ className, items }) {
1212
rows='150px'
1313
width='100%'
1414
>
15-
{items.map(item => <FieldGuideItemAnchor key={item.title} item={item} />)}
15+
{items.map((item, index) => <FieldGuideItemAnchor key={item.title} item={item} itemIndex={index} />)}
1616
</Grid>
1717
)
1818
}

packages/lib-classifier/src/store/FieldGuideStore.js

+6-12
Original file line numberDiff line numberDiff line change
@@ -92,20 +92,14 @@ const FieldGuideStore = types
9292
self.showModal = boolean
9393
}
9494

95-
function setActiveItemIndex (item) {
96-
console.log('calling')
95+
function setActiveItemIndex (index) {
9796
const fieldGuide = self.active
98-
if (fieldGuide) {
99-
const { items } = fieldGuide
100-
const index = items.indexOf(item)
101-
if (items[index]) {
102-
const { icon } = items[index]
103-
if (icon) self.activeMedium = icon
104-
return self.activeItemIndex = index
105-
}
106-
107-
return self.activeItemIndex = undefined
97+
if (fieldGuide && fieldGuide.items.length === index + 1 && fieldGuide.items[index]) {
98+
if (fieldGuide.items[index].icon) self.activeMedium = fieldGuide.items[index].icon
99+
return self.activeItemIndex = index
108100
}
101+
102+
return self.activeItemIndex = undefined
109103
}
110104

111105
return {

packages/lib-classifier/src/store/FieldGuideStore.spec.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ describe('Model > FieldGuideStore', function () {
364364

365365
fetchFieldGuide()
366366
.then(() => {
367-
rootStore.fieldGuide.setActiveItemIndex(fieldGuideWithItems.items[0])
367+
rootStore.fieldGuide.setActiveItemIndex(0)
368368
expect(rootStore.fieldGuide.activeItemIndex).to.equal(0)
369369
expect(rootStore.fieldGuide.activeMedium.toJSON()).to.deep.equal(medium)
370370
}).then(done, done)
@@ -386,7 +386,7 @@ describe('Model > FieldGuideStore', function () {
386386
})
387387

388388
fetchFieldGuide().then(() => {
389-
rootStore.fieldGuide.setActiveItemIndex(fieldGuideWithoutIcon.items[0])
389+
rootStore.fieldGuide.setActiveItemIndex(0)
390390
expect(rootStore.fieldGuide.activeItemIndex).to.equal(0)
391391
expect(rootStore.fieldGuide.activeMedium).to.be.undefined
392392
}).then(done, done)
@@ -411,7 +411,7 @@ describe('Model > FieldGuideStore', function () {
411411

412412
fetchFieldGuide()
413413
.then(() => {
414-
rootStore.fieldGuide.setActiveItemIndex(fieldGuideWithItems.items[0])
414+
rootStore.fieldGuide.setActiveItemIndex(0)
415415
rootStore.fieldGuide.setModalVisibility(true)
416416
})
417417
.then(() => {

0 commit comments

Comments
 (0)