Skip to content

Commit efa1a60

Browse files
committed
fix: temporary match sheets bills with politigraph people
1 parent e52d28c commit efa1a60

File tree

9 files changed

+185
-178
lines changed

9 files changed

+185
-178
lines changed

src/components/BillCard/BillCard.svelte

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
import BillStatusTag from '$components/BillStatusTag/BillStatusTag.svelte';
44
import { BillStatus, type Bill } from '$models/bill';
55
import { twMerge } from 'tailwind-merge';
6-
import Proposer from '$components/Proposer/Proposer.svelte';
7-
import { getProposerFromBill } from '$lib/model-component-adapters/bill-proposer';
6+
// import Proposer from '$components/Proposer/Proposer.svelte';
87
98
export let id: string;
109
export let nickname: string;
@@ -45,8 +44,9 @@
4544
<h3 class="fluid-heading-03 text-text-01">{nickname}</h3>
4645
</a>
4746
<p class="text-sm text-text-02"><span class="mr-1 font-bold">ชื่อทางการ</span>{title}</p>
48-
<p class="font-semibold">เสนอโดย</p>
49-
<Proposer proposer={getProposerFromBill(bill)} />
47+
<!-- TODO: Waiting for new Bill data from Politigraph -->
48+
<!-- <p class="font-semibold">เสนอโดย</p>
49+
<Proposer proposer={getProposerFromBill(bill)} /> -->
5050
</div>
5151

5252
<div

