Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [DHIS2-15830] Add orgUnitId and programId to plugin context #3407

Merged
merged 2 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import { usePluginMessages } from './hooks/usePluginMessages';
import { usePluginCallbacks } from './hooks/usePluginCallbacks';
import { usePluginValues } from './hooks/usePluginValues';
import { formatPluginConfig } from './formatPluginConfig';
import { useLocationQuery } from '../../../utils/routing';

export const FormFieldPlugin = (props: ContainerProps) => {
const { pluginSource, fieldsMetadata, formId, onUpdateField, pluginContext } = props;
const metadataByPluginId = useMemo(() => Object.fromEntries(fieldsMetadata), [fieldsMetadata]);
const configuredPluginIds = useMemo(() => Object.keys(metadataByPluginId), [metadataByPluginId]);
const { programId, orgUnitId } = useLocationQuery();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey,
What about cases where programId is missing from URL parameters (such as on /viewEvent or /enrollmentEventEdit pages)? Should we take it from somewhere else in these cases? 🤔
Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point. Also, I didn't think this quite through I guess. Instead of sending in programId, we should perhaps send in the contextId, i.e. either programId or TETid? Also, they configure the plugin by this contextId, so it should be familiar. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do they need to know if the plugin is injected within a program or a TET context? If not, then a generic contextId makes sense to me.


// Plugin related functionality and feedback
const { pluginValues } = usePluginValues(formId, metadataByPluginId, pluginContext);
Expand Down Expand Up @@ -39,6 +41,8 @@ export const FormFieldPlugin = (props: ContainerProps) => {

return (
<FormFieldPluginComponent
orgUnitId={orgUnitId}
programId={programId}
pluginSource={pluginSource}
fieldsMetadata={formattedMetadata}
values={pluginValues}
Expand All @@ -50,3 +54,4 @@ export const FormFieldPlugin = (props: ContainerProps) => {
/>
);
};

Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ export type ComponentProps = {|
fieldsMetadata: MetadataByPluginId,
formSubmitted: boolean,
values: { [id: string]: any },
orgUnitId: string,
programId: string,
setFieldValue: (SetFieldValueProps) => void,
errors: { [id: string]: Array<string> },
warnings: { [id: string]: Array<string> },
Expand Down