From 86044081c37b23a8fc03052fffc1d2be66f1bc8b Mon Sep 17 00:00:00 2001 From: Dennis Alund Date: Mon, 27 May 2024 19:26:16 +0800 Subject: [PATCH 01/17] Cleaning up firestore indexes --- firestore.indexes.json | 213 +---------------------------------------- 1 file changed, 4 insertions(+), 209 deletions(-) diff --git a/firestore.indexes.json b/firestore.indexes.json index 94fccba4..93e19249 100644 --- a/firestore.indexes.json +++ b/firestore.indexes.json @@ -1,19 +1,5 @@ { "indexes": [ - { - "collectionGroup": "documents", - "queryScope": "COLLECTION", - "fields": [ - { - "fieldPath": "dependencies", - "arrayConfig": "CONTAINS" - }, - { - "fieldPath": "rendered", - "order": "ASCENDING" - } - ] - }, { "collectionGroup": "documents", "queryScope": "COLLECTION", @@ -23,11 +9,7 @@ "order": "ASCENDING" }, { - "fieldPath": "status", - "order": "ASCENDING" - }, - { - "fieldPath": "published", + "fieldPath": "createdAt", "order": "DESCENDING" } ] @@ -41,21 +23,7 @@ "order": "ASCENDING" }, { - "fieldPath": "title", - "order": "ASCENDING" - } - ] - }, - { - "collectionGroup": "documents", - "queryScope": "COLLECTION", - "fields": [ - { - "fieldPath": "documentType", - "order": "ASCENDING" - }, - { - "fieldPath": "title", + "fieldPath": "updatedAt", "order": "DESCENDING" } ] @@ -69,21 +37,7 @@ "order": "ASCENDING" }, { - "fieldPath": "updated", - "order": "ASCENDING" - } - ] - }, - { - "collectionGroup": "documents", - "queryScope": "COLLECTION", - "fields": [ - { - "fieldPath": "documentType", - "order": "ASCENDING" - }, - { - "fieldPath": "updated", + "fieldPath": "publishedAt", "order": "DESCENDING" } ] @@ -101,166 +55,7 @@ "order": "ASCENDING" } ] - }, - { - "collectionGroup": "documents", - "queryScope": "COLLECTION", - "fields": [ - { - "fieldPath": "status", - "order": "ASCENDING" - }, - { - "fieldPath": "title", - "order": "ASCENDING" - } - ] - }, - { - "collectionGroup": "documents", - "queryScope": "COLLECTION", - "fields": [ - { - "fieldPath": "status", - "order": "ASCENDING" - }, - { - "fieldPath": "title", - "order": "DESCENDING" - } - ] - }, - { - "collectionGroup": "documents", - "queryScope": "COLLECTION", - "fields": [ - { - "fieldPath": "status", - "order": "ASCENDING" - }, - { - "fieldPath": "updated", - "order": "ASCENDING" - } - ] - }, - { - "collectionGroup": "documents", - "queryScope": "COLLECTION", - "fields": [ - { - "fieldPath": "status", - "order": "ASCENDING" - }, - { - "fieldPath": "updated", - "order": "DESCENDING" - } - ] - }, - { - "collectionGroup": "files", - "queryScope": "COLLECTION", - "fields": [ - { - "fieldPath": "fileType", - "order": "ASCENDING" - }, - { - "fieldPath": "updated", - "order": "DESCENDING" - } - ] - }, - { - "collectionGroup": "notifications", - "queryScope": "COLLECTION", - "fields": [ - { - "fieldPath": "isRead", - "order": "ASCENDING" - }, - { - "fieldPath": "created", - "order": "DESCENDING" - } - ] - }, - { - "collectionGroup": "notifications", - "queryScope": "COLLECTION", - "fields": [ - { - "fieldPath": "isRead", - "order": "ASCENDING" - }, - { - "fieldPath": "updated", - "order": "DESCENDING" - } - ] - }, - { - "collectionGroup": "themes", - "queryScope": "COLLECTION", - "fields": [ - { - "fieldPath": "fileType", - "order": "ASCENDING" - }, - { - "fieldPath": "updated", - "order": "DESCENDING" - } - ] } ], - "fieldOverrides": [ - { - "collectionGroup": "user", - "fieldPath": "uid", - "ttl": false, - "indexes": [ - { - "order": "ASCENDING", - "queryScope": "COLLECTION" - }, - { - "order": "DESCENDING", - "queryScope": "COLLECTION" - }, - { - "arrayConfig": "CONTAINS", - "queryScope": "COLLECTION" - }, - { - "order": "ASCENDING", - "queryScope": "COLLECTION_GROUP" - } - ] - }, - { - "collectionGroup": "user-invites", - "fieldPath": "email", - "ttl": false, - "indexes": [ - { - "order": "ASCENDING", - "queryScope": "COLLECTION" - }, - { - "order": "DESCENDING", - "queryScope": "COLLECTION" - }, - { - "arrayConfig": "CONTAINS", - "queryScope": "COLLECTION" - }, - { - "order": "ASCENDING", - "queryScope": "COLLECTION_GROUP" - } - ] - } - ] + "fieldOverrides": [] } From dc7112a1d978f75ed48a12c6e19608c587db50bc Mon Sep 17 00:00:00 2001 From: Dennis Alund Date: Mon, 27 May 2024 19:26:37 +0800 Subject: [PATCH 02/17] Updating link to dashboard / home --- hosting/src/components/Sidebar/index.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hosting/src/components/Sidebar/index.tsx b/hosting/src/components/Sidebar/index.tsx index 7eb62d74..8ab9daa2 100644 --- a/hosting/src/components/Sidebar/index.tsx +++ b/hosting/src/components/Sidebar/index.tsx @@ -71,7 +71,7 @@ const Sidebar = ({sidebarOpen, setSidebarOpen}: SidebarProps) => { > {/* */}
- + Logo

Tanam

@@ -83,7 +83,7 @@ const Sidebar = ({sidebarOpen, setSidebarOpen}: SidebarProps) => {
); diff --git a/hosting/src/hooks/useTanamDocumentTypes.tsx b/hosting/src/hooks/useTanamDocumentTypes.tsx index c5a61d98..1d6c1260 100644 --- a/hosting/src/hooks/useTanamDocumentTypes.tsx +++ b/hosting/src/hooks/useTanamDocumentTypes.tsx @@ -7,11 +7,13 @@ import {UserNotification} from "@/models/UserNotification"; interface TanamDocumentTypeHook { data: TanamDocumentTypeClient[]; + totalRecords: number; error: UserNotification | null; } interface SingleTanamDocumentTypeHook { data: TanamDocumentTypeClient | null; + totalRecords: number; error: UserNotification | null; } @@ -22,6 +24,7 @@ interface SingleTanamDocumentTypeHook { */ export function useTanamDocumentTypes(): TanamDocumentTypeHook { const [data, setData] = useState([]); + const [totalRecords, setTotalRecords] = useState(0); const [error, setError] = useState(null); useEffect(() => { @@ -31,6 +34,7 @@ export function useTanamDocumentTypes(): TanamDocumentTypeHook { collectionRef, (snapshot) => { const documentTypes = snapshot.docs.map((doc) => TanamDocumentTypeClient.fromFirestore(doc)); + setTotalRecords(snapshot.size) setData(documentTypes); }, (err) => { @@ -42,7 +46,7 @@ export function useTanamDocumentTypes(): TanamDocumentTypeHook { return () => unsubscribe(); }, []); - return {data, error}; + return {data, totalRecords, error}; } /** @@ -56,11 +60,13 @@ export function useTanamDocumentType(documentTypeId?: string): SingleTanamDocume documentTypeId: null, }; const [data, setData] = useState(null); + const [totalRecords, setTotalRecords] = useState(0); const [error, setError] = useState(null); useEffect(() => { const typeId = documentTypeId ?? paramType; if (!typeId) { + setTotalRecords(0); setData(null); return; } @@ -71,6 +77,7 @@ export function useTanamDocumentType(documentTypeId?: string): SingleTanamDocume docRef, (doc) => { if (doc.exists()) { + setTotalRecords(1); setData(TanamDocumentTypeClient.fromFirestore(doc)); } else { setError(new UserNotification("error", "Error fetching data", "Document type not found")); @@ -85,5 +92,5 @@ export function useTanamDocumentType(documentTypeId?: string): SingleTanamDocume return () => unsubscribe(); }, [documentTypeId, paramType]); - return {data, error}; + return {data, totalRecords, error}; } From 2d2b54beef843b5698b9cb694be0ed7d11623b91 Mon Sep 17 00:00:00 2001 From: Nurfirliana Muzanella Date: Wed, 26 Jun 2024 15:44:52 +0700 Subject: [PATCH 14/17] total records in table --- hosting/src/app/(protected)/[site]/dashboard/page.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hosting/src/app/(protected)/[site]/dashboard/page.tsx b/hosting/src/app/(protected)/[site]/dashboard/page.tsx index 2fb90317..715fd6f9 100644 --- a/hosting/src/app/(protected)/[site]/dashboard/page.tsx +++ b/hosting/src/app/(protected)/[site]/dashboard/page.tsx @@ -15,7 +15,7 @@ export default function DashboardPage() { }; // const {data: document, error: docError} = useTanamDocument(); const {data: document, error: docError} = useTanamRecentDocuments("createdAt"); - const {data: documentTypes, error: typesError} = useTanamDocumentTypes(); + const {data: documentTypes, totalRecords: typeTotalRecords, error: typeError} = useTanamDocumentTypes(); // const {data: documentType, error: typeError} = useTanamDocumentType(document?.documentType); if (docError) { @@ -47,6 +47,7 @@ export default function DashboardPage() {
{documentType.documentTitleField}
,

{documentType.createdAt.toDate().toUTCString()}

])} + totalRecords={typeTotalRecords} /> From 16df5038dd8e77a7d67df2ca8a5d75a0bd90d43d Mon Sep 17 00:00:00 2001 From: Nurfirliana Muzanella Date: Wed, 26 Jun 2024 15:49:31 +0700 Subject: [PATCH 15/17] add total records in another places --- hosting/src/hooks/useTanamDocumentFields.tsx | 5 ++++- hosting/src/hooks/useTanamDocuments.tsx | 9 +++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/hosting/src/hooks/useTanamDocumentFields.tsx b/hosting/src/hooks/useTanamDocumentFields.tsx index e71e122f..51bb475d 100644 --- a/hosting/src/hooks/useTanamDocumentFields.tsx +++ b/hosting/src/hooks/useTanamDocumentFields.tsx @@ -7,6 +7,7 @@ import {UserNotification} from "@/models/UserNotification"; interface TanamDocumentFieldHook { data: TanamDocumentField[]; + totalRecords: number; error: UserNotification | null; } @@ -21,6 +22,7 @@ export function useTanamDocumentFields(documentTypeId?: string): TanamDocumentFi documentTypeId: null, }; const [data, setData] = useState([]); + const [totalRecords, setTotalRecords] = useState(0); const [error, setError] = useState(null); useEffect(() => { @@ -38,6 +40,7 @@ export function useTanamDocumentFields(documentTypeId?: string): TanamDocumentFi const documentTypes = snapshot.docs.map( (doc) => new TanamDocumentField(doc.id, doc.data() as ITanamDocumentField), ); + setTotalRecords(snapshot.size); setData(documentTypes); }, (err) => { @@ -49,5 +52,5 @@ export function useTanamDocumentFields(documentTypeId?: string): TanamDocumentFi return () => unsubscribe(); }, [documentTypeId, paramType]); - return {data, error}; + return {data, totalRecords, error}; } diff --git a/hosting/src/hooks/useTanamDocuments.tsx b/hosting/src/hooks/useTanamDocuments.tsx index e2afb3cb..e12c5833 100644 --- a/hosting/src/hooks/useTanamDocuments.tsx +++ b/hosting/src/hooks/useTanamDocuments.tsx @@ -19,6 +19,7 @@ import {UserNotification} from "@/models/UserNotification"; interface UseTanamDocumentsResult { data: TanamDocumentClient[]; + totalRecords: number; error: UserNotification | null; } @@ -30,6 +31,7 @@ interface UseTanamDocumentsResult { */ export function useTanamDocuments(documentTypeId?: string): UseTanamDocumentsResult { const [data, setData] = useState([]); + const [totalRecords, setTotalRecords] = useState(0); const [error, setError] = useState(null); useEffect(() => { @@ -45,6 +47,7 @@ export function useTanamDocuments(documentTypeId?: string): UseTanamDocumentsRes q, (snapshot) => { const documents = snapshot.docs.map((doc) => TanamDocumentClient.fromFirestore(doc)); + setTotalRecords(snapshot.size); setData(documents); }, (err) => { @@ -56,7 +59,7 @@ export function useTanamDocuments(documentTypeId?: string): UseTanamDocumentsRes return () => unsubscribe(); }, [documentTypeId]); - return {data, error}; + return {data, totalRecords, error}; } type RecentField = "createdAt" | "updatedAt" | "publishedAt"; @@ -77,6 +80,7 @@ export function useTanamRecentDocuments( site: null, }; const [data, setData] = useState([]); + const [totalRecords, setTotalRecords] = useState(0); const [error, setError] = useState(null); useEffect(() => { @@ -102,6 +106,7 @@ export function useTanamRecentDocuments( console.log("Numm docs: ", snapshot.docs.length); const documents = snapshot.docs.map((doc) => TanamDocumentClient.fromFirestore(doc)); console.info("documents :: ", documents); + setTotalRecords(snapshot.size); setData(documents); }, (err) => { @@ -113,7 +118,7 @@ export function useTanamRecentDocuments( return () => unsubscribe(); }, [site]); - return {data, error}; + return {data, totalRecords, error}; } interface UseTanamDocumentResult { From 6b584e56d6c531e203c4c0bc9336333519f4b368 Mon Sep 17 00:00:00 2001 From: Nurfirliana Muzanella Date: Wed, 26 Jun 2024 15:52:57 +0700 Subject: [PATCH 16/17] remove unused code --- .../app/(protected)/[site]/dashboard/page.tsx | 35 +++++++------------ hosting/src/hooks/useTanamDocuments.tsx | 2 -- 2 files changed, 12 insertions(+), 25 deletions(-) diff --git a/hosting/src/app/(protected)/[site]/dashboard/page.tsx b/hosting/src/app/(protected)/[site]/dashboard/page.tsx index 715fd6f9..4959b0af 100644 --- a/hosting/src/app/(protected)/[site]/dashboard/page.tsx +++ b/hosting/src/app/(protected)/[site]/dashboard/page.tsx @@ -3,9 +3,7 @@ import Notification from "@/components/common/Notification"; import Loader from "@/components/common/Loader"; import ContentCard from "@/components/Containers/ContentCard"; import {Table} from "@/components/Table"; -// import {useTanamDocument} from "@/hooks/useTanamDocuments"; -import {useTanamRecentDocuments} from "@/hooks/useTanamDocuments"; -import {useTanamDocumentType, useTanamDocumentTypes} from '@/hooks/useTanamDocumentTypes'; +import {useTanamDocumentTypes} from '@/hooks/useTanamDocumentTypes'; import {useParams} from "next/navigation"; import {Suspense} from "react"; @@ -13,15 +11,12 @@ export default function DashboardPage() { const {site} = useParams<{site: string}>() ?? { site: null, }; - // const {data: document, error: docError} = useTanamDocument(); - const {data: document, error: docError} = useTanamRecentDocuments("createdAt"); const {data: documentTypes, totalRecords: typeTotalRecords, error: typeError} = useTanamDocumentTypes(); - // const {data: documentType, error: typeError} = useTanamDocumentType(document?.documentType); - if (docError) { + if (typeError) { return ( <> - + ); } @@ -33,22 +28,16 @@ export default function DashboardPage() { }>
- site ID :: {site}
- document :: {JSON.stringify(document)}
- documentTypes :: {JSON.stringify(documentTypes)}
- {/* documentType :: {JSON.stringify(documentType)}
*/} - error :: {JSON.stringify(docError)} + [ +
{documentType.id}
, +
{documentType.documentTitleField}
, +

{documentType.createdAt.toDate().toUTCString()}

+ ])} + totalRecords={typeTotalRecords} + /> - -
[ -
{documentType.id}
, -
{documentType.documentTitleField}
, -

{documentType.createdAt.toDate().toUTCString()}

- ])} - totalRecords={typeTotalRecords} - /> diff --git a/hosting/src/hooks/useTanamDocuments.tsx b/hosting/src/hooks/useTanamDocuments.tsx index e12c5833..9372850e 100644 --- a/hosting/src/hooks/useTanamDocuments.tsx +++ b/hosting/src/hooks/useTanamDocuments.tsx @@ -103,9 +103,7 @@ export function useTanamRecentDocuments( const unsubscribe = onSnapshot( q, (snapshot) => { - console.log("Numm docs: ", snapshot.docs.length); const documents = snapshot.docs.map((doc) => TanamDocumentClient.fromFirestore(doc)); - console.info("documents :: ", documents); setTotalRecords(snapshot.size); setData(documents); }, From 7a7f610dabbeaabb85498df7dbe42d1032190aad Mon Sep 17 00:00:00 2001 From: Nurfirliana Muzanella Date: Wed, 26 Jun 2024 15:55:14 +0700 Subject: [PATCH 17/17] fix missing key prop in element --- .../src/app/(protected)/[site]/dashboard/page.tsx | 14 +++++++------- hosting/src/components/Table/Table.tsx | 4 +--- hosting/src/hooks/useTanamDocumentTypes.tsx | 2 +- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/hosting/src/app/(protected)/[site]/dashboard/page.tsx b/hosting/src/app/(protected)/[site]/dashboard/page.tsx index 4959b0af..82be3f91 100644 --- a/hosting/src/app/(protected)/[site]/dashboard/page.tsx +++ b/hosting/src/app/(protected)/[site]/dashboard/page.tsx @@ -3,7 +3,7 @@ import Notification from "@/components/common/Notification"; import Loader from "@/components/common/Loader"; import ContentCard from "@/components/Containers/ContentCard"; import {Table} from "@/components/Table"; -import {useTanamDocumentTypes} from '@/hooks/useTanamDocumentTypes'; +import {useTanamDocumentTypes} from "@/hooks/useTanamDocumentTypes"; import {useParams} from "next/navigation"; import {Suspense} from "react"; @@ -28,12 +28,12 @@ export default function DashboardPage() { }>
-
[ -
{documentType.id}
, -
{documentType.documentTitleField}
, -

{documentType.createdAt.toDate().toUTCString()}

+
[ +
{documentType.id}
, +
{documentType.documentTitleField}
, +

{documentType.createdAt.toDate().toUTCString()}

, ])} totalRecords={typeTotalRecords} /> diff --git a/hosting/src/components/Table/Table.tsx b/hosting/src/components/Table/Table.tsx index f0b08899..7e9cdf60 100644 --- a/hosting/src/components/Table/Table.tsx +++ b/hosting/src/components/Table/Table.tsx @@ -56,9 +56,7 @@ export function Table({headers, rows, totalRecords}: TableProps): JSX.Element {
-
- Total Records: {totalRecords ?? rows.length} -
+
Total Records: {totalRecords ?? rows.length}
); diff --git a/hosting/src/hooks/useTanamDocumentTypes.tsx b/hosting/src/hooks/useTanamDocumentTypes.tsx index 1d6c1260..0577c6a2 100644 --- a/hosting/src/hooks/useTanamDocumentTypes.tsx +++ b/hosting/src/hooks/useTanamDocumentTypes.tsx @@ -34,7 +34,7 @@ export function useTanamDocumentTypes(): TanamDocumentTypeHook { collectionRef, (snapshot) => { const documentTypes = snapshot.docs.map((doc) => TanamDocumentTypeClient.fromFirestore(doc)); - setTotalRecords(snapshot.size) + setTotalRecords(snapshot.size); setData(documentTypes); }, (err) => {