|
|
@@ -72,6 +72,8 @@ export default function DatabasePage() {
|
|
|
const [currentPage, setCurrentPage] = useState(1)
|
|
|
const documentListRef = useRef<HTMLDivElement>(null)
|
|
|
|
|
|
+ const [justCreated, setJustCreated] = useState<string[]>([])
|
|
|
+
|
|
|
const { data: collectionsData, isLoading: collectionsLoading } = useQuery({
|
|
|
queryKey: ['database-collections'],
|
|
|
queryFn: () => databaseApi.listCollections(),
|
|
|
@@ -133,6 +135,11 @@ export default function DatabasePage() {
|
|
|
mutationFn: ({ name, settings }: { name: string; settings?: CollectionSettings }) =>
|
|
|
databaseApi.createCollection(name, settings),
|
|
|
onSuccess: (_, { name }) => {
|
|
|
+ // The database does not list a collection until it holds a document, so
|
|
|
+ // refetching would drop the one just created and the whole thing would
|
|
|
+ // look like it had not worked. Remembered here until it shows up on its
|
|
|
+ // own.
|
|
|
+ setJustCreated((prev) => (prev.includes(name) ? prev : [...prev, name]))
|
|
|
queryClient.invalidateQueries({ queryKey: ['database-collections'] })
|
|
|
setShowNewCollectionModal(false)
|
|
|
setNewCollectionName('')
|
|
|
@@ -299,8 +306,17 @@ export default function DatabasePage() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- const collections: string[] = collectionsData?.collections || []
|
|
|
+ const fetched: string[] = collectionsData?.collections || []
|
|
|
+ // Anything created this session that the server cannot list yet.
|
|
|
+ const collections: string[] = [
|
|
|
+ ...fetched,
|
|
|
+ ...justCreated.filter((name) => !fetched.includes(name)),
|
|
|
+ ]
|
|
|
const documents: Document[] = documentsData?.documents || []
|
|
|
+ // A collection with nothing in it cannot be queried at all, so its document
|
|
|
+ // list comes back as an error rather than an empty page.
|
|
|
+ const isEmptyNewCollection =
|
|
|
+ !!selectedCollection && justCreated.includes(selectedCollection) && documents.length === 0
|
|
|
const totalDocuments = documentsData?.total || 0
|
|
|
const totalPages = Math.ceil(totalDocuments / PAGE_SIZE)
|
|
|
|
|
|
@@ -563,7 +579,11 @@ export default function DatabasePage() {
|
|
|
))
|
|
|
) : (
|
|
|
<p className="text-sm text-gray-500 dark:text-gray-400 text-center py-4">
|
|
|
- {searchTerm ? 'No matching documents' : 'No documents'}
|
|
|
+ {searchTerm
|
|
|
+ ? 'No matching documents'
|
|
|
+ : isEmptyNewCollection
|
|
|
+ ? 'Created, but empty. The database does not list or return a collection until something writes to it, so this will not appear after a reload until it holds a document.'
|
|
|
+ : 'No documents'}
|
|
|
</p>
|
|
|
)}
|
|
|
</div>
|