Skip to content

Commit

Permalink
[241] Make the explorer use editingContextId instead of projectId
Browse files Browse the repository at this point in the history
Bug: #241
Signed-off-by: Stéphane Bégaudeau <[email protected]>
  • Loading branch information
sbegaudeau committed Jan 18, 2021
1 parent ffb4ab3 commit a7faa3c
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2020 Obeo.
* Copyright (c) 2019, 2021 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -29,8 +29,8 @@ public class TreeConfiguration implements IRepresentationConfiguration {

private final List<String> expanded;

public TreeConfiguration(UUID projectId, List<String> expanded) {
String uniqueId = projectId.toString() + expanded.toString();
public TreeConfiguration(UUID editingContextId, List<String> expanded) {
String uniqueId = editingContextId.toString() + expanded.toString();
this.treeId = UUID.nameUUIDFromBytes(uniqueId.getBytes());
this.expanded = Objects.requireNonNull(expanded);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2020 Obeo.
* Copyright (c) 2019, 2021 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -29,15 +29,15 @@
*/
@GraphQLInputObjectType
public final class TreeEventInput implements IInput {
private UUID projectId;
private UUID editingContextId;

private List<String> expanded;

@GraphQLID
@GraphQLField
@GraphQLNonNull
public UUID getProjectId() {
return this.projectId;
public UUID getEditingContextId() {
return this.editingContextId;
}

@GraphQLField
Expand All @@ -48,7 +48,7 @@ public UUID getProjectId() {

@Override
public String toString() {
String pattern = "{0} '{'projectId: {1}, expanded: {2}'}'"; //$NON-NLS-1$
return MessageFormat.format(pattern, this.getClass().getSimpleName(), this.projectId, this.expanded);
String pattern = "{0} '{'editingContextId: {1}, expanded: {2}'}'"; //$NON-NLS-1$
return MessageFormat.format(pattern, this.getClass().getSimpleName(), this.editingContextId, this.expanded);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ public Publisher<IPayload> get(DataFetchingEnvironment environment) throws Excep
String subscriptionId = this.dataFetchingEnvironmentService.getSubscriptionId(environment);
Principal principal = this.dataFetchingEnvironmentService.getPrincipal(environment).orElse(null);

var treeConfiguration = new TreeConfiguration(input.getProjectId(), input.getExpanded());
var treeConfiguration = new TreeConfiguration(input.getEditingContextId(), input.getExpanded());

// @formatter:off
return this.editingContextEventProcessorRegistry.getOrCreateEditingContextEventProcessor(input.getProjectId())
return this.editingContextEventProcessorRegistry.getOrCreateEditingContextEventProcessor(input.getEditingContextId())
.flatMap(processor -> processor.acquireRepresentationEventProcessor(ITreeEventProcessor.class, treeConfiguration, new SubscriptionDescription(principal, subscriptionId)))
.map(IRepresentationEventProcessor::getOutputEvents)
.orElse(Flux.empty());
Expand Down
11 changes: 9 additions & 2 deletions frontend/src/explorer/Explorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,23 @@ import { Tree } from 'tree/Tree';
import styles from './Explorer.module.css';

const propTypes = {
editingContextId: PropTypes.string.isRequired,
tree: PropTypes.object.isRequired,
onExpand: PropTypes.func.isRequired,
selection: PropTypes.object,
setSelection: PropTypes.func.isRequired,
};

export const Explorer = ({ projectId, tree, onExpand, selection, setSelection }) => {
export const Explorer = ({ editingContextId, tree, onExpand, selection, setSelection }) => {
return (
<div className={styles.explorer} data-testid="explorer">
<Tree projectId={projectId} tree={tree} onExpand={onExpand} selection={selection} setSelection={setSelection} />
<Tree
editingContextId={editingContextId}
tree={tree}
onExpand={onExpand}
selection={selection}
setSelection={setSelection}
/>
</div>
);
};
Expand Down
13 changes: 10 additions & 3 deletions frontend/src/explorer/ExplorerWebSocketContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,19 @@ import { getTreeEventSubscription } from './getTreeEventSubscription';
import { initialState, reducer } from './reducer';

const propTypes = {
editingContextId: PropTypes.string.isRequired,
selection: PropTypes.object,
setSelection: PropTypes.func.isRequired,
};

export const ExplorerWebSocketContainer = ({ projectId, selection, setSelection }) => {
export const ExplorerWebSocketContainer = ({ editingContextId, selection, setSelection }) => {
const [state, dispatch] = useReducer(reducer, initialState);
const { viewState, tree, expanded, maxDepth, message } = state;

const { error } = useSubscription(gql(getTreeEventSubscription(maxDepth)), {
variables: {
input: {
projectId,
editingContextId,
expanded,
},
},
Expand Down Expand Up @@ -71,7 +72,13 @@ export const ExplorerWebSocketContainer = ({ projectId, selection, setSelection
}

return (
<Explorer projectId={projectId} tree={tree} onExpand={onExpand} selection={selection} setSelection={setSelection} />
<Explorer
editingContextId={editingContextId}
tree={tree}
onExpand={onExpand}
selection={selection}
setSelection={setSelection}
/>
);
};
ExplorerWebSocketContainer.propTypes = propTypes;
7 changes: 3 additions & 4 deletions frontend/src/tree/Tree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ import React, { useEffect, useRef } from 'react';
import { TreeItem } from 'tree/TreeItem';

const propTypes = {
editingContextId: PropTypes.string.isRequired,
tree: PropTypes.object.isRequired,
onExpand: PropTypes.func.isRequired,
selection: PropTypes.object,
displayedRepresentation: PropTypes.object,
setSelection: PropTypes.func.isRequired,
};

export const Tree = ({ projectId, tree, onExpand, selection, displayedRepresentation, setSelection }) => {
export const Tree = ({ editingContextId, tree, onExpand, selection, setSelection }) => {
const treeElement = useRef(null);

useEffect(() => {
Expand Down Expand Up @@ -88,12 +88,11 @@ export const Tree = ({ projectId, tree, onExpand, selection, displayedRepresenta
{tree.children.map((item) => (
<li key={item.id}>
<TreeItem
projectId={projectId}
editingContextId={editingContextId}
item={item}
depth={1}
onExpand={onExpand}
selection={selection}
// displayedRepresentation={displayedRepresentation} TODO TreeItem has no such prop
setSelection={setSelection}
/>
</li>
Expand Down
19 changes: 10 additions & 9 deletions frontend/src/tree/TreeItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,15 @@ const menuPositionDelta = {
};

const propTypes = {
editingContextId: PropTypes.string.isRequired,
item: PropTypes.object.isRequired,
depth: PropTypes.number.isRequired,
onExpand: PropTypes.func.isRequired,
selection: PropTypes.object,
setSelection: PropTypes.func.isRequired,
};

export const TreeItem = ({ projectId, item, depth, onExpand, selection, setSelection }) => {
export const TreeItem = ({ editingContextId, item, depth, onExpand, selection, setSelection }) => {
const initialState = {
modalDisplayed: null,
x: 0,
Expand Down Expand Up @@ -288,7 +289,7 @@ export const TreeItem = ({ projectId, item, depth, onExpand, selection, setSelec
});
contextMenu = (
<TreeItemDocumentContextMenu
projectId={projectId}
projectId={editingContextId}
documentId={item.id}
x={x}
y={y}
Expand Down Expand Up @@ -370,7 +371,7 @@ export const TreeItem = ({ projectId, item, depth, onExpand, selection, setSelec
const onDeleteObject = () => {
const variables = {
input: {
projectId,
projectId: editingContextId,
objectId: item.id,
},
};
Expand Down Expand Up @@ -430,10 +431,10 @@ export const TreeItem = ({ projectId, item, depth, onExpand, selection, setSelec
renameDocument({ variables: { input: { documentId: item.id, newName: label } } });
} else if (item?.kind === 'Diagram') {
renameRepresentation({
variables: { input: { projectId: projectId, representationId: item.id, newLabel: label } },
variables: { input: { projectId: editingContextId, representationId: item.id, newLabel: label } },
});
} else {
renameObject({ variables: { input: { projectId: projectId, objectId: item.id, newName: label } } });
renameObject({ variables: { input: { projectId: editingContextId, objectId: item.id, newName: label } } });
}
} else {
setState((prevState) => {
Expand Down Expand Up @@ -507,7 +508,7 @@ export const TreeItem = ({ projectId, item, depth, onExpand, selection, setSelec
};
modal = (
<NewRootObjectModal
projectId={projectId}
projectId={editingContextId}
documentId={item.id}
onObjectCreated={onRootObjectCreated}
onClose={onCloseModal}
Expand Down Expand Up @@ -535,7 +536,7 @@ export const TreeItem = ({ projectId, item, depth, onExpand, selection, setSelec
};
modal = (
<NewObjectModal
projectId={projectId}
projectId={editingContextId}
classId={item.kind}
objectId={item.id}
onObjectCreated={onObjectCreated}
Expand Down Expand Up @@ -564,7 +565,7 @@ export const TreeItem = ({ projectId, item, depth, onExpand, selection, setSelec
};
modal = (
<NewRepresentationModal
projectId={projectId}
projectId={editingContextId}
classId={item.kind}
objectId={item.id}
onRepresentationCreated={onRepresentationCreated}
Expand All @@ -581,7 +582,7 @@ export const TreeItem = ({ projectId, item, depth, onExpand, selection, setSelec
return (
<li key={childItem.id}>
<TreeItem
projectId={projectId}
editingContextId={editingContextId}
item={childItem}
depth={depth + 1}
onExpand={onExpand}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/edit-project/EditProjectLoadedView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const EditProjectLoadedView = ({
setSubscribers,
}) => {
const explorer = (
<ExplorerWebSocketContainer projectId={projectId} selection={selection} setSelection={setSelection} />
<ExplorerWebSocketContainer editingContextId={projectId} selection={selection} setSelection={setSelection} />
);

let representation = (
Expand Down

0 comments on commit a7faa3c

Please sign in to comment.