-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: full plugins support with experimental release
- Loading branch information
1 parent
faba67f
commit dcdecd9
Showing
15 changed files
with
193 additions
and
77 deletions.
There are no files selected for viewing
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
37 changes: 31 additions & 6 deletions
37
src/core_modules/capture-core/components/D2Form/FormFieldPlugin/FormFieldPlugin.component.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 |
---|---|---|
@@ -1,15 +1,40 @@ | ||
// @flow | ||
import React from 'react'; | ||
import i18n from '@dhis2/d2-i18n'; | ||
import React, { useEffect, useRef, useState } from 'react'; | ||
// $FlowFixMe - Export will be part of the next release | ||
import { Plugin } from '@dhis2/app-runtime'; | ||
import type { ComponentProps } from './FormFieldPlugin.types'; | ||
|
||
export const FormFieldPluginComponent = (props: ComponentProps) => { | ||
// eslint-disable-next-line no-unused-vars | ||
const { pluginSource, ...passOnProps } = props; | ||
const containerRef = useRef<?HTMLDivElement>(null); | ||
const [pluginWidth, setPluginWidth] = useState(0); | ||
|
||
useEffect(() => { | ||
const { current: container } = containerRef; | ||
if (!container) return; | ||
|
||
const resizeObserver = new ResizeObserver((entries) => { | ||
entries.forEach(entry => setPluginWidth(entry.contentRect.width)); | ||
}); | ||
|
||
resizeObserver.observe(container); | ||
|
||
// Cleanup function | ||
// eslint-disable-next-line consistent-return | ||
return () => { | ||
resizeObserver.unobserve(container); | ||
resizeObserver.disconnect(); | ||
}; | ||
}, [containerRef]); | ||
|
||
|
||
return ( | ||
<p> | ||
{i18n.t('Plugins are not yet available - Please contact your system administrator')} | ||
</p> | ||
<div ref={containerRef}> | ||
<Plugin | ||
pluginSource={pluginSource} | ||
width={pluginWidth} | ||
{...passOnProps} | ||
/> | ||
</div> | ||
); | ||
}; |
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
20 changes: 6 additions & 14 deletions
20
...es/common/TEIAndEnrollment/useMetadataForRegistrationForm/hooks/useDataEntryFormConfig.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
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
48 changes: 48 additions & 0 deletions
48
src/core_modules/capture-core/components/Pages/common/EnrollmentPlugin/EnrollmentPlugin.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,48 @@ | ||
// @flow | ||
import React, { useEffect, useRef, useState } from 'react'; | ||
// $FlowFixMe - Export will be available in next app-runtime release | ||
import { Plugin } from '@dhis2/app-runtime'; | ||
import { useHistory } from 'react-router-dom'; | ||
|
||
type EnrollmentPluginProps = {| | ||
enrollmentId: string, | ||
programId?: string, | ||
teiId: string, | ||
orgUnitId: string, | ||
pluginSource: string, | ||
|}; | ||
|
||
export const EnrollmentPlugin = ({ pluginSource, ...passOnProps }: EnrollmentPluginProps) => { | ||
const [pluginWidth, setPluginWidth] = useState(undefined); | ||
const history = useHistory(); | ||
const containerRef = useRef<?HTMLDivElement>(); | ||
|
||
useEffect(() => { | ||
const { current: container } = containerRef; | ||
if (!container) return; | ||
|
||
const resizeObserver = new ResizeObserver((entries) => { | ||
entries.forEach(entry => setPluginWidth(entry.contentRect.width)); | ||
}); | ||
|
||
resizeObserver.observe(container); | ||
|
||
// Cleanup function | ||
// eslint-disable-next-line consistent-return | ||
return () => { | ||
resizeObserver.unobserve(container); | ||
resizeObserver.disconnect(); | ||
}; | ||
}, [containerRef]); | ||
|
||
return ( | ||
<div ref={containerRef}> | ||
<Plugin | ||
pluginSource={pluginSource} | ||
width={pluginWidth} | ||
navigate={history.push} | ||
{...passOnProps} | ||
/> | ||
</div> | ||
); | ||
}; |
2 changes: 2 additions & 0 deletions
2
src/core_modules/capture-core/components/Pages/common/EnrollmentPlugin/index.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,2 @@ | ||
// @flow | ||
export { EnrollmentPlugin } from './EnrollmentPlugin'; |
Oops, something went wrong.