diff --git a/packages/forms/frontend/sirius-components-widget-reference/src/components/ModelBrowserTreeView.tsx b/packages/forms/frontend/sirius-components-widget-reference/src/components/ModelBrowserTreeView.tsx index 182c698956d..633a03dd6ef 100644 --- a/packages/forms/frontend/sirius-components-widget-reference/src/components/ModelBrowserTreeView.tsx +++ b/packages/forms/frontend/sirius-components-widget-reference/src/components/ModelBrowserTreeView.tsx @@ -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'; @@ -41,6 +41,7 @@ export const ModelBrowserTreeView = ({ ownerKind, }: ModelBrowserTreeViewProps) => { const classes = useTreeStyle(); + const { converter } = useExplorerViewConfiguration(); const [state, setState] = useState({ filterBarText: '' }); @@ -68,6 +69,7 @@ export const ModelBrowserTreeView = ({ textToFilter={state.filterBarText} textToHighlight={state.filterBarText} markedItemIds={markedItemIds} + converter={converter} /> diff --git a/packages/trees/frontend/sirius-components-trees/src/index.ts b/packages/trees/frontend/sirius-components-trees/src/index.ts index e1f4a09e02d..49a09737860 100644 --- a/packages/trees/frontend/sirius-components-trees/src/index.ts +++ b/packages/trees/frontend/sirius-components-trees/src/index.ts @@ -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'; diff --git a/packages/trees/frontend/sirius-components-trees/src/views/ExplorerView.tsx b/packages/trees/frontend/sirius-components-trees/src/views/ExplorerView.tsx index 9a02e588bdb..ebb7ae3e960 100644 --- a/packages/trees/frontend/sirius-components-trees/src/views/ExplorerView.tsx +++ b/packages/trees/frontend/sirius-components-trees/src/views/ExplorerView.tsx @@ -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) => ({ @@ -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, @@ -112,6 +114,7 @@ export const ExplorerView = (props: WorkbenchViewComponentProps) => { synchronizedWithSelection={state.synchronizedWithSelection} textToHighlight={state.filterBarText} textToFilter={state.filterBarTreeFiltering ? state.filterBarText : null} + converter={converter} /> diff --git a/packages/trees/frontend/sirius-components-trees/src/views/ExplorerViewConfiguration.tsx b/packages/trees/frontend/sirius-components-trees/src/views/ExplorerViewConfiguration.tsx new file mode 100644 index 00000000000..32e6f755da9 --- /dev/null +++ b/packages/trees/frontend/sirius-components-trees/src/views/ExplorerViewConfiguration.tsx @@ -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 { ExplorerViewConfigurationProps, UseExplorerViewConfigurationValue } from './ExplorerViewConfiguration.types'; +import { ExplorerViewContext } from './ExplorerViewContext'; + +export const ExplorerViewConfiguration = ({ children, converter }: ExplorerViewConfigurationProps) => { + return {children}; +}; + +export const useExplorerViewConfiguration = (): UseExplorerViewConfigurationValue => { + const { converter } = useContext(ExplorerViewContext); + return { + converter, + }; +}; diff --git a/packages/trees/frontend/sirius-components-trees/src/views/ExplorerViewConfiguration.types.ts b/packages/trees/frontend/sirius-components-trees/src/views/ExplorerViewConfiguration.types.ts new file mode 100644 index 00000000000..a87a99defbe --- /dev/null +++ b/packages/trees/frontend/sirius-components-trees/src/views/ExplorerViewConfiguration.types.ts @@ -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; +} diff --git a/packages/trees/frontend/sirius-components-trees/src/views/ExplorerViewContext.tsx b/packages/trees/frontend/sirius-components-trees/src/views/ExplorerViewContext.tsx new file mode 100644 index 00000000000..82aa9d2fd82 --- /dev/null +++ b/packages/trees/frontend/sirius-components-trees/src/views/ExplorerViewContext.tsx @@ -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); diff --git a/packages/trees/frontend/sirius-components-trees/src/views/ExplorerViewContext.types.ts b/packages/trees/frontend/sirius-components-trees/src/views/ExplorerViewContext.types.ts new file mode 100644 index 00000000000..346925f4eef --- /dev/null +++ b/packages/trees/frontend/sirius-components-trees/src/views/ExplorerViewContext.types.ts @@ -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; +} diff --git a/packages/trees/frontend/sirius-components-trees/src/views/TreeConverter.types.ts b/packages/trees/frontend/sirius-components-trees/src/views/TreeConverter.types.ts new file mode 100644 index 00000000000..8b63fcee137 --- /dev/null +++ b/packages/trees/frontend/sirius-components-trees/src/views/TreeConverter.types.ts @@ -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; +} diff --git a/packages/trees/frontend/sirius-components-trees/src/views/TreeView.tsx b/packages/trees/frontend/sirius-components-trees/src/views/TreeView.tsx index 3676595d59d..194b482a153 100644 --- a/packages/trees/frontend/sirius-components-trees/src/views/TreeView.tsx +++ b/packages/trees/frontend/sirius-components-trees/src/views/TreeView.tsx @@ -80,6 +80,7 @@ export const TreeView = ({ textToHighlight, textToFilter, markedItemIds = [], + converter, }: TreeViewComponentProps) => { const [{ value, context }, dispatch] = useMachine(treeViewMachine, { context: { @@ -217,7 +218,7 @@ export const TreeView = ({ {tree ? (