Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display a loading bar for the merging process #3864

Merged
merged 36 commits into from Aug 15, 2023
Merged
Changes from 4 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
a570b5d
Display a loading bar for the merging process
CarolineDenis Jul 28, 2023
73b74f8
Call Status in merge component
CarolineDenis Jul 31, 2023
ea2f9d6
In progress
CarolineDenis Jul 31, 2023
ba2a335
Introduce remaining status
CarolineDenis Jul 31, 2023
f9bdff5
Work in progress
CarolineDenis Aug 1, 2023
147161f
Move mergeId setter to parent
CarolineDenis Aug 1, 2023
ff01f05
Remove handleClose from onMerge
CarolineDenis Aug 1, 2023
522f9a9
Modify back end to have access to status
CarolineDenis Aug 1, 2023
1bf0d76
Set status
CarolineDenis Aug 1, 2023
e014af8
Combine states in one state
CarolineDenis Aug 2, 2023
6c8e240
Use destructured object for API response
CarolineDenis Aug 2, 2023
dc45f35
Bring back conditional for array of ids contain less than 2 items
CarolineDenis Aug 2, 2023
9d1adcf
Remove comments
CarolineDenis Aug 2, 2023
d3ae80c
Use destructorCalled
CarolineDenis Aug 2, 2023
5228093
Simplify code
CarolineDenis Aug 2, 2023
52407fe
Narrow down status type
CarolineDenis Aug 2, 2023
c64cf44
Fix back end issue
CarolineDenis Aug 2, 2023
1ecdd23
Add visual loading bar
CarolineDenis Aug 2, 2023
aee2e0b
Comment out code for abort
CarolineDenis Aug 2, 2023
90bbe5f
Modify back end for status
CarolineDenis Aug 2, 2023
4a4c652
refactor(Merging): Clean up status code
maxpatiiuk Aug 3, 2023
8ae8fbc
Export types to new file
CarolineDenis Aug 3, 2023
f3f906a
Merge remote-tracking branch 'origin/v7.9-dev' into merging-progress-bar
CarolineDenis Aug 3, 2023
e20dd88
Add abort button + abort notification
CarolineDenis Aug 3, 2023
257a3fc
Move Status to seprate file
CarolineDenis Aug 3, 2023
7f013a2
Add key to map children
CarolineDenis Aug 3, 2023
7d3013a
Add dimension key to progress dialog to differentiate merging from st…
CarolineDenis Aug 3, 2023
8995d00
Close status dialog and reload query builder after success
CarolineDenis Aug 3, 2023
a162675
Add a close button in status dialog when success
CarolineDenis Aug 4, 2023
8cf24bf
Update merging localized strings
CarolineDenis Aug 4, 2023
f401692
[record-merging] Rerun query after merge has completed
melton-jason Aug 11, 2023
7a2ee15
Display remaining time below loading bar
CarolineDenis Aug 14, 2023
bc9fb10
[record-merging] Create event for record-merging
melton-jason Aug 14, 2023
904ddc9
Revert "[record-merging] Create event for record-merging"
melton-jason Aug 14, 2023
8ae72bc
[record-merging] move event call to Status component
melton-jason Aug 14, 2023
ca751cd
Merge remote-tracking branch 'origin/v7.9-dev' into merging-progress-bar
CarolineDenis Aug 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
76 changes: 74 additions & 2 deletions specifyweb/frontend/js_src/lib/components/Merging/index.tsx
Expand Up @@ -11,7 +11,7 @@ import { treeText } from '../../localization/tree';
import { ajax } from '../../utils/ajax';
import { Http } from '../../utils/ajax/definitions';
import { f } from '../../utils/functools';
import type { RA } from '../../utils/types';
import type { GetSet, RA } from '../../utils/types';
import { filterArray } from '../../utils/types';
import { multiSortFunction, removeKey } from '../../utils/utils';
import { ErrorMessage } from '../Atoms';
Expand Down Expand Up @@ -39,6 +39,9 @@ import { userPreferences } from '../Preferences/userPreferences';
import { SpecifyResource } from '../DataModel/legacyTypes';
import { SaveBlockedDialog } from '../Forms/Save';
import { useBooleanState } from '../../hooks/useBooleanState';
import { softFail } from '../Errors/Crash';
import { wbText } from '../../localization/workbench';
import { RemainingLoadingTime } from '../WorkBench/RemainingLoadingTime';

