Skip to content

Commit

Permalink
Code review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
RadStr committed Feb 5, 2025
1 parent b3ed4db commit 805f43e
Show file tree
Hide file tree
Showing 39 changed files with 490 additions and 337 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { addSemanticClassProfileToVisualModelAction } from "./add-class-profile-
import { addSemanticGeneralizationToVisualModelAction } from "./add-generalization-to-visual-model";
import { addSemanticRelationshipToVisualModelAction } from "./add-relationship-to-visual-model";
import { addSemanticRelationshipProfileToVisualModelAction } from "./add-relationship-profile-to-visual-model";
import { EntityToDelete, checkIfIsAttributeOrAttributeProfile, convertToEntitiesToDeleteType, findTopLevelGroupFromVisualModel, getSelections, getViewportCenterForClassPlacement, setSelectionsInDiagram } from "./utilities";
import { EntityToDelete, checkIfIsAttributeOrAttributeProfile, convertToEntitiesToDeleteType, findTopLevelGroupInVisualModel, getSelections, getViewportCenterForClassPlacement, setSelectionsInDiagram } from "./utilities";
import { removeFromVisualModelAction } from "./remove-from-visual-model";
import { removeFromSemanticModelsAction } from "./remove-from-semantic-model";
import { openCreateAttributeDialogAction } from "./open-create-attribute-dialog";
Expand Down Expand Up @@ -621,7 +621,7 @@ function createActionsContext(
return;
}
withVisualModel(notifications, graph, (visualModel) => {
shiftAttributePositionAction(notifications, visualModel, domainNode, attribute, ShiftAttributeDirection.UP, 1);
shiftAttributePositionAction(notifications, visualModel, domainNode, attribute, ShiftAttributeDirection.Up, 1);
});
};

Expand All @@ -631,7 +631,7 @@ function createActionsContext(
return;
}
withVisualModel(notifications, graph, (visualModel) => {
shiftAttributePositionAction(notifications, visualModel, domainNode, attribute, ShiftAttributeDirection.DOWN, 1);
shiftAttributePositionAction(notifications, visualModel, domainNode, attribute, ShiftAttributeDirection.Down, 1);
});
};

Expand All @@ -654,13 +654,18 @@ function createActionsContext(
withVisualModel(notifications, graph, (visualModel) => {
const entityToDeleteWithAttributeData = entitiesToDelete.map(entityToDelete =>
({...entityToDelete,
isAttributeOrAttributeProfile: checkIfIsAttributeOrAttributeProfile(entityToDelete.identifier, graph.models, entityToDelete.sourceModel)
isAttributeOrAttributeProfile: checkIfIsAttributeOrAttributeProfile(
entityToDelete.identifier, graph.models, entityToDelete.sourceModel)
})
);
const attributesToBeDeleted = entityToDeleteWithAttributeData.filter(entity => entity.isAttributeOrAttributeProfile);
const notAttributesToBeDeleted = entityToDeleteWithAttributeData.filter(entity => !entity.isAttributeOrAttributeProfile);
removeFromVisualModelAction(notifications, visualModel, notAttributesToBeDeleted.map(entitiesToDelete => entitiesToDelete.identifier));
removeAttributesFromVisualModelAction(notifications, classes, visualModel, attributesToBeDeleted.map(entitiesToDelete => entitiesToDelete.identifier));
removeFromVisualModelAction(
notifications, visualModel,
notAttributesToBeDeleted.map(entitiesToDelete => entitiesToDelete.identifier));
removeAttributesFromVisualModelAction(
notifications, classes, visualModel,
attributesToBeDeleted.map(entitiesToDelete => entitiesToDelete.identifier));
});
removeFromSemanticModelsAction(notifications, graph, entitiesToDelete);
};
Expand All @@ -671,13 +676,15 @@ function createActionsContext(

const layoutActiveVisualModel = async (configuration: UserGivenConstraintsVersion4) => {
withVisualModel(notifications, graph, (visualModel) => {
return layoutActiveVisualModelAction(notifications, classes, diagram, graph, visualModel, configuration);
return layoutActiveVisualModelAction(
notifications, classes, diagram, graph, visualModel, configuration);
});
}

const addEntitiesFromSemanticModelToVisualModel = (semanticModel: EntityModel) => {
withVisualModel(notifications, graph, (visualModel) => {
addEntitiesFromSemanticModelToVisualModelAction(notifications, classes, graph, diagram, visualModel, semanticModel);
addEntitiesFromSemanticModelToVisualModelAction(
notifications, classes, graph, diagram, visualModel, semanticModel);
});
};

Expand Down Expand Up @@ -722,7 +729,8 @@ function createActionsContext(
return null;
}).filter(selectionFilter => selectionFilter !== null);

