Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend custom fields to Position, Organization, Location #3377

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
234 changes: 234 additions & 0 deletions anet-dictionary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -476,13 +476,247 @@ fields:

location:
format: LAT_LON
customFields:
multipleButtons:
type: enumset
label: Choose one or more of the options
helpText: Help text for choosing multiple values
choices:
opt1:
label: Option 1
opt2:
label: Option 2
opt3:
label: Option 3
inputFieldName:
type: text
label: Text field
placeholder: Placeholder text for input field
helpText: Help text for text field
colourOptions:
type: enum
label: Choose one of the colours
helpText: Help text for choosing colours
choices:
GREEN:
label: Green
color: '#c2ffb3'
AMBER:
label: Amber
color: '#ffe396'
RED:
label: Red
color: '#ff8279'
textareaFieldName:
type: text
label: Textarea field
placeholder: Placeholder text for textarea field
helpText: Help text for textarea field
componentClass: textarea
style:
height: 200px
visibleWhen: $[?(@.colourOptions === 'GREEN')]
numberFieldName:
type: number
typeError: Number field must be a number
label: Number field
placeholder: Placeholder text for number field
helpText: Help text for number field
validations:
- type: integer
- type: min
params: [5]
- type: max
params: [100]
visibleWhen: $[?((@.colourOptions === 'GREEN')||(@.colourOptions === 'RED'))]
nlt:
type: date
label: Not later than date
helpText: Help text for date field
nlt_dt:
type: datetime
label: Not later than datetime
helpText: Help text for datetime field
arrayFieldName:
type: array_of_objects
label: Array of objects
helpText: Here you can add as many objects as needed
addButtonLabel: Add an object
objectLabel: Object
objectFields:
textF:
type: text
label: Object text
placeholder: Placeholder text for object text field
helpText: Help text for object text field
dateF:
type: date
label: Object date
helpText: Help text for object date field
visibleWhen: $[?(@.colourOptions === 'GREEN')]

position:
name: 'Position Name'
customFields:
multipleButtons:
type: enumset
label: Choose one or more of the options
helpText: Help text for choosing multiple values
choices:
opt1:
label: Option 1
opt2:
label: Option 2
opt3:
label: Option 3
inputFieldName:
type: text
label: Text field
placeholder: Placeholder text for input field
helpText: Help text for text field
colourOptions:
type: enum
label: Choose one of the colours
helpText: Help text for choosing colours
choices:
GREEN:
label: Green
color: '#c2ffb3'
AMBER:
label: Amber
color: '#ffe396'
RED:
label: Red
color: '#ff8279'
textareaFieldName:
type: text
label: Textarea field
placeholder: Placeholder text for textarea field
helpText: Help text for textarea field
componentClass: textarea
style:
height: 200px
visibleWhen: $[?(@.colourOptions === 'GREEN')]
numberFieldName:
type: number
typeError: Number field must be a number
label: Number field
placeholder: Placeholder text for number field
helpText: Help text for number field
validations:
- type: integer
- type: min
params: [5]
- type: max
params: [100]
visibleWhen: $[?((@.colourOptions === 'GREEN')||(@.colourOptions === 'RED'))]
nlt:
type: date
label: Not later than date
helpText: Help text for date field
nlt_dt:
type: datetime
label: Not later than datetime
helpText: Help text for datetime field
arrayFieldName:
type: array_of_objects
label: Array of objects
helpText: Here you can add as many objects as needed
addButtonLabel: Add an object
objectLabel: Object
objectFields:
textF:
type: text
label: Object text
placeholder: Placeholder text for object text field
helpText: Help text for object text field
dateF:
type: date
label: Object date
helpText: Help text for object date field
visibleWhen: $[?(@.colourOptions === 'GREEN')]

organization:
shortName: Name
parentOrg: Parent Organization
customFields:
multipleButtons:
type: enumset
label: Choose one or more of the options
helpText: Help text for choosing multiple values
choices:
opt1:
label: Option 1
opt2:
label: Option 2
opt3:
label: Option 3
inputFieldName:
type: text
label: Text field
placeholder: Placeholder text for input field
helpText: Help text for text field
colourOptions:
type: enum
label: Choose one of the colours
helpText: Help text for choosing colours
choices:
GREEN:
label: Green
color: '#c2ffb3'
AMBER:
label: Amber
color: '#ffe396'
RED:
label: Red
color: '#ff8279'
textareaFieldName:
type: text
label: Textarea field
placeholder: Placeholder text for textarea field
helpText: Help text for textarea field
componentClass: textarea
style:
height: 200px
visibleWhen: $[?(@.colourOptions === 'GREEN')]
numberFieldName:
type: number
typeError: Number field must be a number
label: Number field
placeholder: Placeholder text for number field
helpText: Help text for number field
validations:
- type: integer
- type: min
params: [5]
- type: max
params: [100]
visibleWhen: $[?((@.colourOptions === 'GREEN')||(@.colourOptions === 'RED'))]
nlt:
type: date
label: Not later than date
helpText: Help text for date field
nlt_dt:
type: datetime
label: Not later than datetime
helpText: Help text for datetime field
arrayFieldName:
type: array_of_objects
label: Array of objects
helpText: Here you can add as many objects as needed
addButtonLabel: Add an object
objectLabel: Object
objectFields:
textF:
type: text
label: Object text
placeholder: Placeholder text for object text field
helpText: Help text for object text field
dateF:
type: date
label: Object date
helpText: Help text for object date field
visibleWhen: $[?(@.colourOptions === 'GREEN')]

