-
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: [DHIS2-15475] Form Field Plugins (#3502)
- Loading branch information
1 parent
817ba28
commit 2ccb87b
Showing
13 changed files
with
3,635 additions
and
2,425 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
35 changes: 29 additions & 6 deletions
35
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,38 @@ | ||
// @flow | ||
import React from 'react'; | ||
import i18n from '@dhis2/d2-i18n'; | ||
import React, { useEffect, useRef, useState } from 'react'; | ||
import { Plugin } from '@dhis2/app-runtime/build/es/experimental'; | ||
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 | ||
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
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
Oops, something went wrong.