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 Feb 2, 2023
1 parent d5f4109 commit 4550e73
Show file tree
Hide file tree
Showing 18 changed files with 474 additions and 128 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][project][diagram] Add support for enabling/disabling the focus on a tree view element (that is not revealed yet) if a digram element is selected. Moved the action "New Model" and "Upload model" in a new tree toolbar.

== v2022.11.0

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 4550e73

Please sign in to comment.