Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[2568] Allow developers to change the content of the explorer on the …
…frontend Bug: #2568 Signed-off-by: William Piers <william.piers@obeo.fr>
- Loading branch information
1 parent
639fe06
commit 78bf5b4
Showing
12 changed files
with
226 additions
and
2 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
97 changes: 97 additions & 0 deletions
97
doc/adrs/116_add_support_for_changing_the_content_of_the_explorer.adoc
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,97 @@ | ||
= ADR-115 - Add support for changing the content of the explorer | ||
|
||
== Context | ||
|
||
The Explorer view displays the same version of a tree to all subscribers. | ||
There is no way for the frontend to change the tree for a specific subscriber. | ||
|
||
== Decision | ||
|
||
Addition of a TreeConverter API allowing to redefine the tree content (/packages/trees/frontend/sirius-components-trees/src/views/TreeConverter.types.ts) | ||
|
||
[source,typescript] | ||
---- | ||
interface TreeConverter { | ||
convert(tree: GQLTree): GQLTree; | ||
) | ||
---- | ||
|
||
Addition of an ExplorerViewContext providing a default TreeConverter (/packages/trees/frontend/sirius-components-trees/src/views/ExplorerViewContext.tsx) | ||
|
||
[source,typescript] | ||
---- | ||
const converter: TreeConverter = { | ||
convert: (tree) => tree; | ||
}; | ||
const defaultContext: ExplorerViewContextValue = { | ||
converter | ||
}; | ||
export const ExplorerViewContext = React.createContext(defaultContext); | ||
---- | ||
|
||
Addition of an ExplorerViewConfiguration providing the context to children (/packages/trees/frontend/sirius-components-trees/src/views/ExplorerViewConfiguration.tsx) | ||
|
||
[source,typescript] | ||
---- | ||
export const ExplorerViewConfiguration = ({ children, converter }: ExplorerViewConfigurationProps) => { | ||
return ( | ||
<ExplorerViewContext.Provider value={{ converter }}> | ||
{children} | ||
</ExplorerViewContext.Provider> | ||
); | ||
} | ||
---- | ||
|
||
Addition of an useExplorerViewConfiguration function to provide the configuration to interested components (/packages/trees/frontend/sirius-components-trees/src/views/useExplorerViewConfiguration.ts) | ||
|
||
[source,typescript] | ||
---- | ||
export const useExplorerViewConfiguration = (): UseExplorerViewConfigurationValue => { | ||
const { converter } = useContext(ExplorerViewContext); | ||
return { | ||
converter | ||
}; | ||
} | ||
---- | ||
|
||
Update of the ExplorerView to use the converter (/packages/trees/frontend/sirius-components-trees/src/views/ExplorerView.tsx) | ||
|
||
[source,typescript] | ||
---- | ||
const { converter } = useExplorerViewConfiguration(); | ||
<TreeView converter={converter} ... /> | ||
---- | ||
|
||
Update of the TreeView to use the converter (/packages/trees/frontend/sirius-components-trees/src/views/TreeView.tsx) | ||
|
||
[source,typescript] | ||
---- | ||
<Tree tree={converter.convert(tree)} ... /> | ||
---- | ||
|
||
Export new APIs (/packages/trees/frontend/sirius-components-trees/src/index.ts): | ||
|
||
[source,typescript] | ||
---- | ||
ExplorerViewConfiguration | ||
ExplorerViewConfigurationProps | ||
TreeConverter | ||
---- | ||
|
||
A sirius consumer may encapsulate its components in a ExplorerViewConfiguration which will provide the required filters. | ||
|
||
[source,typescript] | ||
---- | ||
<ExplorerViewConfiguration converter={MyCustomTreeConverter}> | ||
<Workbench ... /> | ||
</ExplorerViewConfiguration> | ||
---- | ||
|
||
== Status | ||
|
||
Accepted | ||
|
||
== Consequences | ||
|
||
None, by default the Explorer works as before. |
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
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
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
27 changes: 27 additions & 0 deletions
27
packages/trees/frontend/sirius-components-trees/src/views/ExplorerViewConfiguration.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,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 <ExplorerViewContext.Provider value={{ converter }}>{children}</ExplorerViewContext.Provider>; | ||
}; | ||
|
||
export const useExplorerViewConfiguration = (): UseExplorerViewConfigurationValue => { | ||
const { converter } = useContext<UseExplorerViewConfigurationValue>(ExplorerViewContext); | ||
return { | ||
converter, | ||
}; | ||
}; |
24 changes: 24 additions & 0 deletions
24
packages/trees/frontend/sirius-components-trees/src/views/ExplorerViewConfiguration.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,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; | ||
} |
25 changes: 25 additions & 0 deletions
25
packages/trees/frontend/sirius-components-trees/src/views/ExplorerViewContext.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,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); |
18 changes: 18 additions & 0 deletions
18
packages/trees/frontend/sirius-components-trees/src/views/ExplorerViewContext.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,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 { TreeConverter } from './TreeConverter.types'; | ||
|
||
export interface ExplorerViewContextValue { | ||
converter: TreeConverter; | ||
} |
18 changes: 18 additions & 0 deletions
18
packages/trees/frontend/sirius-components-trees/src/views/TreeConverter.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,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; | ||
} |
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
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