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

Merge main back into dev #766

Merged
merged 2 commits into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ and this project does **not** adhere to [Semantic Versioning](https://semver.org

## [Unreleased]

## [0.2.1] - 2023-03-11

### Changed

- Revert previous change: Patients, vehicles, personnel and material inside a simulated region are now deleted, when the simulated region is deleted. For vehicles, personnel, and material, they will only be deleted if all that belong together are in the same simulated region.

### Fixed

- Exercises in which simulated regions are deleted no longer crash on import due missing patients in the tick action.

## [0.2.0] - 2023-03-10

### Added
Expand Down Expand Up @@ -76,7 +86,8 @@ and this project does **not** adhere to [Semantic Versioning](https://semver.org

### Initial unstable release of Digitale FüSim MANV

[Unreleased]: https://github.com/hpi-sam/digital-fuesim-manv/compare/0.2.0...HEAD
[0.2.0]: https://github.com/hpi-sam/digital-fuesim-manv/compare/0.1.0...0.2.0
[0.1.0]: https://github.com/hpi-sam/digital-fuesim-manv/compare/v0.0.0...0.1.0
[Unreleased]: https://github.com/hpi-sam/digital-fuesim-manv/compare/v0.2.1...HEAD
[0.2.1]: https://github.com/hpi-sam/digital-fuesim-manv/compare/v0.2.0...v0.2.1
[0.2.0]: https://github.com/hpi-sam/digital-fuesim-manv/compare/v0.1.0...v0.2.0
[0.1.0]: https://github.com/hpi-sam/digital-fuesim-manv/compare/v0.0.0...v0.1.0
[0.0.0]: https://github.com/hpi-sam/digital-fuesim-manv/compare/37bd43bc1beb4aa9ad597b1ac763dd71b5709737...v0.0.0
6 changes: 3 additions & 3 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "digital-fuesim-manv-backend",
"version": "0.2.0",
"version": "0.2.1",
"type": "module",
"scripts": {
"start:once:linux-macos": "NODE_ENV=production node --experimental-specifier-resolution=node dist/src/index.js",
Expand Down
6 changes: 3 additions & 3 deletions benchmark/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion benchmark/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "digital-fuesim-manv-benchmark",
"version": "0.2.0",
"version": "0.2.1",
"type": "module",
"scripts": {
"lint": "eslint --max-warnings 0 --ignore-path .gitignore \"./**/*.{ts,js,yml,html}\"",
Expand Down
2 changes: 1 addition & 1 deletion docs/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ openapi: 3.0.3
info:
title: Digital Fuesim MANV HTTP API
description: HTTP API of the digital-fuesim-manv project
version: 0.2.0
version: 0.2.1
paths:
/api/health:
get:
Expand Down
6 changes: 3 additions & 3 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "digital-fuesim-manv-frontend",
"version": "0.2.0",
"version": "0.2.1",
"type": "module",
"scripts": {
"cy:open": "cypress open",
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "digital-fuesim-manv",
"version": "0.2.0",
"version": "0.2.1",
"type": "module",
"scripts": {
"build": "cd shared && npm run build && cd .. && concurrently \"cd frontend && npm run build\" \"cd backend && npm run build\"",
Expand Down
4 changes: 2 additions & 2 deletions shared/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion shared/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "digital-fuesim-manv-shared",
"version": "0.2.0",
"version": "0.2.1",
"type": "module",
"main": "./dist/index.js",
"esnext": "./dist/index.js",
Expand Down
112 changes: 20 additions & 92 deletions shared/src/store/action-reducers/simulated-region.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { IsString, IsUUID, ValidateNested } from 'class-validator';
import { SimulatedRegion, TransferPoint } from '../../models';
import {
isInSpecificSimulatedRegion,
isInSpecificVehicle,
MapCoordinates,
MapPosition,
SimulatedRegionPosition,
Expand All @@ -22,103 +21,14 @@ import {
MaterialAvailableEvent,
} from '../../simulation';
import { sendSimulationEvent } from '../../simulation/events/utils';
import type { ExerciseState } from '../../state';
import type { Mutable } from '../../utils';
import { cloneDeepMutable, UUID, uuidValidationOptions } from '../../utils';
import { IsLiteralUnion, IsValue } from '../../utils/validators';
import type { Action, ActionReducer } from '../action-reducer';
import { ExpectedReducerError, ReducerError } from '../reducer-error';
import {
deleteTransferPoint,
TransferPointActionReducers,
} from './transfer-point';
import { TransferPointActionReducers } from './transfer-point';
import { isCompletelyLoaded } from './utils/completely-load-vehicle';
import { getElement, getElementByPredicate } from './utils/get-element';

/**
* This function assumes that every SimulatedRegion holds **ONLY** material,vehicles,patients and personnel
* (in any amount) and **ONE** TransferPoint.
* It only deletes material,vehicles and personnel if they are **ALL** in the SimulatedRegion to be deleted
* If one were to add more things to a SimulatedRegion one would have to change this function accordingly.
* @param draftState: The Draft State from which the SimulatedRegion should be deleted.
* @param simulatedRegionId: The Id of the SimulatedRegion that should be deleted.
*/

export function deleteSimulatedRegion(
draftState: Mutable<ExerciseState>,
simulatedRegionId: UUID
) {
// Delete the TransferPoint

const simulatedRegion = getElement(
draftState,
'simulatedRegion',
simulatedRegionId
);

const transferPointId = getElementByPredicate(
draftState,
'transferPoint',
(element) => isInSpecificSimulatedRegion(element, simulatedRegion.id)
).id;

deleteTransferPoint(draftState, transferPointId);

// Find related vehicles

const relatedVehicles = Object.values(draftState.vehicles).filter(
(vehicle) =>
isInSpecificSimulatedRegion(vehicle, simulatedRegionId) &&
Object.keys(vehicle.materialIds).every((materialId) => {
const material = getElement(draftState, 'material', materialId);
return (
isInSpecificSimulatedRegion(material, simulatedRegionId) ||
isInSpecificVehicle(material, vehicle.id)
);
}) &&
Object.keys(vehicle.personnelIds).every((personnelId) => {
const personnel = getElement(
draftState,
'personnel',
personnelId
);
return (
isInSpecificSimulatedRegion(personnel, simulatedRegionId) ||
isInSpecificVehicle(personnel, vehicle.id)
);
})
);

// Find and delete related materials and personnel

relatedVehicles.forEach((vehicle) => {
Object.keys(vehicle.materialIds).forEach(
(vehicleId) => delete draftState.materials[vehicleId]
);
Object.keys(vehicle.personnelIds).forEach(
(personnelId) => delete draftState.personnel[personnelId]
);
});

// Delete related vehicles

relatedVehicles.forEach(
(vehicle) => delete draftState.vehicles[vehicle.id]
);

// Find and delete related patients

Object.values(draftState.patients)
.filter((patients) =>
isInSpecificSimulatedRegion(patients, simulatedRegionId)
)
.forEach((patients) => delete draftState.patients[patients.id]);

// Delete the SimulatedRegion

delete draftState.simulatedRegions[simulatedRegionId];
}

export class AddSimulatedRegionAction implements Action {
@IsValue('[SimulatedRegion] Add simulated region' as const)
readonly type = '[SimulatedRegion] Add simulated region';
Expand Down Expand Up @@ -236,7 +146,25 @@ export namespace SimulatedRegionActionReducers {
{
action: RemoveSimulatedRegionAction,
reducer: (draftState, { simulatedRegionId }) => {
deleteSimulatedRegion(draftState, simulatedRegionId);
const simulatedRegion = getElement(
draftState,
'simulatedRegion',
simulatedRegionId
);
const transferPoint = getElementByPredicate(
draftState,
'transferPoint',
(element) =>
isInSpecificSimulatedRegion(element, simulatedRegion.id)
);
TransferPointActionReducers.removeTransferPoint.reducer(
draftState,
{
type: '[TransferPoint] Remove TransferPoint',
transferPointId: transferPoint.id,
}
);
delete draftState.simulatedRegions[simulatedRegionId];
return draftState;
},
rights: 'trainer',
Expand Down
Loading