From 0c213c8aedc077cab9bd5f6a6712dc6fd9a5d1cc Mon Sep 17 00:00:00 2001 From: Maicol Battistini Date: Mon, 26 Jun 2023 10:15:46 +0200 Subject: [PATCH] =?UTF-8?q?refactor:=20=E2=99=BB=EF=B8=8F=20Refactor=20gen?= =?UTF-8?q?erale?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/inspectionProfiles/Project_Default.xml | 6 ------ resources/ts/Components/Pages/RecordPage.tsx | 13 +++++-------- resources/ts/Components/Pages/RecordsPage.tsx | 4 +++- 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml index a06e954cc..d0375150e 100644 --- a/.idea/inspectionProfiles/Project_Default.xml +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -210,12 +210,6 @@ - - - - - - diff --git a/resources/ts/Components/Pages/RecordPage.tsx b/resources/ts/Components/Pages/RecordPage.tsx index 8b8874f12..7641b035d 100644 --- a/resources/ts/Components/Pages/RecordPage.tsx +++ b/resources/ts/Components/Pages/RecordPage.tsx @@ -4,6 +4,7 @@ import {mdiChevronLeft} from '@mdi/js'; import MdIcon from '@osm/Components/MdIcon'; import Page, {PageAttributes} from '@osm/Components/Page'; import Model from '@osm/Models/Model'; +import {showSnackbar} from '@osm/utils/misc'; import {Builder} from 'coloquent'; import { Children, @@ -20,14 +21,8 @@ export default abstract class RecordPage, A extends Re abstract recordType: Class & typeof Model; record?: M; - public oninit(vnode: Vnode): void { + async oninit(vnode: Vnode) { super.oninit(vnode); - m.redraw(); - } - - async onbeforeupdate(vnode: VnodeDOM) { - super.onbeforeupdate(vnode); - const {id: recordId} = route().params as {id: number | string}; if (recordId !== this.record?.getId()) { await this.loadRecord(recordId); @@ -39,7 +34,9 @@ export default abstract class RecordPage, A extends Re try { const response = await this.modelQuery().find(recordId); this.record = response.getData() || undefined; - } catch { + } catch (e) { + console.error(e); + void showSnackbar(__('Errore durante il caricamento del record')); // Do nothing } } diff --git a/resources/ts/Components/Pages/RecordsPage.tsx b/resources/ts/Components/Pages/RecordsPage.tsx index 05b7cdf62..33393d8c6 100644 --- a/resources/ts/Components/Pages/RecordsPage.tsx +++ b/resources/ts/Components/Pages/RecordsPage.tsx @@ -103,6 +103,7 @@ export default abstract class RecordsPage< } modelQuery() { + // @ts-ignore let query = this.modelType.query(); for (const [attribute, value] of this.filters) { @@ -323,8 +324,9 @@ export default abstract class RecordsPage< return this.recordDialogsStates.get(key)!; } - protected cellValueModifier(value: unknown, attribute: string, record: M): Match { + protected cellValueModifier(value: unknown, attribute: string, record: M): Match { return match(attribute) + .returnType() .with('createdAt', 'updatedAt', () => dayjs(value as Date).format('DD/MM/YYYY HH:mm')); } }