Skip to content

Commit

Permalink
Merge branch 'main' into service-portal/notifications-locale-cleanstring
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Jun 14, 2024
2 parents 75b7fca + 0201be2 commit 5af8a26
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import ConfirmModal from './ConfirmModal/ConfirmModal'
import { ReferenceText } from './impacts/ReferenceText'
import { DraftChangeForm, DraftImpactForm } from '../state/types'

const updateText =
'Ósamræmi er í texta stofnreglugerðar og breytingareglugerðar. Texti breytingareglugerðar þarf að samræmast breytingum sem gerðar hafa verið á stofnreglugerð, eigi breytingarnar að færast inn með réttum hætti.'

export const EditBasics = () => {
const t = useLocale().formatMessage
const { draft, actions } = useDraftingState()
Expand Down Expand Up @@ -174,7 +177,7 @@ export const EditBasics = () => {
<AlertMessage
type="default"
title="Uppfæra texta"
message="Uppfæra texta reglugerðar með breytingum frá fyrsta skrefi. Allur viðbættur texti í núverandi skrefi verður hreinsaður út."
message={updateText}
action={
<Button
icon="reload"
Expand Down Expand Up @@ -233,9 +236,7 @@ export const EditBasics = () => {
isModalVisible
}
title="Uppfæra texta"
message={
'Uppfæra texta reglugerðar með breytingum frá fyrsta skrefi. Allur viðbættur texti í núverandi skrefi verður hreinsaður út.'
}
message={updateText}
onConfirm={() => {
updateEditorText()
setIsModalVisible(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ export const EditImpacts = () => {
</Link>{' '}
hefur ekki verið flutt á island.is.
<br /> Vinsamlegast hafið samband við ritstjóra.
<br />
<Link
color="blue400"
underlineVisibility="hover"
href="mailto:reglugerdir@dmr.is"
>
reglugerdir@dmr.is
</Link>
</h3>
</Inline>
) : lastItem(draft.impacts[selRegOption.value])?.type === 'repeal' ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import cn from 'classnames'
import { HTMLText, useDomid } from '@island.is/regulations'
import { RegulationDraftId } from '@island.is/regulations/admin'
import { useFileUploader } from '../utils/fileUploader'
import { fileUrl } from '../utils/dataHooks'

const KB = 1024

Expand Down Expand Up @@ -80,6 +81,7 @@ export const EditorInput = (props: EditorInputProps) => {
classes={classes}
fileUploader={fileUploader()}
baseText={baseText}
uploadUrl={`${fileUrl}/admin-drafts/files/${props.draftId}`}
onFocus={() => {
setHasFocus(true)
}}
Expand Down
4 changes: 3 additions & 1 deletion libs/portals/admin/regulations-admin/src/utils/dataHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import { getEditUrl } from './routing'
import { createHash } from 'crypto'
import { RegulationDraftTypes, StepNames } from '../types'

export const fileUrl = 'https://files.reglugerd.is'

type QueryResult<T> =
| {
data: T
Expand Down Expand Up @@ -133,7 +135,7 @@ export const useS3Upload = () => {
})
return
}
const location = `https://files.reglugerd.is/${key}`
const location = `${fileUrl}/${key}`
setUploadLocation(location)
setUploadStatus({ uploading: false })
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ const removeRegPrefix = (title: string) => {
return title
}

const removeRegNamePrefix = (name: string) => {
if (/^0+/.test(name)) {
return name.replace(/^0+/, '')
}
return name
}

export const formatAmendingRegTitle = (draft: RegDraftForm) => {
const impactArray = Object.values(draft.impacts)

Expand All @@ -27,18 +34,16 @@ export const formatAmendingRegTitle = (draft: RegDraftForm) => {

const amendingTitles = amendingArray.map(
(item, i) =>
`${i === 0 ? `${PREFIX_AMENDING}` : ''}${item.name.replace(
/^0+/,
'',
)}${removeRegPrefix(item.regTitle)}`,
`${i === 0 ? `${PREFIX_AMENDING}` : ''}${removeRegNamePrefix(
item.name,
)} ${removeRegPrefix(item.regTitle)}`,
)

const repealTitles = repealArray.map(
(item, i) =>
`${i === 0 ? `${PREFIX_REPEALING}` : ''}${item.name.replace(
/^0+/,
'',
)}${removeRegPrefix(item.regTitle)}`,
`${i === 0 ? `${PREFIX_REPEALING}` : ''}${removeRegNamePrefix(
item.name,
)} ${removeRegPrefix(item.regTitle)}`,
)

return PREFIX + [...amendingTitles, ...repealTitles].join(' og ')
Expand All @@ -50,13 +55,16 @@ export const formatAmendingRegTitle = (draft: RegDraftForm) => {
// ----------------------------------------------------------------------

export const formatAmendingRegBody = (
regName: string,
name: string,
repeal?: boolean,
diff?: HTMLText | string | undefined,
regTitle?: string,
) => {
const regName = removeRegNamePrefix(name)
if (repeal) {
const text =
`<p>Reglugerð nr. ${regName} ásamt síðari breytingum fellur brott</p>` as HTMLText
const text = `<p>Reglugerð nr. ${regName} ${
regTitle ? regTitle.replace(/\.$/, '') + ' ' : ''
}fellur brott.</p>` as HTMLText
const gildistaka =
`<p>Reglugerð þessi er sett með heimild í [].</p><p>Reglugerðin öðlast þegar gildi</p>` as HTMLText
return [text, gildistaka]
Expand Down Expand Up @@ -104,7 +112,21 @@ export const formatAmendingRegBody = (
let isNumberList = false
let isLetterList = false
if (element.classList.contains('article__title')) {
articleTitle = element.innerText
const clone = element.cloneNode(true)

if (clone instanceof Element) {
const emElement = clone.querySelector('em')
if (emElement) {
emElement.parentNode?.removeChild(emElement)
}

const textContent = clone.textContent?.trim() ?? ''

articleTitle = textContent
console.log(textContent)
} else {
articleTitle = element.innerText
}
testGroup.title = articleTitle
isArticleTitle = true
paragraph = 0 // Reset paragraph count for the new article
Expand Down Expand Up @@ -156,16 +178,16 @@ export const formatAmendingRegBody = (
if (isParagraph) {
// Paragraph was deleted
pushHtml =
`<p>${paragraph}. mgr. ${articleTitle} ${regNameDisplay} fellur brott</p>` as HTMLText
`<p>${paragraph}. mgr. ${articleTitle} ${regNameDisplay} fellur brott.</p>` as HTMLText
} else if (isArticleTitle) {
// Title was deleted
pushHtml =
`<p>Fyrirsögn ${articleTitle} ${regNameDisplay} fellur brott</p>` as HTMLText
`<p>Fyrirsögn ${articleTitle} ${regNameDisplay} fellur brott.</p>` as HTMLText
} else if (isLetterList || isNumberList) {
// List was deleted
pushHtml = `<p>${
isLetterList ? 'Stafliðir' : 'Töluliðir'
} eftir ${paragraph}. mgr. ${articleTitle} ${regNameDisplay} falla brott</p>` as HTMLText
} eftir ${paragraph}. mgr. ${articleTitle} ${regNameDisplay} falla brott.</p>` as HTMLText
} else {
// We don't know what you deleted, but there was a deletion, and here's the deletelog:
pushHtml =
Expand Down Expand Up @@ -249,7 +271,7 @@ export const formatAmendingRegBody = (
if (testGroup.isDeletion === true) {
const articleTitleNumber = testGroup.title
additionArray.push([
`<p>${articleTitleNumber} ${regNameDisplay} fellur brott</p>` as HTMLText,
`<p>${articleTitleNumber} ${regNameDisplay} fellur brott.</p>` as HTMLText,
])
} else if (testGroup.isAddition === true) {
let prevArticleTitle = ''
Expand Down Expand Up @@ -286,6 +308,7 @@ export const formatAmendingBodyWithArticlePrefix = (
item.type === 'repeal' || draftImpactLength > 1 ? item.name : '',
item.type === 'repeal',
item.type === 'amend' ? item.diff?.value : undefined,
item.regTitle,
),
)
const flatArray = flatten(impactArray)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"@formatjs/intl-locale": "2.4.33",
"@formatjs/intl-numberformat": "7.1.5",
"@hookform/error-message": "2.0.1",
"@island.is/regulations-tools": "0.8.1",
"@island.is/regulations-tools": "0.9.0",
"@keyv/redis": "2.6.1",
"@livechat/widget-core": "1.3.2",
"@nestjs/apollo": "10.1.0",
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10809,9 +10809,9 @@ __metadata:
languageName: unknown
linkType: soft

"@island.is/regulations-tools@npm:0.8.1":
version: 0.8.1
resolution: "@island.is/regulations-tools@npm:0.8.1"
"@island.is/regulations-tools@npm:0.9.0":
version: 0.9.0
resolution: "@island.is/regulations-tools@npm:0.9.0"
dependencies:
"@hugsmidjan/htmldiff-js": ^1.3.0
"@hugsmidjan/qj": ^4.10.2
Expand All @@ -10825,7 +10825,7 @@ __metadata:
peerDependencies:
react: ">=16.8 <20"
react-dom: ">=16.8 <20"
checksum: bdf33c19b3b69e1661c08befb5ab1d578b4aa3923da22bef6665a8f1890ba3b46895d0a919b6f110ef25d8f84757050187ccd014c8bfefc0c2866cbc7764608e
checksum: 9d4950e590721f78c60644ee7f2c16dfb132960c9383e71cce3dbe9037b8e734c6e8609eb44a623e843ec13187759efd45245078ba4e9c60d456068378a28e62
languageName: node
linkType: hard

Expand Down Expand Up @@ -34284,7 +34284,7 @@ __metadata:
"@graphql-codegen/typescript-react-apollo": 3.3.3
"@graphql-codegen/typescript-resolvers": 2.7.3
"@hookform/error-message": 2.0.1
"@island.is/regulations-tools": 0.8.1
"@island.is/regulations-tools": 0.9.0
"@keyv/redis": 2.6.1
"@livechat/widget-core": 1.3.2
"@nestjs/apollo": 10.1.0
Expand Down

0 comments on commit 5af8a26

Please sign in to comment.