Skip to content

Commit

Permalink
[record-merging] Create event for record-merging
Browse files Browse the repository at this point in the history
This fixes a bug in which the Merging Dialog was
closing right when beginning the merge for exactly two agents.
  • Loading branch information
melton-jason committed Aug 14, 2023
1 parent 7a2ee15 commit bc9fb10
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Expand Up @@ -24,6 +24,10 @@ import type { Tables } from './types';

// FEATURE: use this everywhere
export const resourceEvents = eventListener<{
readonly merged: [
source: SpecifyResource<AnySchema>,
target: SpecifyResource<AnySchema>
];
readonly deleted: SpecifyResource<AnySchema>;
}>();

Expand Down
10 changes: 6 additions & 4 deletions specifyweb/frontend/js_src/lib/components/Merging/index.tsx
Expand Up @@ -76,7 +76,7 @@ export function RecordMergingLink({

React.useEffect(
() =>
resourceEvents.on('deleted', (resource) => {
resourceEvents.on('merged', ([resource]) => {
needUpdateQueryResults.current = true;
handleDeleted(resource.id);
}),
Expand Down Expand Up @@ -111,8 +111,10 @@ export function MergingDialog(): JSX.Element | null {
);
React.useEffect(
() =>
resourceEvents.on('deleted', (resource) =>
setIds(ids.filter((id) => id !== resource.id).join(','))
resourceEvents.on('merged', ([resource, target]) =>
setIds(
ids.filter((id) => id !== resource.id || id !== target.id).join(',')
)
),
[ids, setIds]
);
Expand Down Expand Up @@ -252,7 +254,7 @@ function Merging({
* (the RecordMergingLink component is listening to the event)
*/
for (const clone of clones) {
resourceEvents.trigger('deleted', clone);
resourceEvents.trigger('merged', [clone, target]);
}
})
);
Expand Down

0 comments on commit bc9fb10

Please sign in to comment.