hide the revert button on the migration page on the web ui if it cannot be reverted to that revision w/ burnettk (#1935)

Co-authored-by: jasquat <jasquat@users.noreply.github.com>
This commit is contained in:
jasquat 2024-07-16 14:26:58 -04:00 committed by GitHub
parent dfce83c684
commit 461b37d3d9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 80 additions and 43 deletions

View File

@ -1344,6 +1344,12 @@ paths:
description: The unique id of an existing process instance.
schema:
type: integer
- name: target_bpmn_process_hash
in: query
required: false
description: The full bpmn process hash of the target version of the process model.
schema:
type: string
get:
tags:
- Process Instances

View File

@ -551,6 +551,7 @@ def process_instance_reset(
def process_instance_check_can_migrate(
process_instance_id: int,
modified_process_model_identifier: str,
target_bpmn_process_hash: str | None = None,
) -> flask.wrappers.Response:
process_instance = _find_process_instance_by_id_or_raise(process_instance_id)
return_dict: dict = {
@ -560,7 +561,9 @@ def process_instance_check_can_migrate(
"current_bpmn_process_hash": process_instance.bpmn_process.bpmn_process_definition.full_process_model_hash,
}
try:
ProcessInstanceService.check_process_instance_can_be_migrated(process_instance)
ProcessInstanceService.check_process_instance_can_be_migrated(
process_instance, target_bpmn_process_hash=target_bpmn_process_hash
)
except (ProcessInstanceMigrationNotSafeError, ProcessInstanceMigrationUnnecessaryError) as exception:
return_dict["can_migrate"] = False
return_dict["exception_class"] = exception.__class__.__name__

View File

@ -558,3 +558,9 @@ export interface MigrationEvent {
timestamp: string;
username: string;
}
export interface MigrationCheckResult {
can_migrate: boolean;
process_instance_id: number;
current_git_revision: string;
current_bpmn_process_hash: string;
}

View File

@ -21,31 +21,49 @@ import HttpService from '../services/HttpService';
import ProcessBreadcrumb from '../components/ProcessBreadcrumb';
import { useUriListForPermissions } from '../hooks/UriListForPermissions';
import { MigrationEvent } from '../interfaces';
import { MigrationEvent, MigrationCheckResult } from '../interfaces';
import CellRenderer from '../a-spiffui-v2/views/Dashboards/myProcesses/CellRenderer';
function DangerousMigrationButton({
successCallback,
failureCallback,
migrationEvent,
targetBpmnProcessHash,
title,
buttonText = 'Migrate to Newest',
}: {
successCallback: (result: any) => void;
failureCallback: (error: any) => void;
title?: string;
migrationEvent?: MigrationEvent;
targetBpmnProcessHash?: string;
buttonText?: string;
}) {
const params = useParams();
const [openDialog, setOpenDialog] = useState(false);
const [isLoading, setIsLoading] = useState(false);
const { targetUris } = useUriListForPermissions();
const [migrationCheckResult, setMigrationCheckResult] =
useState<MigrationCheckResult | null>(null);
useEffect(() => {
let queryParams = '';
if (targetBpmnProcessHash) {
queryParams = `?target_bpmn_process_hash=${targetBpmnProcessHash}`;
}
HttpService.makeCallToBackend({
path: `/process-instances/${params.process_model_id}/${params.process_instance_id}/check-can-migrate${queryParams}`,
successCallback: (result: any) => setMigrationCheckResult(result),
});
}, [
targetBpmnProcessHash,
params.process_model_id,
params.process_instance_id,
]);
const handleRunMigration = () => {
setIsLoading(true);
let queryParams = '';
if (migrationEvent) {
queryParams = `?target_bpmn_process_hash=${migrationEvent.initial_bpmn_process_hash}`;
if (targetBpmnProcessHash) {
queryParams = `?target_bpmn_process_hash=${targetBpmnProcessHash}`;
}
HttpService.makeCallToBackend({
httpMethod: 'POST',
@ -71,6 +89,7 @@ function DangerousMigrationButton({
setOpenDialog(false);
};
if (migrationCheckResult?.can_migrate) {
return (
<>
<Button
@ -107,6 +126,8 @@ function DangerousMigrationButton({
</Dialog>
</>
);
}
return null;
}
function MigrationStatus({
migrationCheckResult,
@ -159,7 +180,8 @@ function MigrationStatus({
export default function ProcessInstanceMigratePage() {
const params = useParams();
const [migrationCheckResult, setMigrationCheckResult] = useState<any>(null);
const [migrationCheckResult, setMigrationCheckResult] =
useState<MigrationCheckResult | null>(null);
const [migrationResult, setMigrationResult] = useState<any>(null);
const [migrationEvents, setMigrationEvents] = useState<
MigrationEvent[] | null
@ -291,7 +313,7 @@ export default function ProcessInstanceMigratePage() {
successCallback={onMigrationComplete}
failureCallback={onMigrationFailure}
title={`Run another migration to switch to model version: '${data.row.initial_git_revision}'`}
migrationEvent={data.row}
targetBpmnProcessHash={data.row.initial_bpmn_process_hash}
buttonText="Revert"
/>
);