@performant-software/semantic-components 0.5.10 → 0.5.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/index.js +1 -1
- package/build/index.js.map +1 -1
- package/build/main.css +4 -0
- package/package.json +4 -3
- package/src/components/DataTable.js +1 -1
- package/src/components/EmbeddedList.js +17 -4
- package/src/components/KeyValuePairs.js +79 -0
- package/src/components/LazyDocument.css +6 -1
- package/src/components/LazyDocument.js +26 -2
- package/src/components/LazyVideo.js +11 -1
- package/src/components/ReferenceCodeFormDropdown.js +73 -0
- package/src/components/ReferenceCodeFormLabel.js +51 -0
- package/src/hooks/BatchEdit.js +57 -0
- package/src/i18n/en.json +12 -0
- package/src/index.js +7 -0
- package/types/components/DataTable.js.flow +1 -1
- package/types/components/EmbeddedList.js.flow +17 -4
- package/types/components/KeyValuePairs.js.flow +79 -0
- package/types/components/LazyDocument.js.flow +26 -2
- package/types/components/LazyVideo.js.flow +11 -1
- package/types/components/ReferenceCodeFormDropdown.js.flow +73 -0
- package/types/components/ReferenceCodeFormLabel.js.flow +51 -0
- package/types/hooks/BatchEdit.js.flow +57 -0
- package/types/index.js.flow +7 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
|
|
3
|
-
import React, { useState, type Node } from 'react';
|
|
3
|
+
import React, { useState, useEffect, type Node } from 'react';
|
|
4
|
+
import { Document, Page } from 'react-pdf/dist/esm/entry.webpack';
|
|
4
5
|
import {
|
|
5
6
|
Dimmer,
|
|
6
7
|
Icon,
|
|
@@ -27,6 +28,15 @@ type Props = {
|
|
|
27
28
|
const LazyDocument = (props: Props) => {
|
|
28
29
|
const [visible, setVisible] = useState(false);
|
|
29
30
|
const [dimmer, setDimmer] = useState(false);
|
|
31
|
+
const [contentType, setContentType] = useState('');
|
|
32
|
+
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
if (props.src && !props.preview) {
|
|
35
|
+
fetch(props.src)
|
|
36
|
+
.then((response) => response.blob())
|
|
37
|
+
.then((blob) => setContentType(blob.type));
|
|
38
|
+
}
|
|
39
|
+
}, [props.preview, props.src]);
|
|
30
40
|
|
|
31
41
|
if (!visible) {
|
|
32
42
|
return (
|
|
@@ -65,7 +75,21 @@ const LazyDocument = (props: Props) => {
|
|
|
65
75
|
size={props.size}
|
|
66
76
|
/>
|
|
67
77
|
)}
|
|
68
|
-
{ !props.preview && (
|
|
78
|
+
{ !props.preview && props.src && contentType === 'application/pdf' && (
|
|
79
|
+
<Image
|
|
80
|
+
{...props.image}
|
|
81
|
+
size={props.size}
|
|
82
|
+
>
|
|
83
|
+
<Document
|
|
84
|
+
file={props.src}
|
|
85
|
+
>
|
|
86
|
+
<Page
|
|
87
|
+
pageNumber={1}
|
|
88
|
+
/>
|
|
89
|
+
</Document>
|
|
90
|
+
</Image>
|
|
91
|
+
)}
|
|
92
|
+
{ !props.preview && (!props.src || contentType !== 'application/pdf') && (
|
|
69
93
|
<Image
|
|
70
94
|
{...props.image}
|
|
71
95
|
className='placeholder-image'
|
|
@@ -70,7 +70,17 @@ const LazyVideo = (props: Props) => {
|
|
|
70
70
|
size={props.size}
|
|
71
71
|
/>
|
|
72
72
|
)}
|
|
73
|
-
{ !props.preview && (
|
|
73
|
+
{ !props.preview && props.src && (
|
|
74
|
+
<Image
|
|
75
|
+
{...props.image}
|
|
76
|
+
size={props.size}
|
|
77
|
+
>
|
|
78
|
+
<video
|
|
79
|
+
src={props.src}
|
|
80
|
+
/>
|
|
81
|
+
</Image>
|
|
82
|
+
)}
|
|
83
|
+
{ !props.preview && !props.src && (
|
|
74
84
|
<Image
|
|
75
85
|
{...props.image}
|
|
76
86
|
className='placeholder-image'
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
import { ReferenceTablesService } from '@performant-software/shared-components';
|
|
4
|
+
import React, { type ComponentType, useState } from 'react';
|
|
5
|
+
import { Form } from 'semantic-ui-react';
|
|
6
|
+
import EditModal from './EditModal';
|
|
7
|
+
import ReferenceCodeDropdown from './ReferenceCodeDropdown';
|
|
8
|
+
import ReferenceCodeFormLabel from './ReferenceCodeFormLabel';
|
|
9
|
+
import ReferenceTableModal from './ReferenceTableModal';
|
|
10
|
+
|
|
11
|
+
type Props = {
|
|
12
|
+
error?: boolean,
|
|
13
|
+
label?: string,
|
|
14
|
+
required?: boolean,
|
|
15
|
+
referenceTable: string
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const ReferenceCodeFormDropdown: ComponentType<any> = (props: Props) => {
|
|
19
|
+
const {
|
|
20
|
+
error,
|
|
21
|
+
label,
|
|
22
|
+
required,
|
|
23
|
+
referenceTable,
|
|
24
|
+
...rest
|
|
25
|
+
} = props;
|
|
26
|
+
|
|
27
|
+
const [modal, setModal] = useState(false);
|
|
28
|
+
const [dropdownKey, setDropdownKey] = useState(0);
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<>
|
|
32
|
+
<Form.Input
|
|
33
|
+
error={error}
|
|
34
|
+
label={(
|
|
35
|
+
<ReferenceCodeFormLabel
|
|
36
|
+
label={label}
|
|
37
|
+
onClick={() => setModal(true)}
|
|
38
|
+
referenceTable={referenceTable}
|
|
39
|
+
/>
|
|
40
|
+
)}
|
|
41
|
+
required={required}
|
|
42
|
+
>
|
|
43
|
+
<ReferenceCodeDropdown
|
|
44
|
+
{...rest}
|
|
45
|
+
id={referenceTable}
|
|
46
|
+
referenceTable={referenceTable}
|
|
47
|
+
key={dropdownKey}
|
|
48
|
+
/>
|
|
49
|
+
</Form.Input>
|
|
50
|
+
{ modal && (
|
|
51
|
+
<EditModal
|
|
52
|
+
component={ReferenceTableModal}
|
|
53
|
+
item={{ id: referenceTable }}
|
|
54
|
+
onClose={() => setModal(false)}
|
|
55
|
+
onInitialize={(key) => (
|
|
56
|
+
ReferenceTablesService
|
|
57
|
+
.fetchByKey(key)
|
|
58
|
+
.then(({ data }) => data.reference_table)
|
|
59
|
+
)}
|
|
60
|
+
onSave={(record) => (
|
|
61
|
+
ReferenceTablesService
|
|
62
|
+
.save(record)
|
|
63
|
+
.then(({ data }) => data.reference_table)
|
|
64
|
+
.then(() => setDropdownKey((prevKey) => prevKey + 1))
|
|
65
|
+
.finally(() => setModal(false))
|
|
66
|
+
)}
|
|
67
|
+
/>
|
|
68
|
+
)}
|
|
69
|
+
</>
|
|
70
|
+
);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export default ReferenceCodeFormDropdown;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
import React, { type ComponentType } from 'react';
|
|
4
|
+
import { withTranslation } from 'react-i18next';
|
|
5
|
+
import {
|
|
6
|
+
Button,
|
|
7
|
+
Header,
|
|
8
|
+
Icon,
|
|
9
|
+
Popup
|
|
10
|
+
} from 'semantic-ui-react';
|
|
11
|
+
import i18n from '../i18n/i18n';
|
|
12
|
+
|
|
13
|
+
type Props = {
|
|
14
|
+
label: string,
|
|
15
|
+
onClick: () => void,
|
|
16
|
+
referenceTable: string
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const ReferenceCodeFormLabel: ComponentType<any> = withTranslation()((props: Props) => (
|
|
20
|
+
<div>
|
|
21
|
+
<label
|
|
22
|
+
htmlFor={props.referenceTable}
|
|
23
|
+
>
|
|
24
|
+
{ props.label }
|
|
25
|
+
</label>
|
|
26
|
+
<Popup
|
|
27
|
+
hoverable
|
|
28
|
+
trigger={(
|
|
29
|
+
<Icon
|
|
30
|
+
name='info circle'
|
|
31
|
+
style={{
|
|
32
|
+
marginLeft: '0.3em'
|
|
33
|
+
}}
|
|
34
|
+
/>
|
|
35
|
+
)}
|
|
36
|
+
>
|
|
37
|
+
<Header
|
|
38
|
+
content={props.label}
|
|
39
|
+
/>
|
|
40
|
+
<p>{ i18n.t('ReferenceCodeFormLabel.content', { name: props.label })}</p>
|
|
41
|
+
<Button
|
|
42
|
+
content={i18n.t('Common.buttons.edit')}
|
|
43
|
+
icon='edit'
|
|
44
|
+
primary
|
|
45
|
+
onClick={props.onClick}
|
|
46
|
+
/>
|
|
47
|
+
</Popup>
|
|
48
|
+
</div>
|
|
49
|
+
));
|
|
50
|
+
|
|
51
|
+
export default ReferenceCodeFormLabel;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
import React, { useCallback, type ComponentType } from 'react';
|
|
4
|
+
import _ from 'underscore';
|
|
5
|
+
|
|
6
|
+
type Props = {
|
|
7
|
+
items: Array<any>,
|
|
8
|
+
onChange: (items: Array<any>) => void
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const withBatchEdit = (WrappedComponent: ComponentType<any>): any => (props: Props) => {
|
|
12
|
+
/**
|
|
13
|
+
* Adds a new item to the list.
|
|
14
|
+
*
|
|
15
|
+
* @type {(function(): void)|*}
|
|
16
|
+
*/
|
|
17
|
+
const onAddItem = useCallback(() => {
|
|
18
|
+
props.onChange([...props.items, {}]);
|
|
19
|
+
}, [props.items]);
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Removes the item at the passed index from the list.
|
|
23
|
+
*
|
|
24
|
+
* @type {(function(*): void)|*}
|
|
25
|
+
*/
|
|
26
|
+
const onRemoveItem = useCallback((findIndex) => {
|
|
27
|
+
props.onChange(_.reject(props.items, (item, index) => index === findIndex));
|
|
28
|
+
}, [props.items]);
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Updates the passed attribute of the item at the passed index.
|
|
32
|
+
*
|
|
33
|
+
* @type {(function(number, string, ?Event, {value: *}): void)|*}
|
|
34
|
+
*/
|
|
35
|
+
const onUpdateItem = useCallback((findIndex: number, attribute: string, e: ?Event, { value }) => {
|
|
36
|
+
props.onChange(_.map(props.items, (item, index) => (
|
|
37
|
+
index !== findIndex ? item : ({ ...item, [attribute]: value })
|
|
38
|
+
)));
|
|
39
|
+
}, [props.items]);
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<WrappedComponent
|
|
43
|
+
{...props}
|
|
44
|
+
onAddItem={onAddItem}
|
|
45
|
+
onRemoveItem={onRemoveItem}
|
|
46
|
+
onUpdateItem={onUpdateItem}
|
|
47
|
+
/>
|
|
48
|
+
);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export default withBatchEdit;
|
|
52
|
+
|
|
53
|
+
export type BatchEditProps = {
|
|
54
|
+
onAddItem: () => void,
|
|
55
|
+
onRemoveItem: (index: number) => void,
|
|
56
|
+
onUpdateItem: (index: number, attribute: string, e: Event, data: any) => void
|
|
57
|
+
};
|
package/types/index.js.flow
CHANGED
|
@@ -38,6 +38,7 @@ export { default as ItemCollection } from './components/ItemCollection';
|
|
|
38
38
|
export { default as ItemList } from './components/ItemList';
|
|
39
39
|
export { default as Items } from './components/Items';
|
|
40
40
|
export { default as KeyboardField } from './components/KeyboardField';
|
|
41
|
+
export { default as KeyValuePairs } from './components/KeyValuePairs';
|
|
41
42
|
export { default as LazyDocument } from './components/LazyDocument';
|
|
42
43
|
export { default as LazyImage } from './components/LazyImage';
|
|
43
44
|
export { default as LazyVideo } from './components/LazyVideo';
|
|
@@ -59,6 +60,8 @@ export { default as NestedAccordion } from './components/NestedAccordion';
|
|
|
59
60
|
export { default as PlayButton } from './components/PlayButton';
|
|
60
61
|
export { default as PhotoViewer } from './components/PhotoViewer';
|
|
61
62
|
export { default as ReferenceCodeDropdown } from './components/ReferenceCodeDropdown';
|
|
63
|
+
export { default as ReferenceCodeFormDropdown } from './components/ReferenceCodeFormDropdown';
|
|
64
|
+
export { default as ReferenceCodeFormLabel } from './components/ReferenceCodeFormLabel';
|
|
62
65
|
export { default as ReferenceCodeModal } from './components/ReferenceCodeModal';
|
|
63
66
|
export { default as ReferenceTableModal } from './components/ReferenceTableModal';
|
|
64
67
|
export { default as ReferenceTablesList } from './components/ReferenceTablesList';
|
|
@@ -77,10 +80,14 @@ export { default as VideoPlayer } from './components/VideoPlayer';
|
|
|
77
80
|
export { default as VideoPlayerButton } from './components/VideoPlayerButton';
|
|
78
81
|
export { default as ViewXML } from './components/ViewXML';
|
|
79
82
|
|
|
83
|
+
// Hooks
|
|
84
|
+
export { default as BatchEdit } from './hooks/BatchEdit';
|
|
85
|
+
|
|
80
86
|
// Types
|
|
81
87
|
export type { EditPageProps } from './components/EditPage';
|
|
82
88
|
export type { FileUploadProps } from './components/FileUploadModal';
|
|
83
89
|
export type { Props as ListProps } from './components/List';
|
|
90
|
+
export type { BatchEditProps } from './hooks/BatchEdit';
|
|
84
91
|
|
|
85
92
|
// Constants
|
|
86
93
|
export { SORT_ASCENDING, SORT_DESCENDING } from './components/DataList';
|