forked from eclipse-sirius/sirius-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[2570] Allow details view to change its content
Bug: eclipse-sirius#2570 Signed-off-by: William Piers <[email protected]>
- Loading branch information
1 parent
78bf5b4
commit 07cca4a
Showing
14 changed files
with
231 additions
and
11 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/117_add_support_for_changing_the_content_of_the_details_view.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-117 - Add support for changing the content of the details view | ||
|
||
== Context | ||
|
||
The Details view displays the same version of a form to all users. There is now way for the frontend to change the form for a specific user. | ||
|
||
== Decision | ||
|
||
* Addition of a FormConverter API allowing to redefine the form content (/packages/forms/frontend/sirius-components-forms/src/views/FormConverter.types.ts) | ||
|
||
[source,typescript] | ||
---- | ||
interface FormConverter { | ||
convert(form: GQLForm): GQLForm; | ||
) | ||
---- | ||
|
||
* Addition of an DetailsViewContext providing a default FormConverter (/packages/forms/frontend/sirius-components-forms/src/views/DetailsViewContext.tsx) | ||
|
||
[source,typescript] | ||
---- | ||
const converter: FormConverter = { | ||
convert: (form) => form; | ||
}; | ||
const defaultContext: DetailsViewContextValue = { | ||
converter | ||
}; | ||
export const DetailsViewContext = React.createContext(defaultContext); | ||
---- | ||
|
||
* Addition of an DetailsViewConfiguration providing the context to children (/packages/forms/frontend/sirius-components-forms/src/views/DetailsViewConfiguration.tsx) | ||
|
||
[source,typescript] | ||
---- | ||
export const DetailsViewConfiguration = ({ children, converter }: DetailsViewConfigurationProps) => { | ||
return ( | ||
<DetailsViewContext.Provider value={{ converter }}> | ||
{children} | ||
</DetailsViewContext.Provider> | ||
); | ||
} | ||
---- | ||
|
||
* Addition of an useDetailsViewConfiguration function to provide the configuration to interested components (/packages/forms/frontend/sirius-components-forms/src/views/useDetailsViewConfiguration.ts) | ||
|
||
[source,typescript] | ||
---- | ||
export const useDetailsViewConfiguration = (): UseDetailsViewConfigurationValue => { | ||
const { converter } = useContext(DetailsViewContext); | ||
return { | ||
converter | ||
}; | ||
} | ||
---- | ||
|
||
* Update of the DetailsView to use the converter (/packages/forms/frontend/sirius-components-forms/src/views/DetailsView.tsx) | ||
|
||
[source,typescript] | ||
---- | ||
const { converter } = useDetailsViewConfiguration(); | ||
<FormView converter={converter} ... /> | ||
---- | ||
|
||
* Update of the FormView to use the converter (/packages/forms/frontend/sirius-components-forms/src/views/FormView.tsx) | ||
|
||
[source,typescript] | ||
---- | ||
<Form form={converter.convert(form)} ... /> | ||
---- | ||
|
||
* Export new APIs (/packages/forms/frontend/sirius-components-forms/src/index.ts): | ||
|
||
[source,typescript] | ||
---- | ||
DetailsViewConfiguration | ||
DetailsViewConfigurationProps | ||
FormConverter | ||
---- | ||
|
||
* Usage: | ||
A sirius consumer may encapsulate its components in a DetailsViewConfiguration which will provide the required filters. | ||
|
||
[source,typescript] | ||
---- | ||
<DetailsViewConfiguration converter={MyCustomFormConverter}> | ||
<Workbench ... /> | ||
</DetailsViewConfiguration> | ||
---- | ||
|
||
== Status | ||
|
||
Accepted | ||
|
||
== Consequences | ||
|
||
None, by default the Details view 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
27 changes: 27 additions & 0 deletions
27
packages/forms/frontend/sirius-components-forms/src/views/DetailsViewConfiguration.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 React from 'react'; | ||
import { DetailsViewConfigurationProps, UseDetailsViewConfigurationValue } from './DetailsViewConfiguration.types'; | ||
import { DetailsViewContext } from './DetailsViewContext'; | ||
|
||
export const DetailsViewConfiguration = ({ children, converter }: DetailsViewConfigurationProps) => { | ||
return <DetailsViewContext.Provider value={{ converter }}>{children}</DetailsViewContext.Provider>; | ||
}; | ||
|
||
export const useDetailsViewConfiguration = (): UseDetailsViewConfigurationValue => { | ||
const { converter } = React.useContext<UseDetailsViewConfigurationValue>(DetailsViewContext); | ||
return { | ||
converter, | ||
}; | ||
}; |
24 changes: 24 additions & 0 deletions
24
packages/forms/frontend/sirius-components-forms/src/views/DetailsViewConfiguration.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 { FormConverter } from './FormConverter.types'; | ||
|
||
export interface DetailsViewConfigurationProps { | ||
converter: FormConverter; | ||
children: ReactNode; | ||
} | ||
|
||
export interface UseDetailsViewConfigurationValue { | ||
converter: FormConverter; | ||
} |
25 changes: 25 additions & 0 deletions
25
packages/forms/frontend/sirius-components-forms/src/views/DetailsViewContext.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 { DetailsViewContextValue } from './DetailsViewContext.types'; | ||
import { FormConverter } from './FormConverter.types'; | ||
|
||
const converter: FormConverter = { | ||
convert: (form) => form, | ||
}; | ||
|
||
const defaultContext: DetailsViewContextValue = { | ||
converter, | ||
}; | ||
|
||
export const DetailsViewContext = React.createContext(defaultContext); |
17 changes: 17 additions & 0 deletions
17
packages/forms/frontend/sirius-components-forms/src/views/DetailsViewContext.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,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 { FormConverter } from './FormConverter.types'; | ||
export interface DetailsViewContextValue { | ||
converter: FormConverter; | ||
} |
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
18 changes: 18 additions & 0 deletions
18
packages/forms/frontend/sirius-components-forms/src/views/FormConverter.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 { GQLForm } from '../form/FormEventFragments.types'; | ||
|
||
export interface FormConverter { | ||
convert(form: GQLForm): GQLForm; | ||
} |
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