Skip to content

Commit

Permalink
[1588] Deactivate link with editor
Browse files Browse the repository at this point in the history
Bug: eclipse-sirius#1588

Signed-off-by: Michaël Charfadi <michael.charfadi@obeosoft.com>
  • Loading branch information
mcharfadi committed Jan 18, 2023
1 parent d5f4109 commit ffb3ecf
Show file tree
Hide file tree
Showing 7 changed files with 218 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Expand Up @@ -85,6 +85,7 @@
- https://github.com/eclipse-sirius/sirius-components/issues/1507[#1507] [diagram] Missing variables during execution of a source reconnection tool from the View description (otherEnd,semanticOtherEnd,edgeView and editingContext)
- https://github.com/eclipse-sirius/sirius-components/issues/1521[#1521] [view] Canonical creation tools from contextual toolbar have no icons
- https://github.com/eclipse-sirius/sirius-components/issues/1467[#1467] [layout] Elk is now able to compute a list layout. It is an internal change, and thus, nothing should change for the end user
- https://github.com/eclipse-sirius/sirius-components/issues/1588[#1588] [tree] Add support for enabling/disabling synchronisation between toolbar and diagram selection

== v2022.11.0

Expand Down
@@ -0,0 +1,47 @@
/*******************************************************************************
* Copyright (c) 2021, 2023 Obeo.
* This program and the accompanying materials
* are made available under the erms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
describe('/projects/:projectId/edit - Robot Diagram', () => {
beforeEach(() => {
cy.deleteAllProjects();
cy.createProject('Cypress Project').then((res) => {
const projectId = res.body.data.createProject.project.id;
const robot_flow_id = 'c26b6086-b444-3ee6-b8cd-9a4fde5956a7';
cy.createDocument(projectId, robot_flow_id, 'flow').then(() => {
cy.visit(`/projects/${projectId}/edit`);
});
});

cy.getByTestId('flow').dblclick();
cy.getByTestId('Robot').dblclick();
cy.getByTestId('Robot-more').click();
cy.getByTestId('treeitem-contextmenu').findByTestId('new-representation').click();

cy.getByTestId('name').clear();
cy.getByTestId('name').type('Topography');
cy.getByTestId('representationDescription').click();
cy.getByTestId('Topography with auto layout').click();
cy.getByTestId('create-representation').click();
cy.getByTestId('Topography').click();
});

//Default is synchronised
it('can be desynchronised', () => {
cy.getByTestId('tree-synchronise').dblclick();
cy.getByTestId('tree-synchronise').should('have.value', 'desynchronised');
});

it('can be synchronised', () => {
cy.getByTestId('tree-synchronise').dblclick();
cy.getByTestId('tree-synchronise').should('have.value', 'synchronised');
});
});
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021, 2022 Obeo.
* Copyright (c) 2021, 2023 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 All @@ -10,11 +10,8 @@
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
import { Selection } from '../../workbench/Workbench.types';
export interface NewDocumentModalProps {
editingContextId: string;
item: any;
setSelection: (selection: Selection) => void;
onClose: () => void;
}

Expand Down
@@ -0,0 +1,37 @@
/*******************************************************************************
* Copyright (c) 2023 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
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/

import { useMachine } from '@xstate/react';
import { createMachine } from 'xstate';

export const useToggleMachine = (initialActive: boolean = false): [boolean, () => void] => {
const [state, send] = useMachine(() =>
createMachine({
id: 'toggle',
initial: initialActive ? 'active' : 'inactive',
states: {
inactive: {
on: { TOGGLE: 'active' },
},
active: {
on: { TOGGLE: 'inactive' },
},
},
})
);

const isActive = state.matches('active');
const toggle = () => send('TOGGLE');

return [isActive, toggle];
};
@@ -0,0 +1,90 @@
/*******************************************************************************
* Copyright (c) 2023 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
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/

import { NewDocumentModal, UploadDocumentModal } from '@eclipse-sirius/sirius-components';
import IconButton from '@material-ui/core/IconButton';
import { makeStyles } from '@material-ui/core/styles';
import { Add as AddIcon, Publish as PublishIcon, SwapHoriz as SwapHorizIcon } from '@material-ui/icons';
import { useToggleMachine } from '../hook/useToggleMachine';
import { TreeToolBarProps } from './TreeToolBar.types';
const useTreeToolbarStyles = makeStyles((theme) => ({
toolbar: {
display: 'flex',
flexDirection: 'row',
height: theme.spacing(4),
paddingLeft: theme.spacing(1),
paddingRight: theme.spacing(1),
borderBottomWidth: '1px',
borderBottomStyle: 'solid',
justifyContent: 'right',
borderBottomColor: theme.palette.divider,
},
}));

export const TreeToolBar = ({ editingContextId, toggleSynchronize, isPreferenceSynchronise }: TreeToolBarProps) => {
const classes = useTreeToolbarStyles();
const [isNewDocumentModalDisplayed, toggleNewDocumentModal] = useToggleMachine(false);
const [isUploadDocumentModalDisplayed, toggleUploadDocumentModal] = useToggleMachine(false);

const toggleModal = () => {
if (isNewDocumentModalDisplayed)
return <NewDocumentModal editingContextId={editingContextId} onClose={toggleNewDocumentModal} />;
if (isUploadDocumentModalDisplayed)
return (
<UploadDocumentModal
editingContextId={editingContextId}
onDocumentUploaded={toggleUploadDocumentModal}
onClose={toggleUploadDocumentModal}
/>
);
return <></>;
};

const preferenceButtonSynchroniseTitle = isPreferenceSynchronise
? 'Disable synchronisation with diagram'
: 'Enable synchronisation with diagram';
return (
<>
<div className={classes.toolbar}>
<IconButton
size="small"
color="inherit"
aria-label="New model"
title="New model"
onClick={() => toggleNewDocumentModal()}
data-testid="new-model">
<AddIcon />
</IconButton>
<IconButton
size="small"
color="inherit"
aria-label="Upload model"
title="Upload model"
onClick={() => toggleUploadDocumentModal()}
data-testid="upload-document">
<PublishIcon />
</IconButton>
<IconButton
color="inherit"
size="small"
aria-label={preferenceButtonSynchroniseTitle}
title={preferenceButtonSynchroniseTitle}
onClick={() => toggleSynchronize()}
data-testid="upload-document">
<SwapHorizIcon color={isPreferenceSynchronise ? 'inherit' : 'disabled'} />
</IconButton>
</div>
{toggleModal()}
</>
);
};
@@ -0,0 +1,22 @@
/*******************************************************************************
* Copyright (c) 2023 Obeo and others.
* 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
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/

export interface TreeToolBarProps {
toggleSynchronize: () => void;
isPreferenceSynchronise: boolean;
editingContextId: string;
}

export interface TreeToolbarState {
modal: string | null;
}
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2022 Obeo.
* Copyright (c) 2019, 2023 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 All @@ -18,6 +18,8 @@ import { makeStyles } from '@material-ui/core/styles';
import { Close as CloseIcon } from '@material-ui/icons';
import { useMachine } from '@xstate/react';
import { useEffect } from 'react';
import { useToggleMachine } from '../hook/useToggleMachine';
import { TreeToolBar } from '../toolbar/TreeToolBar';
import { Tree } from '../trees/Tree';
import {
GQLExplorerEventData,
Expand All @@ -39,7 +41,6 @@ import {
SynchronizeEvent,
} from './ExplorerViewMachine';
import { getTreeEventSubscription } from './getTreeEventSubscription';

const getTreePathQuery = gql`
query getTreePath($editingContextId: ID!, $treeId: ID!, $selectionEntryIds: [ID!]!) {
viewer {
Expand All @@ -65,14 +66,15 @@ export const ExplorerView = ({ editingContextId, selection, setSelection, readOn
const [{ value, context }, dispatch] = useMachine<ExplorerViewContext, ExplorerViewEvent>(explorerViewMachine);
const { toast, explorerView } = value as SchemaValue;
const { id, tree, expanded, maxDepth, synchronized, message } = context;
const [isPreferenceSynchronise, togglePreferenceSynchronize] = useToggleMachine(true);

const [getTreePath, { loading: treePathLoading, data: treePathData, error: treePathError }] = useLazyQuery<
GQLGetTreePathData,
GQLGetTreePathVariables
>(getTreePathQuery);

useEffect(() => {
if (tree) {
if (tree && synchronized) {
const variables: GQLGetTreePathVariables = {
editingContextId,
treeId: tree.id,
Expand Down Expand Up @@ -133,17 +135,30 @@ export const ExplorerView = ({ editingContextId, selection, setSelection, readOn

// Enable synchronize mode when the selection is explicitly changed
useEffect(() => {
const synchronizeEvent: SynchronizeEvent = { type: 'SYNCHRONIZE', synchronized: true };
dispatch(synchronizeEvent);
if (isPreferenceSynchronise) {
const synchronizeEvent: SynchronizeEvent = { type: 'SYNCHRONIZE', synchronized: true };
dispatch(synchronizeEvent);
}
}, [selection]);

const onExpand = (id: string, depth: number) => {
const handleExpandedEvent: HandleExpandedEvent = { type: 'HANDLE_EXPANDED', id, depth };
dispatch(handleExpandedEvent);
};

const toggleSynchronize = () => {
togglePreferenceSynchronize();
const synchronizeEvent: SynchronizeEvent = { type: 'SYNCHRONIZE', synchronized: !isPreferenceSynchronise };
dispatch(synchronizeEvent);
};
return (
<>
<div className="explorerToolBar">
<TreeToolBar
editingContextId={editingContextId}
toggleSynchronize={toggleSynchronize}
isPreferenceSynchronise={isPreferenceSynchronise}></TreeToolBar>
</div>
<div className={styles.explorerView} data-testid="explorer">
{tree ? (
<Tree
Expand Down

0 comments on commit ffb3ecf

Please sign in to comment.