这是indexloc提供的服务,不要输入任何密码
Skip to content

Create dashboard page #361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
213 changes: 4 additions & 209 deletions firestore.indexes.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
{
"indexes": [
{
"collectionGroup": "documents",
"queryScope": "COLLECTION",
"fields": [
{
"fieldPath": "dependencies",
"arrayConfig": "CONTAINS"
},
{
"fieldPath": "rendered",
"order": "ASCENDING"
}
]
},
{
"collectionGroup": "documents",
"queryScope": "COLLECTION",
Expand All @@ -23,11 +9,7 @@
"order": "ASCENDING"
},
{
"fieldPath": "status",
"order": "ASCENDING"
},
{
"fieldPath": "published",
"fieldPath": "createdAt",
"order": "DESCENDING"
}
]
Expand All @@ -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"
}
]
Expand All @@ -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"
}
]
Expand All @@ -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": []
}
50 changes: 44 additions & 6 deletions firestore.rules
Original file line number Diff line number Diff line change
@@ -1,27 +1,65 @@
service cloud.firestore {
match /databases/{database}/documents {
match /tanam/{siteId} {
allow read: if true;
match /documents/{documentId} {
allow read: if true;
}
}

match /tanam-types/{typeId} {
allow read: if hasAnyRole();
allow write: if isAtLeastAdmin();
allow read: if true;
allow write: if true;
match /fields/{fieldId} {
allow read: if true;
allow write: if true;
}
}

match /tanam-documents/{documentId} {
allow read: if hasAnyRole();
allow write: if isPublisher();
allow read: if true;
allow write: if true;

match /revisions/{revisionId} {
allow read: if hasAnyRole();
allow write: if false;
}
}

match /files/{fileId} {
allow read: if hasAnyRole();
allow write: if isPublisher();
}

match /notifications/{notificationId} {
allow read: if isAtLeastAdmin();
allow write: if isAtLeastAdmin();
}

match /themes/{document=**} {
allow read: if hasAnyRole();
allow write: if isAtLeastAdmin();
}

match /users/{document=**} {
allow read, write: if isAtLeastAdmin();
}

match /user-invites/{document=**} {
allow read, write: if isSuperAdmin();
}

match /users/{userId} {
allow read: if isSignedInAs(userId);
allow write: if isSignedInAs(userId);
}

function hasUserRole(role) {
return isSignedIn() && role == request.auth.token.tanamRole;
return isSignedIn() && role in request.auth.token.tanam[siteId];
}

function hasAnyRole() {
return isSignedIn() && request.auth.token.tanamRole != null;
return isSignedIn() && request.auth.token.tanam[siteId].size() > 0;
}

function isSuperAdmin() {
Expand Down
47 changes: 47 additions & 0 deletions hosting/src/app/(protected)/[site]/dashboard/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"use client";
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 {useParams} from "next/navigation";
import {Suspense} from "react";

export default function DashboardPage() {
const {site} = useParams<{site: string}>() ?? {
site: null,
};
const {data: documentTypes, totalRecords: typeTotalRecords, error: typeError} = useTanamDocumentTypes();

if (typeError) {
return (
<>
<Notification type="error" title="Error loading document" message={typeError?.message || "Unknown error"} />
</>
);
}

return (
<>
{site && (
<div className="grid grid-cols-1 gap-9">
<ContentCard key={site} title="Post Type">
<Suspense fallback={<Loader />}>
<section className="l-dashboard">
<Table
headers={["Id", "Title", "Created At"]}
rows={documentTypes.map((documentType, documentTypeKey) => [
<div key={documentTypeKey}>{documentType.id}</div>,
<div key={documentTypeKey}>{documentType.documentTitleField}</div>,
<p key={documentTypeKey}>{documentType.createdAt.toDate().toUTCString()}</p>,
])}
totalRecords={typeTotalRecords}
/>
</section>
</Suspense>
</ContentCard>
</div>
)}
</>
);
}
6 changes: 3 additions & 3 deletions hosting/src/components/Sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import Image from "next/image";
import Link from "next/link";
import {usePathname} from "next/navigation";
import {useEffect, useRef, useState} from "react";
import {useTanamDocumentTypes} from "../../hooks/useTanamDocumentTypes";
import {useTanamDocumentTypes} from "@/hooks/useTanamDocumentTypes";
import {SidebarExpandableMenu, SidebarExpandableMenuSubItem} from "./SidebarExpandableMenu";
import {SidebarMenuGroup} from "./SidebarMenuGroup";
import {SidebarMenuItem} from "./SidebarMenuItem";
import {SidebarMenuGroup} from "@/components/Sidebar/SidebarMenuGroup";
import {SidebarMenuItem} from "@/components/Sidebar/SidebarMenuItem";

interface SidebarProps {
sidebarOpen: boolean;
Expand Down
Loading