-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add table component to viewer (#920)
* feat: Add table component to viewer * fix: Fix default rowCount * feat: Add generic data on editor view * fix: Refactor form field table styles * test: Add tests * fix: Turn data source into FEEL only * chore: Remove unnecessary new line * chore: Remove FEEL check on dataSource * chore: Sort by asc first * chore: Remove unnecessary label check * chore: Use const instead of let * fix: Create EditorTable * chore: Fix formatting * chore: Make label id optional * fix: Add row gap
- Loading branch information
Showing
13 changed files
with
1,026 additions
and
29 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
packages/form-js-editor/src/features/modeling/behavior/TableDataSourceBehavior.js
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 @@ | ||
import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor'; | ||
|
||
import { get } from 'min-dash'; | ||
|
||
export class TableDataSourceBehavior extends CommandInterceptor { | ||
constructor(eventBus) { | ||
super(eventBus); | ||
|
||
this.preExecute('formField.add', function(context) { | ||
|
||
const { formField } = context; | ||
|
||
if (get(formField, [ 'type' ]) !== 'table') { | ||
return; | ||
} | ||
|
||
context.formField = { | ||
...formField, | ||
dataSource: `=${formField.id}` | ||
}; | ||
}, true); | ||
} | ||
} | ||
|
||
TableDataSourceBehavior.$inject = [ 'eventBus' ]; |
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
54 changes: 54 additions & 0 deletions
54
packages/form-js-editor/src/render/components/editor-form-fields/EditorTable.js
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,54 @@ | ||
import { Label, Table } from '@bpmn-io/form-js-viewer'; | ||
import { editorFormFieldClasses } from '../Util'; | ||
import classNames from 'classnames'; | ||
|
||
/** | ||
* @param {import('@bpmn-io/form-js-viewer/src/render/components/form-fields/Table').Props} props | ||
* @returns {import("preact").JSX.Element} | ||
*/ | ||
export default function EditorTable(props) { | ||
const { columnsExpression, columns, id, label } = props.field; | ||
const shouldUseMockColumns = | ||
(typeof columnsExpression === 'string' && columnsExpression.length > 0) || | ||
(Array.isArray(columns) && columns.length === 0); | ||
const editorColumns = shouldUseMockColumns | ||
? [ | ||
{ key: '1', label: 'Column 1' }, | ||
{ key: '2', label: 'Column 2' }, | ||
{ key: '3', label: 'Column 3' } | ||
] | ||
: columns; | ||
const prefixId = `fjs-form-${id}`; | ||
|
||
return ( | ||
<div class={ editorFormFieldClasses('table', { disabled: true }) }> | ||
<Label id={ prefixId } label={ label } /> | ||
<div class="fjs-table-middle-container"> | ||
<div class="fjs-table-inner-container"> | ||
<table class={ classNames('fjs-table', 'fjs-disabled') } id={ prefixId }> | ||
<thead class="fjs-table-head"> | ||
<tr class="fjs-table-tr"> | ||
{editorColumns.map(({ key, label }) => ( | ||
<th key={ key } class="fjs-table-th"> | ||
{label} | ||
</th> | ||
))} | ||
</tr> | ||
</thead> | ||
<tbody class="fjs-table-body"> | ||
<tr class="fjs-table-tr"> | ||
{editorColumns.map(({ key }) => ( | ||
<td class="fjs-table-td" key={ key }> | ||
Content | ||
</td> | ||
))} | ||
</tr> | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
EditorTable.config = Table.config; |
4 changes: 3 additions & 1 deletion
4
packages/form-js-editor/src/render/components/editor-form-fields/index.js
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 |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import EditorIFrame from './EditorIFrame'; | ||
import EditorText from './EditorText'; | ||
import EditorTable from './EditorTable'; | ||
|
||
export const editorFormFields = [ | ||
EditorIFrame, | ||
EditorText | ||
EditorText, | ||
EditorTable | ||
]; |
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
Oops, something went wrong.