diff --git a/src/common/defaultConfigs.js b/src/common/defaultConfigs.js new file mode 100644 index 00000000..8cb31e50 --- /dev/null +++ b/src/common/defaultConfigs.js @@ -0,0 +1,394 @@ +export const CONCEPT_MAP_DEFAULT_CONFIG = { + name: "FHIR Default (ConceptMap)", + web_default: true, + is_default: false, + config: { + tabs: [ + { + type: "codes", + label: "Codes", + page_size: 25, + default: true, + layout: "table", + }, + { type: "versions", label: "Versions", page_size: 25, layout: "table" }, + { type: "about", label: "About" }, + ], + }, +}; + +export const CODE_SYSTEM_DEFAULT_CONFIG = { + name: "FHIR Default (CodeSystem)", + web_default: true, + is_default: false, + config: { + tabs: [ + { + type: "codes", + label: "Codes", + page_size: 25, + default: true, + layout: "table", + }, + { type: "versions", label: "Versions", page_size: 25, layout: "table" }, + { type: "about", label: "About" }, + ], + }, +}; + +export const VALUE_SET_DEFAULT_CONFIG = { + name: "FHIR Default (ValueSet)", + web_default: true, + is_default: false, + config: { + tabs: [ + { + type: "codes", + label: "Codes", + page_size: 25, + default: true, + layout: "table", + }, + { type: "versions", label: "Versions", page_size: 25, layout: "table" }, + { type: "about", label: "About" }, + ], + }, +}; + +export const FHIR_DEFAULT_CONFIG = { + name: "FHIR Default", + web_default: true, + is_default: false, + config: { + tabs: [ + { type: "CodeSystem", label: "Code Systems", default: true }, + { type: "ValueSet", label: "Value Sets" }, + { type: "ConceptMap", label: "Concept Maps" }, + ], + }, +}; + +const ORG_BACKGROUND_CONFIG = { + background: { + image: "", + backgroundColor: "", + }, + forground: { + color: "", + titleColor: "", + descriptionColor: "", + title: "", + description: "", + }, +}; + +export const ORG_DEFAULT_CONFIG = { + name: "OCL Default (Org)", + web_default: true, + is_default: false, + config: { + header: { + ...ORG_BACKGROUND_CONFIG, + attributes: [ + { + label: "Company", + value: "company", + type: "text", + }, + { + label: "Location", + value: "location", + type: "text", + }, + { + label: "Website", + value: "website", + type: "url", + }, + ], + height: null, + controls: true, + signatures: true, + logo: true, + shrink: false, + }, + tabs: [ + { + type: "sources", + label: "Sources", + page_size: 25, + default: true, + layout: "table", + color: "", + }, + { + type: "collections", + label: "Collections", + page_size: 25, + layout: "table", + color: "", + }, + { + type: "users", + label: "Members", + page_size: 25, + layout: "table", + color: "", + }, + { type: "about", label: "About", color: "" }, + ], + }, +}; + +export const SOURCE_DEFAULT_CONFIG = { + name: "OCL Default (Source)", + web_default: true, + is_default: false, + config: { + header: { + shrink: false, + visibleAttributes: [ + { + label: "Source Type", + value: "source_type", + type: "text", + }, + { + label: "Supported Locales", + value: "supported_locales", + }, + { + label: "Custom Validation Schema", + value: "custom_validation_schema", + type: "text", + }, + ], + invisibleAttributes: [ + { + label: "Canonical Url", + value: "canonical_url", + type: "url", + }, + { + label: "Publisher", + value: "publisher", + type: "text", + }, + { + label: "Purpose", + value: "purpose", + type: "text", + }, + { + label: "Copyright", + value: "copyright", + type: "text", + }, + { + label: "Content Type", + value: "content_type", + type: "text", + }, + { + label: "Revision Date", + value: "revision_date", + type: "date", + }, + { + label: "Revision Date", + value: "revision_date", + type: "date", + }, + { + label: "Identifier", + value: "identifier", + type: "json", + }, + { + label: "Contact", + value: "contact", + type: "json", + }, + { + label: "Jurisdiction", + value: "jurisdiction", + type: "json", + }, + { + label: "Meta", + value: "meta", + type: "json", + }, + { + label: "Collection Reference", + value: "collection_reference", + type: "text", + }, + { + label: "Hierarchy Meaning", + value: "hierarchy_meaning", + type: "text", + }, + { + label: "Experimental", + value: "experimental", + type: "boolean", + }, + { + label: "Case Sensitive", + value: "case_sensitive", + type: "boolean", + }, + { + label: "Compositional", + value: "compositional", + type: "boolean", + }, + { + label: "Version Needed", + value: "version_needed", + type: "boolean", + }, + ], + }, + tabs: [ + { + type: "concepts", + label: "Concepts", + page_size: 25, + default: true, + layout: "table", + }, + { type: "mappings", label: "Mappings", page_size: 25, layout: "table" }, + { type: "versions", label: "Versions", page_size: 25, layout: "table" }, + { type: "about", label: "About" }, + ], + }, +}; + +export const COLLECTION_DEFAULT_CONFIG = { + name: "OCL Default (Collection)", + web_default: true, + is_default: false, + config: { + header: { + shrink: false, + visibleAttributes: [ + { + label: "Short Code", + value: "short_code", + type: "text", + }, + { + label: "Name", + value: "name", + type: "text", + }, + { + label: "Collection Type", + value: "collection_type", + type: "text", + }, + { + label: "Custom Validation Schema", + value: "custom_validation_schema", + type: "text", + }, + { + label: "Supported Locales", + value: "supported_locales", + }, + ], + invisibleAttributes: [ + { + label: "Canonical Url", + value: "canonical_url", + type: "url", + }, + { + label: "Publisher", + value: "publisher", + type: "text", + }, + { + label: "Purpose", + value: "purpose", + type: "text", + }, + { + label: "Copyright", + value: "copyright", + type: "text", + }, + { + label: "Preferred Source", + value: "preferred_source", + type: "text", + }, + { + label: "Custom Resources Linked Source", + value: "custom_resources_linked_source", + type: "text", + }, + { + label: "Revision Date", + value: "revision_date", + type: "date", + }, + { + label: "Identifier", + value: "identifier", + type: "json", + }, + { + label: "Contact", + value: "contact", + type: "json", + }, + { + label: "Jurisdiction", + value: "jurisdiction", + type: "json", + }, + { + label: "Meta", + value: "meta", + type: "json", + }, + { + label: "Immutable", + value: "immutable", + type: "boolean", + }, + { + label: "Locked Date", + value: "locked_date", + type: "date", + }, + { + label: "Experimental", + value: "experimental", + type: "boolean", + }, + ], + }, + tabs: [ + { + type: "concepts", + label: "Concepts", + page_size: 25, + default: true, + layout: "table", + }, + { type: "mappings", label: "Mappings", page_size: 25, layout: "table" }, + { + type: "references", + label: "References", + page_size: 25, + layout: "table", + }, + { type: "versions", label: "Versions", page_size: 25, layout: "table" }, + { type: "about", label: "About" }, + ], + }, +}; diff --git a/src/components/collections/CollectionHome.jsx b/src/components/collections/CollectionHome.jsx index 1c71eb81..5b13f440 100644 --- a/src/components/collections/CollectionHome.jsx +++ b/src/components/collections/CollectionHome.jsx @@ -7,22 +7,10 @@ import CollectionHomeTabs from './CollectionHomeTabs'; import NotFound from '../common/NotFound'; import AccessDenied from '../common/AccessDenied'; import PermissionDenied from '../common/PermissionDenied'; +import { COLLECTION_DEFAULT_CONFIG } from "../../common/defaultConfigs" const TABS = ['details', 'concepts', 'mappings', 'references', 'versions', 'about'] -const DEFAULT_CONFIG = { - name: 'OCL Default (Collection)', - web_default: true, - is_default: false, - config: { - tabs: [ - {type: "concepts", label: "Concepts", page_size: 25, "default": true, layout: 'table'}, - {type: "mappings", label: "Mappings", page_size: 25, layout: 'table'}, - {type: "references", label: "References", page_size: 25, layout: 'table'}, - {type: "versions", label: "Versions", page_size: 25, layout: 'table'}, - {type: "about", label: "About"}, - ] - } -} + class CollectionHome extends React.Component { constructor(props) { @@ -147,7 +135,7 @@ class CollectionHome extends React.Component { this.setState({ isLoading: false, collection: collection, - selectedConfig: defaultCustomConfig || DEFAULT_CONFIG, + selectedConfig: defaultCustomConfig || COLLECTION_DEFAULT_CONFIG, customConfigs: customConfigs, }, () => { if(isEmpty(this.state.versions)) @@ -226,11 +214,11 @@ class CollectionHome extends React.Component { currentVersion={this.getCurrentVersion()} aboutTab={showAboutTab} onVersionUpdate={this.onVersionUpdate} - customConfigs={[...customConfigs, DEFAULT_CONFIG]} + customConfigs={[...customConfigs, COLLECTION_DEFAULT_CONFIG]} onConfigChange={this.onConfigChange} selectedConfig={selectedConfig} showConfigSelection={this.customConfigFeatureApplicable()} - isOCLDefaultConfigSelected={isEqual(selectedConfig, DEFAULT_CONFIG)} + isOCLDefaultConfigSelected={isEqual(selectedConfig, COLLECTION_DEFAULT_CONFIG)} isLoadingVersions={isLoadingVersions} /> diff --git a/src/components/collections/CollectionHomeHeader.jsx b/src/components/collections/CollectionHomeHeader.jsx index 170618da..3a9fbaac 100644 --- a/src/components/collections/CollectionHomeHeader.jsx +++ b/src/components/collections/CollectionHomeHeader.jsx @@ -7,7 +7,7 @@ import { Delete as DeleteIcon, } from '@material-ui/icons'; import { Tooltip, Button, ButtonGroup, Collapse } from '@material-ui/core'; -import { keys, map, startCase, get } from 'lodash'; +import { filter, map, get } from 'lodash'; import { toFullAPIURL, copyURL, nonEmptyCount, currentUserHasAccess } from '../../common/utils'; import { GREEN } from '../../common/constants'; import APIService from '../../services/APIService'; @@ -31,34 +31,21 @@ import RetiredChip from '../common/RetiredChip'; import ProcessingChip from '../common/ProcessingChip'; import ConceptContainerDelete from '../common/ConceptContainerDelete'; import CollapsibleDivider from '../common/CollapsibleDivider'; +import { COLLECTION_DEFAULT_CONFIG } from '../../common/defaultConfigs'; + +const DEFAULT_VISIBLE_ATTRIBUTES = COLLECTION_DEFAULT_CONFIG.config.header.visibleAttributes +const DEFAULT_INVISIBLE_ATTRIBUTES = COLLECTION_DEFAULT_CONFIG.config.header.invisibleAttributes -const HIDDEN_ATTRIBUTES = { - canonical_url: 'url', - publisher: 'text', - purpose: 'text', - copyright: 'text', - preferred_source: 'text', - custom_resources_linked_source: 'text', - revision_date: 'date', - identifier: 'json', - contact: 'json', - jurisdiction: 'json', - meta: 'json', - immutable: 'boolean', - locked_date: 'date', - experimental: 'boolean' -} const CollectionHomeHeader = ({ collection, isVersionedObject, versionedObjectURL, currentURL, config }) => { const downloadFileName = isVersionedObject ? `${collection.type}-${collection.short_code}` : `${collection.type}-${collection.short_code}-${collection.id}`; const hasAccess = currentUserHasAccess(); - const [openHeader, setOpenHeader] = React.useState(!get(config, 'config.shrinkHeader', false)); + const [openHeader, setOpenHeader] = React.useState(!get(config, 'config.header.shrink', false)); const [deleteDialog, setDeleteDialog] = React.useState(false); const [logoURL, setLogoURL] = React.useState(collection.logo_url) const [collectionForm, setCollectionForm] = React.useState(false); const onIconClick = () => copyURL(toFullAPIURL(currentURL)) - const hasManyHiddenAttributes = nonEmptyCount(collection, keys(HIDDEN_ATTRIBUTES)) >= 4; const onLogoUpload = (base64, name) => { APIService.new().overrideURL(versionedObjectURL).appendToUrl('logo/') .post({base64: base64, name: name}) @@ -67,10 +54,36 @@ const CollectionHomeHeader = ({ setLogoURL(get(response, 'data.logo_url', logoURL)) }) } + const getDefaultHiddenAttributes = () => { + return filter(DEFAULT_VISIBLE_ATTRIBUTES, (attr) => { + return !map(get(config, 'config.header.visibleAttributes'),(attr) => attr.value).includes(attr.value) + } + ) + } + const getHiddenAttributes = () => { + if (get(config, 'config.header.invisibleAttributes') === 'object'){ + return {...get(config, 'config.header.invisibleAttributes'), ...getDefaultHiddenAttributes()} + } + else if (get(config, 'config.header.invisibleAttributes')) { + return { DEFAULT_INVISIBLE_ATTRIBUTES, ...getDefaultHiddenAttributes() } + } + else return [] + } + const getVisibleAttributes = ()=>{ + if (get(config, 'config.header.visibleAttributes') === 'object'){ + return get(config, 'config.header.visibleAttributes') + } + else if (get(config, 'config.header.visibleAttributes')) { + return DEFAULT_VISIBLE_ATTRIBUTES + } + else return [] + } + const hasManyHiddenAttributes = nonEmptyCount(collection, map(getHiddenAttributes(),(attr) => attr.value)) >= 4; + React.useEffect( - () => setOpenHeader(!get(config, 'config.shrinkHeader', false)), - [get(config, 'config.shrinkHeader')] + () => setOpenHeader(!get(config, 'config.header.shrink', false)), + [get(config, 'config.header.shrink')] ) const deleteCollection = () => { @@ -163,28 +176,25 @@ const CollectionHomeHeader = ({ {collection.description} } - - - - } gridClass="col-md-12" type="component" /> - + {map(getVisibleAttributes(), (attr) => { + if (attr.value === "supported_locales" || attr.value === "default_locale"){ + return } gridClass="col-md-12" type="component" /> + } + return + })} } gridClass="col-md-12" /> { hasManyHiddenAttributes ?
: { - map(HIDDEN_ATTRIBUTES, (type, attr) => ( - + map(getHiddenAttributes(), (attr) => ( + )) } diff --git a/src/components/common/CollapsibleAttributes.jsx b/src/components/common/CollapsibleAttributes.jsx index 705b0f4a..50e7fbcf 100644 --- a/src/components/common/CollapsibleAttributes.jsx +++ b/src/components/common/CollapsibleAttributes.jsx @@ -3,11 +3,12 @@ import { ArrowDropDown as ArrowDownIcon, ArrowDropUp as ArrowUpIcon } from '@material-ui/icons'; import { Collapse, Chip } from '@material-ui/core'; -import { map, get, startCase, isArray } from 'lodash'; +import { map, get } from 'lodash'; import HeaderAttribute from './HeaderAttribute'; +import SupportedLocales from '../common/SupportedLocales'; const CollapsibleAttributes = ({ - object, urlAttrs, jsonAttrs, textAttrs, dateAttrs, booleanAttrs + object, hiddenAttributes }) => { const [expand, setExpand] = React.useState(false); const onExpand = () => setExpand(!expand); @@ -16,29 +17,15 @@ const CollapsibleAttributes = ({ { - isArray(urlAttrs) && map(urlAttrs, attr => ( - - )) - } - { - isArray(textAttrs) && map(textAttrs, attr => ( - - )) - } - { - isArray(booleanAttrs) && map(booleanAttrs, attr => ( - - )) - } - { - isArray(dateAttrs) && map(dateAttrs, attr => ( - - )) - } - { - isArray(jsonAttrs) && map(jsonAttrs, attr => ( - - )) + map(hiddenAttributes, (attr) => { + const value = get(object, attr.value) + if (!value) return null + + if (attr.value === "supported_locales" || attr.value === "default_locale"){ + return } gridClass="col-md-12" type="component" /> + } + return + }) }
diff --git a/src/components/common/JSONEditor.jsx b/src/components/common/JSONEditor.jsx index 9b2fdb78..d122761b 100644 --- a/src/components/common/JSONEditor.jsx +++ b/src/components/common/JSONEditor.jsx @@ -3,8 +3,9 @@ import JSONInput from 'react-json-editor-ajrm'; import locale from 'react-json-editor-ajrm/locale/en'; const JSONEditor = props => { + return ( - + ) } diff --git a/src/components/fhir/ConceptMapHome.jsx b/src/components/fhir/ConceptMapHome.jsx index 73d038e4..f5568376 100644 --- a/src/components/fhir/ConceptMapHome.jsx +++ b/src/components/fhir/ConceptMapHome.jsx @@ -8,19 +8,7 @@ import NotFound from '../common/NotFound'; import NavigationButtonGroup from '../search/NavigationButtonGroup'; import ContainerHomeHeader from './ContainerHomeHeader'; import ConceptMapGroups from './ConceptMapGroups'; - -const CONCEPT_MAP_DEFAULT_CONFIG = { - name: 'FHIR Default (ConceptMap)', - web_default: true, - is_default: false, - config: { - tabs: [ - {type: "codes", label: "Codes", page_size: 25, "default": true, layout: 'table'}, - {type: "versions", label: "Versions", page_size: 25, layout: 'table'}, - {type: "about", label: "About"}, - ] - } -} +import { CONCEPT_MAP_DEFAULT_CONFIG } from "../../common/defaultConfigs" class ConceptMapHome extends React.Component { constructor(props) { diff --git a/src/components/fhir/ContainerHome.jsx b/src/components/fhir/ContainerHome.jsx index cf8f1009..4c3a9cc2 100644 --- a/src/components/fhir/ContainerHome.jsx +++ b/src/components/fhir/ContainerHome.jsx @@ -6,32 +6,7 @@ import APIService from '../../services/APIService'; import ContainerHomeHeader from './ContainerHomeHeader'; import ContainerHomeTabs from './ContainerHomeTabs'; import { getAppliedServerConfig } from '../../common/utils'; - -const CODE_SYSTEM_DEFAULT_CONFIG = { - name: 'FHIR Default (CodeSystem)', - web_default: true, - is_default: false, - config: { - tabs: [ - {type: "codes", label: "Codes", page_size: 25, "default": true, layout: 'table'}, - {type: "versions", label: "Versions", page_size: 25, layout: 'table'}, - {type: "about", label: "About"}, - ] - } -} - -const VALUE_SET_DEFAULT_CONFIG = { - name: 'FHIR Default (ValueSet)', - web_default: true, - is_default: false, - config: { - tabs: [ - {type: "codes", label: "Codes", page_size: 25, "default": true, layout: 'table'}, - {type: "versions", label: "Versions", page_size: 25, layout: 'table'}, - {type: "about", label: "About"}, - ] - } -} +import { CODE_SYSTEM_DEFAULT_CONFIG, VALUE_SET_DEFAULT_CONFIG} from "../../common/defaultConfigs" class ContainerHome extends React.Component { constructor(props) { diff --git a/src/components/fhir/Fhir.jsx b/src/components/fhir/Fhir.jsx index 751a2621..9ed4dd1b 100644 --- a/src/components/fhir/Fhir.jsx +++ b/src/components/fhir/Fhir.jsx @@ -3,19 +3,7 @@ import { getAppliedServerConfig } from '../../common/utils'; import OrgHomeHeader from '../orgs/OrgHomeHeader'; import FhirTabs from './FhirTabs'; import HeaderAttribute from '../common/HeaderAttribute'; - -const DEFAULT_CONFIG = { - name: 'FHIR Default', - web_default: true, - is_default: false, - config: { - tabs: [ - { type: "CodeSystem", label: "Code Systems", "default": true }, - { type: "ValueSet", label: "Value Sets" }, - { type: "ConceptMap", label: "Concept Maps" }, - ] - } -} +import { FHIR_DEFAULT_CONFIG } from "../../common/defaultConfigs" class Fhir extends React.Component { constructor(props) { @@ -23,7 +11,7 @@ class Fhir extends React.Component { this.serverConfig = getAppliedServerConfig() this.state = { tab: this.getDefaultTab(), - config: DEFAULT_CONFIG + config: FHIR_DEFAULT_CONFIG } } diff --git a/src/components/fhir/OwnerHome.jsx b/src/components/fhir/OwnerHome.jsx index cadbceca..93724fe9 100644 --- a/src/components/fhir/OwnerHome.jsx +++ b/src/components/fhir/OwnerHome.jsx @@ -6,19 +6,7 @@ import { import { getAppliedServerConfig } from '../../common/utils'; import FhirTabs from './FhirTabs'; import OwnerButton from '../common/OwnerButton'; - -const DEFAULT_CONFIG = { - name: 'FHIR Default', - web_default: true, - is_default: false, - config: { - tabs: [ - { type: "CodeSystem", label: "Code Systems", "default": true }, - { type: "ValueSet", label: "Value Sets" }, - { type: "ConceptMap", label: "Concept Maps" }, - ] - } -} +import { FHIR_DEFAULT_CONFIG } from "../../common/defaultConfigs" class OwnerHome extends React.Component { constructor(props) { @@ -36,7 +24,7 @@ class OwnerHome extends React.Component { this.state = { owner: {ownerType: ownerType, owner: owner, id: owner,}, tab: this.getDefaultTab(), - config: DEFAULT_CONFIG + config: FHIR_DEFAULT_CONFIG } } diff --git a/src/components/orgs/OrgHome.jsx b/src/components/orgs/OrgHome.jsx index 4722efb0..f4ecd4c4 100644 --- a/src/components/orgs/OrgHome.jsx +++ b/src/components/orgs/OrgHome.jsx @@ -12,43 +12,7 @@ import OrgHomeTabs from './OrgHomeTabs'; import NotFound from '../common/NotFound'; import AccessDenied from '../common/AccessDenied'; import PermissionDenied from '../common/PermissionDenied'; - -const BACKGROUND_CONFIG = { - background: { - image: '', - backgroundColor: '', - }, - forground: { - color: '', - titleColor: '', - descriptionColor: '', - title: '', - description: "" - }, -} - -const DEFAULT_CONFIG = { - name: 'OCL Default (Org)', - web_default: true, - is_default: false, - config: { - header: { - ...BACKGROUND_CONFIG, - height: '', - controls: true, - attributes: true, - signatures: true, - logo: true, - shrink: false, - }, - tabs: [ - {type: "sources", label: "Sources", page_size: 25, "default": true, layout: 'table', color: ''}, - {type: "collections", label: "Collections", page_size: 25, layout: 'table', color: ''}, - {type: "users", label: "Members", page_size: 25, layout: 'table', color: ''}, - {type: "about", label: "About", color: ''}, - ] - } -} +import { ORG_DEFAULT_CONFIG } from "../../common/defaultConfigs" class OrgHome extends React.Component { constructor(props) { @@ -159,7 +123,7 @@ class OrgHome extends React.Component { this.setState({ isLoading: false, org: org, - selectedConfig: defaultCustomConfig || DEFAULT_CONFIG, + selectedConfig: defaultCustomConfig || ORG_DEFAULT_CONFIG, customConfigs: customConfigs, }, this.setTab) } @@ -248,7 +212,7 @@ class OrgHome extends React.Component { onPinCreate={this.createPin} onPinDelete={this.deletePin} showPin={isCurrentUserMemberOfOrg} - customConfigs={[...customConfigs, DEFAULT_CONFIG]} + customConfigs={[...customConfigs, ORG_DEFAULT_CONFIG]} onConfigChange={this.onConfigChange} aboutTab={showAboutTab} showConfigSelection={this.customConfigFeatureApplicable()} @@ -274,7 +238,7 @@ class OrgHome extends React.Component { onPinCreate={this.createPin} onPinDelete={this.deletePin} showPin={isCurrentUserMemberOfOrg} - customConfigs={[...customConfigs, DEFAULT_CONFIG]} + customConfigs={[...customConfigs, ORG_DEFAULT_CONFIG]} onConfigChange={this.onConfigChange} aboutTab={showAboutTab} showConfigSelection={this.customConfigFeatureApplicable()} @@ -302,7 +266,7 @@ class OrgHome extends React.Component { onPinCreate={this.createPin} onPinDelete={this.deletePin} showPin={isCurrentUserMemberOfOrg} - customConfigs={[...customConfigs, DEFAULT_CONFIG]} + customConfigs={[...customConfigs, ORG_DEFAULT_CONFIG]} onConfigChange={this.onConfigChange} selectedConfig={selectedConfig} aboutTab={showAboutTab} diff --git a/src/components/orgs/OrgHomeHeader.jsx b/src/components/orgs/OrgHomeHeader.jsx index 3a4c52f6..cb6b1bfa 100644 --- a/src/components/orgs/OrgHomeHeader.jsx +++ b/src/components/orgs/OrgHomeHeader.jsx @@ -5,7 +5,7 @@ import { Edit as EditIcon, } from '@material-ui/icons'; import { Tooltip, ButtonGroup, Button, Collapse } from '@material-ui/core'; -import { isEmpty, get } from 'lodash'; +import { isEmpty, get, map } from 'lodash'; import { toFullAPIURL, copyURL, currentUserHasAccess } from '../../common/utils'; import APIService from '../../services/APIService'; import OwnerButton from '../common/OwnerButton'; @@ -21,18 +21,21 @@ import CommonFormDrawer from '../common/CommonFormDrawer'; import DownloadButton from '../common/DownloadButton'; import CollapsibleDivider from '../common/CollapsibleDivider'; import OrgForm from './OrgForm'; +import { ORG_DEFAULT_CONFIG } from "../../common/defaultConfigs" + +const DEFAULT_VISIBLE_ATTRIBUTES = ORG_DEFAULT_CONFIG.config.header.attributes const OrgHomeHeader = ({ org, url, fhir, extraComponents, config }) => { const downloadFileName = `Org-${get(org, 'id')}`; - const [openHeader, setOpenHeader] = React.useState(!get(config, 'config.shrinkHeader', false)); + const [openHeader, setOpenHeader] = React.useState(!get(config, 'config.header.shrink', false)); const [logoURL, setLogoURL] = React.useState(org.logo_url) const [orgForm, setOrgForm] = React.useState(false); const hasAccess = currentUserHasAccess(); const onIconClick = () => copyURL(toFullAPIURL(url)); React.useEffect( - () => setOpenHeader(!get(config, 'config.shrinkHeader', false)), - [get(config, 'config.shrinkHeader')] + () => setOpenHeader(!get(config, 'config.header.shrink', false)), + [get(config, 'config.header.shrink')] ) const onLogoUpload = (base64, name) => { @@ -44,6 +47,16 @@ const OrgHomeHeader = ({ org, url, fhir, extraComponents, config }) => { }) } + const getVisibleAttributes = ()=>{ + if (typeof get(config, 'config.header.attributes') === 'object') { + return get(config, 'config.header.attributes') + } + else if (get(config, 'config.header.attributes')) { + return DEFAULT_VISIBLE_ATTRIBUTES + } + else return [] + } + return (
@@ -96,7 +109,9 @@ const OrgHomeHeader = ({ org, url, fhir, extraComponents, config }) => { {org.description}
} - + {map(getVisibleAttributes(), (attr) => { + return + })} } gridClass="col-md-12" />
{ diff --git a/src/components/sources/SourceHome.jsx b/src/components/sources/SourceHome.jsx index 5b5252f4..5c9f490e 100644 --- a/src/components/sources/SourceHome.jsx +++ b/src/components/sources/SourceHome.jsx @@ -12,23 +12,10 @@ import PermissionDenied from '../common/PermissionDenied'; import ConceptHome from '../concepts/ConceptHome'; import MappingHome from '../mappings/MappingHome'; import '../common/Split.scss'; +import { SOURCE_DEFAULT_CONFIG } from "../../common/defaultConfigs" const TABS = ['details', 'concepts', 'mappings', 'versions', 'about'] -const DEFAULT_CONFIG = { - name: 'OCL Default (Source)', - web_default: true, - is_default: false, - config: { - tabs: [ - {type: "concepts", label: "Concepts", page_size: 25, "default": true, layout: 'table'}, - {type: "mappings", label: "Mappings", page_size: 25, layout: 'table'}, - {type: "versions", label: "Versions", page_size: 25, layout: 'table'}, - {type: "about", label: "About"}, - ] - } -} - class SourceHome extends React.Component { constructor(props) { super(props); @@ -177,7 +164,7 @@ class SourceHome extends React.Component { this.setState({ isLoading: false, source: source, - selectedConfig: defaultCustomConfig || DEFAULT_CONFIG, + selectedConfig: defaultCustomConfig || SOURCE_DEFAULT_CONFIG, customConfigs: customConfigs, }, () => { this.fetchSummary() @@ -263,11 +250,11 @@ class SourceHome extends React.Component { currentVersion={this.getCurrentVersion()} aboutTab={showAboutTab} onVersionUpdate={this.onVersionUpdate} - customConfigs={[...customConfigs, DEFAULT_CONFIG]} + customConfigs={[...customConfigs, SOURCE_DEFAULT_CONFIG]} onConfigChange={this.onConfigChange} selectedConfig={selectedConfig} showConfigSelection={this.customConfigFeatureApplicable()} - isOCLDefaultConfigSelected={isEqual(selectedConfig, DEFAULT_CONFIG)} + isOCLDefaultConfigSelected={isEqual(selectedConfig, SOURCE_DEFAULT_CONFIG)} isLoadingVersions={isLoadingVersions} splitView={splitView} onSelect={this.onResourceSelect} diff --git a/src/components/sources/SourceHomeHeader.jsx b/src/components/sources/SourceHomeHeader.jsx index 1e537d5d..de26e993 100644 --- a/src/components/sources/SourceHomeHeader.jsx +++ b/src/components/sources/SourceHomeHeader.jsx @@ -7,7 +7,7 @@ import { Delete as DeleteIcon, } from '@material-ui/icons'; import { Tooltip, ButtonGroup, Button, Collapse } from '@material-ui/core'; -import { isEmpty, keys, map, startCase, get } from 'lodash'; +import { isEmpty, map, filter, get } from 'lodash'; import { toFullAPIURL, copyURL, nonEmptyCount, currentUserHasAccess } from '../../common/utils'; import { GREEN } from '../../common/constants'; import APIService from '../../services/APIService'; @@ -31,36 +31,21 @@ import RetiredChip from '../common/RetiredChip'; import ProcessingChip from '../common/ProcessingChip'; import ConceptContainerDelete from '../common/ConceptContainerDelete'; import CollapsibleDivider from '../common/CollapsibleDivider'; +import { SOURCE_DEFAULT_CONFIG } from '../../common/defaultConfigs'; + +const DEFAULT_VISIBLE_ATTRIBUTES = SOURCE_DEFAULT_CONFIG.config.header.visibleAttributes +const DEFAULT_INVISIBLE_ATTRIBUTES = SOURCE_DEFAULT_CONFIG.config.header.invisibleAttributes -const HIDDEN_ATTRIBUTES = { - canonical_url: 'url', - publisher: 'text', - purpose: 'text', - copyright: 'text', - content_type: 'text', - revision_date: 'date', - identifier: 'json', - contact: 'json', - jurisdiction: 'json', - meta: 'json', - collection_reference: 'text', - hierarchy_meaning: 'text', - experimental: 'boolean', - case_sensitive: 'boolean', - compositional: 'boolean', - version_needed: 'boolean', -} const SourceHomeHeader = ({ source, isVersionedObject, versionedObjectURL, currentURL, config, splitView }) => { const downloadFileName = isVersionedObject ? `${source.type}-${source.short_code}` : `${source.type}-${source.short_code}-${source.id}`; const hasAccess = currentUserHasAccess(); - const [openHeader, setOpenHeader] = React.useState(!get(config, 'config.shrinkHeader', false)); + const [openHeader, setOpenHeader] = React.useState(!get(config, 'config.header.shrink', false)); const [deleteDialog, setDeleteDialog] = React.useState(false); const [logoURL, setLogoURL] = React.useState(source.logo_url) const [sourceForm, setSourceForm] = React.useState(false); const onIconClick = () => copyURL(toFullAPIURL(currentURL)) - const hasManyHiddenAttributes = nonEmptyCount(source, keys(HIDDEN_ATTRIBUTES)) >= 4; const onLogoUpload = (base64, name) => { APIService.new().overrideURL(versionedObjectURL).appendToUrl('logo/') .post({base64: base64, name: name}) @@ -69,10 +54,36 @@ const SourceHomeHeader = ({ setLogoURL(get(response, 'data.logo_url', logoURL)) }) } + const getDefaultHiddenAttributes = () => { + return filter(DEFAULT_VISIBLE_ATTRIBUTES, (attr) => { + return !map(get(config, 'config.header.visibleAttributes'),(attr) => attr.value).includes(attr.value) + } + ) + } + const getVisibleAttributes = ()=>{ + if (get(config, 'config.header.visibleAttributes') === 'object'){ + return get(config, 'config.header.visibleAttributes') + } + else if (get(config, 'config.header.visibleAttributes')) { + return DEFAULT_VISIBLE_ATTRIBUTES + } + else return [] + } + const getHiddenAttributes = () => { + if (get(config, 'config.header.invisibleAttributes') === 'object'){ + return {...get(config, 'config.header.invisibleAttributes'), ...getDefaultHiddenAttributes()} + } + else if (get(config, 'config.header.invisibleAttributes')) { + return { DEFAULT_INVISIBLE_ATTRIBUTES, ...getDefaultHiddenAttributes() } + } + else return [] + } + const hasManyHiddenAttributes = nonEmptyCount(source, map(getHiddenAttributes(),(attr) => attr.value)) >= 4; + React.useEffect( - () => setOpenHeader(!get(config, 'config.shrinkHeader', false)), - [get(config, 'config.shrinkHeader')] + () => setOpenHeader(!get(config, 'config.header.shrink', false)), + [get(config, 'config.header.shrink')] ) React.useEffect(() => { @@ -170,26 +181,25 @@ const SourceHomeHeader = ({ {source.description}
} - - } gridClass="col-md-12" type="component" /> - + {map(getVisibleAttributes(), (attr) => { + if (attr.value === "supported_locales" || attr.value === "default_locale"){ + return } gridClass="col-md-12" type="component" /> + } + return + })} } gridClass="col-md-12" /> { hasManyHiddenAttributes ?
: { - map(HIDDEN_ATTRIBUTES, (type, attr) => ( - + map(getHiddenAttributes(), (attr) => ( + )) }