Skip to content

Commit

Permalink
Merge branch 'main' of github.com:island-is/island.is into j-s/table_…
Browse files Browse the repository at this point in the history
…refacotring
  • Loading branch information
oddsson committed Jul 9, 2024
2 parents f298551 + 13b66f5 commit 26a6a28
Show file tree
Hide file tree
Showing 15 changed files with 82 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ export class EndorsementList extends Model {
@HasMany(() => Endorsement)
endorsements?: Endorsement[]

@ApiProperty()
endorsementCounter?: number

@ApiProperty()
@Column({
type: DataType.JSONB,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
BadRequestException,
} from '@nestjs/common'
import { InjectModel } from '@nestjs/sequelize'
import { Op } from 'sequelize'
import { Op, Sequelize } from 'sequelize'
import type { Logger } from '@island.is/logging'
import { LOGGER_PROVIDER } from '@island.is/logging'
import { EndorsementList } from './endorsementList.model'
Expand Down Expand Up @@ -76,8 +76,28 @@ export class EndorsementListService {
after: query.after,
before: query.before,
primaryKeyField: 'counter',
orderOption: [['counter', 'DESC']],
orderOption: [
['endorsementCounter', 'DESC'],
['counter', 'DESC'],
],
where: where,
attributes: {
include: [
[
Sequelize.fn('COUNT', Sequelize.col('endorsements.id')),
'endorsementCounter',
],
],
},
include: [
{
model: Endorsement,
required: false, // Required false for left outer join so that counts come for 0 as well
duplicating: false,
attributes: [],
},
],
group: ['EndorsementList.id'],
})
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { ReactNode } from 'react'
import { ReactNode } from 'react'

import {
Box,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Locale } from '@island.is/shared/types'

import { Stack } from '@island.is/island-ui/core'
import { Locale } from '@island.is/shared/types'
import { OfficialJournalOfIcelandAdvertsResponse } from '@island.is/web/graphql/schema'
import { useLinkResolver } from '@island.is/web/hooks'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import format from 'date-fns/format'
import is from 'date-fns/locale/is'
import { Locale } from '@island.is/shared/types'

import { LinkV2, Table as T, Text } from '@island.is/island-ui/core'
import { Locale } from '@island.is/shared/types'
import { OfficialJournalOfIcelandAdvertsResponse } from '@island.is/web/graphql/schema'
import { useLinkResolver } from '@island.is/web/hooks'

Expand Down
7 changes: 3 additions & 4 deletions apps/web/components/OfficialJournalOfIceland/OJOIWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { ReactNode, useEffect, useState } from 'react'
import { ReactNode, useEffect, useState } from 'react'
import { useWindowSize } from 'react-use'
import NextLink from 'next/link'

Expand All @@ -12,7 +12,7 @@ import {
} from '@island.is/island-ui/core'
import { theme } from '@island.is/island-ui/theme'
import { Footer as WebFooter } from '@island.is/web/components'
import { Image, Organization } from '@island.is/web/graphql/schema'
import { Organization } from '@island.is/web/graphql/schema'
import { usePlausiblePageview } from '@island.is/web/hooks'
import SidebarLayout from '@island.is/web/screens/Layouts/SidebarLayout'

Expand Down Expand Up @@ -135,12 +135,11 @@ export const OJOIWrapper = ({

{!sidebarContent && children}

<Box className="rs_read">
<Box className="rs_read" background="blue100">
<WebFooter
imageUrl={organization.logo?.url}
heading={organization.title}
columns={organization.footerItems}
background={organization?.footerConfig?.background}
titleVariant="h2"
/>
</Box>
Expand Down
2 changes: 1 addition & 1 deletion apps/web/screens/OfficialJournalOfIceland/OJOIAdvert.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useIntl } from 'react-intl'
import { Locale } from '@island.is/shared/types'

import { Box, Button, Link, Stack, Text } from '@island.is/island-ui/core'
import { Locale } from '@island.is/shared/types'
import {
ContentLanguage,
CustomPageUniqueIdentifier,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useCallback, useEffect, useMemo, useState } from 'react'
import { useIntl } from 'react-intl'
import { Locale } from '@island.is/shared/types'
import debounce from 'lodash/debounce'
import { useRouter } from 'next/router'

Expand All @@ -18,6 +17,7 @@ import {
Text,
} from '@island.is/island-ui/core'
import { debounceTime } from '@island.is/shared/constants'
import { Locale } from '@island.is/shared/types'
import {
ContentLanguage,
CustomPageUniqueIdentifier,
Expand Down
2 changes: 1 addition & 1 deletion apps/web/screens/OfficialJournalOfIceland/OJOIHome.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useIntl } from 'react-intl'
import { Locale } from '@island.is/shared/types'
import NextLink from 'next/link'

import {
Expand All @@ -13,6 +12,7 @@ import {
Stack,
Text,
} from '@island.is/island-ui/core'
import { Locale } from '@island.is/shared/types'
import { SLICE_SPACING } from '@island.is/web/constants'
import {
ContentLanguage,
Expand Down
4 changes: 2 additions & 2 deletions apps/web/screens/OfficialJournalOfIceland/OJOISearch.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useEffect, useMemo, useState } from 'react'
import { useIntl } from 'react-intl'
import { Locale } from '@island.is/shared/types'
import debounce from 'lodash/debounce'
import { useRouter } from 'next/router'
import { useLazyQuery } from '@apollo/client'
Expand All @@ -16,6 +15,7 @@ import {
Text,
} from '@island.is/island-ui/core'
import { debounceTime } from '@island.is/shared/constants'
import { Locale } from '@island.is/shared/types'
import {
ContentLanguage,
CustomPageUniqueIdentifier,
Expand Down Expand Up @@ -487,7 +487,7 @@ OJOISearch.getProps = async ({ apolloClient, locale }) => {
}

return {
initialAdverts: officialJournalOfIcelandAdverts.adverts,
initialAdverts: officialJournalOfIcelandAdverts?.adverts,
categories: officialJournalOfIcelandCategories?.categories,
departments: officialJournalOfIcelandDepartments?.departments,
types: officialJournalOfIcelandTypes?.types,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,7 @@ export class EndorsementList {

@Field({ nullable: true })
owner?: string

@Field({ nullable: true })
endorsementCounter?: number
}
24 changes: 22 additions & 2 deletions libs/island-ui/core/src/lib/Navigation/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ export const Navigation: FC<React.PropsWithChildren<NavigationProps>> = ({
title = 'Efnisyfirlit',
titleLink,
titleIcon,

activeItemTitle,
label,
colorScheme = 'blue',
Expand All @@ -168,7 +167,28 @@ export const Navigation: FC<React.PropsWithChildren<NavigationProps>> = ({
mobileNavigationButtonCloseLabel = 'Close',
}) => {
const [mobileMenuOpen, setMobileMenuOpen] = useState(false)
const [activeAccordions, setActiveAccordions] = useState<Array<string>>([])

const [activeAccordions, setActiveAccordions] = useState<Array<string>>(
() => {
const initialActivePathIndex = items?.findIndex(
(item) => item.active && item.accordion,
)

if (initialActivePathIndex > 0) {
//first level only
return [
`1-${items?.findIndex(
(item) =>
item.active &&
item.accordion &&
item.items?.some((child) => child.active),
)}`,
]
}

return []
},
)

const color = colorSchemeColors[colorScheme]['color']
const activeColor = colorSchemeColors[colorScheme]['activeColor']
Expand Down
22 changes: 20 additions & 2 deletions libs/nest/pagination/src/lib/paginate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,26 @@ export async function paginate<T = any>({

const [instances, totalCount, cursorCount] = await Promise.all([
Model.findAll(paginationQueryOptions),
Model.count(totalCountQueryOptions),
Model.count(cursorCountQueryOptions),
Model.count(totalCountQueryOptions).then(
// If the query does relation aggregations, then the count will be an array.
// Since we are only interested in the list length, not related elements, we
// can just take the length of the array.

(count: Array<unknown> | number) => {
if (Array.isArray(count)) {
return count.length
}
return count
},
),
Model.count(cursorCountQueryOptions).then(
(count: Array<unknown> | number) => {
if (Array.isArray(count)) {
return count.length
}
return count
},
),
])

if (before) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ const Petitions = () => {
</Stack>
</Box>
)}

{openSignedLists && openSignedLists.length > 0 && (
<Box marginTop={6}>
<Text variant="h4" marginBottom={2}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const GetGeneralPetitionLists = gql`
description
closedDate
openedDate
endorsementCounter
adminLock
meta
owner
Expand Down

0 comments on commit 26a6a28

Please sign in to comment.