Skip to content

Commit

Permalink
Merge branch 'develop' into MIM-801-smaller-img-for-mobile-and-lazy-l…
Browse files Browse the repository at this point in the history
…oading
  • Loading branch information
Carl-OW authored Sep 24, 2024
2 parents efd6c91 + 9462320 commit 900b004
Show file tree
Hide file tree
Showing 14 changed files with 257 additions and 210 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Gradle Project settings
projectName = mimir
version = 2.12.0
version = 2.13.1

# XP App values
appDisplayName = Mimir application
Expand Down
380 changes: 200 additions & 180 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
},
"homepage": "https://github.com/statisticsnorway/mimir#readme",
"devDependencies": {
"@babel/cli": "~7.24.8",
"@babel/cli": "~7.25.6",
"@babel/core": "~7.25.2",
"@babel/preset-env": "~7.25.4",
"@babel/preset-react": "~7.24.7",
Expand Down Expand Up @@ -74,7 +74,7 @@
"@item-enonic-types/lib-thymeleaf": "~2.1.0",
"@item-enonic-types/lib-time": "~1.0.4",
"@reduxjs/toolkit": "~2.2.7",
"@statisticsnorway/ssb-component-library": "~2.2.14",
"@statisticsnorway/ssb-component-library": "~2.2.16",
"@types/grecaptcha": "^3.0.9",
"@types/ramda": "~0.30.2",
"@types/react": "~18.3.5",
Expand All @@ -89,15 +89,15 @@
"babel-preset-env": "~1.7.0",
"browser-sync": "^3.0.2",
"cross-env": "~7.0.3",
"cssnano": "~7.0.5",
"cssnano": "~7.0.6",
"esbuild-plugin-replace": "^1.4.0",
"esbuild-sass-plugin": "^2.16.1",
"eslint": "~8.57.0",
"eslint-config-google": "~0.14.0",
"eslint-config-prettier": "~9.1.0",
"eslint-plugin-import": "~2.29.1",
"eslint-plugin-import": "~2.30.0",
"eslint-plugin-prettier": "~5.2.1",
"eslint-plugin-react": "~7.35.0",
"eslint-plugin-react": "~7.35.2",
"feather-icons": "~4.29.2",
"file-loader": "~6.2.0",
"glob": "~10.4.1",
Expand All @@ -115,7 +115,7 @@
"npm-run-all": "~4.1.5",
"npm-safe-install": "~1.1.0",
"numeral": "~2.0.6",
"postcss": "~8.4.43",
"postcss": "~8.4.45",
"postcss-loader": "~8.1.1",
"postcss-normalize": "~10.0.1",
"prettier": "~3.3.3",
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/lib/ssb/cache/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,9 @@ export function setupHandlers(socket: Socket): void {

function purgeVarnishCache(): HttpResponse {
const baseUrl: string =
app.config && app.config['ssb.internal.baseUrl'] ? app.config['ssb.internal.baseUrl'] : 'https://i.ssb.no'
app.config && app.config['ssb.internal.serverside.baseUrl']
? app.config['ssb.internal.serverside.baseUrl']
: 'https://ext-i.ssb.no'
const response: HttpResponse = request({
url: `${baseUrl}/xp_clear`,
method: 'PURGE',
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/lib/ssb/dashboard/statreg/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const STAT_REG_SVC_PROP = 'ssb.statreg.baseUrl'
export const STAT_REG_SVC_PROP = 'ssb.statreg.serverside.baseUrl'

export const CONTACTS_URL = `/kontakt/listSomXml`
export const STATISTICS_URL = `/statistics`
Expand Down
23 changes: 17 additions & 6 deletions src/main/resources/lib/ssb/dataset/tbprocessor/tbprocessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,7 @@ function getDataAndMetaData(
content: Content<DataSource>,
processXml?: string
): TbprocessorParsedResponse<TbmlDataUniform> | null {
const baseUrl: string =
app.config && app.config['ssb.tbprocessor.baseUrl']
? app.config['ssb.tbprocessor.baseUrl']
: 'https://i.ssb.no/tbprocessor'
const baseUrl: string = app.config?.['ssb.tbprocessor.serverside.baseUrl'] ?? 'https://ext-i.ssb.no/tbprocessor'
const dataPath = `/process/tbmldata/`
const sourceListPath = `/document/sourceList/`
const language: string = content.language || ''
Expand All @@ -94,8 +91,9 @@ function getDataAndMetaData(
dataSource.tbprocessor &&
isUrl(dataSource.tbprocessor.urlOrId)
) {
tbmlDataUrl = `${dataSource.tbprocessor.urlOrId as string}${language === 'en' ? `?lang=${language}` : ''}`
sourceListUrl = `${dataSource.tbprocessor.urlOrId as string}`.replace(dataPath, sourceListPath)
const tbprocessorUrl = fixTbProcessorUrl(dataSource.tbprocessor.urlOrId as string)
tbmlDataUrl = `${tbprocessorUrl}${language === 'en' ? `?lang=${language}` : ''}`
sourceListUrl = `${tbprocessorUrl}`.replace(dataPath, sourceListPath)
}

const tbmlParsedResponse: TbprocessorParsedResponse<TbmlDataUniform> | null = tryRequestTbmlData<TbmlDataUniform>(
Expand Down Expand Up @@ -221,6 +219,19 @@ function addSourceList(
: null
}

function fixTbProcessorUrl(url: string): string {
if (url.includes('/i.test.ssb.no')) {
return url.replace('/i.test.ssb.no', '/ext-i.test.ssb.no')
}
if (url.includes('/i.qa.ssb.no')) {
return url.replace('/i.qa.ssb.no', '/ext-i.qa.ssb.no')
}
if (url.includes('/i.ssb.no')) {
return url.replace('/i.ssb.no', '/ext-i.ssb.no')
}
return url
}

export function fetchTbprocessorData(
content: Content<DataSource>,
processXml?: string
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/lib/ssb/statreg/statistics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export function fetchStatistics(): Array<StatisticInListing> | null {
}
} catch (error) {
const message = `Failed to fetch data from statreg: Statistics (${error})`
log.error(message)
logUserDataQuery('Statistics', {
file: '/lib/ssb/statreg/statistics.ts',
function: 'fetchStatistics',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { type TableProps } from '/lib/types/partTypes/table'
import { type AccordionData } from '/lib/types/partTypes/accordion'

export type AttachmentTablesFiguresProps = {
Expand All @@ -12,6 +13,6 @@ export type AttachmentTablesFiguresProps = {
export interface AttachmentTablesFiguresData extends AccordionData {
contentType: string
subHeader: string
props?: object
props?: TableProps | object
pageContributions?: XP.PageContributions
}
1 change: 1 addition & 0 deletions src/main/resources/lib/types/partTypes/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface TableProps {
sourceTableLabel: string
statBankWebUrl: string
hiddenTitle: string | undefined
checkIsOverflowing?: boolean
}

export interface TableStandardSymbolLink {
Expand Down
22 changes: 14 additions & 8 deletions src/main/resources/react4xp/_entries/AttachmentTablesFigures.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
type AttachmentTablesFiguresProps,
type AttachmentTablesFiguresData,
} from '../../lib/types/partTypes/attachmentTablesFigures'
import { type TableProps } from '../../lib/types/partTypes/table'

import Table from '../table/Table'

Expand All @@ -15,6 +16,14 @@ function AttachmentTableFigures(props: AttachmentTablesFiguresProps) {
const { accordions, freeText, showAll, showLess, title } = props
const currentElement = useRef<null | HTMLLIElement>(null)
const [focusElement, setFocusElement] = useState(false)
const [checkOverflow, setCheckOverflow] = useState(false)

useEffect(() => {
if (focusElement && currentElement.current) {
const btn = currentElement.current.firstChild?.firstChild as HTMLButtonElement
btn.focus()
}
}, [isHidden])

function toggleBox() {
setIsHidden((prevState) => !prevState)
Expand Down Expand Up @@ -79,7 +88,7 @@ function AttachmentTableFigures(props: AttachmentTablesFiguresProps) {

function renderAccordionBody(accordion: AttachmentTablesFiguresData) {
if (accordion.contentType === `${props.appName}:table`) {
return <Table {...accordion.props} />
return <Table checkIsOverflowing={checkOverflow} {...(accordion.props as TableProps)} />
} else {
// Table or figure from content studio (no user input), hence no need to sanitize
return <div dangerouslySetInnerHTML={{ __html: accordion.body! }}></div>
Expand All @@ -89,13 +98,6 @@ function AttachmentTableFigures(props: AttachmentTablesFiguresProps) {
const location = window.location
const anchor = location && location.hash !== '' ? location.hash.substr(1) : undefined

useEffect(() => {
if (focusElement && currentElement.current) {
const btn = currentElement.current.firstChild?.firstChild as HTMLButtonElement
btn.focus()
}
}, [isHidden])

return (
<React.Fragment>
<h2>{title}</h2>
Expand All @@ -113,6 +115,10 @@ function AttachmentTableFigures(props: AttachmentTablesFiguresProps) {
header={accordion.open}
subHeader={accordion.subHeader}
openByDefault={anchor && accordion.id && accordion.id === anchor}
onToggle={() => {
// Check for Table overflow when toggling accordion
setCheckOverflow((prev) => !prev)
}}
>
{renderAccordionBody(accordion)}
</Accordion>
Expand Down
7 changes: 6 additions & 1 deletion src/main/resources/react4xp/table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,12 @@ function Table(props: TableProps) {
function createTable() {
const { tableClass } = props.table
return (
<SSBTable className={tableClass} caption={addCaption()} dataNoteRefs={props.table.caption?.noterefs}>
<SSBTable
className={tableClass}
caption={addCaption()}
dataNoteRefs={props.table.caption?.noterefs}
checkIsOverflowing={props.checkIsOverflowing}
>
{props.table.thead?.map((t, index) => (
<React.Fragment key={index}>
{addThead(index)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ const ENONIC_PROJECT_ID = app.config && app.config['ssb.project.id'] ? app.confi
const contentStudioBaseUrl = `${DEFAULT_CONTENTSTUDIO_URL}/${ENONIC_PROJECT_ID}/edit/`

const INTERNAL_BASE_URL =
app.config && app.config['ssb.internal.baseUrl'] ? app.config['ssb.internal.baseUrl'] : 'https://i.ssb.no'
app.config && app.config['ssb.internal.serverside.baseUrl']
? app.config['ssb.internal.serverside.baseUrl']
: 'https://ext-i.ssb.no'

export function get(req: XP.Request): XP.Response {
const contentToFix = query<Content<Article>>({
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/site/parts/tbmlPreview/tbmlPreview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function get(req: XP.Request): XP.Response {
function renderPart(req: XP.Request): XP.Response {
const tbmlId = req.params.tbmlid
const language = req.params.sprak ?? 'no'
const baseUrl: string = app.config?.['ssb.tbprocessor.baseUrl'] || 'https://i.ssb.no/tbprocessor'
const baseUrl: string = app.config?.['ssb.tbprocessor.serverside.baseUrl'] ?? 'https://ext-i.ssb.no/tbprocessor'
const tbProceessorUrl = `${baseUrl}/process/tbmldata/${tbmlId}?lang=${language}`
const tbmlData: TbprocessorParsedResponse<TbmlDataUniform> | null = tbmlId
? (getTbmlData(tbProceessorUrl) as TbprocessorParsedResponse<TbmlDataUniform>)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ export function run(params: BanVarnishPageCacheConfig): void {
}

function purgePageFromVarnish(pageId: string): HttpResponse {
const baseUrl: string = app.config?.['ssb.internal.baseUrl']
? (app.config['ssb.internal.baseUrl'] as string)
: 'https://i.ssb.no'
const baseUrl: string = app.config?.['ssb.internal.serverside.baseUrl'] ?? 'https://ext-i.ssb.no'
const response: HttpResponse = request({
url: `${baseUrl}/xp_page_clear`,
method: 'PURGE',
Expand Down

0 comments on commit 900b004

Please sign in to comment.