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

Change link/unlink behaviour to directly apply changes without showing modal or message #2523

Merged
merged 9 commits into from
Sep 4, 2024
84 changes: 28 additions & 56 deletions src/components/record/related-table-actions.tsx
Original file line number Diff line number Diff line change
@@ -1,53 +1,50 @@
import { MouseEvent, useState, useRef, useLayoutEffect } from 'react';
import { MouseEvent, useLayoutEffect, useRef, useState } from 'react';

// components
import DisplayValue from '@isrd-isi-edu/chaise/src/components/display-value';
import ChaiseTooltip from '@isrd-isi-edu/chaise/src/components/tooltip';
import RecordsetModal from '@isrd-isi-edu/chaise/src/components/modals/recordset-modal';
import DeleteConfirmationModal, { DeleteConfirmationModalTypes } from '@isrd-isi-edu/chaise/src/components/modals/delete-confirmation-modal';
import RecordsetModal from '@isrd-isi-edu/chaise/src/components/modals/recordset-modal';
import ChaiseTooltip from '@isrd-isi-edu/chaise/src/components/tooltip';
import Dropdown from 'react-bootstrap/Dropdown';
// hooks
import useRecord from '@isrd-isi-edu/chaise/src/hooks/record';
import useAuthn from '@isrd-isi-edu/chaise/src/hooks/authn';
import useAlert from '@isrd-isi-edu/chaise/src/hooks/alerts';
import useAuthn from '@isrd-isi-edu/chaise/src/hooks/authn';
import useError from '@isrd-isi-edu/chaise/src/hooks/error';
import useRecord from '@isrd-isi-edu/chaise/src/hooks/record';

// models
import { CommentDisplayModes } from '@isrd-isi-edu/chaise/src/models/displayname';
import { LogActions, LogParentActions, LogReloadCauses, LogStackPaths, LogStackTypes } from '@isrd-isi-edu/chaise/src/models/log';
import { RecordRelatedModel } from '@isrd-isi-edu/chaise/src/models/record';
import { LogActions, LogParentActions, LogReloadCauses } from '@isrd-isi-edu/chaise/src/models/log';
import {
RecordsetConfig,
RecordsetDisplayMode,
RecordsetProps,
RecordsetSelectMode,
SelectedRow,
} from '@isrd-isi-edu/chaise/src/models/recordset';
import { LogStackPaths, LogStackTypes } from '@isrd-isi-edu/chaise/src/models/log';
import { CommentDisplayModes } from '@isrd-isi-edu/chaise/src/models/displayname';

// providers
import { ChaiseAlertType } from '@isrd-isi-edu/chaise/src/providers/alerts';
jrchudy marked this conversation as resolved.
Show resolved Hide resolved

// services
import { LogService } from '@isrd-isi-edu/chaise/src/services/log';
import { CookieService } from '@isrd-isi-edu/chaise/src/services/cookie';
import { ConfigService } from '@isrd-isi-edu/chaise/src/services/config';
import { CookieService } from '@isrd-isi-edu/chaise/src/services/cookie';
import { LogService } from '@isrd-isi-edu/chaise/src/services/log';

// utils
import { addQueryParamsToURL } from '@isrd-isi-edu/chaise/src/utils/uri-utils';
import {
CUSTOM_EVENTS,
RECORDSET_DEFAULT_PAGE_SIZE,
} from '@isrd-isi-edu/chaise/src/utils/constants';
import { getRandomInt } from '@isrd-isi-edu/chaise/src/utils/math-utils';
import {
allowCustomModeRelated,
displayCustomModeRelated,
getPrefillCookieObject,
} from '@isrd-isi-edu/chaise/src/utils/record-utils';
import {
RECORDSET_DEFAULT_PAGE_SIZE,
CUSTOM_EVENTS,
} from '@isrd-isi-edu/chaise/src/utils/constants';
import { windowRef } from '@isrd-isi-edu/chaise/src/utils/window-ref';
import { getRandomInt } from '@isrd-isi-edu/chaise/src/utils/math-utils';
import { fireCustomEvent } from '@isrd-isi-edu/chaise/src/utils/ui-utils';
import Q from 'q';
import { addQueryParamsToURL } from '@isrd-isi-edu/chaise/src/utils/uri-utils';
import { windowRef } from '@isrd-isi-edu/chaise/src/utils/window-ref';
import ResizeSensor from 'css-element-queries/src/ResizeSensor';

