-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #157 from performant-software/feature/udcsl28_media
UDCSL #28 - Media
- Loading branch information
Showing
12 changed files
with
313 additions
and
0 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
packages/semantic-ui/src/components/ReferenceCodeFormDropdown.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// @flow | ||
|
||
import { ReferenceTablesService } from '@performant-software/shared-components'; | ||
import React, { type ComponentType, useEffect, useState } from 'react'; | ||
import { Form } from 'semantic-ui-react'; | ||
import EditModal from './EditModal'; | ||
import ReferenceCodeDropdown from './ReferenceCodeDropdown'; | ||
import ReferenceCodeFormLabel from './ReferenceCodeFormLabel'; | ||
import ReferenceTableModal from './ReferenceTableModal'; | ||
|
||
type Props = { | ||
error?: boolean, | ||
label?: string, | ||
required?: boolean, | ||
referenceTable: string | ||
}; | ||
|
||
const ReferenceCodeFormDropdown: ComponentType<any> = (props: Props) => { | ||
const { | ||
error, | ||
label, | ||
required, | ||
referenceTable: key, | ||
...rest | ||
} = props; | ||
|
||
const [modal, setModal] = useState(false); | ||
const [dropdownKey, setDropdownKey] = useState(0); | ||
const [referenceTable, setReferenceTable] = useState({ key }); | ||
|
||
/** | ||
* Looks up the existing reference table base on the passed key. | ||
*/ | ||
useEffect(() => ( | ||
ReferenceTablesService | ||
.fetchByKey(key) | ||
.then(({ data }) => setReferenceTable((prevTable) => ({ | ||
...prevTable, | ||
...data.reference_table | ||
}))) | ||
), [key]); | ||
|
||
return ( | ||
<> | ||
<Form.Input | ||
error={error} | ||
label={( | ||
<ReferenceCodeFormLabel | ||
label={label} | ||
onClick={() => setModal(true)} | ||
referenceTable={referenceTable.key} | ||
/> | ||
)} | ||
required={required} | ||
> | ||
<ReferenceCodeDropdown | ||
{...rest} | ||
id={referenceTable} | ||
referenceTable={referenceTable.key} | ||
key={dropdownKey} | ||
/> | ||
</Form.Input> | ||
{ modal && ( | ||
<EditModal | ||
component={ReferenceTableModal} | ||
item={referenceTable} | ||
onClose={() => setModal(false)} | ||
onSave={(record) => ( | ||
ReferenceTablesService | ||
.save(record) | ||
.then(({ data }) => data.reference_table) | ||
.then(() => setDropdownKey((prevKey) => prevKey + 1)) | ||
.finally(() => setModal(false)) | ||
)} | ||
/> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default ReferenceCodeFormDropdown; |
51 changes: 51 additions & 0 deletions
51
packages/semantic-ui/src/components/ReferenceCodeFormLabel.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// @flow | ||
|
||
import React, { type ComponentType } from 'react'; | ||
import { withTranslation } from 'react-i18next'; | ||
import { | ||
Button, | ||
Header, | ||
Icon, | ||
Popup | ||
} from 'semantic-ui-react'; | ||
import i18n from '../i18n/i18n'; | ||
|
||
type Props = { | ||
label: string, | ||
onClick: () => void, | ||
referenceTable: string | ||
}; | ||
|
||
const ReferenceCodeFormLabel: ComponentType<any> = withTranslation()((props: Props) => ( | ||
<div> | ||
<label | ||
htmlFor={props.referenceTable} | ||
> | ||
{ props.label } | ||
</label> | ||
<Popup | ||
hoverable | ||
trigger={( | ||
<Icon | ||
name='info circle' | ||
style={{ | ||
marginLeft: '0.3em' | ||
}} | ||
/> | ||
)} | ||
> | ||
<Header | ||
content={props.label} | ||
/> | ||
<p>{ i18n.t('ReferenceCodeFormLabel.content', { name: props.label })}</p> | ||
<Button | ||
content={i18n.t('Common.buttons.edit')} | ||
icon='edit' | ||
primary | ||
onClick={props.onClick} | ||
/> | ||
</Popup> | ||
</div> | ||
)); | ||
|
||
export default ReferenceCodeFormLabel; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// @flow | ||
|
||
import NestedAttributesTransform from './NestedAttributesTransform'; | ||
|
||
class References extends NestedAttributesTransform { | ||
getPayloadKeys(): Array<string> { | ||
return [ | ||
'reference_code_id' | ||
]; | ||
} | ||
} | ||
|
||
const ReferencesTransform: References = new References(); | ||
export default ReferencesTransform; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// @flow | ||
|
||
const bodyParser = require('body-parser'); | ||
const ControlledVocabulary = require('./routes/ControlledVocabulary'); | ||
|
||
const expressMiddleWare = (router) => { | ||
router.use(bodyParser.urlencoded({ extended: false })); | ||
router.use(bodyParser.json()); | ||
|
||
ControlledVocabulary.addRoutes(router); | ||
}; | ||
|
||
module.exports = expressMiddleWare; |
51 changes: 51 additions & 0 deletions
51
packages/storybook/.storybook/routes/ControlledVocabulary.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// @flow | ||
|
||
const addRoutes = (router) => { | ||
const codes = [{ | ||
id: 1, | ||
reference_table_id: 1, | ||
name: 'Boston, MA' | ||
}, { | ||
id: 2, | ||
reference_table_id: 1, | ||
name: 'New York, NY' | ||
}, { | ||
id: 3, | ||
reference_table_id: 1, | ||
name: 'Los Angeles, CA' | ||
}]; | ||
|
||
router.get('/controlled_vocabulary/reference_codes', (request, response) => { | ||
response.send({ | ||
list: { | ||
count: codes.length, | ||
page: 1, | ||
pages: 1 | ||
}, | ||
reference_codes: codes | ||
}); | ||
|
||
response.end(); | ||
}); | ||
|
||
router.get('/controlled_vocabulary/reference_tables/:id', (request, response) => { | ||
response.send({ | ||
reference_table: { | ||
id: 1, | ||
name: 'Locations', | ||
key: 'locations', | ||
reference_codes: codes | ||
} | ||
}) | ||
|
||
response.end(); | ||
}); | ||
|
||
router.put('/controlled_vocabulary/reference_tables/:id', (request, response) => { | ||
response.end(); | ||
}); | ||
}; | ||
|
||
module.exports = { | ||
addRoutes | ||
}; |
39 changes: 39 additions & 0 deletions
39
packages/storybook/src/semantic-ui/ReferenceCodeDropdown.stories.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// @flow | ||
|
||
import React, { useState } from 'react'; | ||
import { action } from '@storybook/addon-actions'; | ||
import { withA11y } from '@storybook/addon-a11y'; | ||
import { withKnobs } from '@storybook/addon-knobs'; | ||
import ReferenceCodeDropdown from '../../../semantic-ui/src/components/ReferenceCodeDropdown'; | ||
|
||
export default { | ||
title: 'Components/Semantic UI/ReferenceCodeDropdown', | ||
decorators: [withA11y, withKnobs] | ||
}; | ||
|
||
export const Default = () => ( | ||
<ReferenceCodeDropdown | ||
fluid | ||
label='Locations' | ||
required | ||
onChange={action('change')} | ||
referenceTable='locations' | ||
value='' | ||
/> | ||
); | ||
|
||
export const Multiple = () => { | ||
const [value, setValue] = useState([]); | ||
|
||
return ( | ||
<ReferenceCodeDropdown | ||
fluid | ||
label='Locations' | ||
multiple | ||
required | ||
onChange={(selected) => setValue(selected)} | ||
referenceTable='locations' | ||
value={value} | ||
/> | ||
); | ||
}; |
27 changes: 27 additions & 0 deletions
27
packages/storybook/src/semantic-ui/ReferenceCodeFormDropdown.stories.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// @flow | ||
|
||
import React from 'react'; | ||
import { withA11y } from '@storybook/addon-a11y'; | ||
import { withKnobs } from '@storybook/addon-knobs'; | ||
import { action } from '@storybook/addon-actions'; | ||
import { Form } from 'semantic-ui-react'; | ||
import ReferenceCodeFormDropdown from '../../../semantic-ui/src/components/ReferenceCodeFormDropdown'; | ||
import useDragDrop from '../../../shared/src/utils/DragDrop'; | ||
|
||
export default { | ||
title: 'Components/Semantic UI/ReferenceCodeFormDropdown', | ||
decorators: [withA11y, withKnobs] | ||
}; | ||
|
||
export const Default = useDragDrop(() => ( | ||
<Form> | ||
<ReferenceCodeFormDropdown | ||
fluid | ||
label='Locations' | ||
required | ||
onChange={action('change')} | ||
referenceTable='locations' | ||
value='' | ||
/> | ||
</Form> | ||
)); |
20 changes: 20 additions & 0 deletions
20
packages/storybook/src/semantic-ui/ReferenceCodeFormLabel.stories.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// @flow | ||
|
||
import React from 'react'; | ||
import { withA11y } from '@storybook/addon-a11y'; | ||
import { withKnobs } from '@storybook/addon-knobs'; | ||
import { action } from '@storybook/addon-actions'; | ||
import ReferenceCodeFormLabel from '../../../semantic-ui/src/components/ReferenceCodeFormLabel'; | ||
|
||
export default { | ||
title: 'Components/Semantic UI/ReferenceCodeFormLabel', | ||
decorators: [withA11y, withKnobs] | ||
}; | ||
|
||
export const Default = () => ( | ||
<ReferenceCodeFormLabel | ||
label='Locations' | ||
onClick={action('click')} | ||
referenceTable='locations' | ||
/> | ||
); |