src/components/Proposer/Proposer.story.svelte

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414
{orientation}
1515
proposer={{
1616
id: 'พริษฐ์-วัชรสินธุ',
17-
firstname: 'พริษฐ์',
18-
lastname: 'วัชรสินธุ',
19-
avatar: 'https://via.placeholder.com/64',
17+
name: 'พริษฐ์ วัชรสินธุ',
18+
image: 'https://via.placeholder.com/64',
2019
assembly: {
2120
id: 'สภาผู้แทนราษฎร-26',
2221
abbreviation: 'ส.ส.',
@@ -32,8 +31,7 @@
3231
{orientation}
3332
proposer={{
3433
id: 'คณะรัฐมนตรี-64',
35-
isCabinet: true,
36-
abbreviation: 'คณะรัฐมนตรี',
34+
abbreviation: 'ครม.',
3735
term: 64,
3836
startedAt: new Date('04/09/2024')
3937
}}
@@ -44,8 +42,7 @@
4442
{orientation}
4543
proposer={{
4644
id: 'สภาผู้แทนราษฎร-26',
47-
isCabinet: false,
48-
abbreviation: 'ส.ส.',
45+
abbreviation: 'สส.',
4946
term: 26,
5047
startedAt: new Date('01/01/2023')
5148
}}

src/components/Proposer/Proposer.svelte

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
<script context="module" lang="ts">
22
export type PoliticianProposer = {
33
id: string;
4-
firstname: string;
5-
lastname: string;
6-
avatar: string;
4+
name: string;
5+
image: string | null;
76
assembly?: {
87
id: string;
9-
abbreviation: string;
10-
term: number;
11-
startedAt: Date;
8+
abbreviation: string | null;
9+
term: number | null;
10+
startedAt: Date | string | null;
1211
};
1312
partyName?: string;
1413
};
1514
1615
export type AssemblyProposer = {
1716
id: string;
18-
isCabinet: boolean;
1917
abbreviation: string;
2018
term: number;
21-
startedAt: Date;
19+
startedAt: Date | string | null;
2220
};
2321
2422
export type PeopleProposer = {
@@ -44,47 +42,57 @@
4442
4543
$: isLandscape = orientation === 'landscape';
4644
47-
function getBudistYear(date: Date) {
45+
function getBudistYear(date: string | Date) {
4846
return dayjs(date).format('BBBB');
4947
}
5048
</script>
5149

52-
<div class="flex {isLandscape ? 'flex-col gap-x-2 md:flex-row' : 'flex-col'}">
50+
<div class="flex items-center {isLandscape ? 'flex-col gap-x-2 md:flex-row' : 'flex-col'}">
5351
{#if proposer === undefined}
5452
<p class="text-sm text-gray-60">ไม่พบข้อมูล</p>
55-
{:else if 'firstname' in proposer}
56-
{@const { id, firstname, lastname, avatar, assembly, partyName } = proposer}
53+
{:else if 'image' in proposer}
54+
{@const { id, name, image, assembly, partyName } = proposer}
5755
<figure class="h-6 w-6 shrink-0 overflow-hidden rounded-full bg-gray-20">
58-
<img src={avatar} alt="{firstname} {lastname}" class="h-full w-full" loading="lazy" />
56+
<img
57+
src={image || '/images/politicians/_placeholder.webp'}
58+
alt=""
59+
class="h-full w-full"
60+
loading="lazy"
61+
/>
5962
</figure>
60-
<div>
61-
<p class="text-sm">
62-
<a href="/politicians/{id}" class="text-black">
63-
{firstname}
64-
{lastname}
63+
<p class="text-sm">
64+
<a href="/politicians/{id}" class="text-black">
65+
{name}
66+
</a>
67+
{#if assembly}
68+
<a href="/assemblies/{assembly.id}" class="text-sm text-black underline">
69+
{assembly.abbreviation} ชุดที่ {assembly.term}
70+
{#if assembly.startedAt}
71+
({getBudistYear(assembly.startedAt)})
72+
{/if}
6573
</a>
66-
{#if assembly}
67-
<a href="/assemblies/{assembly.id}" class="text-sm text-black underline">
68-
{assembly.abbreviation} ชุดที่ {assembly.term} ({getBudistYear(assembly.startedAt)})
69-
</a>
70-
{/if}
71-
</p>
72-
{#if partyName}
73-
<span class="text-sm text-gray-60">พรรค{partyName}</span>
7474
{/if}
75-
</div>
75+
</p>
76+
{#if partyName}
77+
<span class="text-sm text-gray-60">พรรค{partyName}</span>
78+
{/if}
7679
{:else if 'term' in proposer}
77-
{@const { id, abbreviation, term, isCabinet, startedAt } = proposer}
80+
{@const { id, abbreviation, term, startedAt } = proposer}
7881
<div class="flex h-6 w-6 items-center justify-center rounded-full bg-black">
7982
<svelte:component
80-
this={isCabinet ? GeneralIcon : PoliticianIcon}
83+
this={abbreviation === 'ครม.' ? GeneralIcon : PoliticianIcon}
8184
class="stroke-white"
8285
size={16}
8386
/>
8487
</div>
8588
<a href="/assemblies/{id}" class="text-sm text-black">
8689
{abbreviation}
87-
<span class="underline">ชุดที่ {term} ({getBudistYear(startedAt)})</span>
90+
<span class="underline"
91+
>ชุดที่ {term}
92+
{#if startedAt}
93+
({getBudistYear(startedAt)})
94+
{/if}
95+
</span>
8896
</a>
8997
{:else}
9098
{@const { ledBy, signatoryCount } = proposer}
Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
<script lang="ts">
2-
import type { Politician } from '$models/politician';
3-
4-
export let name: string;
5-
export let politicians: (Politician | string)[];
6-
7-
$: party =
8-
typeof politicians[0] === 'object'
9-
? politicians[0].partyRoles.find((e) => !e.endedAt)?.party
10-
: undefined;
2+
export let politicianCount: number;
3+
export let party:
4+
| {
5+
id?: string;
6+
name: string;
7+
logo?: string;
8+
}
9+
| undefined = undefined;
1110
</script>
1211

1312
<div class="flex gap-2">
@@ -18,8 +17,11 @@
1817
<img src={party?.logo || '/images/politicians/_placeholder.webp'} alt="" />
1918
</div>
2019
<div class="flex">
21-
<!-- TODO: link to party when implemented -->
22-
<p>{party ? 'พรรค' : ''}{name}</p>
23-
<p class="body-02 ml-1 text-text-02">{politicians.length} คน</p>
20+
{#if party?.id}
21+
<a href="/party?/{party?.id}">พรรค{party?.name}</a>
22+
{:else}
23+
<p>พรรค{party?.name}</p>
24+
{/if}
25+
<p class="body-02 ml-1 text-text-02">{politicianCount} คน</p>
2426
</div>
2527
</div>

src/components/bills/CoProposer.svelte

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
11
<script lang="ts">
2-
import type { Politician } from '$models/politician';
3-
42
export let index: number;
5-
export let politician: Politician | string;
6-
export let billProposedOn: Date;
7-
8-
$: party =
9-
typeof politician === 'object'
10-
? politician.partyRoles?.find(
11-
({ startedAt, endedAt }) =>
12-
billProposedOn.getTime() >= startedAt.getTime() &&
13-
(!endedAt || billProposedOn.getTime() <= endedAt.getTime())
14-
)?.party
15-
: undefined;
3+
export let politician: {
4+
id?: string;
5+
name: string;
6+
};
7+
export let partyLogo: string | null = null;
168
</script>
179

1810
<tr>
@@ -23,14 +15,12 @@
2315
class="flex items-center justify-center overflow-hidden rounded-full border border-gray-30"
2416
style="width: 16px; height: 16px;"
2517
>
26-
<img src={party?.logo || '/images/politicians/_placeholder.webp'} alt="" />
18+
<img src={partyLogo || '/images/politicians/_placeholder.webp'} alt="" />
2719
</div>
28-
{#if typeof politician === 'object'}
29-
<a class="text-black underline" href="/politicians/{politician.id}"
30-
>{politician.firstname} {politician.lastname}</a
31-
>
20+
{#if politician.id}
21+
<a class="text-black underline" href="/politicians/{politician.id}">{politician.name}</a>
3222
{:else}
33-
<p>{politician}</p>
23+
<p>{politician.name}</p>
3424
{/if}
3525
</div>
3626
</td>

src/components/bills/ModalListCoProposers.svelte

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
<script lang="ts">
22
import { showModalListCoProposer } from '$components/bills/store';
3-
import type { Politician } from '$models/politician';
43
import CloseLarge from 'carbon-icons-svelte/lib/CloseLarge.svelte';
54
import CoProposer from './CoProposer.svelte';
5+
import type { ComponentProps } from 'svelte';
66
7-
export let coProposedByPoliticians: (Politician | string)[];
8-
export let billProposedOn: Date;
7+
export let coProposedByPoliticians: ComponentProps<CoProposer>['politician'][];
98
</script>
109

1110
{#if $showModalListCoProposer}
@@ -32,7 +31,7 @@
3231
<div class="flex flex-col pb-5 pl-8 pr-5">
3332
<table class="w-full">
3433
{#each coProposedByPoliticians as politician, i}
35-
<CoProposer index={i + 1} {politician} {billProposedOn} />
34+
<CoProposer index={i + 1} {politician} />
3635
{/each}
3736
</table>
3837
</div>

src/lib/model-component-adapters/bill-proposer.ts

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/routes/bills/[id]/+page.server.ts

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { queryPoliticiansVote } from '$lib/politigraph/vote/with-politician';
77
import { createSeo } from '$lib/seo';
88
import type { Bill } from '$models/bill';
99
import { BillEventType, type BillEvent } from '$models/bill-event';
10+
import type { Politician } from '$models/politician';
1011
import type { ComponentProps } from 'svelte';
1112

1213
export async function entries() {
@@ -71,8 +72,26 @@ export async function load({ params }) {
7172
}))
7273
);
7374

75+
// TODO: workaround to temporary match old sheet politician id with new politician politigraph id
76+
const proposedLedByPolitician = bill.proposedLedByPolitician
77+
? await mapOldPoliticianToNewPolitician(bill.proposedOn, bill.proposedLedByPolitician)
78+
: undefined;
79+
const coProposedByPoliticians = bill.coProposedByPoliticians
80+
? await Promise.all(
81+
bill.coProposedByPoliticians.map((politician) =>
82+
typeof politician === 'string'
83+
? { name: politician }
84+
: mapOldPoliticianToNewPolitician(bill.proposedOn, politician)
85+
)
86+
)
87+
: undefined;
88+
7489
return {
75-
bill,
90+
bill: {
91+
...bill,
92+
proposedLedByPolitician,
93+
coProposedByPoliticians
94+
},
7695
// TODO: merged bill data is not ready yet
7796
mergedBills: [] as Bill[], // Bills that got merged into this bill.
7897
// TODO: Remove this when we migrate bill to Politigraph
@@ -93,3 +112,60 @@ export async function load({ params }) {
93112
})
94113
};
95114
}
115+
116+
async function mapOldPoliticianToNewPolitician(billProposedDate: Date, politician: Politician) {
117+
const { memberships, ...rest } = (
118+
await graphql.query({
119+
people: {
120+
__args: {
121+
where: {
122+
firstname_EQ: politician.firstname,
123+
lastname_EQ: politician.lastname
124+
}
125+
},
126+
id: true,
127+
name: true,
128+
image: true,
129+
memberships: {
130+
__args: {
131+
where: {
132+
start_date_LTE: billProposedDate.toUTCString(),
133+
OR: [{ end_date_EQ: null }, { end_date_GTE: billProposedDate.toUTCString() }]
134+
}
135+
},
136+
posts: {
137+
label: true,
138+
organizations: {
139+
id: true,
140+
name: true,
141+
image: true,
142+
term: true,
143+
abbreviation: true,
144+
classification: true,
145+
founding_date: true
146+
}
147+
}
148+
}
149+
}
150+
})
151+
).people[0];
152+
153+
const assembly = memberships.find(
154+
(m) => m.posts[0].organizations[0].classification !== 'POLITICAL_PARTY'
155+
);
156+
157+
return {
158+
...rest,
159+
party: memberships.find((m) => m.posts[0].organizations[0].classification === 'POLITICAL_PARTY')
160+
?.posts[0].organizations[0],
161+
assembly: assembly
162+
? {
163+
id: assembly.posts[0].organizations[0].id,
164+
abbreviation: assembly.posts[0].organizations[0].abbreviation,
165+
term: assembly.posts[0].organizations[0].term,
166+
startedAt: assembly.posts[0].organizations[0].founding_date,
167+
postLabel: assembly.posts[0].label
168+
}
169+
: undefined
170+
};
171+
}

0 commit comments

Comments
 (0)