|
|
@@ -637,6 +637,36 @@ export default function DatabasePage() {
|
|
|
>
|
|
|
<Settings className="w-4 h-4" />
|
|
|
</button>
|
|
|
+ {/* Deletion, where somebody looking at a collection would expect
|
|
|
+ it rather than behind the settings gear. The conditions are the
|
|
|
+ server's, not this button's: it refuses a protected collection
|
|
|
+ and refuses one that still holds documents. Disabled with the
|
|
|
+ reason showing, rather than enabled and then refused. */}
|
|
|
+ <button
|
|
|
+ onClick={() => {
|
|
|
+ if (!selectedCollection) return
|
|
|
+ if (!confirm(`Delete the collection "${selectedCollection}"?\n\nIt is empty, so nothing is lost, but it cannot be undone.`)) return
|
|
|
+ dropCollectionMutation.mutate(selectedCollection)
|
|
|
+ }}
|
|
|
+ disabled={
|
|
|
+ !collectionInfo ||
|
|
|
+ collectionInfo.protection !== 'none' ||
|
|
|
+ collectionInfo.documentCount > 0 ||
|
|
|
+ dropCollectionMutation.isPending
|
|
|
+ }
|
|
|
+ className="p-1.5 text-gray-400 hover:text-red-600 dark:hover:text-red-400 hover:bg-gray-100 dark:hover:bg-slate-700 rounded disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:text-gray-400"
|
|
|
+ title={
|
|
|
+ !collectionInfo
|
|
|
+ ? 'Reading the collection...'
|
|
|
+ : collectionInfo.protection !== 'none'
|
|
|
+ ? 'This collection belongs to SmartBotic and cannot be deleted here'
|
|
|
+ : collectionInfo.documentCount > 0
|
|
|
+ ? `Still holds ${collectionInfo.documentCount.toLocaleString()} ${collectionInfo.documentCount === 1 ? 'document' : 'documents'} - delete them first`
|
|
|
+ : 'Delete this empty collection'
|
|
|
+ }
|
|
|
+ >
|
|
|
+ <Trash2 className="w-4 h-4" />
|
|
|
+ </button>
|
|
|
</div>
|
|
|
)}
|
|
|
</div>
|
|
|
@@ -1140,8 +1170,9 @@ export default function DatabasePage() {
|
|
|
<div className="pt-4 border-t border-gray-200 dark:border-slate-700 space-y-2">
|
|
|
<p className="text-gray-900 dark:text-gray-100 font-medium">Delete this collection</p>
|
|
|
<p className="text-xs text-gray-500 dark:text-gray-400">
|
|
|
- Removes the collection and all {collectionInfo.documentCount.toLocaleString()} of
|
|
|
- its documents. There is no undo, so the name has to be typed to confirm.
|
|
|
+ {collectionInfo.documentCount > 0
|
|
|
+ ? `It still holds ${collectionInfo.documentCount.toLocaleString()} ${collectionInfo.documentCount === 1 ? 'document' : 'documents'}. Delete those first - a collection with data in it is not dropped, because emptying it shows what is going and dropping it does not.`
|
|
|
+ : 'The collection is empty, so nothing is lost. There is no undo, so the name has to be typed to confirm.'}
|
|
|
</p>
|
|
|
<input
|
|
|
type="text"
|
|
|
@@ -1152,7 +1183,11 @@ export default function DatabasePage() {
|
|
|
/>
|
|
|
<button
|
|
|
onClick={() => dropCollectionMutation.mutate(selectedCollection)}
|
|
|
- disabled={dropConfirmText !== selectedCollection || dropCollectionMutation.isPending}
|
|
|
+ disabled={
|
|
|
+ dropConfirmText !== selectedCollection ||
|
|
|
+ collectionInfo.documentCount > 0 ||
|
|
|
+ dropCollectionMutation.isPending
|
|
|
+ }
|
|
|
className="px-3 py-1.5 rounded bg-red-600 text-white hover:bg-red-700 disabled:opacity-40 disabled:cursor-not-allowed"
|
|
|
>
|
|
|
{dropCollectionMutation.isPending ? 'Deleting...' : 'Delete collection'}
|