const filteredSelection = filterSelection(state.selections, relevantSelectionFilters, VisibilityFilter.ONLY_VISIBLE, null);
const filteredSelection = filterSelection(
state.selections, relevantSelectionFilters, VisibilityFilter.OnlyVisible, null);
setSelectionsInDiagram(filteredSelection, diagram);
};

Expand All @@ -738,7 +746,9 @@ function createActionsContext(
visibilityFilter: VisibilityFilter,
semanticModelFilter: Record<string, boolean> | null
) => {
const selectionExtension = await extendSelectionAction(notifications, graph, classes, nodeSelection, extensionTypes, visibilityFilter, false, semanticModelFilter);
const selectionExtension = await extendSelectionAction(
notifications, graph, classes, nodeSelection,
extensionTypes, visibilityFilter, false, semanticModelFilter);
return selectionExtension.selectionExtension;
};

Expand All @@ -748,25 +758,29 @@ function createActionsContext(
visibilityFilter: VisibilityFilter,
semanticModelFilter: Record<string, boolean> | null
) => {
return filterSelectionAction(notifications, graph, classes, selections, allowedClasses, visibilityFilter, semanticModelFilter);
return filterSelectionAction(
notifications, graph, classes, selections, allowedClasses, visibilityFilter, semanticModelFilter);
};

