Skip to content

Commit db4a748

Browse files
authored
Ward leader data spacing fixes and component for displaying ward leader website data (#323)
Added links-list component to render different kinds of websites/social media with a small component test
1 parent ac6d262 commit db4a748

File tree

3 files changed

+84
-0
lines changed

3 files changed

+84
-0
lines changed

cypress/component/links-list.cy.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import linksList from "../../src/components/links-list.vue";
2+
3+
describe('Links List Component', () => {
4+
it('renders correctly with props', () => {
5+
const props = [
6+
{
7+
title: 'Instagram - John Doe',
8+
url: 'https://www.example.com'
9+
},
10+
{
11+
title: 'LinkedIn - John Doe',
12+
url: 'https://www.linkedin.com'
13+
}
14+
]
15+
cy.mount(linksList, {props:{links:props}})
16+
// Assert it has 2 <li> children
17+
cy.get('li').should('have.length', 2)
18+
// Check URL rendering
19+
cy.get('li a').eq(0).should('have.attr', 'href', props[0].url)
20+
cy.get('li a').eq(1).should('have.attr', 'href', props[1].url)
21+
})
22+
23+
})

src/components/links-list.vue

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<template>
2+
<li v-for="(link, index) in links" :key="index">
3+
<a
4+
:href="link.url"
5+
target="_blank"
6+
rel="noopener noreferrer"
7+
:title="link.title"
8+
>{{ link.title }}</a
9+
>
10+
</li>
11+
</template>
12+
13+
<script>
14+
export default {
15+
name: "links-list",
16+
props: {
17+
links: {
18+
type: Array,
19+
required: true,
20+
validator: (links) => {
21+
return links.every((link) => "title" in link && "url" in link);
22+
},
23+
},
24+
},
25+
};
26+
</script>
27+
28+
<style scoped>
29+
ul {
30+
list-style-type: none;
31+
padding: 0;
32+
}
33+
</style>

src/views/ward-leader.vue

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@
167167
<li v-if="leader.twitter">
168168
<a :href="leader.twitter">Twitter</a>
169169
</li>
170+
<links-list :links="leaderLinks"></links-list>
170171
</ul>
171172
<ask-detail
172173
:thePage="feedbackPage"
@@ -252,6 +253,7 @@ import { mapState, mapGetters, mapActions } from "vuex";
252253
import StatsBar from "../components/stats-bar.vue";
253254
import CommitteePerson from "../components/committee-person.vue";
254255
import WardMap from "../components/ward-map.vue";
256+
import LinksList from "../components/links-list.vue";
255257
import AskDetail from "../components/ask-detail.vue";
256258
import { formatNumber, ordinalize } from "../util";
257259
import { TURNOUT_ELECTION } from "../config";
@@ -338,6 +340,31 @@ export default {
338340
return this.allCommitteePersons.filter((p) => p.fullName === "VACANT")
339341
.length;
340342
},
343+
leaderLinks() {
344+
let websites = this.leader.websites;
345+
if (websites === undefined) {
346+
return [];
347+
}
348+
let linkData = websites
349+
.map((obj) =>
350+
Object.fromEntries(
351+
Object.entries(obj).filter(([key]) => key === "fields"),
352+
),
353+
)
354+
.sort((a, b) => {
355+
const platformA = a.fields.platform.toUpperCase();
356+
const platformB = b.fields.platform.toUpperCase();
357+
return platformA.localeCompare(platformB);
358+
});
359+
360+
linkData = linkData.map((item) => {
361+
return {
362+
title: `${item.fields.platform} - ${item.fields.title}`,
363+
url: item.fields.url,
364+
};
365+
});
366+
return linkData;
367+
},
341368
},
342369
methods: {
343370
...mapActions({
@@ -374,6 +401,7 @@ export default {
374401
"committee-person": CommitteePerson,
375402
"ward-map": WardMap,
376403
"ask-detail": AskDetail,
404+
"links-list": LinksList,
377405
},
378406
};
379407

0 commit comments

Comments
 (0)