Skip to content

Commit

Permalink
Merge branch 'feature/shibui-1917-custom-attrs' into feature/shibui-1788
Browse files Browse the repository at this point in the history
  • Loading branch information
rmathis committed Jun 21, 2021
2 parents f11db6a + d064f0a commit 5d6d183
Show file tree
Hide file tree
Showing 11 changed files with 170 additions and 26 deletions.
20 changes: 20 additions & 0 deletions backend/src/main/resources/i18n/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,17 @@ value.template=Template
value.string=String
value.boolean=Boolean
value.list=List
value.long=Long
value.double=Double
value.duration=Duration
value.spring-bean-id=Spring Bean ID
value.BOOLEAN=Boolean
value.SELECTION_LIST=List
value.STRING=String
value.LONG=Long
value.DOUBLE=Double
value.DURATION=Duration
value.SPRING_BEAN_ID=Spring Bean ID

brand.header.title=Source Management
brand.logo-link-label=Shibboleth
Expand Down Expand Up @@ -140,11 +148,23 @@ label.entity-attribute-default=Default Value
tooltip.entity-attribute-default=Default Value
label.entity-attribute-list-options=List options
tooltip.entity-attribute-list-options=List options
label.entity-attribute-friendly-name=Friendly name
tooltip.entity-attribute-friendly-name=Friendly name
label.entity-attribute-attr-name=Attribute name
tooltip.entity-attribute-attr-name=This is normally a uri or urn
label.entity-attribute-display-name=Display name
tooltip.entity-attribute-display-name=Display name

label.entity-attribute-persist-friendly-name=Persist Friendly Name
label.entity-attribute-persist-type=Persist Type
tooltip.entity-attribute-persist-friendly-name=Persist Friendly Name
tooltip.entity-attribute-persist-type=Persist Type

label.entity-attributes=Entity Attributes
label.custom-entity-attributes=Custom Entity Attributes
label.help-text=Help text
label.default-value=Default Value
label.new-attribute=New Custom Entity Attribute

