Skip to content

Commit

Permalink
[173] Migrate the properties to MaterialUI and XState
Browse files Browse the repository at this point in the history
Bug: #173
Signed-off-by: Stéphane Bégaudeau <stephane.begaudeau@obeo.fr>
Signed-off-by: Laurent Fasani <laurent.fasani@obeo.fr>
  • Loading branch information
sbegaudeau committed Feb 15, 2021
1 parent 0d5a3de commit 7af67b0
Show file tree
Hide file tree
Showing 29 changed files with 1,256 additions and 626 deletions.
2 changes: 1 addition & 1 deletion frontend/src/form/Form.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export interface Textarea extends Widget {

export interface Checkbox extends Widget {
label: string;
booleanValue: string;
booleanValue: boolean;
}

export interface Select extends Widget {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/form/FormWebSocketContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export const FormWebSocketContainer = ({ editingContextId, representationId }: R
if (formWebSocketContainer === 'ready') {
content = (
<Properties
projectId={editingContextId}
editingContextId={editingContextId}
form={form}
subscribers={subscribers}
widgetSubscriptions={widgetSubscriptions}
Expand Down
6 changes: 2 additions & 4 deletions frontend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,15 @@ export * from './onboarding/NewRepresentationArea';
export * from './onboarding/RepresentationsArea';
export * from './project/Permission';
export * from './project/ProjectProvider';
export * from './properties/group/Group';
export * from './properties/page/Page';
export * from './properties/Group';
export * from './properties/Page';
export * from './properties/pagelist/PageList';
export * from './properties/Properties';
export * from './properties/PropertiesWebSocketContainer';
export * from './properties/propertysections/CheckboxPropertySection';
export * from './properties/propertysections/ListPropertySection';
export * from './properties/propertysections/PropertySectionSubscribers';
export * from './properties/propertysections/RadioPropertySection';
export * from './properties/propertysections/SelectPropertySection';
export * from './properties/propertysections/TextareaPropertySection';
export * from './properties/propertysections/TextfieldPropertySection';
export * from './tree/Tree';
export * from './tree/TreeItem';
Expand Down
125 changes: 125 additions & 0 deletions frontend/src/properties/Group.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*******************************************************************************
* Copyright (c) 2019, 2021 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 { makeStyles } from '@material-ui/core/styles';
import Typography from '@material-ui/core/Typography';
import { Checkbox, List, Radio, Select, Textarea, Textfield, Widget, WidgetSubscription } from 'form/Form.types';
import { GroupProps } from 'properties/Group.types';
import { CheckboxPropertySection } from 'properties/propertysections/CheckboxPropertySection';
import { ListPropertySection } from 'properties/propertysections/ListPropertySection';
import { RadioPropertySection } from 'properties/propertysections/RadioPropertySection';
import { SelectPropertySection } from 'properties/propertysections/SelectPropertySection';
import { TextfieldPropertySection } from 'properties/propertysections/TextfieldPropertySection';
import React from 'react';

const useGroupStyles = makeStyles((theme) => ({
group: {
display: 'flex',
flexDirection: 'column',
},
title: {
whiteSpace: 'nowrap',
overflow: 'hidden',
textOverflow: 'ellipsis',
},
sections: {
display: 'flex',
flexDirection: 'column',
'& > *': {
marginBottom: theme.spacing(2),
},
},
}));

export const Group = ({ editingContextId, formId, group, widgetSubscriptions }: GroupProps) => {
const classes = useGroupStyles();

let propertySections = group.widgets.map((widget) =>
widgetToPropertySection(editingContextId, formId, widget, widgetSubscriptions)
);

return (
<div className={classes.group}>
<Typography variant="subtitle1" className={classes.title} gutterBottom>
{group.label}
</Typography>
<div className={classes.sections}>{propertySections}</div>
</div>
);
};

const isTextfield = (widget: Widget): widget is Textfield => widget.__typename === 'Textfield';
const isTextarea = (widget: Widget): widget is Textarea => widget.__typename === 'Textarea';
const isCheckbox = (widget: Widget): widget is Checkbox => widget.__typename === 'Checkbox';
const isSelect = (widget: Widget): widget is Select => widget.__typename === 'Select';
const isRadio = (widget: Widget): widget is Radio => widget.__typename === 'Radio';
const isList = (widget: Widget): widget is List => widget.__typename === 'List';

const widgetToPropertySection = (
editingContextId: string,
formId: string,
widget: Widget,
widgetSubscriptions: WidgetSubscription[]
) => {
let subscribers = [];
widgetSubscriptions
.filter((subscription) => subscription.widgetId === widget.id)
.forEach((subscription) => subscribers.push(...subscription.subscribers));

let propertySection = null;
if (isTextfield(widget) || isTextarea(widget)) {
propertySection = (
<TextfieldPropertySection
editingContextId={editingContextId}
formId={formId}
widget={widget}
subscribers={subscribers}
key={widget.id}
/>
);
} else if (isCheckbox(widget)) {
propertySection = (
<CheckboxPropertySection
editingContextId={editingContextId}
formId={formId}
widget={widget}
subscribers={subscribers}
key={widget.id}
/>
);
} else if (isSelect(widget)) {
propertySection = (
<SelectPropertySection
editingContextId={editingContextId}
formId={formId}
widget={widget}
subscribers={subscribers}
key={widget.id}
/>
);
} else if (isRadio(widget)) {
propertySection = (
<RadioPropertySection
editingContextId={editingContextId}
formId={formId}
widget={widget}
subscribers={subscribers}
key={widget.id}
/>
);
} else if (isList(widget)) {
propertySection = <ListPropertySection widget={widget} key={widget.id} subscribers={subscribers} />;
} else {
console.error(`Unsupported widget type ${widget.__typename}`);
}
return propertySection;
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2020 Obeo.
* Copyright (c) 2021 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
Expand All @@ -10,28 +10,11 @@
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
.group {
display: flex;
flex-direction: column;
}

.title {
color: var(--daintree);
font-weight: var(--font-weight-bold);
font-size: var(--font-size-4);
white-space: nowrap;
margin-bottom: 8px;
}

.sections {
display: flex;
flex-direction: column;
}
import { Group, WidgetSubscription } from 'form/Form.types';

.propertySection {
display: flex;
flex-direction: column;
border-top: 1px solid var(--daintree-lighten-90);
padding-top: 8px;
padding-bottom: 8px;
export interface GroupProps {
editingContextId: string;
formId: string;
group: Group;
widgetSubscriptions: WidgetSubscription[];
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2020 Obeo.
* Copyright (c) 2019, 2021 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
Expand All @@ -10,17 +10,29 @@
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
import { Group } from 'properties/group/Group';
import { makeStyles } from '@material-ui/core/styles';
import { Group } from 'properties/Group';
import { PageProps } from 'properties/Page.types';
import React from 'react';
import styles from './Page.module.css';

export const Page = ({ projectId, formId, page, widgetSubscriptions }) => {
const usePageStyles = makeStyles((theme) => ({
page: {
display: 'flex',
flexDirection: 'column',
'& > *': {
marginBottom: theme.spacing(2),
},
},
}));

export const Page = ({ editingContextId, formId, page, widgetSubscriptions }: PageProps) => {
const classes = usePageStyles();
return (
<div className={styles.page}>
<div className={classes.page}>
{page.groups.map((group) => {
return (
<Group
projectId={projectId}
editingContextId={editingContextId}
formId={formId}
group={group}
widgetSubscriptions={widgetSubscriptions}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2020 Obeo.
* Copyright (c) 2021 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
Expand All @@ -10,10 +10,11 @@
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
.label {
font-size: var(--font-size-5);
font-weight: var(--font-weight-bold);
color: var(--daintree-lighten-20);
white-space: nowrap;
margin-bottom: 8px;
import { Page, WidgetSubscription } from 'form/Form.types';

export interface PageProps {
editingContextId: string;
formId: string;
page: Page;
widgetSubscriptions: WidgetSubscription[];
}
44 changes: 0 additions & 44 deletions frontend/src/properties/Properties.module.css

This file was deleted.

Loading

0 comments on commit 7af67b0

Please sign in to comment.