type RelatedTableActionsProps = {
Expand Down Expand Up @@ -420,12 +417,6 @@ const RelatedTableActions = ({
.create(submissionRows, logObj)
.then(() => {
setAddPureBinaryModalProps(null);
addAlert(
<>
<code><DisplayValue value={usedRef.displayname}></DisplayValue></code> records have been successfully linked.
</>,
ChaiseAlertType.SUCCESS
);

const details = relatedModel.recordsetProps.config.containerDetails!;
updateRecordPage(true, undefined, [
Expand Down Expand Up @@ -519,29 +510,15 @@ const RelatedTableActions = ({
setShowPureBinarySpinner(true);

validateSessionBeforeMutation(() => {
const deleteResponse = (response: any) => {
setShowPureBinarySpinner(false);

// Show modal popup summarizing total # of deletions succeeded and failed
response.clickOkToDismiss = true;

// TODO: - improve partial success and use TRS to check delete rights before giving a checkbox
// - some errors could have been because of row level security
dispatchError({
error: response,
jrchudy marked this conversation as resolved.
Show resolved Hide resolved
isDismissible: true,
closeBtnCallback: () => {
// ask recordset to update the modal
if (!!containerRef.current) {
// NOTE: This feels very against React but the complexity of our flow control provider seems to warrant doing this
fireCustomEvent(CUSTOM_EVENTS.FORCE_UPDATE_RECORDSET, containerRef.current, {
cause: LogReloadCauses.ENTITY_BATCH_UNLINK,
pageStates: { updateResult: true, updateCount: true, updateFacets: true },
response: response,
});
}
},
});
const deleteResponse = () => {
leafReference
jrchudy marked this conversation as resolved.
Show resolved Hide resolved
.deleteBatchAssociationTuples(relatedModel.recordsetProps.parentTuple, selectedRows)
.then(()=>{
setUnlinkPureBinaryModalProps(null);
updateRecordPage(true, LogReloadCauses.RELATED_BATCH_UNLINK);
})
.catch(deleteError)
.finally(()=>setShowPureBinarySpinner(false));
jrchudy marked this conversation as resolved.
Show resolved Hide resolved
};
jrchudy marked this conversation as resolved.
Show resolved Hide resolved

const deleteError = (err: any) => {
Expand All @@ -554,10 +531,7 @@ const RelatedTableActions = ({
};

if (!CONFIRM_DELETE) {
return leafReference
jrchudy marked this conversation as resolved.
Show resolved Hide resolved
.deleteBatchAssociationTuples(relatedModel.recordsetProps.parentTuple, selectedRows)
.then(deleteResponse)
.catch(deleteError);
return deleteResponse();
}

logRecordClientAction(LogActions.UNLINK_INTEND);
Expand All @@ -574,10 +548,7 @@ const RelatedTableActions = ({
title: 'Confirm Unlink',
onConfirm: () => {
setShowDeleteConfirmationModal(null);
return leafReference
.deleteBatchAssociationTuples(relatedModel.recordsetProps.parentTuple, selectedRows)
.then(deleteResponse)
.catch(deleteError);
return deleteResponse();
},
onCancel: () => {
setShowDeleteConfirmationModal(null);
Expand All @@ -588,6 +559,7 @@ const RelatedTableActions = ({
});
});
};

setUnlinkPureBinarySubmitCB(() => submitCB);

setUnlinkPureBinaryModalProps({
Expand Down
Loading