label.metadata-source=Metadata Source
label.metadata-sources=Metadata Sources
Expand Down
133 changes: 125 additions & 8 deletions ui/public/assets/schema/attribute/attribute.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
"type": "object",
"required": [
"name",
"attributeType"
"attributeType",
"attributeFriendlyName",
"attributeName",
"displayName"
],
"properties": {
"name": {
Expand All @@ -19,14 +22,67 @@
"enum": [
"STRING",
"BOOLEAN",
"SELECTION_LIST"
"SELECTION_LIST",
"LONG",
"DOUBLE",
"DURATION",
"SPRING_BEAN_ID"
],
"enumNames": [
"value.string",
"value.boolean",
"value.list"
"value.list",
"value.long",
"value.double",
"value.duration",
"value.spring-bean-id"
]
},
"attributeFriendlyName": {
"type": "string",
"title": "label.entity-attribute-friendly-name",
"description": "tooltip.entity-attribute-friendly-name",
"minLength": 1,
"maxLength": 255
},
"attributeName": {
"type": "string",
"title": "label.entity-attribute-attr-name",
"description": "tooltip.entity-attribute-attr-name",
"minLength": 1,
"maxLength": 255
},
"persistFriendlyName": {
"type": "string",
"title": "label.entity-attribute-persist-friendly-name",
"description": "tooltip.entity-attribute-persist-friendly-name",
"minLength": 1,
"maxLength": 255
},
"persistType": {
"type": "string",
"title": "label.entity-attribute-persist-type",
"description": "tooltip.entity-attribute-persist-type",
"minLength": 1,
"maxLength": 255,
"enum": [
"boolean",
"string",
"number"
],
"enumNames": [
"boolean",
"string",
"number"
]
},
"displayName": {
"type": "string",
"title": "label.entity-attribute-display-name",
"description": "tooltip.entity-attribute-display-name",
"minLength": 1,
"maxLength": 255
},
"helpText": {
"title": "label.entity-attribute-help",
"description": "tooltip.entity-attribute-help",
Expand All @@ -45,7 +101,7 @@
"STRING"
]
},
"defaultValueString": {
"defaultValue": {
"title": "label.entity-attribute-default",
"description": "tooltip.entity-attribute-default",
"type": "string"
Expand All @@ -59,12 +115,73 @@
"BOOLEAN"
]
},
"defaultValueBoolean": {
"defaultValue": {
"title": "label.entity-attribute-default",
"description": "tooltip.entity-attribute-default",
"type": "string",
"default": "true",
"enumNames": [
"True",
"False"
]
}
}
},
{
"properties": {
"attributeType": {
"enum": [
"DURATION"
]
},
"defaultValue": {
"title": "label.entity-attribute-default",
"description": "tooltip.entity-attribute-default",
"type": "string",
"pattern": "^(R\\d*\\/)?P(?:\\d+(?:\\.\\d+)?Y)?(?:\\d+(?:\\.\\d+)?M)?(?:\\d+(?:\\.\\d+)?W)?(?:\\d+(?:\\.\\d+)?D)?(?:T(?:\\d+(?:\\.\\d+)?H)?(?:\\d+(?:\\.\\d+)?M)?(?:\\d+(?:\\.\\d+)?S)?)?$"
}
}
},
{
"properties": {
"attributeType": {
"enum": [
"LONG"
]
},
"defaultValue": {
"title": "label.entity-attribute-default",
"description": "tooltip.entity-attribute-default",
"type": "string"
}
}
},
{
"properties": {
"attributeType": {
"enum": [
"DOUBLE"
]
},
"defaultValue": {
"title": "label.entity-attribute-default",
"description": "tooltip.entity-attribute-default",
"type": "string"
}
}
},
{
"properties": {
"attributeType": {
"enum": [
"INTEGER"
]
},
"defaultValue": {
"title": "label.entity-attribute-default",
"description": "tooltip.entity-attribute-default",
"type": "boolean",
"default": true,
"enumNames": ["True", "False"]
"type": "string",
"pattern": "^\\d+$"
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/form/component/fields/FilterTargetField.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const FilterTargetField = ({

/*eslint-disable react-hooks/exhaustive-deps*/
React.useEffect(() => {
if (term && term.length >= 4) {
if (term?.length >= 4) {
searchIds(term);
}
}, [term]);
Expand Down
4 changes: 2 additions & 2 deletions ui/src/app/form/component/templates/FieldTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export function FieldTemplate ({
{children}
</div>
<div>
{rawHelp && rawErrors.length < 1 && (
<Form.Text className={rawErrors.length > 0 ? "text-danger" : "text-muted"} id={id}>
{rawHelp && rawErrors?.length < 1 && (
<Form.Text className={rawErrors?.length > 0 ? "text-danger" : "text-muted"} id={id}>
<Translate value={rawHelp} />
</Form.Text>
)}
Expand Down
8 changes: 4 additions & 4 deletions ui/src/app/form/component/widgets/OptionWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const OptionWidget = ({
}
};

const defaultInputValue = typeof value === 'object' && value && value.label ? value.label : value;
const defaultInputValue = typeof value === 'object' && value && value.label ? value.label : value ? value : '';

const [ inputValue, setInputValue ] = React.useState( defaultInputValue );

Expand All @@ -90,7 +90,7 @@ const OptionWidget = ({

return (
<Form.Group className="mb-0">
<Form.Label className={`${(touched && rawErrors.length > 0) ? "text-danger" : ""}`}>
<Form.Label className={`${(touched && rawErrors?.length > 0) ? "text-danger" : ""}`}>
<span>
<Translate value={label || schema.title} />
{(label || schema.title) && required ? <FontAwesomeIcon icon={faAsterisk} className="text-danger ml-2" size="sm" /> : null}
Expand All @@ -104,7 +104,7 @@ const OptionWidget = ({
onChange={ _onChange }
allowNew={true}
multiple={false}
className={`toggle-typeahead ${rawErrors.length > 0 ? "is-invalid" : ""}`}
className={`toggle-typeahead ${rawErrors?.length > 0 ? "is-invalid" : ""}`}
options={opts}
placeholder={uiSchema['ui:placeholder'] ? translator(uiSchema['ui:placeholder'] ): ''}
disabled={disabled || readonly}
Expand All @@ -122,7 +122,7 @@ const OptionWidget = ({
<ToggleButton isOpen={isMenuShown} onClick={e => toggleMenu()} disabled={disabled || readonly} />
)}
</Typeahead>
{rawErrors.length > 0 && touched && (
{rawErrors?.length > 0 && touched && (
<ListGroup as="ul">
{rawErrors.map((error, i) => {
return (
Expand Down
6 changes: 3 additions & 3 deletions ui/src/app/form/component/widgets/SelectWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const SelectWidget = ({

return (
<Form.Group>
<Form.Label className={`${touched && rawErrors.length > 0 ? "text-danger" : ""}`}>
<Form.Label className={`${touched && rawErrors?.length > 0 ? "text-danger" : ""}`}>
<span>
<Translate value={label || schema.title} />
{(label || schema.title) && required ? <FontAwesomeIcon icon={faAsterisk} className="ml-2 text-danger" size="sm" /> : null}
Expand All @@ -103,7 +103,7 @@ const SelectWidget = ({
disabled={disabled}
readOnly={readonly}
autoFocus={autofocus}
className={touched && rawErrors.length > 0 ? "is-invalid" : ""}
className={touched && rawErrors?.length > 0 ? "is-invalid" : ""}
onBlur={
onBlur &&
((event) => {
Expand Down Expand Up @@ -132,7 +132,7 @@ const SelectWidget = ({
</option>
)}
</Form.Control>
{rawErrors.length > 0 && touched && (
{rawErrors?.length > 0 && touched && (
<ListGroup as="ul">
{rawErrors.map((error, i) => {
return (
Expand Down
8 changes: 4 additions & 4 deletions ui/src/app/form/component/widgets/TextWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ const TextWidget = ({
_onBlur(evt);
};

// const classNames = [rawErrors.length > 0 ? "is-invalid" : "", type === 'file' ? 'custom-file-label': ""]
// const classNames = [rawErrors?.length > 0 ? "is-invalid" : "", type === 'file' ? 'custom-file-label': ""]
return (
<Form.Group className="mb-0">
<Form.Label className={`${rawErrors.length > 0 && touched ? "text-danger" : ""}`}>
<Form.Label className={`${rawErrors?.length > 0 && touched ? "text-danger" : ""}`}>
<span>
<Translate value={label || schema.title} />
{(label || schema.title) && required ?
Expand All @@ -56,7 +56,7 @@ const TextWidget = ({
required={required}
disabled={disabled}
readOnly={readonly}
className={rawErrors.length > 0 && touched ? "is-invalid" : ""}
className={rawErrors?.length > 0 && touched ? "is-invalid" : ""}
list={schema.examples ? `examples_${id}` : undefined}
type={inputType}
value={value || value === 0 ? value : ""}
Expand All @@ -73,7 +73,7 @@ const TextWidget = ({
})}
</datalist>
) : null}
{rawErrors.length > 0 && touched && (
{rawErrors?.length > 0 && touched && (
<ListGroup as="ul">
{rawErrors.map((error, i) => {
return (
Expand Down
4 changes: 2 additions & 2 deletions ui/src/app/form/component/widgets/TextareaWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const TextareaWidget = ({

return (
<>
<Form.Label className={`${touched && rawErrors.length > 0 ? "text-danger" : ""}`}>
<Form.Label className={`${touched && rawErrors?.length > 0 ? "text-danger" : ""}`}>
<span>
<Translate value={label || schema.title} />
{(label || schema.title) && required ? <FontAwesomeIcon icon={faAsterisk} className="ml-2 text-danger" size="sm" /> : null}
Expand All @@ -69,7 +69,7 @@ const TextareaWidget = ({
onFocus={_onFocus}
/>
</InputGroup>
{rawErrors.length > 0 && touched && (
{rawErrors?.length > 0 && touched && (
<ListGroup as="ul">
{rawErrors.map((error, i) => {
return (
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/form/component/widgets/UpDownWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const UpDownWidget = ({
onBlur={onCustomBlur}
onFocus={_onFocus}
/>
{rawErrors.length > 0 && touched && (
{rawErrors?.length > 0 && touched && (
<ListGroup as="ul">
{rawErrors.map((error, i) => {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ export const CustomAttributeDefinition = {
fields: [
'name',
'attributeType',
'attributeName',
'attributeFriendlyName',
'displayName',
'persistFriendlyName',
'persistType',
'helpText'
]
},
Expand Down
4 changes: 3 additions & 1 deletion ui/src/app/metadata/editor/MetadataAttributeEditor.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { MetadataFormContext, setFormDataAction, setFormErrorAction } from '../hoc/MetadataFormContext';
import { MetadataDefinitionContext, MetadataSchemaContext } from '../hoc/MetadataSchema';
import { transformErrors } from '../domain/transform';

import Form from '@rjsf/bootstrap-4';

Expand Down Expand Up @@ -44,7 +45,8 @@ export function MetadataAttributeEditor({ children }) {
fields={fields}
widgets={widgets}
liveValidate={true}
ErrorList={ErrorListTemplate}>
ErrorList={ErrorListTemplate}
transformErrors={transformErrors}>
<></>
</Form>
</div>
Expand Down

0 comments on commit 5d6d183

Please sign in to comment.