Skip to content

Commit

Permalink
[2568] Allow explorer to change its content
Browse files Browse the repository at this point in the history
Bug: eclipse-sirius#2568
Signed-off-by: William Piers <[email protected]>
  • Loading branch information
wpiers committed Nov 14, 2023
1 parent 7b38cbc commit c30dcfa
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
import { TreeView } from '@eclipse-sirius/sirius-components-trees';
import { TreeView, useExplorerViewConfiguration } from '@eclipse-sirius/sirius-components-trees';
import { makeStyles } from '@material-ui/core/styles';
import { useState } from 'react';
import { ModelBrowserFilterBar } from './ModelBrowserFilterBar';
Expand Down Expand Up @@ -41,6 +41,7 @@ export const ModelBrowserTreeView = ({
ownerKind,
}: ModelBrowserTreeViewProps) => {
const classes = useTreeStyle();
const { converter } = useExplorerViewConfiguration();

const [state, setState] = useState<ModelBrowserTreeViewState>({ filterBarText: '' });

Expand Down Expand Up @@ -68,6 +69,7 @@ export const ModelBrowserTreeView = ({
textToFilter={state.filterBarText}
textToHighlight={state.filterBarText}
markedItemIds={markedItemIds}
converter={converter}
/>
</div>
</>
Expand Down
5 changes: 4 additions & 1 deletion packages/trees/frontend/sirius-components-trees/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ export * from './treeitems/TreeItemContextMenu';
export * from './treeitems/TreeItemContextMenu.types';
export * from './treeitems/TreeItemContextMenuContribution';
export * from './treeitems/TreeItemContextMenuContribution.types';
export * from './treeitems/filterTreeItem';
export * from './views/ExplorerView';
export * from './views/ExplorerViewConfiguration';
export * from './views/ExplorerViewConfiguration.types';
export * from './views/TreeConverter.types';
export * from './views/TreeView';
export * from './views/TreeView.types';
export * from './treeitems/filterTreeItem';
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { TreeToolBarContext } from '../toolbar/TreeToolBarContext';
import { TreeToolBarContextValue } from '../toolbar/TreeToolBarContext.types';
import { FilterBar } from '../trees/FilterBar';
import { ExplorerViewState } from './ExplorerView.types';
import { useExplorerViewConfiguration } from './ExplorerViewConfiguration';
import { TreeView } from './TreeView';

const useStyles = makeStyles((theme) => ({
Expand All @@ -34,6 +35,7 @@ const useStyles = makeStyles((theme) => ({

export const ExplorerView = (props: WorkbenchViewComponentProps) => {
const styles = useStyles();
const { converter } = useExplorerViewConfiguration();
const initialState: ExplorerViewState = {
synchronizedWithSelection: true,
filterBar: false,
Expand Down Expand Up @@ -112,6 +114,7 @@ export const ExplorerView = (props: WorkbenchViewComponentProps) => {
synchronizedWithSelection={state.synchronizedWithSelection}
textToHighlight={state.filterBarText}
textToFilter={state.filterBarTreeFiltering ? state.filterBarText : null}
converter={converter}
/>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*******************************************************************************
* 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 { useContext } from 'react';
import { ExplorerViewContext } from './ExplorerViewContext';
import { ExplorerViewConfigurationProps, UseExplorerViewConfigurationValue } from './ExplorerViewConfiguration.types';

export const ExplorerViewConfiguration = ({ children, converter }: ExplorerViewConfigurationProps) => {
return <ExplorerViewContext.Provider value={{ converter }}>{children}</ExplorerViewContext.Provider>;
};

export const useExplorerViewConfiguration = (): UseExplorerViewConfigurationValue => {
const { converter } = useContext(ExplorerViewContext);
return {
converter,
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*******************************************************************************
* 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 { ReactNode } from 'react';
import { TreeConverter } from './TreeConverter.types';

export interface ExplorerViewConfigurationProps {
converter: TreeConverter;
children: ReactNode;
}

export interface UseExplorerViewConfigurationValue {
converter: TreeConverter;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*******************************************************************************
* 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 React from 'react';
import { TreeConverter } from './TreeConverter.types';
import { ExplorerViewContextValue } from './ExplorerViewContext.types';

const converter: TreeConverter = {
convert: (tree) => tree,
};

const defaultContext: ExplorerViewContextValue = {
converter,
};

export const ExplorerViewContext = React.createContext(defaultContext);
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*******************************************************************************
* 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 { TreeConverter } from './TreeConverter.types';
export interface ExplorerViewContextValue {
converter: TreeConverter;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*******************************************************************************
* 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 { GQLTree } from './TreeView.types';

export interface TreeConverter {
convert(tree: GQLTree): GQLTree;
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export const TreeView = ({
textToHighlight,
textToFilter,
markedItemIds = [],
converter,
}: TreeViewComponentProps) => {
const [{ value, context }, dispatch] = useMachine<TreeViewContext, TreeViewEvent>(treeViewMachine, {
context: {
Expand Down Expand Up @@ -217,7 +218,7 @@ export const TreeView = ({
{tree ? (
<Tree
editingContextId={editingContextId}
tree={tree}
tree={converter.convert(tree)}
onExpand={onExpand}
onExpandAll={onExpandAll}
selection={selection}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*******************************************************************************/

import { WorkbenchViewComponentProps } from '@eclipse-sirius/sirius-components-core';
import { TreeConverter } from './TreeConverter.types';

export interface TreeViewComponentProps extends WorkbenchViewComponentProps {
treeId: string;
Expand All @@ -20,6 +21,7 @@ export interface TreeViewComponentProps extends WorkbenchViewComponentProps {
textToHighlight: string | null;
textToFilter: string | null;
markedItemIds?: string[];
converter: TreeConverter;
}

export interface GQLTreeEventVariables {
Expand Down

0 comments on commit c30dcfa

Please sign in to comment.