const highlightNodeInExplorationModeFromCatalog = (classIdentifier: string, modelOfClassWhichStartedHighlighting: string) => {
const highlightNodeInExplorationModeFromCatalog = (
classIdentifier: string,
modelOfClassWhichStartedHighlighting: string
) => {
withVisualModel(notifications, graph, (visualModel) => {
const nodeIdentifier = visualModel.getVisualEntityForRepresented(classIdentifier)?.identifier;
const isClassInVisualModel = nodeIdentifier !== undefined;
if (!isClassInVisualModel) {
return;
}

diagram.actions().highlightNodeInExplorationModeFromCatalog(nodeIdentifier, modelOfClassWhichStartedHighlighting);
diagram.actions().highlightNodeInExplorationModeFromCatalog(
nodeIdentifier, modelOfClassWhichStartedHighlighting);
});
}

// Prepare and set diagram callbacks.

const callbacks: DiagramCallbacks = {

onShowNodeDetail: (node) => openDetailDialog(node.externalIdentifier),

onEditNode: (node) => openModifyDialog(node.externalIdentifier),
Expand Down Expand Up @@ -812,7 +826,7 @@ function createActionsContext(
onToggleAnchorForNode: (nodeIdentifier) => {
console.log("Application.onToggleAnchorForNode", { nodeIdentifier });
withVisualModel(notifications, graph, (visualModel) => {
const topLevelGroup = findTopLevelGroupFromVisualModel(nodeIdentifier, visualModel);
const topLevelGroup = findTopLevelGroupInVisualModel(nodeIdentifier, visualModel);
toggleAnchorAction(notifications, visualModel, topLevelGroup ?? nodeIdentifier);
});
},
Expand Down Expand Up @@ -870,7 +884,7 @@ function createActionsContext(
withVisualModel(notifications, graph, (visualModel) => {
openCreateClassDialogAndCreateGeneralizationAction(
notifications, dialogs, classes, useClasses, options, graph, diagram,
visualModel, nodeIdentifier, isCreatedClassParent, positionToPlaceClassOn,
visualModel, nodeIdentifier, isCreatedClassParent, positionToPlaceClassOn
);
});
},
Expand All @@ -895,6 +909,15 @@ function createActionsContext(
const selectionIdentifiers = nodeSelection.concat(edgeSelection);
deleteVisualElements(selectionIdentifiers);
},
onRemoveAttributeFromVisualModel: function (attribute: string, _nodeIdentifer: string): void {
removeAttributesFromVisualModel([attribute])
},
onMoveAttributeUp: function (attribute: string, nodeIdentifer: string): void {
shiftAttributeUp(attribute, nodeIdentifer);
},
onMoveAttributeDown: function (attribute: string, nodeIdentifer: string): void {
shiftAttributeDown(attribute, nodeIdentifer);
},
};

diagram.setCallbacks(callbacks);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const addClassNeighborhoodToVisualModelAction = (
areIdentifiersFromVisualModel: false
};
const neighborhoodPromise = extendSelectionAction(notifications, graph, classes, inputForExtension,
[ExtensionType.ASSOCIATION, ExtensionType.GENERALIZATION], VisibilityFilter.ALL, false, null);
[ExtensionType.Association, ExtensionType.Generalization], VisibilityFilter.All, false, null);
neighborhoodPromise.then(neighborhood => {
const classesOrClassProfilesToAdd: EntityToAddToVisualModel[] = [{identifier, position: null}];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@ export function addSemanticAttributeToVisualModelAction(
notifications: UseNotificationServiceWriterType,
visualModel: WritableVisualModel,
domainIdentifier: string,
attribute: string | null,
attribute: string,
position: number | null,
) {
if(attribute === null) {
return;
}
const visualNode = visualModel.getVisualEntityForRepresented(domainIdentifier);
if(visualNode === null) {
notifications.error("The visual node representing domain is not present.");
return;
}
if(!isVisualNode(visualNode)) {
Expand All @@ -34,6 +32,7 @@ export function addSemanticAttributeToVisualModelAction(
visualModel.updateVisualEntity(visualNode.identifier, {content: newContent});
}

// TODO RadStr: 1 Action per file
/**
* @returns The visual content (attributes) of node to relevant values existing in semantic model.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ function createDefaultRelationshipProfiles(
) {
const writableSemanticModel = graph.models.get(writableCmeModel.dsIdentifier) as InMemorySemanticModel; // Casting ... the correctness should be already validated
for(const edgeToProfile of edgesToProfile) {
createDefaultRelationshipProfile(notifications, graph, writableSemanticModel, visualModel, edgeToProfile, createdClassProfiles, shouldBeAddedToVisualModel);
createDefaultRelationshipProfile(
notifications, graph, writableSemanticModel, visualModel,
edgeToProfile, createdClassProfiles, shouldBeAddedToVisualModel);
}
}

Expand All @@ -143,13 +145,13 @@ function createDefaultRelationshipProfile(
createdClassProfiles: Record<string, string | null>,
shouldBeAddedToVisualModel: boolean
) {
const relationshipOrRelationshipProfileToBeProfiled = getAndValidateRelationshipOrRelationshipProfileToBeProfiled(notifications, graph, entityToProfile);
if(relationshipOrRelationshipProfileToBeProfiled === null) {
const relationshipToProfile = getAndValidateRelationshipToBeProfiled(notifications, graph, entityToProfile);
if(relationshipToProfile === null) {
return;
}

const ends: SemanticModelRelationshipEndUsage[] | undefined = [];
for (const end of relationshipOrRelationshipProfileToBeProfiled.ends) {
for (const end of relationshipToProfile.ends) {
if(end.concept === null) {
return;
}
Expand All @@ -170,12 +172,12 @@ function createDefaultRelationshipProfile(
}

let usageNote = null;
if(isSemanticModelRelationshipUsage(relationshipOrRelationshipProfileToBeProfiled)) {
usageNote = relationshipOrRelationshipProfileToBeProfiled.usageNote;
if(isSemanticModelRelationshipUsage(relationshipToProfile)) {
usageNote = relationshipToProfile.usageNote;
}

const { success, id: identifier } = model.executeOperation(createRelationshipUsage({
usageOf: relationshipOrRelationshipProfileToBeProfiled.id,
usageOf: relationshipToProfile.id,
usageNote: usageNote,
ends: ends,
}));
Expand All @@ -192,26 +194,27 @@ function createDefaultRelationshipProfile(
}
}

function getAndValidateRelationshipOrRelationshipProfileToBeProfiled(
function getAndValidateRelationshipToBeProfiled(
notifications: UseNotificationServiceWriterType,
graph: ModelGraphContextType,
entityToProfile: string
): SemanticModelRelationship | SemanticModelRelationshipUsage | null {
const relationshipOrRelationshipProfileToBeProfiled = graph.aggregatorView.getEntities()?.[entityToProfile]?.aggregatedEntity;
if(relationshipOrRelationshipProfileToBeProfiled === undefined || relationshipOrRelationshipProfileToBeProfiled === null) {
const relationshipToProfile = graph.aggregatorView.getEntities()?.[entityToProfile]?.aggregatedEntity;
if(relationshipToProfile === undefined || relationshipToProfile === null) {
notifications.error("The entity (edge) to be profiled from selection is not present in aggregatorView");
return null;
}
if(isSemanticModelClassUsage(relationshipOrRelationshipProfileToBeProfiled)) { // The visual edge representing class profile
if(isSemanticModelClassUsage(relationshipToProfile)) { // The visual edge representing class profile
return null;
}
if(isSemanticModelGeneralization(relationshipOrRelationshipProfileToBeProfiled)) {
if(isSemanticModelGeneralization(relationshipToProfile)) {
return null;
}
if(!isSemanticModelRelationship(relationshipOrRelationshipProfileToBeProfiled) && !isSemanticModelRelationshipUsage(relationshipOrRelationshipProfileToBeProfiled)) {
if(!isSemanticModelRelationship(relationshipToProfile) &&
!isSemanticModelRelationshipUsage(relationshipToProfile)) {
notifications.error("The entity to be profiled from selection is not a association or association profile");
return null;
}

return relationshipOrRelationshipProfileToBeProfiled;
return relationshipToProfile;
}
Loading

0 comments on commit 805f43e

Please sign in to comment.