Skip to content

Commit

Permalink
Merge pull request #4 from ricokahler/fix/refresh-after-bulk-delete
Browse files Browse the repository at this point in the history
fix: refresh after bulk delete
  • Loading branch information
ricokahler authored Mar 28, 2021
2 parents 98df37d + db6825d commit ab4ac58
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
14 changes: 10 additions & 4 deletions src/bulk-actions-menu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ interface Props {
className?: string;
typeName: string;
selectedIds: Set<string>;
onDelete: () => void;
}

const ErroredDocuments = ({ e, schemaType }: { e: any; schemaType: any }) => {
Expand Down Expand Up @@ -61,7 +62,12 @@ const ErroredDocuments = ({ e, schemaType }: { e: any; schemaType: any }) => {
const removeDraftPrefix = (s: string) =>
s.startsWith('drafts.') ? s.substring('drafts.'.length) : s;

function BulkActionsMenu({ className, selectedIds, typeName }: Props) {
function BulkActionsMenu({
className,
selectedIds,
typeName,
onDelete,
}: Props) {
const buttonId = useMemo(nanoid, []);
const schemaType = useMemo(() => schema.get(typeName), [typeName]);
const toast = useToast();
Expand All @@ -88,7 +94,7 @@ function BulkActionsMenu({ className, selectedIds, typeName }: Props) {

const draftIdsThatAlsoHavePublishedIds = ids.filter(
(id) =>
id.startsWith('drafts.') && idSet.has(id.substring('drafts.'.length)),
id.startsWith('drafts.') && idSet.has(id.substring('drafts.'.length))
);

const t = client.transaction();
Expand Down Expand Up @@ -225,6 +231,7 @@ function BulkActionsMenu({ className, selectedIds, typeName }: Props) {
}

await t.commit();
onDelete();
} catch (e) {
console.warn(e);

Expand All @@ -234,8 +241,7 @@ function BulkActionsMenu({ className, selectedIds, typeName }: Props) {
<>
<p>
The bulk delete failed. This usually occurs because there are
other documents referencing the documents you’re trying to
delete.
other documents referencing the documents you’re trying to delete.
</p>

<ErroredDocuments e={e} schemaType={schemaType} />
Expand Down
15 changes: 10 additions & 5 deletions src/create-super-pane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ function createSuperPane(typeName: string, S: any) {
}, [client.refresh]);

const fields = schemaType.fields.filter((field: any) =>
selectedColumns.has(field.name),
selectedColumns.has(field.name)
);

const atLeastOneSelected = client.results.some((i) =>
selectedIds.has(i._normalizedId),
selectedIds.has(i._normalizedId)
);
const allSelected = client.results.every((i) =>
selectedIds.has(i._normalizedId),
selectedIds.has(i._normalizedId)
);

return (
Expand All @@ -98,6 +98,11 @@ function createSuperPane(typeName: string, S: any) {
className={styles.clearButton}
selectedIds={selectedIds}
typeName={typeName}
onDelete={() => {
setSelectedIds(new Set());
client.setPage(0);
client.refresh();
}}
/>
</div>
</div>
Expand Down Expand Up @@ -172,7 +177,7 @@ function createSuperPane(typeName: string, S: any) {
router.resolveIntentLink('edit', {
id: item._id,
type: item._type,
}),
})
);
};

Expand All @@ -193,7 +198,7 @@ function createSuperPane(typeName: string, S: any) {
<td
className={classNames(
styles.checkboxCell,
'prevent-nav',
'prevent-nav'
)}
>
<input
Expand Down

0 comments on commit ab4ac58

Please sign in to comment.