Skip to content

Commit

Permalink
[1588] Add support to stop revealing the selection in the explorer
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 authored and sbegaudeau committed Feb 13, 2023
1 parent f5417c8 commit 8337e69
Show file tree
Hide file tree
Showing 18 changed files with 496 additions and 140 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.adoc
Expand Up @@ -44,6 +44,7 @@ On top of that, creating more complex subscriptions involving the representation
The scheduling policy of our various `IRepresentationEventProcessor` will thus be updated in order to ensure that the subscription will be performed in another thread.
- https://github.com/eclipse-sirius/sirius-components/issues/1615[#1615] [diagram] `DiagramDescription.getTools()` has been removed.
It was not actually used, as tools have long been found in `DiagramDescription.getToolSections()` instead.
- https://github.com/eclipse-sirius/sirius-components/issues/1588[#1588] [project] Moved the action "New Model" and "Upload model" in a new tree toolbar

=== Dependency update

Expand Down Expand Up @@ -91,6 +92,9 @@ Using the view DSL, one can use the expression `aql:collapsingState.toString() =
- https://github.com/eclipse-sirius/sirius-components/issues/1583[#1583] [diagram] Add support for diagram nodes labels' auto-wrap
+
image:doc/images/Diagram_node_labels_auto_wrap.png[width=517,height=424]
- https://github.com/eclipse-sirius/sirius-components/issues/1588[#1588] [tree] Add support for enabling/disabling the synchronization between the explorer and the current selection.
When it is enabled, if the current selection is not visible in the explorer, it will be revealed by expanding the relevant tree items.
On the other hand, when it is disabled, the selection will be visible in the explorer but no tree items will be automatically expanded.

=== Improvements

Expand Down
@@ -0,0 +1,119 @@
/*******************************************************************************
* Copyright (c) 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 - Tree toolbar', () => {
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();
});

it('Deactivate the synchronisation mode does not reveal the semantic element selected on a diagram but activating it will', () => {
// 1. Deactivate the synchronisation mode
cy.getByTestId('tree-synchronise').click();

// 2. On the diagram, click on the 'CaptureSubSystem'
cy.getByTestId('CaptureSubSystem').should('exist');
cy.getByTestId('Label - CaptureSubSystem').click();

// 3. CHECK that the 'CaptureSubSystem' node is visible and selected in the explorer
cy.getByTestId('selected').contains('CaptureSubSystem');

// 4. On the diagram, click on the 'DSP'
cy.getByTestId('DSP').should('not.exist');
cy.getByTestId('Label - DSP').click();

// 5. CHECK that the 'DSP' node is not visible and not selected in the explorer
cy.getByTestId('DSP').should('not.exist');
cy.getByTestId('selected').should('not.exist');

// 6. Activate the synchronisation mode
cy.getByTestId('tree-synchronise').click();

// 5. CHECK that the 'GPU' node is visible and selected
cy.getByTestId('DSP').should('exist');
cy.getByTestId('selected').findByTestId('DSP').should('exist');
});

it('can open the new model modal', () => {
cy.getByTestId('new-model').click();

cy.get('.MuiDialog-container').should('be.visible');
cy.getByTestId('navbar-contextmenu').should('not.exist');

cy.getByTestId('name').type('{esc}');
cy.get('.MuiDialog-container').should('not.exist');
});

it('requires a name to create a new model', () => {
cy.getByTestId('new-model').click();
cy.getByTestId('create-document').should('be.disabled');
});

it('can create a new document by clicking on the create button', () => {
cy.getByTestId('new-model').click();

cy.getByTestId('name-input').should('be.enabled');
cy.getByTestId('name').type('nobel');

cy.getByTestId('create-document').should('be.enabled');
cy.getByTestId('create-document').click();

cy.get('.MuiDialog-container').should('not.exist');
cy.getByTestId('explorer').contains('nobel');
});

it('can open the upload document modal', () => {
cy.getByTestId('upload-document').click();

cy.get('.MuiDialog-container').should('be.visible');

cy.get('.MuiDialog-container').type('{esc}');
cy.get('.MuiDialog-container').should('not.exist');
});
});

//The upload function doesn't exist anymore.
it.skip('can upload an existing document', () => {
cy.getByTestId('upload-document').click();

cy.fixture('Robot.xmi').then((fileContent) => {
cy.getByTestId('file').upload({
fileContent,
fileName: 'robot',
mimeType: 'text/xml',
encoding: 'utf8',
});

cy.getByTestId('upload-document').click();

cy.get('.MuiDialog-container').should('not.exist');
cy.getByTestId('explorer').contains('robot');
});
});
@@ -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 erms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -33,48 +33,6 @@ describe('/projects/:projectId/edit - Project Context Menu', () => {
cy.getByTestId('navbar-contextmenu').should('not.exist');
});

it('can open the new model modal', () => {
cy.getByTestId('more').click();
cy.getByTestId('new-model').click();

cy.get('.MuiDialog-container').should('be.visible');
cy.getByTestId('navbar-contextmenu').should('not.exist');

cy.getByTestId('name').type('{esc}');
cy.get('.MuiDialog-container').should('not.exist');
});

it('requires a name to create a new model', () => {
cy.getByTestId('more').click();
cy.getByTestId('new-model').click();
cy.getByTestId('create-document').should('be.disabled');
});

it('can create a new document by clicking on the create button', () => {
cy.getByTestId('more').click();
cy.getByTestId('new-model').click();

cy.getByTestId('name-input').should('be.enabled');
cy.getByTestId('name').type('nobel');

cy.getByTestId('create-document').should('be.enabled');
cy.getByTestId('create-document').click();

cy.get('.MuiDialog-container').should('not.exist');
cy.getByTestId('explorer').contains('nobel');
});

it('can open the upload document modal', () => {
cy.getByTestId('more').click();
cy.getByTestId('upload-document').click();

cy.get('.MuiDialog-container').should('be.visible');
cy.getByTestId('navbar-contextmenu').should('not.be.visible');

cy.get('.MuiDialog-container').type('{esc}');
cy.get('.MuiDialog-container').should('not.exist');
});

it('contains a download link', () => {
cy.getByTestId('more').click();
cy.getByTestId('download-link').should('have.attr', 'href');
Expand All @@ -96,23 +54,3 @@ describe('/projects/:projectId/edit - Project Context Menu', () => {
cy.url().should('match', new RegExp(Cypress.config().baseUrl + '/projects'));
});
});

//The upload function doesn't exist anymore.
it.skip('can upload an existing document', () => {
cy.getByTestId('more').click();
cy.getByTestId('upload-document').click();

cy.fixture('Robot.xmi').then((fileContent) => {
cy.getByTestId('file').upload({
fileContent,
fileName: 'robot',
mimeType: 'text/xml',
encoding: 'utf8',
});

cy.getByTestId('upload-document').click();

cy.get('.MuiDialog-container').should('not.exist');
cy.getByTestId('explorer').contains('robot');
});
});
4 changes: 1 addition & 3 deletions packages/core/frontend/sirius-components/src/index.ts
@@ -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,11 +18,9 @@ export * from './core/form/Form';
export * from './errors/ErrorBoundary';
export * from './icons';
export * from './modals/delete-project/DeleteProjectModal';
export * from './modals/new-document/NewDocumentModal';
export * from './modals/new-object/NewObjectModal';
export * from './modals/new-representation/NewRepresentationModal';
export * from './modals/new-root-object/NewRootObjectModal';
export * from './modals/rename-project/RenameProjectModal';
export * from './modals/upload-document/UploadDocumentModal';
export * from './onboarding/OnboardArea';
export * from './views/FormContainer';
@@ -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 @@ -10,12 +10,7 @@
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
import {
DeleteProjectModal,
NewDocumentModal,
RenameProjectModal,
UploadDocumentModal,
} from '@eclipse-sirius/sirius-components';
import { DeleteProjectModal, RenameProjectModal } from '@eclipse-sirius/sirius-components';
import { ServerContext } from '@eclipse-sirius/sirius-components-core';
import IconButton from '@material-ui/core/IconButton';
import ListItemIcon from '@material-ui/core/ListItemIcon';
Expand All @@ -24,12 +19,10 @@ import Menu from '@material-ui/core/Menu';
import MenuItem from '@material-ui/core/MenuItem';
import { emphasize, makeStyles } from '@material-ui/core/styles';
import Typography from '@material-ui/core/Typography';
import AddIcon from '@material-ui/icons/Add';
import DeleteIcon from '@material-ui/icons/Delete';
import EditIcon from '@material-ui/icons/Edit';
import GetAppIcon from '@material-ui/icons/GetApp';
import MoreVertIcon from '@material-ui/icons/MoreVert';
import PublishIcon from '@material-ui/icons/Publish';
import SettingsIcon from '@material-ui/icons/Settings';
import React, { useContext, useReducer } from 'react';
import { Link as RouterLink, Redirect } from 'react-router-dom';
Expand Down Expand Up @@ -97,13 +90,7 @@ export const EditProjectNavbar = ({ project }: EditProjectNavbarProps) => {

let modal = null;
if (project) {
if (modalDisplayed === 'CreateDocument') {
modal = <NewDocumentModal editingContextId={project.currentEditingContext.id} onClose={onCloseModal} />;
} else if (modalDisplayed === 'UploadDocument') {
modal = (
<UploadDocumentModal editingContextId={project.id} onDocumentUploaded={onCloseModal} onClose={onCloseModal} />
);
} else if (modalDisplayed === 'RenameProject') {
if (modalDisplayed === 'RenameProject') {
modal = (
<RenameProjectModal
projectId={project.id}
Expand Down Expand Up @@ -142,23 +129,6 @@ export const EditProjectNavbar = ({ project }: EditProjectNavbarProps) => {
anchorEl={projectMenuAnchor}
data-testid="navbar-contextmenu"
onClose={() => dispatch({ type: HANDLE_CLOSE_CONTEXT_MENU__ACTION })}>
<MenuItem
onClick={() => dispatch({ modalDisplayed: 'CreateDocument', type: HANDLE_SHOW_MODAL__ACTION })}
data-testid="new-model">
<ListItemIcon>
<AddIcon />
</ListItemIcon>
<ListItemText primary="New model" />
</MenuItem>
<MenuItem
divider
data-testid="upload-document"
onClick={() => dispatch({ modalDisplayed: 'UploadDocument', type: HANDLE_SHOW_MODAL__ACTION })}>
<ListItemIcon>
<PublishIcon />
</ListItemIcon>
<ListItemText primary="Upload model" />
</MenuItem>
<MenuItem onClick={() => dispatch({ modalDisplayed: 'RenameProject', type: HANDLE_SHOW_MODAL__ACTION })}>
<ListItemIcon>
<EditIcon />
Expand Down
@@ -0,0 +1,54 @@
/*******************************************************************************
* 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
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/

export const sendFile = async (httpOrigin: string, query: string, variables: any, file: File) => {
const operations = {
query,
variables,
};

const formData = new FormData();
formData.append('operations', JSON.stringify(operations));
formData.append('map', JSON.stringify({ '0': 'variables.file' }));
formData.append('0', file);

const csrfToken = getCookie('XSRF-TOKEN');

const response = await fetch(`${httpOrigin}/api/graphql/upload`, {
method: 'POST',
body: formData,
credentials: 'include',
mode: 'cors',
headers: {
'X-XSRF-TOKEN': csrfToken,
},
});

return await response.json();
};

const getCookie = (name: string): string => {
let cookieValue: string = null;
if (document.cookie && document.cookie !== '') {
const cookies = document.cookie.split(';');
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i].trim();
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) === name + '=') {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
};

0 comments on commit 8337e69

Please sign in to comment.