advisor:

Expand Down
14 changes: 14 additions & 0 deletions client/src/components/CustomFields.js
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,20 @@ const FIELD_COMPONENTS = {
[CUSTOM_FIELD_TYPE.ARRAY_OF_ANET_OBJECTS]: ArrayOfAnetObjectsField
}

// mutates the object
export function initInvisibleFields(
anetObj,
config,
parentFieldName = DEFAULT_CUSTOM_FIELDS_PARENT
) {
if (anetObj[parentFieldName]) {
// set initial invisible custom fields
anetObj[parentFieldName][
INVISIBLE_CUSTOM_FIELDS_FIELD
] = getInvisibleFields(config, parentFieldName, anetObj)
}
}

export function getInvisibleFields(
fieldsConfig = {},
parentFieldName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const widgetPropsOrganization = {
overlayColumns: ["Name"],
filterDefs: entityFilters,
queryParams: { status: Model.STATUS.ACTIVE },
fields: Models.Organization.autocompleteQuery,
fields: Models.Organization.autocompleteQueryWithNotes,
addon: ORGANIZATIONS_ICON
}

Expand All @@ -84,7 +84,7 @@ const widgetPropsPosition = {
overlayColumns: ["Position", "Organization", "Current Occupant"],
filterDefs: entityFilters,
queryParams: { status: Model.STATUS.ACTIVE },
fields: Models.Position.autocompleteQuery,
fields: Models.Position.autocompleteQueryWithNotes,
addon: POSITIONS_ICON
}

Expand All @@ -94,7 +94,7 @@ const widgetPropsLocation = {
overlayColumns: ["Name"],
filterDefs: entityFilters,
queryParams: { status: Model.STATUS.ACTIVE },
fields: Models.Location.autocompleteQuery,
fields: Models.Location.autocompleteQueryWithNotes,
addon: LOCATIONS_ICON
}

Expand Down
14 changes: 13 additions & 1 deletion client/src/models/Location.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import Model from "components/Model"
import Model, {
createCustomFieldsSchema,
GRAPHQL_NOTES_FIELDS
} from "components/Model"
import { convertLatLngToMGRS, convertMGRSToLatLng } from "geoUtils"
import _isEmpty from "lodash/isEmpty"
import LOCATIONS_ICON from "resources/locations.png"
Expand All @@ -17,6 +20,11 @@ export default class Location extends Model {
REPORT_APPROVAL: "REPORT_APPROVAL"
}

// create yup schema for the customFields, based on the customFields config
static customFieldsSchema = createCustomFieldsSchema(
Settings.fields.location.customFields
)

static yupSchema = yup
.object()
.shape({
Expand Down Expand Up @@ -118,10 +126,14 @@ export default class Location extends Model {
.nullable()
.default([])
})
// not actually in the database, the database contains the JSON customFields
.concat(Location.customFieldsSchema)
.concat(Model.yupSchema)

static autocompleteQuery = "uuid, name"

static autocompleteQueryWithNotes = `${this.autocompleteQuery} ${GRAPHQL_NOTES_FIELDS}`

static hasCoordinates(location) {
return (
location &&
Expand Down
14 changes: 13 additions & 1 deletion client/src/models/Organization.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import Model from "components/Model"
import Model, {
createCustomFieldsSchema,
GRAPHQL_NOTES_FIELDS
} from "components/Model"
import ORGANIZATIONS_ICON from "resources/organizations.png"
import Settings from "settings"
import utils from "utils"
Expand All @@ -20,6 +23,11 @@ export default class Organization extends Model {
REPORT_APPROVAL: "REPORT_APPROVAL"
}

// create yup schema for the customFields, based on the customFields config
static customFieldsSchema = createCustomFieldsSchema(
Settings.fields.organization.customFields
)

static yupSchema = yup
.object()
.shape({
Expand Down Expand Up @@ -89,11 +97,15 @@ export default class Organization extends Model {
positions: yup.array().nullable().default([]),
tasks: yup.array().nullable().default([])
})
// not actually in the database, the database contains the JSON customFields
.concat(Organization.customFieldsSchema)
.concat(Model.yupSchema)

static autocompleteQuery =
"uuid, shortName, longName, identificationCode, type"

static autocompleteQueryWithNotes = `${this.autocompleteQuery} ${GRAPHQL_NOTES_FIELDS}`

static humanNameOfStatus(status) {
return utils.sentenceCase(status)
}
Expand Down
Loading