Skip to content

Commit

Permalink
fix: review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikmv committed Aug 12, 2024
1 parent 8be30ca commit 039c1ac
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const TooltipOrgUnit = ({ orgUnitName, ancestors, tooltip }: Props) => {
const tooltipParts = tooltip ? tooltip.split(orgUnitName) : [orgUnitName];

return (
<Tooltip content={orgUnitNameFullPath} openDelay={400}>
<Tooltip content={orgUnitNameFullPath} openDelay={400} maxWidth={900}>
<span>
{tooltip ? (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,7 @@ const WidgetProfilePlain = ({
.filter(item => item.displayInList)
.map((clientAttribute) => {
const { attribute, key, valueType } = clientAttribute;
const value = valueType === 'ORGANISATION_UNIT' ? (
clientAttribute.value) : (
convertClientToView(clientAttribute)
);
const value = convertClientToView(clientAttribute);
return {
attribute, key, value, valueType, reactKey: attribute,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,20 @@ const getOrganisationUnitSubvalue = async ({ attribute, querySingleResource }: S
resource: 'organisationUnits',
id: attribute.value,
params: {
fields: 'id,name',
fields: 'id,name,ancestors[displayName,level]',
},
});
return { ...organisationUnit };

const orgUnitClientValue = {
id: organisationUnit.id,
orgUnitName: organisationUnit.name,
ancestors: organisationUnit.ancestors.map(ancestor => ({
displayName: ancestor.displayName,
level: ancestor.level,
})),
};

return orgUnitClientValue;
};

export const subValueGetterByElementType = {
Expand Down
35 changes: 9 additions & 26 deletions src/core_modules/capture-ui/FlatList/FlatList.component.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';
// @flow
import React, { type ComponentType } from 'react';
import cx from 'classnames';
import { colors, spacersNum } from '@dhis2/ui';
import { withStyles } from '@material-ui/core';
import { useOrgUnitNameWithAncestors } from '../../capture-core/metadataRetrieval/orgUnitName';
import { convertValue } from '../../capture-core/converters/clientToView';
import type { Props } from './flatList.types';

const itemStyles = {
overflow: 'hidden',
Expand Down Expand Up @@ -36,41 +36,24 @@ const styles = {
},
};

const FlatListItem = ({ item, classes, lastItemKey }) => {
const { displayName: orgUnitName, ancestors } = useOrgUnitNameWithAncestors(item.value?.id);

const orgUnitClientValue = {
orgUnitName,
ancestors,
};

return (
const FlatListPlain = ({ list, classes, dataTest }: Props) => {
const lastItemKey = list[list.length - 1]?.reactKey;
const renderItem = item => (
<div
key={item.reactKey}
className={cx(classes.itemRow, { isLastItem: item.reactKey === lastItemKey })}
>
<div className={classes.itemKey}>{item.key}:</div>
<div className={classes.itemValue}>
{item.valueType === 'ORGANISATION_UNIT' ? (
convertValue(orgUnitClientValue, item.valueType)
) : (
item.value
)}
</div>
<div className={classes.itemValue}>{item.value}</div>
</div>
);
};

const FlatListPlain = ({ list, classes, dataTest }) => {
const lastItemKey = list[list.length - 1]?.reactKey;

return (
<div data-test={dataTest}>
{list.map(item => (
<FlatListItem key={item.reactKey} item={item} classes={classes} lastItemKey={lastItemKey} />
))}
{list.map(item => renderItem(item))}
</div>
);
};

export const FlatList = withStyles(styles)(FlatListPlain);
export const FlatList: ComponentType<$Diff<Props, CssClasses>> = withStyles(styles)(FlatListPlain);
2 changes: 1 addition & 1 deletion src/core_modules/capture-ui/FlatList/flatList.types.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @flow
export type Props = {|
list: { reactKey: string, key: string, value: { id: string, name: string }, valueType?: string }[],
list: { reactKey: string, key: string, value: Object, valueType?: string }[],
dataTest?: string,
...CssClasses,
|};

0 comments on commit 039c1ac

Please sign in to comment.