From 75c0f9bdd9fbf44638cecdc624bd1df585095bfc Mon Sep 17 00:00:00 2001 From: Chris Thompson Date: Mon, 27 Nov 2023 06:08:19 -0800 Subject: [PATCH] Working, requests busted --- src/components/Firestore/CollectionList.tsx | 5 +- .../Requests/RequestDetails/Header/index.tsx | 2 +- .../Requests/RequestsCard/Table/TableRow.tsx | 2 +- src/components/Firestore/Requests/index.tsx | 4 +- src/components/Firestore/index.tsx | 54 ++++++++++--------- src/components/Firestore/useAutoSelect.tsx | 13 ++--- src/routes.test.tsx | 8 +-- src/routes.ts | 4 +- 8 files changed, 48 insertions(+), 44 deletions(-) diff --git a/src/components/Firestore/CollectionList.tsx b/src/components/Firestore/CollectionList.tsx index 62bf0f3d9..26738b455 100644 --- a/src/components/Firestore/CollectionList.tsx +++ b/src/components/Firestore/CollectionList.tsx @@ -79,6 +79,7 @@ const CollectionList: React.FC> = ({ const newCollection = reference ? collection(reference, value.collectionId) : collection(firestore, value.collectionId); + const databaseId = "(default)" // FIXME where do we get the database ID from? await setDoc(doc(newCollection, value.document.id), value.document.data); // Redirect to the new collection @@ -89,10 +90,10 @@ const CollectionList: React.FC> = ({ .map((uri) => encodeURIComponent(uri)) .join('/'); history.push( - `/firestore/asdf/data/${encodedReferencePath}/${encodedCollectionId}` // FIXME + `/firestore/${databaseId}/data/${encodedReferencePath}/${encodedCollectionId}` ); } else { - history.push(`/firestore/asdf/data/${encodedCollectionId}`); + history.push(`/firestore/${databaseId}/data/${encodedCollectionId}`); } } }; diff --git a/src/components/Firestore/Requests/RequestDetails/Header/index.tsx b/src/components/Firestore/Requests/RequestDetails/Header/index.tsx index 60d16f7a4..06eb22f3e 100644 --- a/src/components/Firestore/Requests/RequestDetails/Header/index.tsx +++ b/src/components/Firestore/Requests/RequestDetails/Header/index.tsx @@ -60,7 +60,7 @@ const RequestDetailsHeader: React.FC> = ({ className="Firestore-Request-Details-Header-Return-Button" icon={{ icon: 'arrow_back_ios', size: 'small' }} tag={Link} - to="/firestore/(default)/requests" // FIXME consider if we care to go back to the current DB page or default + to="/firestore/fdsa/requests" // FIXME consider if we care to go back to the current DB page or default label="header-return-button" /> diff --git a/src/components/Firestore/Requests/RequestsCard/Table/TableRow.tsx b/src/components/Firestore/Requests/RequestsCard/Table/TableRow.tsx index bbc27548c..073fd460e 100644 --- a/src/components/Firestore/Requests/RequestsCard/Table/TableRow.tsx +++ b/src/components/Firestore/Requests/RequestsCard/Table/TableRow.tsx @@ -79,7 +79,7 @@ const RequestTableRow: React.FC> = ({ return ( history.push(`/firestore/(default)/requests/${requestId}`)} // FIXME DB id here + onClick={() => history.push(`/firestore/fdsa/requests/${requestId}`)} // FIXME DB id here > > = () => { style={{ flex: 1 }} > - +
{/* TODO: Finish developing the RequestsHeader in order to render it */} {/* */} @@ -58,7 +58,7 @@ const Requests: React.FC> = () => { ) => { diff --git a/src/components/Firestore/index.tsx b/src/components/Firestore/index.tsx index d089be929..0afd7d13a 100644 --- a/src/components/Firestore/index.tsx +++ b/src/components/Firestore/index.tsx @@ -69,28 +69,30 @@ interface FirestoreTabRoute { label: string; exact: boolean; } -const firestoreRoutes: ReadonlyArray = [ - { - path: '/firestore/asdf/data', - label: 'Data', - exact: false, - }, - { - path: '/firestore/(default)/requests', - label: 'Requests', - exact: false, - }, -]; export const Firestore: React.FC> = React.memo( () => { const location = useLocation(); + const databaseId = location.pathname.split("/")[2]; const history = useHistory(); const [isRefreshing, setIsRefreshing] = useState(false); const eject = useEjector(); - + const firestoreRoutes: ReadonlyArray = [ + { + path: `/firestore/${databaseId}/data`, + label: 'Data', + exact: false, + }, + { + path: `/firestore/${databaseId}/requests`, + label: 'Requests', + exact: false, + }, + ]; // TODO: do something better here! - const path = location.pathname.replace(/^\/firestore\/data/, ''); + // Regex based (roughly) on valid DB IDs here: + // https://firebase.google.com/docs/firestore/manage-databases#database_id + const path = location.pathname.replace(/^\/firestore\/[a-zA-Z0-9-]{1,63}\/data/, ''); const showCollectionShell = path.split('/').length < 2; const showDocumentShell = path.split('/').length < 3; @@ -117,13 +119,13 @@ export const Firestore: React.FC> = React.memo( if (!shouldNuke) return; setIsRefreshing(true); await eject(); - handleNavigate(); + handleNavigate(databaseId); setIsRefreshing(false); } - function handleNavigate(path?: string) { + function handleNavigate(path?: string, databaseId: string = "default") { // TODO: move to routing constants - const root = '/firestore/asdf/data'; // FIXME + const root = `/firestore/${databaseId}/data`; if (path === undefined) { history.push(root); } else { @@ -163,20 +165,21 @@ export const Firestore: React.FC> = React.memo(
- + - + - - + + @@ -186,6 +189,7 @@ export const Firestore: React.FC> = React.memo( interface FirestoreDataCardProps { path: string; + databaseId: string; handleClearData: () => void; handleNavigate: (path?: string) => void; showCollectionShell: boolean; @@ -196,11 +200,13 @@ const FirestoreDataCard: React.FC< React.PropsWithChildren > = ({ path, + databaseId, handleClearData, handleNavigate, showCollectionShell, showDocumentShell, -}) => ( +}) => { +console.log("my path is:" + path); return ( <>
@@ -212,7 +218,7 @@ const FirestoreDataCard: React.FC< @@ -235,7 +241,7 @@ const FirestoreDataCard: React.FC< -); +)}; const FirestoreRequestsCard: React.FC< React.PropsWithChildren diff --git a/src/components/Firestore/useAutoSelect.tsx b/src/components/Firestore/useAutoSelect.tsx index 28eb9c58f..2f10897c0 100644 --- a/src/components/Firestore/useAutoSelect.tsx +++ b/src/components/Firestore/useAutoSelect.tsx @@ -17,12 +17,9 @@ import { ReactNode, useEffect, useState } from 'react'; import { Redirect, useLocation, useRouteMatch } from 'react-router-dom'; -export const FIRESTORE_DATA_URL = '/firestore/asdf/data'; // FIXME -const FIRESTORE_DATA_URL_PATH_LENGTH = FIRESTORE_DATA_URL.split('/').length; - /** * Given a list of collections or documents, auto select the first item. Only - * works on root (`/firestore/data`) or top level collections (`/firestore/data/users`) + * works on root (`/firestore/DB/data`) or top level collections (`/firestore/DB/data/users`) * to prevent deep auto selection. */ export function useAutoSelect(list?: T[] | null) { @@ -31,11 +28,11 @@ export function useAutoSelect(list?: T[] | null) { const [autoSelect, setAutoSelect] = useState(null); useEffect(() => { + const splitUrl = url.split('/'); const isRootOrRootCollection = - url === FIRESTORE_DATA_URL || - // /firestore/data/users - (url.startsWith(FIRESTORE_DATA_URL) && // FIXME need a fuzzy match here - url.split('/').length === FIRESTORE_DATA_URL_PATH_LENGTH + 1); + (splitUrl.length === 4 || splitUrl.length === 5) + && splitUrl[1] === "firestore" // The first segment is empty string + && splitUrl[3] === "data"; const hasNothingSelected = url === pathname; const firstChild = list?.[0]; const shouldAutoSelect = isRootOrRootCollection && hasNothingSelected; diff --git a/src/routes.test.tsx b/src/routes.test.tsx index b4dd2ec2e..0592d64a8 100644 --- a/src/routes.test.tsx +++ b/src/routes.test.tsx @@ -37,8 +37,8 @@ describe('getSanitizedPathData', () => { describe('Firestore', () => { it('scrubs Firestore path data', () => { - expect(scrubPathData('/firestore/asdf/data/myCollection/myDoc')).toEqual({ - scrubbedPath: '/firestore/asdf/data/:path*', + expect(scrubPathData('/firestore/default/data/myCollection/myDoc')).toEqual({ + scrubbedPath: '/firestore/default/data/:path*', pathLabel: 'Firestore', }); }); @@ -46,10 +46,10 @@ describe('getSanitizedPathData', () => { it('scrubs deeply nested Firestore paths', () => { expect( scrubPathData( - '/firestore/asdf/data/myCollection/myDoc/mySubCollection/mySubDoc' + '/firestore/default/data/myCollection/myDoc/mySubCollection/mySubDoc' ) ).toEqual({ - scrubbedPath: '/firestore/asdf/data/:path*', + scrubbedPath: '/firestore/default/data/:path*', pathLabel: 'Firestore', }); }); diff --git a/src/routes.ts b/src/routes.ts index 4f4cada27..531a1e850 100644 --- a/src/routes.ts +++ b/src/routes.ts @@ -45,8 +45,8 @@ const routesToSanitize: string[] = [ '/extensions/:instanceId', // Firestore - '/firestore/asdf/data/:path*', - '/firestore/(default)/requests/:requestId', + '/firestore/:databaseId/data/:path*', + '/firestore/:databaseId/requests/:requestId', // Storage '/storage/:bucket/:path*',