export const recordMergingTables = new Set<keyof Tables>(['Agent']);

Expand Down Expand Up @@ -171,6 +174,16 @@ function Merging({
true
);

const [mergeId, setMergeId] = React.useState('');

const [loadingBar, setLoadingBar] = React.useState(false);

React.useEffect(() => {
if (mergeId !== '') {
setLoadingBar(true);
}
}, [mergeId]);

return records === undefined || merged === undefined ? null : (
<MergeDialogContainer
buttons={
Expand Down Expand Up @@ -199,6 +212,9 @@ function Merging({
onClose={handleClose}
>
{typeof error === 'string' && <ErrorMessage>{error}</ErrorMessage>}
{loadingBar && (
<Status mergingId={mergeId} loadingBar={[loadingBar, setLoadingBar]} />
CarolineDenis marked this conversation as resolved.
Show resolved Hide resolved
)}
<CompareRecords
formId={id('form')}
needUpdate={needUpdate}
Expand Down Expand Up @@ -239,6 +255,7 @@ function Merging({
errorMode: 'dismissible',
}
).then((response) => {
setMergeId(response.data);
if (response.status === Http.NOT_ALLOWED) {
CarolineDenis marked this conversation as resolved.
Show resolved Hide resolved
setError(response.data);
return;
Expand All @@ -248,6 +265,7 @@ function Merging({
}

setError(undefined);
// setLoadingBar(true);
handleClose();
})
);
Expand All @@ -261,9 +279,11 @@ function Merging({
function MergeButton<SCHEMA extends AnySchema>({
id,
mergeResource,
}: {
}: // mergeId,
{
readonly id: (suffix: string) => string;
readonly mergeResource: SpecifyResource<SCHEMA>;
// readonly mergeId: string;
}): JSX.Element {
const [formId] = React.useState(id('form'));
const [saveBlocked, setSaveBlocked] = React.useState(false);
Expand Down Expand Up @@ -361,6 +381,58 @@ function MergeButton<SCHEMA extends AnySchema>({
);
}

export function Status({
CarolineDenis marked this conversation as resolved.
Show resolved Hide resolved
mergingId,
loadingBar: [_, setLoadingBar],
}: {
readonly mergingId: string;
readonly loadingBar: GetSet<boolean>;
}): JSX.Element {
const [status, setStatus] = React.useState<string>();
const [total, setTotal] = React.useState<number>();
const [current, setCurrent] = React.useState<number>();
CarolineDenis marked this conversation as resolved.
Show resolved Hide resolved

React.useEffect(() => {
const fetchStatus = () =>
void ajax(`/api/merging_status/${mergingId}/`, {
// eslint-disable-next-line @typescript-eslint/naming-convention
headers: { Accept: 'application/json' },
})
.then((data) => {
CarolineDenis marked this conversation as resolved.
Show resolved Hide resolved
console.log(data);
CarolineDenis marked this conversation as resolved.
Show resolved Hide resolved
if (data === null) return undefined;
else {
// setStatus(data.status);
// setTotal(data.total);
// setCurrent(data.current);
globalThis.setTimeout(fetchStatus, 2000);
}
return undefined;
CarolineDenis marked this conversation as resolved.
Show resolved Hide resolved
})
.catch(softFail);
fetchStatus();
}, [mergingId]);

return (
<Dialog
buttons={
<Button.Danger onClick={() => setLoadingBar(false)}>
CarolineDenis marked this conversation as resolved.
Show resolved Hide resolved
{wbText.stop()}
CarolineDenis marked this conversation as resolved.
Show resolved Hide resolved
</Button.Danger>
}
className={{ container: dialogClassNames.narrowContainer }}
header={mergingText.mergeRecords()}
onClose={undefined}
>
{'test'}
CarolineDenis marked this conversation as resolved.
Show resolved Hide resolved
{status}
{current !== undefined && total !== undefined ? (
<RemainingLoadingTime current={current} total={total} />
) : null}
</Dialog>
);
}

export function MergeDialogContainer({
children,
buttons,
Expand Down