Skip to content

Commit 8488d93

Browse files
authored
Merge pull request #278 from GBSL-Informatik:regression-page-index-loading-behavior
regression(page-index): fix loading clashes of 'replace' and 'add-if-missing' load configs
2 parents fca6430 + d930d89 commit 8488d93

7 files changed

Lines changed: 35 additions & 13 deletions

File tree

packages/tdev/page-read-check/model/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { iTaskableDocument } from '@tdev-models/iTaskableDocument';
44
import { Document as DocumentProps, TypeDataMapping, Factory } from '@tdev-api/document';
55
import DocumentStore from '@tdev-stores/DocumentStore';
66
import { ModelMeta } from './ModelMeta';
7-
import { mdiBookCheck, mdiBookCheckOutline, mdiBookEducation, mdiBookOpenVariantOutline } from '@mdi/js';
7+
import { mdiBookCheck, mdiBookEducation, mdiBookOpenVariantOutline } from '@mdi/js';
88
import { fSeconds, fSecondsLong } from '../helpers/time';
99

1010
export const createModel: Factory = (data, store) => {

src/components/EditingOverview/index.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import styles from './styles.module.scss';
55
import { observer } from 'mobx-react-lite';
66
import { useStore } from '@tdev-hooks/useStore';
77
import Button from '@tdev-components/shared/Button';
8-
import { mdiAccountAlert, mdiAccountSyncOutline, mdiCheckboxMultipleMarkedCircle } from '@mdi/js';
8+
import { mdiAccountSyncOutline, mdiCheckboxMultipleMarkedCircle } from '@mdi/js';
99
import { StateType } from '@tdev-api/document';
1010
import Icon from '@mdi/react';
1111
import Popup from 'reactjs-popup';
@@ -62,10 +62,11 @@ const EditingOverview = observer(() => {
6262
if (!isBrowser || !currentUser || !currentPage) {
6363
return null;
6464
}
65-
const taskStates = currentPage.taskableDocuments.filter((ts) => RWAccess.has(ts.root?.permission)) || [];
66-
if (taskStates.length === 0) {
65+
const taskableDocumentsCount = currentPage.taskableDocumentRootIds.length;
66+
if (taskableDocumentsCount === 0) {
6767
return null;
6868
}
69+
const taskStates = currentPage.taskableDocuments.filter((ts) => RWAccess.has(ts.root?.permission)) || [];
6970
const someChecked = taskStates.some((d) => d.isDone);
7071
const allChecked = someChecked && taskStates.every((d) => d.isDone);
7172
return (

src/hooks/useDocumentRoot.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ export const useDocumentRoot = <Type extends DocumentType>(
4646
() => documentRootStore.find(id),
4747
(docRoot) => {
4848
if (docRoot) {
49+
if (docRoot.isLoadable && !docRoot.isLoaded) {
50+
documentRootStore.loadInNextBatch(
51+
id!,
52+
meta,
53+
{ skipCreate: !!skipCreate, documentType: loadOnlyType, documentRoot: 'replace' },
54+
access
55+
);
56+
}
4957
return;
5058
}
5159
if (addDummyToStore) {

src/hooks/useFirstMainDocument.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const useFirstMainDocument = <Type extends DocumentType>(
2525
loadOnlyType?: DocumentType
2626
) => {
2727
const defaultDocId = useDummyId(documentRootId);
28-
const documentRoot = useDocumentRoot(documentRootId, meta, true, access, undefined, loadOnlyType);
28+
const documentRoot = useDocumentRoot(documentRootId, meta, true, access, false, loadOnlyType);
2929
const userStore = useStore('userStore');
3030
const documentStore = useStore('documentStore');
3131
const [dummyDocument] = React.useState(

src/models/Page.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,9 @@ export default class Page {
209209

210210
@computed
211211
get stepsOnPage(): number {
212-
return this.taskableDocuments.length;
212+
// use the id's, otherwise not yet created documents would not be counted,
213+
// which leads to wrong progress values until all documents are loaded
214+
return this.taskableDocumentRootIds.length;
213215
}
214216

215217
@computed

src/stores/DocumentRootStore.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,13 @@ export class DocumentRootStore extends iStore {
146146
accessConfig?: Partial<Config>
147147
) {
148148
if (this.queued.has(id)) {
149-
return;
149+
const currentConfig = this.queued.get(id);
150+
const needsReplacement =
151+
loadConfig?.documentRoot === 'replace' && currentConfig?.load.documentRoot !== 'replace';
152+
if (!needsReplacement) {
153+
// already queued with same or higher loadConfig - do nothing
154+
return;
155+
}
150156
}
151157
this.queued.set(id, {
152158
meta: meta,

src/stores/PageStore.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,14 @@ export const SidebarVersions = (
2222
).versions.map((version) => {
2323
const versionPath = ensureTrailingSlash(version.path);
2424
const slashCount = version.path.split('/').length + 1;
25-
const rdocs = version.docs.filter(
26-
(doc) =>
25+
const rdocs = version.docs.filter((doc) => {
26+
if (version.mainDocId === 'index' && doc.id === version.mainDocId) {
27+
return true;
28+
}
29+
return (
2730
doc.path.startsWith(version.path) && doc.path.replace(/\/$/, '').split('/').length === slashCount
28-
);
31+
);
32+
});
2933
return {
3034
name: version.name,
3135
rootPaths: rdocs.map((doc) => ensureTrailingSlash(doc.path)),
@@ -136,14 +140,15 @@ export class PageStore extends iStore {
136140

137141
@action
138142
setCurrentPath(path: string | undefined) {
139-
if (path === this.currentPath) {
143+
const normalizedPath = path?.replace(BasePathRegex, '/');
144+
if (normalizedPath === this.currentPath) {
140145
return;
141146
}
142-
if (!path) {
147+
if (!normalizedPath) {
143148
this.currentPath = undefined;
144149
return;
145150
}
146-
this.currentPath = path.replace(BasePathRegex, '/');
151+
this.currentPath = normalizedPath;
147152
if (this.isPageIndexLoaded) {
148153
this.loadTaskableDocuments(this.currentStudentGroupName);
149154
}

0 commit comments

Comments
 (0)