forked from eclipse-sirius/sirius-web
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug: eclipse-sirius#1588 Signed-off-by: Michaël Charfadi <michael.charfadi@obeosoft.com>
- Loading branch information
Showing
7 changed files
with
218 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
integration-tests/cypress/integration/project/edit/explorer-toolbar_spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
packages/trees/frontend/sirius-components-trees/src/hook/useToggleMachine.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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]; | ||
}; |
90 changes: 90 additions & 0 deletions
90
packages/trees/frontend/sirius-components-trees/src/toolbar/TreeToolBar.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()} | ||
</> | ||
); | ||
}; |
22 changes: 22 additions & 0 deletions
22
packages/trees/frontend/sirius-components-trees/src/toolbar/TreeToolBar.types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters