Skip to content

Commit 1369617

Browse files
committed
Addresses Review Comments
1 parent 524deac commit 1369617

File tree

4 files changed

+35
-36
lines changed

4 files changed

+35
-36
lines changed

db/sqldb/portfolio.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
"github.com/jackc/pgx/v5/pgtype"
1111
)
1212

13+
// Curious why this query uses array aggregation in its nested queries?
14+
// See https://github.com/RMI-PACTA/app/pull/91#discussion_r1437712435
1315
func portfolioQueryStanza(where string) string {
1416
return fmt.Sprintf(`
1517
WITH selected_portfolio_ids AS (
@@ -232,7 +234,6 @@ func rowToPortfolio(row rowScanner) (*pacta.Portfolio, error) {
232234
if err := checkSizesEquivalent("initiatives", len(initiativesIDs), len(initiativesAddedByIDs), len(initiativesCreatedAts)); err != nil {
233235
return nil, err
234236
}
235-
seenInitiativeIDs := make(map[pacta.InitiativeID]bool)
236237
for i := range initiativesIDs {
237238
if !initiativesIDs[i].Valid && !initiativesCreatedAts[i].Valid {
238239
continue // skip nulls
@@ -243,11 +244,6 @@ func rowToPortfolio(row rowScanner) (*pacta.Portfolio, error) {
243244
if !initiativesCreatedAts[i].Valid {
244245
return nil, fmt.Errorf("initiative createdAt must be non-null")
245246
}
246-
id := pacta.InitiativeID(initiativesIDs[i].String)
247-
if seenInitiativeIDs[id] {
248-
continue // Skip duplicates, see MULTI_LEFT_JOIN note.
249-
}
250-
seenInitiativeIDs[id] = true
251247
var addedBy *pacta.User
252248
if initiativesAddedByIDs[i].Valid {
253249
addedBy = &pacta.User{ID: pacta.UserID(initiativesAddedByIDs[i].String)}

db/sqldb/portfolio_group.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func rowToPortfolioGroup(row rowScanner) (*pacta.PortfolioGroup, error) {
138138
if err != nil {
139139
return nil, fmt.Errorf("scanning into portfolio_group row: %w", err)
140140
}
141-
if err := checkSizesEquivalent("portfolio group memberhsip", len(mid), len(mca)); err != nil {
141+
if err := checkSizesEquivalent("portfolio group membership", len(mid), len(mca)); err != nil {
142142
return nil, err
143143
}
144144
for i := range mid {

frontend/composables/useURLParams.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,33 @@ export const useURLParams = () => {
3939
void router.replace(qs)
4040
}
4141

42+
const fromQueryReactive = (key: string): WritableComputedRef<string | undefined> => {
43+
return computed({
44+
get: () => getVal(router.currentRoute.value.query, key),
45+
set: (val: string | undefined) => { setVal(key, val) },
46+
})
47+
}
48+
49+
const fromQueryReactiveWithDefault = (key: string, def: string): WritableComputedRef<string> => {
50+
const fqr = fromQueryReactive(key)
51+
return computed({
52+
get: () => fqr.value ?? def,
53+
set: (val: string) => {
54+
if (val === def) {
55+
fqr.value = undefined
56+
} else {
57+
fqr.value = val
58+
}
59+
},
60+
})
61+
}
62+
4263
return {
4364
fromQuery: (key: string): string | undefined => {
4465
return getVal(route.query, key)
4566
},
46-
fromQueryReactive: (key: string): WritableComputedRef<string | undefined> => {
47-
return computed({
48-
get: () => getVal(router.currentRoute.value.query, key),
49-
set: (val: string | undefined) => { setVal(key, val) },
50-
})
51-
},
67+
fromQueryReactive,
68+
fromQueryReactiveWithDefault,
5269
fromParams: (key: string): string | undefined => {
5370
return getVal(route.params, key)
5471
},

frontend/pages/my-data.vue

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<script setup lang="ts">
22
const prefix = 'pages/my-data'
33
4-
const { fromQueryReactive } = useURLParams()
4+
const { fromQueryReactiveWithDefault } = useURLParams()
55
const { t } = useI18n()
66
const pactaClient = usePACTA()
77
const { loading: { withLoading } } = useModal()
88
99
const tt = (s: string) => t(`${prefix}.${s}`)
1010
11-
const selectedPortfolioIdsQP = fromQueryReactive('pids')
12-
const selectedPortfolioGroupIdsQP = fromQueryReactive('pgids')
13-
const tabQP = fromQueryReactive('tab')
11+
const selectedPortfolioIdsQP = fromQueryReactiveWithDefault('pids', '')
12+
const selectedPortfolioGroupIdsQP = fromQueryReactiveWithDefault('pgids', '')
13+
const tabQP = fromQueryReactiveWithDefault('tab', 'p')
1414
1515
const [
1616
{ data: incompleteUploadsData, refresh: refreshIncompleteUploadsApi },
@@ -46,26 +46,12 @@ const refreshAll = async () => {
4646
}
4747
4848
const selectedPortfolioIds = computed<string[]>({
49-
get: () => (selectedPortfolioIdsQP.value ?? '').split(','),
50-
set: (v: string[]) => {
51-
if (v.length === 0) {
52-
selectedPortfolioIdsQP.value = undefined
53-
} else {
54-
v.sort()
55-
selectedPortfolioIdsQP.value = v.join(',')
56-
}
57-
},
49+
get: () => selectedPortfolioIdsQP.value.split(','),
50+
set: (v: string[]) => { selectedPortfolioIdsQP.value = v.join(',') },
5851
})
5952
const selectedPortfolioGroupIds = computed<string[]>({
60-
get: () => (selectedPortfolioGroupIdsQP.value ?? '').split(','),
61-
set: (v: string[]) => {
62-
if (v.length === 0) {
63-
selectedPortfolioGroupIdsQP.value = undefined
64-
} else {
65-
v.sort()
66-
selectedPortfolioGroupIdsQP.value = v.join(',')
67-
}
68-
},
53+
get: () => selectedPortfolioGroupIdsQP.value.split(','),
54+
set: (v: string[]) => { selectedPortfolioGroupIdsQP.value = v.join(',') },
6955
})
7056
interface TabToIndexMap {
7157
iu: number
@@ -91,7 +77,7 @@ const tabToIndexMap = computed(() => {
9177
})
9278
const activeIndex = computed<number>({
9379
get: () => {
94-
const tab = (tabQP.value ?? 'p') as keyof TabToIndexMap
80+
const tab = tabQP.value as keyof TabToIndexMap
9581
const result = tabToIndexMap.value[tab]
9682
if (result === undefined) {
9783
console.error(`Unknown tab ${tab}`)

0 commit comments

Comments
 (0)