From 263248479777a0c474d93f4cb071ad3e1e7cf886 Mon Sep 17 00:00:00 2001 From: GHaralds Date: Mon, 5 May 2025 13:13:02 +0000 Subject: [PATCH 01/53] Add API logic to publish bill XML --- client-sdk/src/services/BillService.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/client-sdk/src/services/BillService.ts b/client-sdk/src/services/BillService.ts index 1fdc5c1..e2dd55e 100644 --- a/client-sdk/src/services/BillService.ts +++ b/client-sdk/src/services/BillService.ts @@ -89,4 +89,21 @@ export class BillService { }, }); } + /** + * Publish bill XML. + * @param id + * @returns any Successful response + * @throws ApiError + */ + public static billControllerPublishXml( + id: number, + ): CancelablePromise { + return __request(OpenAPI, { + method: 'POST', + url: '/api/bills/{id}/xml', + path: { + 'id': id, + }, + }); + } } From e59fbbd69862fb9134d5cf95cf88b212d1358b81 Mon Sep 17 00:00:00 2001 From: GHaralds Date: Mon, 5 May 2025 13:14:05 +0000 Subject: [PATCH 02/53] Add publishDocument --- client/src/features/Bills/useBillPage.ts | 26 +++++++++++++++++++++--- client/src/pages/BillPage.tsx | 4 +++- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/client/src/features/Bills/useBillPage.ts b/client/src/features/Bills/useBillPage.ts index 50314be..cf5a5bd 100644 --- a/client/src/features/Bills/useBillPage.ts +++ b/client/src/features/Bills/useBillPage.ts @@ -1,6 +1,6 @@ import { notification } from 'antd'; -import { BillDocumentService, DocumentService } from 'client-sdk'; -import { LawEditor, getTitle } from 'law-document'; +import { BillDocumentService, DocumentService, BillService } from 'client-sdk'; +import { LawEditor, getTitle, exportXml } from 'law-document'; import { useCallback, useEffect, useState } from 'react'; import { useNavigate, useParams } from 'react-router'; import modal from 'antd/es/modal'; @@ -146,6 +146,25 @@ const useBillPage = (disableActions = false, billPage = '/bill') => { useEffect(loadDocument, [loadDocument]); + const publishDocument = useCallback((editor: LawEditor) => { + if (!bill || !bill.id || !selected) { + log('not publish'); + return; + } + log('publish bill document', { bill, selected }); + + BillService.billControllerPublishXml(bill.id) + .then((billItem) => { + log('published bill', { billItem }); + setError(false); + }) + .catch((error) => { + log('Error publishing bill'); + setError(true); + console.error(error); + }); + }, [bill, selected, exportXml]); + return { bill, openDocument, @@ -158,10 +177,11 @@ const useBillPage = (disableActions = false, billPage = '/bill') => { slate, originalDocument, loadDocument, + publishDocument, hasBillLoadingError: hasBillError, hasDocumentLoadingError: hasError, importError, }; }; -export default useBillPage; \ No newline at end of file +export default useBillPage; diff --git a/client/src/pages/BillPage.tsx b/client/src/pages/BillPage.tsx index f20d7c4..0256b67 100644 --- a/client/src/pages/BillPage.tsx +++ b/client/src/pages/BillPage.tsx @@ -31,6 +31,7 @@ const BillPage: FC = () => { xml, originalDocument, saveDocument, + publishDocument, hasBillLoadingError, hasDocumentLoadingError, isBillDocument, @@ -80,6 +81,7 @@ const BillPage: FC = () => { originalDocument={originalDocument!} xml={xml!} saveDocument={saveDocument} + publishDocument={publishDocument} readOnly={!isBillDocument} bill={bill} t={t} @@ -98,4 +100,4 @@ const BillPage: FC = () => { ); }; -export default BillPage; \ No newline at end of file +export default BillPage; From 3808a7aea1adfee28f840de5d63567c6863c6082 Mon Sep 17 00:00:00 2001 From: GHaralds Date: Mon, 5 May 2025 13:14:59 +0000 Subject: [PATCH 03/53] Export API to publish bill --- server/src/controllers/BillController.ts | 24 ++++++++++++++++++++- server/src/index.ts | 2 +- server/src/integration/lagasafnApi/index.ts | 6 +++++- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/server/src/controllers/BillController.ts b/server/src/controllers/BillController.ts index e3192ed..0ee6400 100644 --- a/server/src/controllers/BillController.ts +++ b/server/src/controllers/BillController.ts @@ -4,6 +4,7 @@ import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi'; import { exportBillXml } from 'law-document'; import Bill from '../entities/Bill'; import BillDocument from '../entities/BillDocument'; +import { postBillForValidation, postBillForPublishing } from '../integration/lagasafnApi'; @JsonController() @OpenAPI({ @@ -39,6 +40,27 @@ class BillController { return Bill.save(bill); } + @Post('/bills/:id/xml') + async publish( + @Param('id') id: number, + ) { + const bill = await Bill.findOneOrFail({ where: { id } }) ; + const documents = await BillDocument.find({ + where: { bill }, + select: ['originalXml', 'content', 'identifier', 'title'] + }); + const billXml = await exportBillXml(bill.title, documents); + + console.log(JSON.stringify(billXml)); + // First, validate XML. + await postBillForValidation( billXml ); + + // Second, publish the XML. + await postBillForPublishing( billXml ); + + return billXml; + } + @Put('/bills/:id') @ResponseSchema(Bill) update( @@ -49,4 +71,4 @@ class BillController { } } -export default BillController; \ No newline at end of file +export default BillController; diff --git a/server/src/index.ts b/server/src/index.ts index 6f5d297..a2f18ce 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -20,4 +20,4 @@ void (async () => { console.log('Generating Client SDK...'); exec('npm run build:sdk'); } -})(); \ No newline at end of file +})(); diff --git a/server/src/integration/lagasafnApi/index.ts b/server/src/integration/lagasafnApi/index.ts index b16aa49..9d73ecf 100644 --- a/server/src/integration/lagasafnApi/index.ts +++ b/server/src/integration/lagasafnApi/index.ts @@ -7,4 +7,8 @@ export const postBillForValidation = async (billXml: string) => { } catch (error) { console.log('Request to lagasafn failed', error); } -}; \ No newline at end of file +}; + +export const postBillForPublishing = async( billxml: string) => { + console.log('Bill published'); +}; From b0f3a2e93d8e436aa9eb2bcde0c7ce33ccbeb81f Mon Sep 17 00:00:00 2001 From: GHaralds Date: Mon, 5 May 2025 13:16:29 +0000 Subject: [PATCH 04/53] Add publishDocument --- law-document-editor/src/Editor/Editor.tsx | 9 +++++---- law-document-editor/src/Editor/Toolbar/Toolbar.tsx | 8 +++++--- .../src/Editor/useEditorNaviationBlock.ts | 12 ++++++++++-- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/law-document-editor/src/Editor/Editor.tsx b/law-document-editor/src/Editor/Editor.tsx index 9f11d72..4b76bd3 100644 --- a/law-document-editor/src/Editor/Editor.tsx +++ b/law-document-editor/src/Editor/Editor.tsx @@ -28,16 +28,17 @@ interface Props { xml: string; readOnly?: boolean; saveDocument?: (editor: LawEditor) => void; + publishDocument?: (editor: LawEditor) => void; bill?: Bill; navigationBlocker: NavigationBlocker; t: Translator; } export const Editor: FC = (props) => { - const { slate, originalDocument, xml, readOnly, saveDocument, bill, navigationBlocker, t } = props; + const { slate, originalDocument, xml, readOnly, saveDocument, publishDocument, bill, navigationBlocker, t } = props; const hasHighlight = useEditorConfig(state => state.highlightStructure); const editor = useMemo(() => createEditor(), []); - const { handleChange, handleSave } = useEditorNavigationBlock(editor, navigationBlocker, saveDocument); + const { handleChange, handleSave, handlePublish } = useEditorNavigationBlock(editor, navigationBlocker, saveDocument, publishDocument); useEffect(() => { editor.children = slate; @@ -71,7 +72,7 @@ export const Editor: FC = (props) => { - { readOnly ? null : } + { readOnly ? null : } = (props) => { ); -}; \ No newline at end of file +}; diff --git a/law-document-editor/src/Editor/Toolbar/Toolbar.tsx b/law-document-editor/src/Editor/Toolbar/Toolbar.tsx index fa1e21b..2e7b64f 100644 --- a/law-document-editor/src/Editor/Toolbar/Toolbar.tsx +++ b/law-document-editor/src/Editor/Toolbar/Toolbar.tsx @@ -9,12 +9,13 @@ import { Translator } from '../../translations'; interface Props { saveDocument?: (editor: LawEditor) => void; + publishDocument?: (editor: LawEditor) => void; bill?: Bill; t: Translator; navigationBlocker: NavigationBlocker; } -export const Toolbar: FC = ({ saveDocument, bill, t, navigationBlocker }) => { +export const Toolbar: FC = ({ saveDocument, publishDocument, bill, t, navigationBlocker }) => { const { setAutoNumberIncrements, setHighlightStructure, @@ -34,6 +35,7 @@ export const Toolbar: FC = ({ saveDocument, bill, t, navigationBlocker }) {saveDocument && } {bill && } - + {publishDocument && } + ); -}; \ No newline at end of file +}; diff --git a/law-document-editor/src/Editor/useEditorNaviationBlock.ts b/law-document-editor/src/Editor/useEditorNaviationBlock.ts index 65299de..a1d2931 100644 --- a/law-document-editor/src/Editor/useEditorNaviationBlock.ts +++ b/law-document-editor/src/Editor/useEditorNaviationBlock.ts @@ -1,5 +1,6 @@ import { LawEditor } from 'law-document'; import { useCallback } from 'react'; +import { exportXml } from 'law-document'; export interface NavigationBlocker { blockNavigation: () => void; @@ -8,7 +9,7 @@ export interface NavigationBlocker { goTo: (path: string) => void; } -export const useEditorNavigationBlock = (editor: LawEditor, navigationBlocker: NavigationBlocker, saveDocument?: (editor: LawEditor) => void) => { +export const useEditorNavigationBlock = (editor: LawEditor, navigationBlocker: NavigationBlocker, saveDocument?: (editor: LawEditor) => void, publishDocument?: (editor: LawEditor) => void) => { const { isNavigationBlocked, blockNavigation, unblockNavigation } = navigationBlocker; const handleChange = useCallback(() => { @@ -35,8 +36,15 @@ export const useEditorNavigationBlock = (editor: LawEditor, navigationBlocker: N } }, [editor, isNavigationBlocked, saveDocument, unblockNavigation]); + const handlePublish = useCallback(() => { + if (publishDocument) { + publishDocument(editor); + } + }, [editor, publishDocument]); + return { handleChange, handleSave, + handlePublish, }; -}; \ No newline at end of file +}; From daf4338a7253e5b69bf43f4ee8050911d071f1aa Mon Sep 17 00:00:00 2001 From: GHaralds Date: Mon, 5 May 2025 13:16:50 +0000 Subject: [PATCH 05/53] Add translation for publishing bill --- law-document/src/slate/config/translations.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/law-document/src/slate/config/translations.ts b/law-document/src/slate/config/translations.ts index 377244a..28e4579 100644 --- a/law-document/src/slate/config/translations.ts +++ b/law-document/src/slate/config/translations.ts @@ -92,5 +92,6 @@ export const translations: { [key: string]: { [key: string]: string } } = { 'Open Bill Preview': 'Opna frumvarpsyfirlit', 'This bill is still empty!': 'Þetta frumvarp er enn tómt!', 'Tip: Start editing this bill by adding a document to it.': 'Ábending: Byrjaðu á að breyta þessu frumvarpi með því að bæta við skjali í það.', + 'Publish Bill': 'Birta frumvarp', }, -}; \ No newline at end of file +}; From f1dada6ad9380693f149f24cb0ff42da83db7ce5 Mon Sep 17 00:00:00 2001 From: GHaralds Date: Mon, 5 May 2025 14:02:03 +0000 Subject: [PATCH 06/53] Fix selection of bill --- server/src/controllers/BillController.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/server/src/controllers/BillController.ts b/server/src/controllers/BillController.ts index 0ee6400..59185bc 100644 --- a/server/src/controllers/BillController.ts +++ b/server/src/controllers/BillController.ts @@ -46,12 +46,11 @@ class BillController { ) { const bill = await Bill.findOneOrFail({ where: { id } }) ; const documents = await BillDocument.find({ - where: { bill }, - select: ['originalXml', 'content', 'identifier', 'title'] + where: { id: bill.id }, + select: ['content'] }); const billXml = await exportBillXml(bill.title, documents); - console.log(JSON.stringify(billXml)); // First, validate XML. await postBillForValidation( billXml ); From d6e1b3854d4b6e579909efe46b5a303feef5da7f Mon Sep 17 00:00:00 2001 From: GHaralds Date: Mon, 5 May 2025 14:04:18 +0000 Subject: [PATCH 07/53] Fix indent --- client/src/pages/BillPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/pages/BillPage.tsx b/client/src/pages/BillPage.tsx index 0256b67..d72bb1b 100644 --- a/client/src/pages/BillPage.tsx +++ b/client/src/pages/BillPage.tsx @@ -31,7 +31,7 @@ const BillPage: FC = () => { xml, originalDocument, saveDocument, - publishDocument, + publishDocument, hasBillLoadingError, hasDocumentLoadingError, isBillDocument, From d7502eebb9e4fa17111301075f26b59e92b37e7f Mon Sep 17 00:00:00 2001 From: GHaralds Date: Mon, 5 May 2025 14:04:57 +0000 Subject: [PATCH 08/53] Fix indent --- client/src/pages/BillPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/pages/BillPage.tsx b/client/src/pages/BillPage.tsx index d72bb1b..2fac4b8 100644 --- a/client/src/pages/BillPage.tsx +++ b/client/src/pages/BillPage.tsx @@ -81,7 +81,7 @@ const BillPage: FC = () => { originalDocument={originalDocument!} xml={xml!} saveDocument={saveDocument} - publishDocument={publishDocument} + publishDocument={publishDocument} readOnly={!isBillDocument} bill={bill} t={t} From 04e08ed518488b996068011d5d1e441f04edd76b Mon Sep 17 00:00:00 2001 From: GHaralds Date: Mon, 5 May 2025 14:05:58 +0000 Subject: [PATCH 09/53] Fix indent --- law-document-editor/src/Editor/Toolbar/Toolbar.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/law-document-editor/src/Editor/Toolbar/Toolbar.tsx b/law-document-editor/src/Editor/Toolbar/Toolbar.tsx index 2e7b64f..fd5589d 100644 --- a/law-document-editor/src/Editor/Toolbar/Toolbar.tsx +++ b/law-document-editor/src/Editor/Toolbar/Toolbar.tsx @@ -36,6 +36,6 @@ export const Toolbar: FC = ({ saveDocument, publishDocument, bill, t, nav {saveDocument && } {bill && } {publishDocument && } - + ); }; From 76940900c3f6a4b0d018a66ef2b284ce3eff9c7f Mon Sep 17 00:00:00 2001 From: GHaralds Date: Mon, 5 May 2025 14:06:32 +0000 Subject: [PATCH 10/53] Fix indent --- law-document/src/slate/config/translations.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/law-document/src/slate/config/translations.ts b/law-document/src/slate/config/translations.ts index 28e4579..f339681 100644 --- a/law-document/src/slate/config/translations.ts +++ b/law-document/src/slate/config/translations.ts @@ -92,6 +92,6 @@ export const translations: { [key: string]: { [key: string]: string } } = { 'Open Bill Preview': 'Opna frumvarpsyfirlit', 'This bill is still empty!': 'Þetta frumvarp er enn tómt!', 'Tip: Start editing this bill by adding a document to it.': 'Ábending: Byrjaðu á að breyta þessu frumvarpi með því að bæta við skjali í það.', - 'Publish Bill': 'Birta frumvarp', + 'Publish Bill': 'Birta frumvarp', }, }; From 75ea4229e94fda6350b7d12f8aea7b4df7df25bc Mon Sep 17 00:00:00 2001 From: GHaralds Date: Mon, 5 May 2025 14:19:01 +0000 Subject: [PATCH 11/53] Fix indent --- server/src/controllers/BillController.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/server/src/controllers/BillController.ts b/server/src/controllers/BillController.ts index 59185bc..71ac8fe 100644 --- a/server/src/controllers/BillController.ts +++ b/server/src/controllers/BillController.ts @@ -25,6 +25,7 @@ class BillController { } @Get('/bills/:id/xml') + @ContentType("text/xml") async getXml(@Param('id') id: number) { const bill = await Bill.findOneOrFail({ where: { id } }) ; const documents = await BillDocument.find({ @@ -51,13 +52,13 @@ class BillController { }); const billXml = await exportBillXml(bill.title, documents); - // First, validate XML. - await postBillForValidation( billXml ); + // First, validate XML. + await postBillForValidation( billXml ); // Second, publish the XML. - await postBillForPublishing( billXml ); + await postBillForPublishing( billXml ); - return billXml; + return billXml; } @Put('/bills/:id') From 528897080e970f2475b6d12a0c289e7269ae2868 Mon Sep 17 00:00:00 2001 From: GHaralds Date: Mon, 5 May 2025 14:30:51 +0000 Subject: [PATCH 12/53] Load ContentType --- server/src/controllers/BillController.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/controllers/BillController.ts b/server/src/controllers/BillController.ts index 71ac8fe..79701f7 100644 --- a/server/src/controllers/BillController.ts +++ b/server/src/controllers/BillController.ts @@ -1,5 +1,5 @@ import passport from 'koa-passport'; -import { Body, Get, JsonController, Param, Post, Put, UseBefore } from 'routing-controllers'; +import { Body, Get, JsonController, Param, Post, Put, UseBefore, ContentType } from 'routing-controllers'; import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi'; import { exportBillXml } from 'law-document'; import Bill from '../entities/Bill'; From 2372bc52e792f9d70b987f404e88ebd65e22b74d Mon Sep 17 00:00:00 2001 From: GHaralds Date: Mon, 5 May 2025 14:32:18 +0000 Subject: [PATCH 13/53] Log more detail --- server/src/integration/lagasafnApi/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/integration/lagasafnApi/index.ts b/server/src/integration/lagasafnApi/index.ts index 9d73ecf..cf0f3bc 100644 --- a/server/src/integration/lagasafnApi/index.ts +++ b/server/src/integration/lagasafnApi/index.ts @@ -9,6 +9,6 @@ export const postBillForValidation = async (billXml: string) => { } }; -export const postBillForPublishing = async( billxml: string) => { - console.log('Bill published'); +export const postBillForPublishing = async( billXml: string) => { + console.log('Bill XML published: ' + billXml); }; From bf45c1ea3ea90b32d757e0c554dd5776492a8b2d Mon Sep 17 00:00:00 2001 From: GHaralds Date: Mon, 5 May 2025 15:06:25 +0000 Subject: [PATCH 14/53] Fix indent, await, content-type --- server/src/controllers/BillController.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/server/src/controllers/BillController.ts b/server/src/controllers/BillController.ts index 79701f7..28fa07a 100644 --- a/server/src/controllers/BillController.ts +++ b/server/src/controllers/BillController.ts @@ -25,7 +25,6 @@ class BillController { } @Get('/bills/:id/xml') - @ContentType("text/xml") async getXml(@Param('id') id: number) { const bill = await Bill.findOneOrFail({ where: { id } }) ; const documents = await BillDocument.find({ @@ -42,6 +41,7 @@ class BillController { } @Post('/bills/:id/xml') + @ContentType('text/xml') async publish( @Param('id') id: number, ) { @@ -50,16 +50,16 @@ class BillController { where: { id: bill.id }, select: ['content'] }); - const billXml = await exportBillXml(bill.title, documents); + const billXml = exportBillXml(bill.title, documents); // First, validate XML. await postBillForValidation( billXml ); // Second, publish the XML. - await postBillForPublishing( billXml ); + postBillForPublishing( billXml ); return billXml; - } + } @Put('/bills/:id') @ResponseSchema(Bill) From 2125dcb92a8c6806f8f6d9d4cf1b6eb326594438 Mon Sep 17 00:00:00 2001 From: GHaralds Date: Mon, 5 May 2025 15:06:39 +0000 Subject: [PATCH 15/53] Remove async() for now --- server/src/integration/lagasafnApi/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/integration/lagasafnApi/index.ts b/server/src/integration/lagasafnApi/index.ts index cf0f3bc..bf14ce3 100644 --- a/server/src/integration/lagasafnApi/index.ts +++ b/server/src/integration/lagasafnApi/index.ts @@ -9,6 +9,6 @@ export const postBillForValidation = async (billXml: string) => { } }; -export const postBillForPublishing = async( billXml: string) => { +export const postBillForPublishing = ( billXml: string) => { console.log('Bill XML published: ' + billXml); }; From 4b138cc2d346b4ecd000a35b0e885100a6b8a2de Mon Sep 17 00:00:00 2001 From: GHaralds Date: Mon, 5 May 2025 15:17:56 +0000 Subject: [PATCH 16/53] Fix indent, remove arguments not needed --- client/src/features/Bills/useBillPage.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/client/src/features/Bills/useBillPage.ts b/client/src/features/Bills/useBillPage.ts index cf5a5bd..ab42d07 100644 --- a/client/src/features/Bills/useBillPage.ts +++ b/client/src/features/Bills/useBillPage.ts @@ -146,14 +146,15 @@ const useBillPage = (disableActions = false, billPage = '/bill') => { useEffect(loadDocument, [loadDocument]); - const publishDocument = useCallback((editor: LawEditor) => { + const publishDocument = useCallback() => { if (!bill || !bill.id || !selected) { - log('not publish'); + log('not publish'); return; } + log('publish bill document', { bill, selected }); - BillService.billControllerPublishXml(bill.id) + BillService.billControllerPublishXml(bill.id) .then((billItem) => { log('published bill', { billItem }); setError(false); @@ -163,7 +164,7 @@ const useBillPage = (disableActions = false, billPage = '/bill') => { setError(true); console.error(error); }); - }, [bill, selected, exportXml]); + }, [bill, selected]); return { bill, @@ -177,7 +178,7 @@ const useBillPage = (disableActions = false, billPage = '/bill') => { slate, originalDocument, loadDocument, - publishDocument, + publishDocument, hasBillLoadingError: hasBillError, hasDocumentLoadingError: hasError, importError, From 679fd827c04e4769b1584e3bd347654cfa898777 Mon Sep 17 00:00:00 2001 From: GHaralds Date: Mon, 5 May 2025 15:18:18 +0000 Subject: [PATCH 17/53] Remove arguments not needed --- law-document-editor/src/Editor/Editor.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/law-document-editor/src/Editor/Editor.tsx b/law-document-editor/src/Editor/Editor.tsx index 4b76bd3..9723fd4 100644 --- a/law-document-editor/src/Editor/Editor.tsx +++ b/law-document-editor/src/Editor/Editor.tsx @@ -28,7 +28,7 @@ interface Props { xml: string; readOnly?: boolean; saveDocument?: (editor: LawEditor) => void; - publishDocument?: (editor: LawEditor) => void; + publishDocument?: () => void; bill?: Bill; navigationBlocker: NavigationBlocker; t: Translator; From faa6e3128d688d681204c62b43e5983e669e4235 Mon Sep 17 00:00:00 2001 From: GHaralds Date: Mon, 5 May 2025 15:23:19 +0000 Subject: [PATCH 18/53] Fix lint --- client/src/features/Bills/useBillPage.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/features/Bills/useBillPage.ts b/client/src/features/Bills/useBillPage.ts index ab42d07..0fba133 100644 --- a/client/src/features/Bills/useBillPage.ts +++ b/client/src/features/Bills/useBillPage.ts @@ -146,7 +146,7 @@ const useBillPage = (disableActions = false, billPage = '/bill') => { useEffect(loadDocument, [loadDocument]); - const publishDocument = useCallback() => { + const publishDocument = useCallback(() => { if (!bill || !bill.id || !selected) { log('not publish'); return; From fb3b4160101844cc59122587c13802d46dc5b9ef Mon Sep 17 00:00:00 2001 From: GHaralds Date: Mon, 5 May 2025 16:20:49 +0000 Subject: [PATCH 19/53] Correct URL to validation endpoint --- server/src/integration/lagasafnApi/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/integration/lagasafnApi/index.ts b/server/src/integration/lagasafnApi/index.ts index bf14ce3..9949dbd 100644 --- a/server/src/integration/lagasafnApi/index.ts +++ b/server/src/integration/lagasafnApi/index.ts @@ -3,12 +3,12 @@ import { lagasafnApi } from '../../config/lagasafnApi'; export const postBillForValidation = async (billXml: string) => { try { - await axios.post(lagasafnApi.url, billXml); + await axios.post(lagasafnApi.url + '/api/bill/validate', billXml); } catch (error) { console.log('Request to lagasafn failed', error); } }; export const postBillForPublishing = ( billXml: string) => { - console.log('Bill XML published: ' + billXml); + console.log('Bill XML published!'); }; From 438253052a6e9479d55ae658a73dc141a40b686c Mon Sep 17 00:00:00 2001 From: GHaralds Date: Tue, 6 May 2025 13:40:33 +0000 Subject: [PATCH 20/53] Auto-generated update --- client-sdk/src/services/BillService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client-sdk/src/services/BillService.ts b/client-sdk/src/services/BillService.ts index e2dd55e..f87ac77 100644 --- a/client-sdk/src/services/BillService.ts +++ b/client-sdk/src/services/BillService.ts @@ -90,7 +90,7 @@ export class BillService { }); } /** - * Publish bill XML. + * Publish xml * @param id * @returns any Successful response * @throws ApiError From fb7a4299f31aec31f1cf7af6bf46305c1c4cd496 Mon Sep 17 00:00:00 2001 From: GHaralds Date: Tue, 6 May 2025 13:57:56 +0000 Subject: [PATCH 21/53] Rename publishDocument() to publishBill() --- client/src/features/Bills/useBillPage.ts | 4 ++-- client/src/pages/BillPage.tsx | 4 ++-- law-document-editor/src/Editor/Editor.tsx | 8 ++++---- law-document-editor/src/Editor/Toolbar/Toolbar.tsx | 6 +++--- law-document-editor/src/Editor/useEditorNaviationBlock.ts | 8 ++++---- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/client/src/features/Bills/useBillPage.ts b/client/src/features/Bills/useBillPage.ts index 0fba133..01a4b6e 100644 --- a/client/src/features/Bills/useBillPage.ts +++ b/client/src/features/Bills/useBillPage.ts @@ -146,7 +146,7 @@ const useBillPage = (disableActions = false, billPage = '/bill') => { useEffect(loadDocument, [loadDocument]); - const publishDocument = useCallback(() => { + const publishBill = useCallback(() => { if (!bill || !bill.id || !selected) { log('not publish'); return; @@ -178,7 +178,7 @@ const useBillPage = (disableActions = false, billPage = '/bill') => { slate, originalDocument, loadDocument, - publishDocument, + publishBill, hasBillLoadingError: hasBillError, hasDocumentLoadingError: hasError, importError, diff --git a/client/src/pages/BillPage.tsx b/client/src/pages/BillPage.tsx index 2fac4b8..1e0385d 100644 --- a/client/src/pages/BillPage.tsx +++ b/client/src/pages/BillPage.tsx @@ -31,7 +31,7 @@ const BillPage: FC = () => { xml, originalDocument, saveDocument, - publishDocument, + publishBill, hasBillLoadingError, hasDocumentLoadingError, isBillDocument, @@ -81,7 +81,7 @@ const BillPage: FC = () => { originalDocument={originalDocument!} xml={xml!} saveDocument={saveDocument} - publishDocument={publishDocument} + publishBill={publishBill} readOnly={!isBillDocument} bill={bill} t={t} diff --git a/law-document-editor/src/Editor/Editor.tsx b/law-document-editor/src/Editor/Editor.tsx index 9723fd4..6a74d33 100644 --- a/law-document-editor/src/Editor/Editor.tsx +++ b/law-document-editor/src/Editor/Editor.tsx @@ -28,17 +28,17 @@ interface Props { xml: string; readOnly?: boolean; saveDocument?: (editor: LawEditor) => void; - publishDocument?: () => void; + publishBill?: () => void; bill?: Bill; navigationBlocker: NavigationBlocker; t: Translator; } export const Editor: FC = (props) => { - const { slate, originalDocument, xml, readOnly, saveDocument, publishDocument, bill, navigationBlocker, t } = props; + const { slate, originalDocument, xml, readOnly, saveDocument, publishBill, bill, navigationBlocker, t } = props; const hasHighlight = useEditorConfig(state => state.highlightStructure); const editor = useMemo(() => createEditor(), []); - const { handleChange, handleSave, handlePublish } = useEditorNavigationBlock(editor, navigationBlocker, saveDocument, publishDocument); + const { handleChange, handleSave, handlePublish } = useEditorNavigationBlock(editor, navigationBlocker, saveDocument, publishBill); useEffect(() => { editor.children = slate; @@ -72,7 +72,7 @@ export const Editor: FC = (props) => { - { readOnly ? null : } + { readOnly ? null : } void; - publishDocument?: (editor: LawEditor) => void; + publishBill?: (editor: LawEditor) => void; bill?: Bill; t: Translator; navigationBlocker: NavigationBlocker; } -export const Toolbar: FC = ({ saveDocument, publishDocument, bill, t, navigationBlocker }) => { +export const Toolbar: FC = ({ saveDocument, publishBill, bill, t, navigationBlocker }) => { const { setAutoNumberIncrements, setHighlightStructure, @@ -35,7 +35,7 @@ export const Toolbar: FC = ({ saveDocument, publishDocument, bill, t, nav {saveDocument && } {bill && } - {publishDocument && } + {publishBill && } ); }; diff --git a/law-document-editor/src/Editor/useEditorNaviationBlock.ts b/law-document-editor/src/Editor/useEditorNaviationBlock.ts index a1d2931..6cfc64a 100644 --- a/law-document-editor/src/Editor/useEditorNaviationBlock.ts +++ b/law-document-editor/src/Editor/useEditorNaviationBlock.ts @@ -9,7 +9,7 @@ export interface NavigationBlocker { goTo: (path: string) => void; } -export const useEditorNavigationBlock = (editor: LawEditor, navigationBlocker: NavigationBlocker, saveDocument?: (editor: LawEditor) => void, publishDocument?: (editor: LawEditor) => void) => { +export const useEditorNavigationBlock = (editor: LawEditor, navigationBlocker: NavigationBlocker, saveDocument?: (editor: LawEditor) => void, publishBill?: (editor: LawEditor) => void) => { const { isNavigationBlocked, blockNavigation, unblockNavigation } = navigationBlocker; const handleChange = useCallback(() => { @@ -37,10 +37,10 @@ export const useEditorNavigationBlock = (editor: LawEditor, navigationBlocker: N }, [editor, isNavigationBlocked, saveDocument, unblockNavigation]); const handlePublish = useCallback(() => { - if (publishDocument) { - publishDocument(editor); + if (publishBill) { + publishBill(editor); } - }, [editor, publishDocument]); + }, [editor, publishBill]); return { handleChange, From 464bf60dec2e750c606dcdfd49996e04f39b4548 Mon Sep 17 00:00:00 2001 From: GHaralds Date: Tue, 6 May 2025 13:59:16 +0000 Subject: [PATCH 22/53] Use XML headers by default --- server/src/integration/lagasafnApi/index.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server/src/integration/lagasafnApi/index.ts b/server/src/integration/lagasafnApi/index.ts index 9949dbd..c49ba62 100644 --- a/server/src/integration/lagasafnApi/index.ts +++ b/server/src/integration/lagasafnApi/index.ts @@ -1,6 +1,8 @@ import axios from 'axios'; import { lagasafnApi } from '../../config/lagasafnApi'; +axios.defaults.headers.post['Content-Type'] = 'application/xml'; + export const postBillForValidation = async (billXml: string) => { try { await axios.post(lagasafnApi.url + '/api/bill/validate', billXml); From 3afdbcaa2599e11955a637f76e0f283a98db5006 Mon Sep 17 00:00:00 2001 From: GHaralds Date: Tue, 6 May 2025 13:59:39 +0000 Subject: [PATCH 23/53] Update definition of publishXml() --- server/src/controllers/BillController.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/server/src/controllers/BillController.ts b/server/src/controllers/BillController.ts index 28fa07a..5071dec 100644 --- a/server/src/controllers/BillController.ts +++ b/server/src/controllers/BillController.ts @@ -42,7 +42,10 @@ class BillController { @Post('/bills/:id/xml') @ContentType('text/xml') - async publish( + @OpenAPI({ + description: 'Publish bill XML', + }) + async publishXml( @Param('id') id: number, ) { const bill = await Bill.findOneOrFail({ where: { id } }) ; From 409ba5f129f966d307b17e0385274b249d57931e Mon Sep 17 00:00:00 2001 From: GHaralds Date: Tue, 6 May 2025 16:45:03 +0000 Subject: [PATCH 24/53] Add logic to publish bill --- server/src/integration/lagasafnApi/index.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/server/src/integration/lagasafnApi/index.ts b/server/src/integration/lagasafnApi/index.ts index c49ba62..42987ab 100644 --- a/server/src/integration/lagasafnApi/index.ts +++ b/server/src/integration/lagasafnApi/index.ts @@ -7,10 +7,18 @@ export const postBillForValidation = async (billXml: string) => { try { await axios.post(lagasafnApi.url + '/api/bill/validate', billXml); } catch (error) { + // FIXME: Let user know of error. console.log('Request to lagasafn failed', error); } + console.log('Bill validated!'); }; -export const postBillForPublishing = ( billXml: string) => { +export const postBillForPublishing = async (billXml: string) => { + try { + await axios.post(lagasafnApi.url + '/api/bill/publish', billXml); + } catch (error) { + // FIXME: Let user know of error. + console.log('Request to lagasafn failed', error); + } console.log('Bill XML published!'); }; From 7a471908df0ff89c74a298d0655a2213bfbc041c Mon Sep 17 00:00:00 2001 From: GHaralds Date: Tue, 6 May 2025 16:45:20 +0000 Subject: [PATCH 25/53] Updated comment --- client-sdk/src/services/BillService.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/client-sdk/src/services/BillService.ts b/client-sdk/src/services/BillService.ts index f87ac77..72464fb 100644 --- a/client-sdk/src/services/BillService.ts +++ b/client-sdk/src/services/BillService.ts @@ -91,6 +91,7 @@ export class BillService { } /** * Publish xml + * Publish bill XML * @param id * @returns any Successful response * @throws ApiError From 47dd2cb2d25efc32712603c98cf0684f0fb00926 Mon Sep 17 00:00:00 2001 From: GHaralds Date: Thu, 8 May 2025 15:49:15 +0000 Subject: [PATCH 26/53] Catch error, parse and re-throw --- server/src/integration/lagasafnApi/index.ts | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/server/src/integration/lagasafnApi/index.ts b/server/src/integration/lagasafnApi/index.ts index 42987ab..e788d42 100644 --- a/server/src/integration/lagasafnApi/index.ts +++ b/server/src/integration/lagasafnApi/index.ts @@ -6,19 +6,15 @@ axios.defaults.headers.post['Content-Type'] = 'application/xml'; export const postBillForValidation = async (billXml: string) => { try { await axios.post(lagasafnApi.url + '/api/bill/validate', billXml); - } catch (error) { - // FIXME: Let user know of error. - console.log('Request to lagasafn failed', error); + } catch (error: any) { + throw new Error( ( error?.response.data?.message ?? 'Unknown error' ) ) } - console.log('Bill validated!'); }; export const postBillForPublishing = async (billXml: string) => { try { await axios.post(lagasafnApi.url + '/api/bill/publish', billXml); - } catch (error) { - // FIXME: Let user know of error. - console.log('Request to lagasafn failed', error); + } catch (error: any) { + throw new Error( ( error?.response.data?.message ?? 'Unknown error' ) ) } - console.log('Bill XML published!'); }; From 67b622aa28ea712ff8ad14f9cfd05e6752a0b53c Mon Sep 17 00:00:00 2001 From: GHaralds Date: Thu, 8 May 2025 16:11:15 +0000 Subject: [PATCH 27/53] Catch any errors, re-throw using HttpError() --- server/src/controllers/BillController.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/server/src/controllers/BillController.ts b/server/src/controllers/BillController.ts index 5071dec..448e7e2 100644 --- a/server/src/controllers/BillController.ts +++ b/server/src/controllers/BillController.ts @@ -1,5 +1,5 @@ import passport from 'koa-passport'; -import { Body, Get, JsonController, Param, Post, Put, UseBefore, ContentType } from 'routing-controllers'; +import { Body, Get, JsonController, Param, Post, Put, UseBefore, ContentType, HttpError } from 'routing-controllers'; import { OpenAPI, ResponseSchema } from 'routing-controllers-openapi'; import { exportBillXml } from 'law-document'; import Bill from '../entities/Bill'; @@ -55,11 +55,15 @@ class BillController { }); const billXml = exportBillXml(bill.title, documents); - // First, validate XML. - await postBillForValidation( billXml ); + try { + // First, validate XML. + await postBillForValidation( billXml ); - // Second, publish the XML. - postBillForPublishing( billXml ); + // Second, publish the XML. + await postBillForPublishing( billXml ); + } catch( error: any ) { + throw new HttpError( 400, error?.message ?? 'Unknown error' ); + } return billXml; } From 3b4c76f015f54c42b9e13cf24cb0808c78cae6e6 Mon Sep 17 00:00:00 2001 From: GHaralds Date: Thu, 8 May 2025 16:26:57 +0000 Subject: [PATCH 28/53] Fix lint --- server/src/controllers/BillController.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/controllers/BillController.ts b/server/src/controllers/BillController.ts index 448e7e2..d6ee7d5 100644 --- a/server/src/controllers/BillController.ts +++ b/server/src/controllers/BillController.ts @@ -62,7 +62,7 @@ class BillController { // Second, publish the XML. await postBillForPublishing( billXml ); } catch( error: any ) { - throw new HttpError( 400, error?.message ?? 'Unknown error' ); + throw new HttpError( 400, error?.message ); } return billXml; From 523030c2fd07b8f563d34272b67c379ab055ee18 Mon Sep 17 00:00:00 2001 From: GHaralds Date: Fri, 9 May 2025 10:51:56 +0000 Subject: [PATCH 29/53] Hide publish button when document is not saved --- law-document-editor/src/Editor/Toolbar/Toolbar.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/law-document-editor/src/Editor/Toolbar/Toolbar.tsx b/law-document-editor/src/Editor/Toolbar/Toolbar.tsx index 456f2fc..ee17b3e 100644 --- a/law-document-editor/src/Editor/Toolbar/Toolbar.tsx +++ b/law-document-editor/src/Editor/Toolbar/Toolbar.tsx @@ -35,7 +35,7 @@ export const Toolbar: FC = ({ saveDocument, publishBill, bill, t, navigat {saveDocument && } {bill && } - {publishBill && } + {publishBill && } ); }; From ac30a18fef0215209841f2812819553f30a9f288 Mon Sep 17 00:00:00 2001 From: GHaralds Date: Fri, 9 May 2025 11:03:04 +0000 Subject: [PATCH 30/53] Add notification about bill being published --- client/src/features/Bills/useBillPage.ts | 1 + law-document/src/slate/config/translations.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/client/src/features/Bills/useBillPage.ts b/client/src/features/Bills/useBillPage.ts index 01a4b6e..8032272 100644 --- a/client/src/features/Bills/useBillPage.ts +++ b/client/src/features/Bills/useBillPage.ts @@ -156,6 +156,7 @@ const useBillPage = (disableActions = false, billPage = '/bill') => { BillService.billControllerPublishXml(bill.id) .then((billItem) => { + notification.success({ message: t('Bill published'), description: `${selected} ${bill.title}` }); log('published bill', { billItem }); setError(false); }) diff --git a/law-document/src/slate/config/translations.ts b/law-document/src/slate/config/translations.ts index f339681..06347e6 100644 --- a/law-document/src/slate/config/translations.ts +++ b/law-document/src/slate/config/translations.ts @@ -93,5 +93,6 @@ export const translations: { [key: string]: { [key: string]: string } } = { 'This bill is still empty!': 'Þetta frumvarp er enn tómt!', 'Tip: Start editing this bill by adding a document to it.': 'Ábending: Byrjaðu á að breyta þessu frumvarpi með því að bæta við skjali í það.', 'Publish Bill': 'Birta frumvarp', + 'Bill published': 'Frumvarp hefur verið birt', }, }; From 37414ca9555867604416870431bec264b954bb68 Mon Sep 17 00:00:00 2001 From: GHaralds Date: Fri, 9 May 2025 11:04:44 +0000 Subject: [PATCH 31/53] Fix indent --- law-document-editor/src/Editor/useEditorNaviationBlock.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/law-document-editor/src/Editor/useEditorNaviationBlock.ts b/law-document-editor/src/Editor/useEditorNaviationBlock.ts index 6cfc64a..4e3f1a7 100644 --- a/law-document-editor/src/Editor/useEditorNaviationBlock.ts +++ b/law-document-editor/src/Editor/useEditorNaviationBlock.ts @@ -37,9 +37,9 @@ export const useEditorNavigationBlock = (editor: LawEditor, navigationBlocker: N }, [editor, isNavigationBlocked, saveDocument, unblockNavigation]); const handlePublish = useCallback(() => { - if (publishBill) { - publishBill(editor); - } + if (publishBill) { + publishBill(editor); + } }, [editor, publishBill]); return { From 45c9df85146ec7c04bd31fa6006f26dbb1fe6c59 Mon Sep 17 00:00:00 2001 From: GHaralds Date: Fri, 9 May 2025 11:08:14 +0000 Subject: [PATCH 32/53] Fix indent --- law-document-editor/src/Editor/useEditorNaviationBlock.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/law-document-editor/src/Editor/useEditorNaviationBlock.ts b/law-document-editor/src/Editor/useEditorNaviationBlock.ts index 4e3f1a7..9cdbb26 100644 --- a/law-document-editor/src/Editor/useEditorNaviationBlock.ts +++ b/law-document-editor/src/Editor/useEditorNaviationBlock.ts @@ -45,6 +45,6 @@ export const useEditorNavigationBlock = (editor: LawEditor, navigationBlocker: N return { handleChange, handleSave, - handlePublish, + handlePublish, }; }; From 5b23e9a86fc03597bcc525a95fca8edc3c428b09 Mon Sep 17 00:00:00 2001 From: GHaralds Date: Fri, 9 May 2025 11:10:02 +0000 Subject: [PATCH 33/53] Fix lint --- server/src/integration/lagasafnApi/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/integration/lagasafnApi/index.ts b/server/src/integration/lagasafnApi/index.ts index e788d42..3638fd9 100644 --- a/server/src/integration/lagasafnApi/index.ts +++ b/server/src/integration/lagasafnApi/index.ts @@ -7,7 +7,7 @@ export const postBillForValidation = async (billXml: string) => { try { await axios.post(lagasafnApi.url + '/api/bill/validate', billXml); } catch (error: any) { - throw new Error( ( error?.response.data?.message ?? 'Unknown error' ) ) + throw new Error( ( error?.response.data?.message ?? 'Unknown error' ) ); } }; @@ -15,6 +15,6 @@ export const postBillForPublishing = async (billXml: string) => { try { await axios.post(lagasafnApi.url + '/api/bill/publish', billXml); } catch (error: any) { - throw new Error( ( error?.response.data?.message ?? 'Unknown error' ) ) + throw new Error( ( error?.response.data?.message ?? 'Unknown error' ) ); } }; From 12b370bdd7bbea2f34c49310a05ae39950673fc7 Mon Sep 17 00:00:00 2001 From: GHaralds Date: Fri, 9 May 2025 11:16:41 +0000 Subject: [PATCH 34/53] Force type --- server/src/controllers/BillController.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/controllers/BillController.ts b/server/src/controllers/BillController.ts index d6ee7d5..6a08054 100644 --- a/server/src/controllers/BillController.ts +++ b/server/src/controllers/BillController.ts @@ -62,7 +62,7 @@ class BillController { // Second, publish the XML. await postBillForPublishing( billXml ); } catch( error: any ) { - throw new HttpError( 400, error?.message ); + throw new HttpError( 400, error?.message ); } return billXml; From b77125f74bcaad5869ca4389bcbdae8fa9e70a3b Mon Sep 17 00:00:00 2001 From: GHaralds Date: Fri, 9 May 2025 11:19:17 +0000 Subject: [PATCH 35/53] Stop including exportXml, not needed --- client/src/features/Bills/useBillPage.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/features/Bills/useBillPage.ts b/client/src/features/Bills/useBillPage.ts index 8032272..e576585 100644 --- a/client/src/features/Bills/useBillPage.ts +++ b/client/src/features/Bills/useBillPage.ts @@ -1,6 +1,6 @@ import { notification } from 'antd'; import { BillDocumentService, DocumentService, BillService } from 'client-sdk'; -import { LawEditor, getTitle, exportXml } from 'law-document'; +import { LawEditor, getTitle } from 'law-document'; import { useCallback, useEffect, useState } from 'react'; import { useNavigate, useParams } from 'react-router'; import modal from 'antd/es/modal'; From 31cd857ebfaff0c9da9e7543052303938d2e2134 Mon Sep 17 00:00:00 2001 From: GHaralds Date: Fri, 9 May 2025 11:21:28 +0000 Subject: [PATCH 36/53] Add t() to dependency array --- client/src/features/Bills/useBillPage.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/features/Bills/useBillPage.ts b/client/src/features/Bills/useBillPage.ts index e576585..2173e25 100644 --- a/client/src/features/Bills/useBillPage.ts +++ b/client/src/features/Bills/useBillPage.ts @@ -165,7 +165,7 @@ const useBillPage = (disableActions = false, billPage = '/bill') => { setError(true); console.error(error); }); - }, [bill, selected]); + }, [bill, selected, t]); return { bill, From b839fc98a5414f7843d0ed5827e70f5cea22eb65 Mon Sep 17 00:00:00 2001 From: GHaralds Date: Fri, 9 May 2025 11:23:59 +0000 Subject: [PATCH 37/53] Fix indent --- law-document-editor/src/Editor/Toolbar/Toolbar.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/law-document-editor/src/Editor/Toolbar/Toolbar.tsx b/law-document-editor/src/Editor/Toolbar/Toolbar.tsx index ee17b3e..3debea2 100644 --- a/law-document-editor/src/Editor/Toolbar/Toolbar.tsx +++ b/law-document-editor/src/Editor/Toolbar/Toolbar.tsx @@ -35,7 +35,7 @@ export const Toolbar: FC = ({ saveDocument, publishBill, bill, t, navigat {saveDocument && } {bill && } - {publishBill && } + {publishBill && } ); }; From e50d2728948b9a7e614905cf8a10c3802646cfa5 Mon Sep 17 00:00:00 2001 From: GHaralds Date: Fri, 9 May 2025 11:25:29 +0000 Subject: [PATCH 38/53] Remove exportXml from imports, not used --- law-document-editor/src/Editor/useEditorNaviationBlock.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/law-document-editor/src/Editor/useEditorNaviationBlock.ts b/law-document-editor/src/Editor/useEditorNaviationBlock.ts index 9cdbb26..5c5fbb3 100644 --- a/law-document-editor/src/Editor/useEditorNaviationBlock.ts +++ b/law-document-editor/src/Editor/useEditorNaviationBlock.ts @@ -1,6 +1,5 @@ import { LawEditor } from 'law-document'; import { useCallback } from 'react'; -import { exportXml } from 'law-document'; export interface NavigationBlocker { blockNavigation: () => void; From 3f79bfc262ecd01c0b65e0f7d06162e7d5c1685f Mon Sep 17 00:00:00 2001 From: GHaralds Date: Mon, 12 May 2025 10:41:44 +0000 Subject: [PATCH 39/53] Remove references to handlePublish & implementation --- law-document-editor/src/Editor/Editor.tsx | 4 ++-- .../src/Editor/useEditorNaviationBlock.ts | 9 +-------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/law-document-editor/src/Editor/Editor.tsx b/law-document-editor/src/Editor/Editor.tsx index 6a74d33..7260595 100644 --- a/law-document-editor/src/Editor/Editor.tsx +++ b/law-document-editor/src/Editor/Editor.tsx @@ -38,7 +38,7 @@ export const Editor: FC = (props) => { const { slate, originalDocument, xml, readOnly, saveDocument, publishBill, bill, navigationBlocker, t } = props; const hasHighlight = useEditorConfig(state => state.highlightStructure); const editor = useMemo(() => createEditor(), []); - const { handleChange, handleSave, handlePublish } = useEditorNavigationBlock(editor, navigationBlocker, saveDocument, publishBill); + const { handleChange, handleSave } = useEditorNavigationBlock(editor, navigationBlocker, saveDocument); useEffect(() => { editor.children = slate; @@ -72,7 +72,7 @@ export const Editor: FC = (props) => { - { readOnly ? null : } + { readOnly ? null : } void; } -export const useEditorNavigationBlock = (editor: LawEditor, navigationBlocker: NavigationBlocker, saveDocument?: (editor: LawEditor) => void, publishBill?: (editor: LawEditor) => void) => { +export const useEditorNavigationBlock = (editor: LawEditor, navigationBlocker: NavigationBlocker, saveDocument?: (editor: LawEditor) => void) => { const { isNavigationBlocked, blockNavigation, unblockNavigation } = navigationBlocker; const handleChange = useCallback(() => { @@ -35,15 +35,8 @@ export const useEditorNavigationBlock = (editor: LawEditor, navigationBlocker: N } }, [editor, isNavigationBlocked, saveDocument, unblockNavigation]); - const handlePublish = useCallback(() => { - if (publishBill) { - publishBill(editor); - } - }, [editor, publishBill]); - return { handleChange, handleSave, - handlePublish, }; }; From 8729793ccd3fa91034992fbdd3e033139cd2f972 Mon Sep 17 00:00:00 2001 From: "Gudmundur D. Haraldsson" <8835135+gudmdharalds@users.noreply.github.com> Date: Mon, 12 May 2025 11:50:16 +0000 Subject: [PATCH 40/53] Update turbo.json --- turbo.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/turbo.json b/turbo.json index 0a593a7..b81b81c 100644 --- a/turbo.json +++ b/turbo.json @@ -17,7 +17,8 @@ "cache": false }, "test": { - "outputs": [""] + "outputs": [""], + "env": ["DATABASE_PORT", "DATABASE_USER", "DATABASE_NAME", "DATABASE_PASSWORD"] }, "typecheck": { "outputs": [] @@ -44,4 +45,4 @@ "persistent": true } } -} \ No newline at end of file +} From edc1410103724037b1d81d427fb7b76636c55bf0 Mon Sep 17 00:00:00 2001 From: "Gudmundur D. Haraldsson" <8835135+gudmdharalds@users.noreply.github.com> Date: Mon, 12 May 2025 11:53:26 +0000 Subject: [PATCH 41/53] Update turbo.json --- turbo.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/turbo.json b/turbo.json index b81b81c..1bfa8e1 100644 --- a/turbo.json +++ b/turbo.json @@ -17,8 +17,7 @@ "cache": false }, "test": { - "outputs": [""], - "env": ["DATABASE_PORT", "DATABASE_USER", "DATABASE_NAME", "DATABASE_PASSWORD"] + "outputs": [""] }, "typecheck": { "outputs": [] From 54030c9fabe78f8be45910433d2e03d062dd421e Mon Sep 17 00:00:00 2001 From: GHaralds Date: Tue, 13 May 2025 11:08:39 +0000 Subject: [PATCH 42/53] Publish all documents that compose bill --- server/src/controllers/BillController.ts | 41 +++++++++++++++--------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/server/src/controllers/BillController.ts b/server/src/controllers/BillController.ts index 6a08054..ace19f0 100644 --- a/server/src/controllers/BillController.ts +++ b/server/src/controllers/BillController.ts @@ -48,24 +48,35 @@ class BillController { async publishXml( @Param('id') id: number, ) { - const bill = await Bill.findOneOrFail({ where: { id } }) ; - const documents = await BillDocument.find({ - where: { id: bill.id }, - select: ['content'] - }); - const billXml = exportBillXml(bill.title, documents); + const bills = await Bill.find({ where: { id } }); - try { - // First, validate XML. - await postBillForValidation( billXml ); - - // Second, publish the XML. - await postBillForPublishing( billXml ); - } catch( error: any ) { - throw new HttpError( 400, error?.message ); + if ( bills.length < 1 || ! bills[0]?.documents ) { + throw new HttpError( 404, 'Unable to find bill documents'); } - return billXml; + const billsXml: string[] = []; + + bills[0].documents.forEach( async bill => { + const documents = await BillDocument.find({ + where: { id: bill.id }, + select: ['content'] + }); + + const billXml = exportBillXml(bill.title, documents); + billsXml.push( billXml ); + + try { + // First, validate XML. + await postBillForValidation( billXml ); + + // Second, publish the XML. + await postBillForPublishing( billXml ); + } catch( error: any ) { + throw new HttpError( 400, error?.message ); + } + } ); + + return billsXml; } @Put('/bills/:id') From d8e46bc2e65a8a362c3599980c5f5f64f7163fe1 Mon Sep 17 00:00:00 2001 From: GHaralds Date: Thu, 15 May 2025 13:30:22 +0000 Subject: [PATCH 43/53] Update API endpoint paths --- server/src/integration/lagasafnApi/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/integration/lagasafnApi/index.ts b/server/src/integration/lagasafnApi/index.ts index 3638fd9..11c9a08 100644 --- a/server/src/integration/lagasafnApi/index.ts +++ b/server/src/integration/lagasafnApi/index.ts @@ -5,7 +5,7 @@ axios.defaults.headers.post['Content-Type'] = 'application/xml'; export const postBillForValidation = async (billXml: string) => { try { - await axios.post(lagasafnApi.url + '/api/bill/validate', billXml); + await axios.post(lagasafnApi.url + '/api/bill/document/validate', billXml); } catch (error: any) { throw new Error( ( error?.response.data?.message ?? 'Unknown error' ) ); } @@ -13,7 +13,7 @@ export const postBillForValidation = async (billXml: string) => { export const postBillForPublishing = async (billXml: string) => { try { - await axios.post(lagasafnApi.url + '/api/bill/publish', billXml); + await axios.post(lagasafnApi.url + '/api/bill/document/publish', billXml); } catch (error: any) { throw new Error( ( error?.response.data?.message ?? 'Unknown error' ) ); } From 5b335a94420b4bb66a33f021590a36f684940187 Mon Sep 17 00:00:00 2001 From: "Gudmundur D. Haraldsson" <8835135+gudmdharalds@users.noreply.github.com> Date: Wed, 21 May 2025 15:11:43 +0000 Subject: [PATCH 44/53] Update useBillPage.ts --- client/src/features/Bills/useBillPage.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/client/src/features/Bills/useBillPage.ts b/client/src/features/Bills/useBillPage.ts index 2173e25..decdec9 100644 --- a/client/src/features/Bills/useBillPage.ts +++ b/client/src/features/Bills/useBillPage.ts @@ -148,7 +148,6 @@ const useBillPage = (disableActions = false, billPage = '/bill') => { const publishBill = useCallback(() => { if (!bill || !bill.id || !selected) { - log('not publish'); return; } From bb3ff0d5199cc0846a222ecde86b89788d0af86c Mon Sep 17 00:00:00 2001 From: GHaralds Date: Wed, 21 May 2025 15:57:23 +0000 Subject: [PATCH 45/53] Update strings & translations --- client/src/features/Bills/CreateBillButton.tsx | 4 ++-- law-document-editor/src/Editor/Toolbar/AddEntryModal.tsx | 4 ++-- law-document/src/slate/config/translations.ts | 3 +-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/client/src/features/Bills/CreateBillButton.tsx b/client/src/features/Bills/CreateBillButton.tsx index 4656916..fda794f 100644 --- a/client/src/features/Bills/CreateBillButton.tsx +++ b/client/src/features/Bills/CreateBillButton.tsx @@ -25,7 +25,7 @@ const CreateBillButton: FC = ({ onSubmit }) => { > {t('Create New Bill')} - +
@@ -34,4 +34,4 @@ const CreateBillButton: FC = ({ onSubmit }) => { ); }; -export default CreateBillButton; \ No newline at end of file +export default CreateBillButton; diff --git a/law-document-editor/src/Editor/Toolbar/AddEntryModal.tsx b/law-document-editor/src/Editor/Toolbar/AddEntryModal.tsx index ae0585b..7e3cfaf 100644 --- a/law-document-editor/src/Editor/Toolbar/AddEntryModal.tsx +++ b/law-document-editor/src/Editor/Toolbar/AddEntryModal.tsx @@ -11,10 +11,10 @@ interface Props { export const AddEntryModal: FC = ({ isOpen, onClose, t }) => { return ( - +
); -}; \ No newline at end of file +}; diff --git a/law-document/src/slate/config/translations.ts b/law-document/src/slate/config/translations.ts index 06347e6..6451158 100644 --- a/law-document/src/slate/config/translations.ts +++ b/law-document/src/slate/config/translations.ts @@ -41,7 +41,6 @@ export const translations: { [key: string]: { [key: string]: string } } = { 'Increase following chapters nr attribute and title?': 'Uppfæra númer og nöfn færslna sem koma á eftir', 'Cancel': 'Hætta við', 'Add': 'Bæta við', - 'Add new Entry': 'Bæta við nýrri færslu', 'Create a title for this paragraph. Needs to be first text of paragraph': 'Búðu til titil fyrir þessa málsgrein. Þarf að vera fyrsti texti málsgreinar', 'Create a name for this paragraph. Needs to be first text of paragraph if there is no title or be right after the title': 'Búðu til nafn fyrir þessa málsgrein. Þarf að vera fyrsti texti málsgreinar ef það er enginn titill eða vera rétt á eftir titlinum', 'Format the selected text as its own sentence.': 'Gera valinn texta að málslið.', @@ -77,7 +76,7 @@ export const translations: { [key: string]: { [key: string]: string } } = { 'Documents in the Bill': 'Skjöl í frumvarpi', 'Add document to bill and start editing': 'Bæta við skjali í frumvarp og byrja að breyta', 'Remove document from bill and delete changes': 'Fjarlægja skjal úr frumvarpi og eyða breytingum', - 'Create New Bill': 'Búa til nýtt frumvarp', + 'Create New Bill': 'Stofna nýtt frumvarp', 'Delete Bill Document': 'Eyða skjali', 'Are you sure you want to permanently and irreversibly delete this document?': 'Ertu viss um að þú viljir eyða þessu skjali varanlega og óafturkræft?', 'Yes, delete!': 'Já, eyða!', From 2fa9762cc9ba7c8a7585ba0efde01a7434b0104c Mon Sep 17 00:00:00 2001 From: Ch1ll0ut1 <6835266+ch1ll0ut1@users.noreply.github.com> Date: Tue, 27 May 2025 16:26:28 +0700 Subject: [PATCH 46/53] Fix new entry modal having correct title --- law-document-editor/src/Editor/Toolbar/AddEntryModal.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/law-document-editor/src/Editor/Toolbar/AddEntryModal.tsx b/law-document-editor/src/Editor/Toolbar/AddEntryModal.tsx index 7e3cfaf..fa934c0 100644 --- a/law-document-editor/src/Editor/Toolbar/AddEntryModal.tsx +++ b/law-document-editor/src/Editor/Toolbar/AddEntryModal.tsx @@ -11,7 +11,7 @@ interface Props { export const AddEntryModal: FC = ({ isOpen, onClose, t }) => { return ( - +
From 75404ce3a460d3e03f1b1604e51ae8e1d3ba63b3 Mon Sep 17 00:00:00 2001 From: Ch1ll0ut1 <6835266+ch1ll0ut1@users.noreply.github.com> Date: Tue, 27 May 2025 16:27:57 +0700 Subject: [PATCH 47/53] Remove unnecessary boolean conversion --- law-document-editor/src/Editor/Toolbar/Toolbar.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/law-document-editor/src/Editor/Toolbar/Toolbar.tsx b/law-document-editor/src/Editor/Toolbar/Toolbar.tsx index 3debea2..a3312d9 100644 --- a/law-document-editor/src/Editor/Toolbar/Toolbar.tsx +++ b/law-document-editor/src/Editor/Toolbar/Toolbar.tsx @@ -35,7 +35,7 @@ export const Toolbar: FC = ({ saveDocument, publishBill, bill, t, navigat {saveDocument && } {bill && } - {publishBill && } + {publishBill && } ); }; From fec31fb6a774c1c1b90d4522cdad3d7d741eba94 Mon Sep 17 00:00:00 2001 From: Ch1ll0ut1 <6835266+ch1ll0ut1@users.noreply.github.com> Date: Tue, 27 May 2025 16:29:02 +0700 Subject: [PATCH 48/53] Revert removal of translation for "Add Entry" --- law-document/src/slate/config/translations.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/law-document/src/slate/config/translations.ts b/law-document/src/slate/config/translations.ts index 6451158..6b9f4f3 100644 --- a/law-document/src/slate/config/translations.ts +++ b/law-document/src/slate/config/translations.ts @@ -41,6 +41,7 @@ export const translations: { [key: string]: { [key: string]: string } } = { 'Increase following chapters nr attribute and title?': 'Uppfæra númer og nöfn færslna sem koma á eftir', 'Cancel': 'Hætta við', 'Add': 'Bæta við', + 'Add new Entry': 'Bæta við nýrri færslu', 'Create a title for this paragraph. Needs to be first text of paragraph': 'Búðu til titil fyrir þessa málsgrein. Þarf að vera fyrsti texti málsgreinar', 'Create a name for this paragraph. Needs to be first text of paragraph if there is no title or be right after the title': 'Búðu til nafn fyrir þessa málsgrein. Þarf að vera fyrsti texti málsgreinar ef það er enginn titill eða vera rétt á eftir titlinum', 'Format the selected text as its own sentence.': 'Gera valinn texta að málslið.', From 5e9c1cd48ffbcf33ccc0150ba6a2f9dae819c7ed Mon Sep 17 00:00:00 2001 From: Ch1ll0ut1 <6835266+ch1ll0ut1@users.noreply.github.com> Date: Tue, 27 May 2025 16:31:59 +0700 Subject: [PATCH 49/53] Change setting axios headers from globally to locally --- server/src/integration/lagasafnApi/index.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/server/src/integration/lagasafnApi/index.ts b/server/src/integration/lagasafnApi/index.ts index 11c9a08..243d3c9 100644 --- a/server/src/integration/lagasafnApi/index.ts +++ b/server/src/integration/lagasafnApi/index.ts @@ -1,11 +1,19 @@ -import axios from 'axios'; +import axios, { AxiosRequestConfig } from 'axios'; import { lagasafnApi } from '../../config/lagasafnApi'; -axios.defaults.headers.post['Content-Type'] = 'application/xml'; +const config: AxiosRequestConfig = { + headers: { + 'Content-Type': 'application/xml', + }, +}; export const postBillForValidation = async (billXml: string) => { try { - await axios.post(lagasafnApi.url + '/api/bill/document/validate', billXml); + await axios.post( + lagasafnApi.url + '/api/bill/document/validate', + billXml, + config + ); } catch (error: any) { throw new Error( ( error?.response.data?.message ?? 'Unknown error' ) ); } @@ -13,7 +21,11 @@ export const postBillForValidation = async (billXml: string) => { export const postBillForPublishing = async (billXml: string) => { try { - await axios.post(lagasafnApi.url + '/api/bill/document/publish', billXml); + await axios.post( + lagasafnApi.url + '/api/bill/document/publish', + billXml, + config + ); } catch (error: any) { throw new Error( ( error?.response.data?.message ?? 'Unknown error' ) ); } From f7c7cc64cdc521582061f2a29bf500e5fb9a9d1b Mon Sep 17 00:00:00 2001 From: Ch1ll0ut1 <6835266+ch1ll0ut1@users.noreply.github.com> Date: Tue, 27 May 2025 16:34:04 +0700 Subject: [PATCH 50/53] Fix some minor syntax in lagasafnApi file --- server/src/integration/lagasafnApi/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/integration/lagasafnApi/index.ts b/server/src/integration/lagasafnApi/index.ts index 243d3c9..595e76e 100644 --- a/server/src/integration/lagasafnApi/index.ts +++ b/server/src/integration/lagasafnApi/index.ts @@ -15,7 +15,7 @@ export const postBillForValidation = async (billXml: string) => { config ); } catch (error: any) { - throw new Error( ( error?.response.data?.message ?? 'Unknown error' ) ); + throw new Error(error?.response.data?.message ?? 'Unknown error'); } }; @@ -27,6 +27,6 @@ export const postBillForPublishing = async (billXml: string) => { config ); } catch (error: any) { - throw new Error( ( error?.response.data?.message ?? 'Unknown error' ) ); + throw new Error(error?.response.data?.message ?? 'Unknown error'); } }; From f9fad7c36425aadabe3551ef755ac175f864059b Mon Sep 17 00:00:00 2001 From: Ch1ll0ut1 <6835266+ch1ll0ut1@users.noreply.github.com> Date: Tue, 27 May 2025 16:56:43 +0700 Subject: [PATCH 51/53] . --- server/src/integration/lagasafnApi/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/integration/lagasafnApi/index.ts b/server/src/integration/lagasafnApi/index.ts index 595e76e..63c206d 100644 --- a/server/src/integration/lagasafnApi/index.ts +++ b/server/src/integration/lagasafnApi/index.ts @@ -15,7 +15,7 @@ export const postBillForValidation = async (billXml: string) => { config ); } catch (error: any) { - throw new Error(error?.response.data?.message ?? 'Unknown error'); + throw new Error(error?.response.data?.message || 'Unknown error'); } }; @@ -27,6 +27,6 @@ export const postBillForPublishing = async (billXml: string) => { config ); } catch (error: any) { - throw new Error(error?.response.data?.message ?? 'Unknown error'); + throw new Error(error?.response.data?.message || 'Unknown error'); } }; From 896c9ba8e7af8a2e88b4960bb663bebcf03ff3a5 Mon Sep 17 00:00:00 2001 From: Ch1ll0ut1 <6835266+ch1ll0ut1@users.noreply.github.com> Date: Tue, 27 May 2025 17:13:59 +0700 Subject: [PATCH 52/53] Fix tests of DocumentService --- server/src/services/DocumentService.test.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/server/src/services/DocumentService.test.ts b/server/src/services/DocumentService.test.ts index f235e96..2c43855 100644 --- a/server/src/services/DocumentService.test.ts +++ b/server/src/services/DocumentService.test.ts @@ -13,10 +13,8 @@ describe('DocumentService', () => { const identifier = '2023.65'; xmlContent = ''; - const [doc1, doc2] = await Promise.all([ - findOrImportDocument(identifier), - findOrImportDocument(identifier), - ]); + const doc1 = await findOrImportDocument(identifier); + const doc2 = await findOrImportDocument(identifier); expect(doc1).toEqual(doc2); }); From 1238a455ece3a31136bddf7e77b82d2d8a21da69 Mon Sep 17 00:00:00 2001 From: Ch1ll0ut1 <6835266+ch1ll0ut1@users.noreply.github.com> Date: Tue, 27 May 2025 17:18:03 +0700 Subject: [PATCH 53/53] Remove error in case external api is unavailable --- server/src/integration/lagasafnApi/index.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/server/src/integration/lagasafnApi/index.ts b/server/src/integration/lagasafnApi/index.ts index 63c206d..27feca1 100644 --- a/server/src/integration/lagasafnApi/index.ts +++ b/server/src/integration/lagasafnApi/index.ts @@ -15,7 +15,8 @@ export const postBillForValidation = async (billXml: string) => { config ); } catch (error: any) { - throw new Error(error?.response.data?.message || 'Unknown error'); + // Do not interrupt processing in case of external service failure + console.log('Request to lagasafn failed', error); } }; @@ -27,6 +28,7 @@ export const postBillForPublishing = async (billXml: string) => { config ); } catch (error: any) { - throw new Error(error?.response.data?.message || 'Unknown error'); + // Do not interrupt processing in case of external service failure + console.log('Request to lagasafn failed', error); } };