Skip to content

Commit

Permalink
Added ScaLarList comp to fix properties with List settings not displa…
Browse files Browse the repository at this point in the history
…yed (#388)

Co-authored-by: manasa <[email protected]>
  • Loading branch information
4manasa and manasa authored Oct 18, 2023
1 parent f0b5878 commit 1b79dc2
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/bridge/react_pconnect.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import UserReference from '../components/forms/UserReference';
import Confirmation from '../components/templates/Confirmation';
import BannerPage from '../components/templates/BannerPage';
import QuickCreate from '../components/widgets/QuickCreate';
import ScalarList from '../components/forms/ScalarList';

const isClassIDCompare = (key, prev) => {
return !(key === 'classID' && !prev[key]);
Expand Down Expand Up @@ -298,6 +299,10 @@ const getComponent = c11nEnv => {
component = RootContainer;
break;

case 'ScalarList':
component = ScalarList;
break;

case 'SimpleTable':
component = SimpleTable;
break;
Expand Down
21 changes: 21 additions & 0 deletions src/components/forms/ScalarList/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "ScalarList",
"type": "Field",
"properties": [
{
"component": "$this.componentType",
"format": "COMPONENTDEFINITION"
},
{
"label": "List settings",
"format": "GROUP",
"properties": [
{
"name": "filter",
"label": "Filter by",
"format": "SCALARLISTFILTER"
}
]
}
]
}
62 changes: 62 additions & 0 deletions src/components/forms/ScalarList/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/* eslint-disable react/no-array-index-key */
import React from 'react';
import FieldValueList from '../../designSystemExtensions/FieldValueList';
import PropTypes from 'prop-types';

function CommaSeparatedList(props) {
const { items } = props;

return (
<ul style={{ padding: '0', margin: '0' }}>
{items.map((value, index) => {
return <span key={index}>{value}</span>;
})}
</ul>
);
}

export default function ScalarList(props) {
const {
label,
getPConnect,
componentType,
value: scalarValues,
displayMode,
hideLabel,
...restProps
} = props;

const items = scalarValues?.map(scalarValue => {
return getPConnect().createComponent({
type: componentType,
config: {
value: scalarValue,
displayMode: 'LABELS_LEFT',
label,
...restProps,
readOnly: 'true'
}
});
});

if (['LABELS_LEFT', 'STACKED_LARGE_VAL', 'DISPLAY_ONLY'].includes(displayMode)) {
const displayComp = (
<div>
<CommaSeparatedList items={items} />
</div>
);
return displayComp;
}

const displayComp = <CommaSeparatedList items={items} />;

return <FieldValueList name={hideLabel ? '' : label} value={displayComp} variant='stacked' />;
}

ScalarList.defaultProps = {};
ScalarList.propTypes = {
getPConnect: PropTypes.func.isRequired,
displayInModal: PropTypes.bool,
hideLabel: PropTypes.bool,
value: PropTypes.arrayOf(PropTypes.any)
};

0 comments on commit 1b79dc2

Please sign in to comment.