-
Notifications
You must be signed in to change notification settings - Fork 19
Header customization added #10
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
base: master
Are you sure you want to change the base?
Changes from 4 commits
91fbc4f
3e39af1
54f3a28
e42ef90
9254913
ba026ba
3dbb1aa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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'; | ||
|
|
@@ -32,33 +32,43 @@ import ProcessingChip from '../common/ProcessingChip'; | |
| import ConceptContainerDelete from '../common/ConceptContainerDelete'; | ||
| import CollapsibleDivider from '../common/CollapsibleDivider'; | ||
|
|
||
| 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 DEFAULT_VISIBLE_ATTRIBUTES = [ | ||
| { | ||
| 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", | ||
| } | ||
| ] | ||
|
|
||
| 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 +77,21 @@ const CollectionHomeHeader = ({ | |
| setLogoURL(get(response, 'data.logo_url', logoURL)) | ||
| }) | ||
| } | ||
| const getDefaultHiddenAttributes = () => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for single line methods you dont need {} and return: |
||
| return filter(DEFAULT_VISIBLE_ATTRIBUTES, (attr) => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for single argument you dont (). |
||
| return !map(get(config, 'config.header.visibleAttributes'),(attr) => attr.value).includes(attr.value) | ||
| } | ||
| ) | ||
| } | ||
| const getHiddenAttributes = () => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for single line methods you dont need {} and return: |
||
| return {...get(config, 'config.header.invisibleAttributes'), ...getDefaultHiddenAttributes()} | ||
| } | ||
| 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 +184,25 @@ const CollectionHomeHeader = ({ | |
| {collection.description} | ||
| </div> | ||
| } | ||
| <HeaderAttribute label="Short Code" value={collection.short_code} gridClass="col-md-12" /> | ||
| <HeaderAttribute label="Name" value={collection.name} gridClass="col-md-12" /> | ||
| <HeaderAttribute label="Collection Type" value={collection.collection_type} gridClass="col-md-12" /> | ||
| <HeaderAttribute label="Supported Locales" value={<SupportedLocales {...collection} />} gridClass="col-md-12" type="component" /> | ||
| <HeaderAttribute label="Custom Validation Schema" value={collection.custom_validation_schema} gridClass="col-md-12" /> | ||
| {map(get(config, 'config.header.visibleAttributes'), (attr) => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for single argument you dont (). |
||
| if (attr.value === "supported_locales" || attr.value === "default_locale"){ | ||
| return <HeaderAttribute key={attr.label} label="Supported Locales" value={<SupportedLocales {...collection} />} gridClass="col-md-12" type="component" /> | ||
| } | ||
| return <HeaderAttribute key={attr.label} label={attr.label} value={collection[attr.value]} type={attr.type} gridClass="col-md-12"/> | ||
| })} | ||
| <HeaderAttribute label="Custom Attributes" value={<CustomAttributesPopup attributes={collection.extras} />} gridClass="col-md-12" /> | ||
| { | ||
| hasManyHiddenAttributes ? | ||
| <div className='col-md-12 no-side-padding'> | ||
| <CollapsibleAttributes | ||
| hiddenAttributes={getHiddenAttributes()} | ||
| object={collection} | ||
| urlAttrs={['canonical_url']} | ||
| textAttrs={['publisher', 'purpose', 'copyright', 'preferred_source', 'custom_resources_linked_source']} | ||
| dateAttrs={['revision_date', 'locked_date']} | ||
| jsonAttrs={['identifier', 'contact', 'jurisdiction']} | ||
| booleanAttrs={['immutable', 'experimental']} | ||
| /> | ||
| </div> : | ||
| <React.Fragment> | ||
| { | ||
| map(HIDDEN_ATTRIBUTES, (type, attr) => ( | ||
| <HeaderAttribute key={attr} label={`${startCase(attr)}`} value={get(collection, attr)} gridClass="col-md-12" type={type} /> | ||
| map(getHiddenAttributes(), (attr) => ( | ||
| <HeaderAttribute key={attr.label} label={attr.label} value={get(collection, attr.value)} gridClass="col-md-12" type={attr.type} /> | ||
| )) | ||
| } | ||
| </React.Fragment> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,9 +34,25 @@ const DEFAULT_CONFIG = { | |
| config: { | ||
| header: { | ||
| ...BACKGROUND_CONFIG, | ||
| height: '', | ||
| attributes: [ | ||
| { | ||
| label: "Company", | ||
| value: "company", | ||
| type:"text" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. space after |
||
| }, | ||
| { | ||
| label: "Location", | ||
| value: "location", | ||
| type:"text" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. space after |
||
| }, | ||
| { | ||
| label: "Website", | ||
| value: "website", | ||
| type:"url" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. space after |
||
| }, | ||
| ], | ||
| height: null, | ||
| controls: true, | ||
| attributes: true, | ||
| signatures: true, | ||
| logo: true, | ||
| shrink: false, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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'; | ||
|
|
@@ -24,15 +24,15 @@ import OrgForm from './OrgForm'; | |
|
|
||
| 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) => { | ||
|
|
@@ -96,7 +96,9 @@ const OrgHomeHeader = ({ org, url, fhir, extraComponents, config }) => { | |
| {org.description} | ||
| </div> | ||
| } | ||
| <HeaderAttribute label="Company" value={org.company} gridClass="col-md-12" /> | ||
| {map(get(config, 'config.header.attributes'), (attr) => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for single argument you dont (). |
||
| return <HeaderAttribute key={attr.label} label={attr.label} value={org[attr.value]} type={attr.type} gridClass="col-md-12" /> | ||
| })} | ||
| <HeaderAttribute label="Custom Attributes" value={!isEmpty(org.extras) && <CustomAttributesPopup attributes={org.extras} />} gridClass="col-md-12" /> | ||
| <div className='col-md-12 no-side-padding flex-vertical-center' style={{paddingTop: '10px'}}> | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this come from DEFAULT_CONFIG? why redefine here?