Skip to content

Commit

Permalink
Fixes for RevisionsDialog
Browse files Browse the repository at this point in the history
- Dismiss modal on save
- Prevent form from submitting on button clicks
- Controls document revision change through manager fn
- Fix unchecked access on revisions list
  • Loading branch information
allanlasser committed Jan 8, 2024
1 parent 7a2055b commit 71c2c94
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 13 deletions.
9 changes: 7 additions & 2 deletions src/api/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,18 @@ export async function changeAccess(ids, access) {

export async function changeRevisionControl(ids, revision_control) {
// Enable or disable revision control on specified documents
await session.patch(
apiUrl(`documents/`),
const { data } = await session.patch(
apiUrl(
queryBuilder(`documents/`, {
expand: [DEFAULT_EXPAND, "revisions"].join(","),
}),
),
ids.map((id) => ({
id,
revision_control,
})),
);
return data;
}

export async function reprocessDocument(ids, forceOcr, ocrEngine) {
Expand Down
12 changes: 8 additions & 4 deletions src/common/dialog/RevisionsDialog.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
export let enabled: boolean = false;
export let revisions: Revision[] | null = [];
export let onSave: (enabled: boolean) => void;
export let onCancel: () => {};
export let onCancel: () => void;
$: sortedRevisions =
revisions?.sort((a, b) => {
return b.version - a.version;
}) ?? [];
}) ?? null;
let user;
let loading = false;
Expand Down Expand Up @@ -57,7 +57,7 @@
<PremiumBadge />
</header>

{#if enabled}
{#if enabled && Array.isArray(revisions)}
<div class="overflow-scroll">
<table class="revisions">
{#each sortedRevisions as revision}
Expand Down Expand Up @@ -89,7 +89,11 @@
{/if}

{#if isPremiumOrg(user?.organization)}
<form>
<form
on:submit={(event) => {
event.preventDefault();
}}
>
<label class="revision-control-input">
<input
type="checkbox"
Expand Down
12 changes: 8 additions & 4 deletions src/common/dialog/RevisionsDialogContainer.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { changeRevisionControl } from "../../api/document.js";
import { changeRevisionControlForDocuments } from "../../manager/documents";
import { viewer } from "../../viewer/viewer.js";
import RevisionsDialog from "./RevisionsDialog.svelte";
import emitter from "../../emit.js";
Expand All @@ -12,9 +12,13 @@
const documentId = document?.id;
const revisions = document?.revisions;
const enabled = document?.revisionControl;
const onSave = (enabled: boolean) =>
changeRevisionControl([documentId], enabled);
const onCancel = () => emit.dismiss();
const onSave = async (enabled: boolean) => {
await changeRevisionControlForDocuments([document], enabled);
emit.dismiss();
};
const onCancel = () => {
emit.dismiss();
};
</script>

<RevisionsDialog {documentId} {revisions} {enabled} {onSave} {onCancel} />
28 changes: 25 additions & 3 deletions src/manager/documents.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import {
editMetadata,
addData,
removeData,
} from "@/api/document.js";
changeRevisionControl,
} from "../api/document.js";
import {
addDocumentsToProject,
removeDocumentsFromProject,
} from "@/api/project.js";
import { layout, hideAccess } from "./layout.js";
} from "../api/project.js";
import { layout, hideAccess, hideRevisions } from "./layout.js";
import { wrapLoad, wrapSeparate } from "@/util/wrapLoad.js";
import { showConfirm } from "./confirmDialog.js";
import { router } from "@/router/router.js";
Expand Down Expand Up @@ -433,6 +434,27 @@ export async function changeAccessForDocuments(
hideAccess();
}

export async function changeRevisionControlForDocuments(
documents,
revision_control,
) {
await wrapLoad(layout, async () => {
await changeRevisionControl(
documents.map((doc) => doc.id),
revision_control,
);
documents.forEach((doc) => {
updateInCollection(doc, (d) => {
d.doc = {
...d.doc,
revision_control,
};
});
});
});
hideRevisions();
}

export async function changeOwnerForDocuments(
documents,
user,
Expand Down

0 comments on commit 71c2c94

Please sign in to comment.