Skip to content

Commit 76e5fdc

Browse files
committed
Refactoring of the main hook
1 parent cb5b209 commit 76e5fdc

File tree

13 files changed

+187
-305
lines changed

13 files changed

+187
-305
lines changed

src/components/Editor/ExpressionContainer/index.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import { FHIRPathUIEditorProps } from '../types';
66
import { styles } from '../../../styles';
77

88
export function ExpressionContainer(props: FHIRPathUIEditorProps) {
9-
const { handleExecute, resource, expression, isExecuteActive, setExpression } = props;
10-
const onClick = () => handleExecute(resource, expression)
11-
const onChange = (value: string | undefined) => setExpression(value ?? "")
9+
const { handleExecute, isExecuteActive, entity, setEntity } = props;
10+
const onClick = () => handleExecute(entity.response ?? '', entity.expression ?? '')
11+
const onChange = (
12+
value: string | undefined) => setEntity({ ...entity, ...{ expression: value ?? "" } });
1213
const editorOptions = {
1314
formatOnPaste: true,
1415
formatOnType: true,
@@ -30,7 +31,7 @@ export function ExpressionContainer(props: FHIRPathUIEditorProps) {
3031
</div>
3132
<Editor
3233
defaultLanguage="ruby"
33-
value={expression}
34+
value={entity.expression}
3435
onChange={onChange}
3536
options={editorOptions}
3637
/>

src/components/Editor/ResourceContainer/index.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import { FHIRPathUIEditorProps } from '../types';
44
import { styles } from '../../../styles';
55

66
export function ResourceContainer(props: FHIRPathUIEditorProps) {
7-
const { url, handleUrlChange, handleFetch, resourceFormat, setResource, resource } = props;
8-
const onSearch = () => handleFetch(url);
9-
const onChange = (value: string | undefined) => setResource(value ?? "");
7+
const { handleUrlChange, handleFetch, resourceFormat, entity, setEntity } = props;
8+
const onSearch = () => handleFetch(entity.url ?? "");
9+
const onChange = (
10+
value: string | undefined) => setEntity({ ...entity, ...{ response: value ?? "" } });
1011
const editorOptions = {
1112
formatOnPaste: true,
1213
formatOnType: true
@@ -20,7 +21,7 @@ export function ResourceContainer(props: FHIRPathUIEditorProps) {
2021
allowClear
2122
enterButton="Request"
2223
size="middle"
23-
value={url}
24+
value={entity.url}
2425
loading={props.isLoading}
2526
onChange={handleUrlChange}
2627
onSearch={onSearch}
@@ -29,7 +30,7 @@ export function ResourceContainer(props: FHIRPathUIEditorProps) {
2930
height="85vh"
3031
key={resourceFormat}
3132
defaultLanguage={resourceFormat}
32-
value={resource}
33+
value={entity.response}
3334
onChange={onChange}
3435
options={editorOptions}
3536
/>

src/components/Editor/ResultContainer/index.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { List } from "antd";
77

88
export function ResultContainer(props: FHIRPathUIEditorProps) {
99
return (
10-
<div style={{ padding: '16px' }}>
10+
<div style={{ padding: '16px'}}>
1111
<div style={styles.contextActions}>
1212
<Button
1313
type="primary"
@@ -24,9 +24,12 @@ export function ResultContainer(props: FHIRPathUIEditorProps) {
2424
</Button>
2525
</div>
2626
<List
27-
style={{ overflow: 'hidden' }}
27+
pagination={{
28+
position: 'bottom',
29+
align: 'center',
30+
}}
2831
size="small"
29-
dataSource={props.result}
32+
dataSource={props.entity.result}
3033
renderItem={(item) => (
3134
<List.Item>
3235
<pre>{JSON.stringify(item, null, 2)}</pre>

src/components/Editor/hooks.ts

Lines changed: 0 additions & 192 deletions
This file was deleted.

src/components/Editor/index.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@ export function FHIRPathUIEditor(props: FHIRPathUIEditorProps) {
1111
return (
1212
<Allotment defaultSizes={[550, 250]}>
1313
<ResourceContainer {...props} />
14-
<div style={styles.expressionAndResultContainer}>
15-
<Allotment defaultSizes={[100, 300]} vertical>
16-
<ExpressionContainer {...props} />
17-
<ResultContainer {...props} />
18-
</Allotment>
14+
<div>
15+
<ExpressionContainer {...props} />
16+
<ResultContainer {...props} />
1917
</div>
2018
</Allotment>
2119
);

src/components/Editor/types.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
1+
import {ServiceEntity} from "../../types";
2+
13
export interface FHIRPathUIEditorProps {
2-
setUrl: (v: string) => void;
4+
entity: ServiceEntity;
5+
setEntity: (v: ServiceEntity) => void;
36
shareLink: string;
4-
url: string;
57
handleUrlChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
68
handleFetch: (v: string) => void;
79
resourceFormat: string;
8-
setResource: (v: string) => void;
9-
resource: string;
1010
handleExecute: (r: string, expression: string) => void;
11-
expression: string;
1211
isExecuteActive: boolean;
13-
setExpression: (v: string) => void;
1412
handleShareResult: () => void;
1513
isShareResultActive: boolean;
1614
handleShare: () => void;
1715
isShareActive: boolean;
18-
result: any[];
1916
isLoading: boolean;
2017
isGetResourceActive: boolean;
2118
copyToClipboard: (toCopy: string, successMessage: string, errorMessage: string) => void;

src/components/HistoryContainer/index.tsx

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,47 @@
11
import moment from 'moment';
22
import { List, Button, Space, Tag, Typography, Popover } from 'antd';
33
import { getExecutionsHistory } from '../../containers/HistoryContainer/utils';
4-
import { ExecutionItem } from '../../containers/HistoryContainer/types';
54
import { styles } from '../../styles';
6-
import { detectFormat, convertToFormat } from '../../utils/format';
5+
import { convertToFormat } from '../../utils/format';
76
import {
87
MinusCircleOutlined,
98
} from '@ant-design/icons';
9+
import {ServiceEntity} from "../../types";
1010

1111
const { Text } = Typography;
1212

1313
export interface HistoryContainerItemProps {
14-
item: ExecutionItem;
15-
setResource: (v: string) => void;
16-
setUrl: (v: string) => void;
17-
setExpression: (v: string) => void;
14+
entity: ServiceEntity;
15+
setEntity: (v: ServiceEntity) => void;
1816
}
1917

2018
function HistoryContainerItem(props: HistoryContainerItemProps) {
21-
const { item, setResource, setUrl, setExpression } = props;
22-
const { response, url, expression, status, requestType } = item;
23-
const formattedDate = moment(item.dateTime).format('YYYY-MM-DD HH:mm')
19+
const { entity, setEntity } = props;
20+
const { response, url, expression, status, requestType } = entity;
21+
const formattedDate = moment(entity.dateTime).format('YYYY-MM-DD HH:mm')
2422
const onClick = () => {
25-
setResource(response);
26-
setUrl(url);
27-
setExpression(expression);
23+
setEntity({
24+
...entity,
25+
...{
26+
response: response,
27+
url: url,
28+
expression: expression,
29+
}
30+
})
2831
}
2932
const truncateToPreview = (text: string, maxLength = 35): string => {
3033
return text.length <= maxLength ? text : text.slice(0, maxLength) + '...';
3134
}
3235
const content = (
3336
<div style={{ maxWidth: 500 }}>
34-
<p><code>{status === "not-asked" ? truncateToPreview(convertToFormat(response, 'json'), 1000) : url}</code></p>
37+
<p><code>{status === "not-asked" ? truncateToPreview(convertToFormat(response ?? '', 'json'), 1000) : url}</code></p>
3538
<p><code>{expression}</code></p>
3639
</div>
3740
);
3841

3942
const itemContent = status === "not-asked" ?
40-
{ tagColor: "default", tagIcon: <MinusCircleOutlined />, tagText: '', previewText: JSON.parse(convertToFormat(response, 'json'))?.['resourceType'] } :
41-
{ tagColor: status, tagIcon: null, tagText: requestType.toUpperCase(), previewText: url }
43+
{ tagColor: "default", tagIcon: <MinusCircleOutlined />, tagText: '', previewText: JSON.parse(convertToFormat(response ?? '', 'json'))?.['resourceType'] } :
44+
{ tagColor: status, tagIcon: null, tagText: requestType?.toUpperCase(), previewText: url }
4245

4346
return (
4447
<Space>
@@ -52,15 +55,14 @@ function HistoryContainerItem(props: HistoryContainerItemProps) {
5255
}
5356

5457

55-
export function HistoryContainer(props: Omit<HistoryContainerItemProps, "item">) {
56-
const renderItem = (item: ExecutionItem) => {
58+
export function HistoryContainer(props: HistoryContainerItemProps) {
59+
const renderItem = (entity: ServiceEntity) => {
5760
return (
5861
<List.Item>
5962
<HistoryContainerItem
60-
item={item}
61-
setResource={props.setResource}
62-
setUrl={props.setUrl}
63-
setExpression={props.setExpression} />
63+
entity={entity}
64+
setEntity={props.setEntity}
65+
/>
6466
</List.Item>
6567
);
6668
}

0 commit comments

Comments
 (0)