Skip to content

Commit

Permalink
feat: DHIS2-10321 adds View Dashboard button on duplicates modal (#1496)
Browse files Browse the repository at this point in the history
* feat: adds button

* chore: space
  • Loading branch information
paschalidi authored Feb 25, 2021
1 parent 55b7314 commit 14058b1
Show file tree
Hide file tree
Showing 19 changed files with 189 additions and 138 deletions.
6 changes: 3 additions & 3 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,9 @@ msgstr ""
msgid "Save as new"
msgstr ""

msgid "View dashboard"
msgstr ""

msgid "Create for"
msgstr ""

Expand Down Expand Up @@ -802,9 +805,6 @@ msgstr ""
msgid "Choose a type to start searching"
msgstr ""

msgid "View dashboard"
msgstr ""

msgid "View active enrollment"
msgstr ""

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
// @flow
import React from 'react';
import type { ComponentType, Element } from 'react';
import type { ComponentType } from 'react';
import { withStyles } from '@material-ui/core';
import { CardListItem } from './CardListItem.component';
import { makeElementsContainerSelector } from './CardList.selectors';
import type { CardDataElementsInformation, SearchResultItem } from '../Pages/Search/SearchResults/SearchResults.types';
import type { CardDataElementsInformation } from '../Pages/Search/SearchResults/SearchResults.types';
import type { ListItem, RenderCustomCardActions } from './CardList.types';

type OwnProps = $ReadOnly<{|
dataElements: CardDataElementsInformation,
items: Array<SearchResultItem>,
items: Array<ListItem>,
currentProgramId?: string,
currentSearchScopeName?: string,
noItemsText?: string,
getCustomItemBottomElements?: (itemProps: Object) => Element<any>,
renderCustomCardActions?: RenderCustomCardActions,
|}>

const getStyles = (theme: Theme) => ({
Expand All @@ -22,10 +23,11 @@ const getStyles = (theme: Theme) => ({
},
});


const CardListIndex = ({
classes,
items,
getCustomItemBottomElements,
renderCustomCardActions,
dataElements,
noItemsText,
currentProgramId,
Expand All @@ -47,7 +49,7 @@ const CardListIndex = ({
item={item}
currentSearchScopeName={currentSearchScopeName}
currentProgramId={currentProgramId}
getCustomBottomElements={getCustomItemBottomElements}
renderCustomCardActions={renderCustomCardActions}
profileImageDataElement={profileImageDataElement}
dataElements={dataElementsExceptProfileImage}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// @flow
import { type Node } from 'react';
import { typeof enrollmentTypes } from './CardList.constants';

export type Tei = $ReadOnly<{
created: string,
orgUnit: string,
trackedEntityInstance: string,
lastUpdated: string,
trackedEntityType: string,
deleted: boolean,
featureType: string,
programOwners: Array<any>,
enrollments: Array<any>,
relationships: ?Array<any>,
orgUnit: string,
attributes: Array<{
lastUpdated: string,
code: string,
displayName: string,
created: string,
valueType: string,
attribute: string,
value: string
}>
}>

export type ListItem = {|
+id: string,
+values: {
[elementId: string]: any,
},
+tei: Tei,
|}

export type RenderCustomCardActions = ({item: ListItem, programName?: string, enrollmentType: $Keys<enrollmentTypes>}) => Node
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,33 @@
import i18n from '@dhis2/d2-i18n';
import React from 'react';
import moment from 'moment';
import type { ComponentType, Element } from 'react';
import type { ComponentType } from 'react';
import { Avatar, Grid, withStyles } from '@material-ui/core';
import DoneIcon from '@material-ui/icons/Done';
import { colors, Tag } from '@dhis2/ui';
import type {
CardDataElementsInformation,
CardProfileImageElementInformation,
SearchResultItem,
} from '../Pages/Search/SearchResults/SearchResults.types';
import { availableCardListButtonState, enrollmentTypes } from './CardList.constants';
import { enrollmentTypes } from './CardList.constants';
import { ListEntry } from './ListEntry.component';
import { dataElementTypes } from '../../metaData';
import type { ListItem, RenderCustomCardActions } from './CardList.types';

type OwnProps = $ReadOnly<{|
item: SearchResultItem,
item: ListItem,
currentSearchScopeName?: string,
currentProgramId?: string,
getCustomBottomElements?: (props: Object) => Element<any>,
renderCustomCardActions?: RenderCustomCardActions,
profileImageDataElement: ?CardProfileImageElementInformation,
dataElements: CardDataElementsInformation,
|}>;

type Props = $ReadOnly<{|
...OwnProps,
...CssClasses
|}>;

const getStyles = (theme: Theme) => ({
itemContainer: {
maxWidth: theme.typography.pxToRem(600),
Expand Down Expand Up @@ -58,22 +63,11 @@ const getStyles = (theme: Theme) => ({
height: theme.typography.pxToRem(44),
marginRight: theme.typography.pxToRem(8),
},
buttonMargin: {
marginTop: theme.typography.pxToRem(8),
},
});

const deriveNavigationButtonState =
(type): $Keys<typeof availableCardListButtonState> => {
switch (type) {
case enrollmentTypes.ACTIVE:
return availableCardListButtonState.SHOW_VIEW_ACTIVE_ENROLLMENT_BUTTON;
case enrollmentTypes.CANCELLED:
case enrollmentTypes.COMPLETED:
return availableCardListButtonState.SHOW_RE_ENROLLMENT_BUTTON;
default:
return availableCardListButtonState.DONT_SHOW_BUTTON;
}
};


const deriveEnrollmentType =
(enrollments, currentProgramId): $Keys<typeof enrollmentTypes> => {
if (!currentProgramId) {
Expand Down Expand Up @@ -116,11 +110,11 @@ const CardListItemIndex = ({
item,
classes,
profileImageDataElement,
getCustomBottomElements,
renderCustomCardActions,
dataElements,
currentProgramId,
currentSearchScopeName,
}: OwnProps & CssClasses) => {
}: Props) => {
const renderImageDataElement = (imageElement: CardProfileImageElementInformation) => {
const imageValue = item.values[imageElement.id];
return (
Expand Down Expand Up @@ -227,15 +221,23 @@ const CardListItemIndex = ({
</div>

{
getCustomBottomElements &&
getCustomBottomElements({
item,
navigationButtonsState: deriveNavigationButtonState(enrollmentType),
programName: currentSearchScopeName,
})
renderCustomCardActions
&&
<div className={classes.buttonMargin}>
{
renderCustomCardActions({
item,
// we pass the programName because we have the case that the scope of the search
// can be different that the scopeId from the url
// this can happen for example when you are registering through the relationships
programName: currentSearchScopeName,
enrollmentType,
})
}
</div>
}
</div>
);
};

export const CardListItem: ComponentType<OwnProps> = withStyles(getStyles)(CardListItemIndex);
export const CardListItem: ComponentType<$Diff<Props, CssClasses>> = withStyles(getStyles)(CardListItemIndex);
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as React from 'react';
import i18n from '@dhis2/d2-i18n';
import Paper from '@material-ui/core/Paper';
import withStyles from '@material-ui/core/styles/withStyles';
import NewRelatonship from '../../../Pages/NewRelationship/NewRelationship.container';
import NewRelationship from '../../../Pages/NewRelationship/NewRelationship.container';
import ConfirmDialog from '../../../Dialogs/ConfirmDialog.component';
import LinkButton from '../../../Buttons/LinkButton.component';

Expand Down Expand Up @@ -111,7 +111,7 @@ class NewEventNewRelationshipWrapper extends React.Component<Props, State> {
</div>
<Paper className={classes.newRelationshipPaper}>
{/* $FlowFixMe[cannot-spread-inexact] automated comment */}
<NewRelatonship
<NewRelationship
header={i18n.t('New event relationship')}
onGetUnsavedAttributeValues={this.onGetUnsavedAttributeValues}
{...passOnProps}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class ExistingTEIContents extends React.Component<Props> {
</DialogTitle>
<CardList
currentProgramId={programId}
// $FlowFixMe
items={items}
dataElements={dataElements}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import FeedbacksSection from '../Pages/ViewEvent/RightColumn/FeedbacksSection/Fe
import IndicatorsSection from '../Pages/ViewEvent/RightColumn/IndicatorsSection/IndicatorsSection.container';

type Props = {
onLink: (teiId: string) => void,
onLink: (teiId: string, values: Object) => void,
classes: {
stickyOnScroll: string,
}
Expand All @@ -34,7 +34,8 @@ const componentContainers = [

class DataEntryWidgetOutputComponent extends React.Component<Props> {
renderComponent = (container: {id: string, Component: React.ComponentType<any> }, props: Object) => {
const { onLink, ...otherProps } = props;
const { renderCardActions, ...otherProps } = props;

const passOnProps = container.id === 'WarningsSection' ? props : otherProps;
return (
<container.Component key={container.id} {...passOnProps} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { connect } from 'react-redux';
import React, { type ComponentType } from 'react';
import GeneralOutputComponent from './DataEntryWidgetOutput.component';
import getDataEntryKey from '../DataEntry/common/getDataEntryKey';
import type { RenderCustomCardActions } from '../CardList/CardList.types';

type OwnProps = {|
onLink?: (teiId: string) => void,
renderCardActions?: RenderCustomCardActions,
dataEntryId: string,
selectedScopeId: string,
|}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import i18n from '@dhis2/d2-i18n';
import { Button } from '../../../Buttons';
import { WarningMessageCreator } from './WarningMessageCreator.component';
import { PossibleDuplicatesDialog } from '../../../PossibleDuplicatesDialog';
import type { RenderCustomCardActions } from '../../../CardList/CardList.types';

type Props = {|
onLink: Function,
renderCardActions: RenderCustomCardActions,
selectedScopeId: string,
dataEntryId: string
|};
Expand Down Expand Up @@ -44,7 +45,7 @@ export class SearchGroupDuplicate extends React.Component<Props, State> {
}

render() {
const { onLink, selectedScopeId, dataEntryId } = this.props;
const { selectedScopeId, dataEntryId, renderCardActions } = this.props;
const { duplicatesReviewDialogOpen } = this.state;

return (
Expand All @@ -59,8 +60,8 @@ export class SearchGroupDuplicate extends React.Component<Props, State> {
selectedScopeId={selectedScopeId}
open={duplicatesReviewDialogOpen}
onCancel={this.handleCloseReviewDialog}
onLink={onLink}
extraActions={this.getHideButton()}
renderCardActions={renderCardActions}
/>
</React.Fragment>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ const searchGroupCountSelector = (state, props) =>
state.dataEntriesSearchGroupsResults[props.dataEntryKey].main &&
state.dataEntriesSearchGroupsResults[props.dataEntryKey].main.count;

const onLinkSelector = (state, props) => props.onLink;
const renderCardActionsSelector = (state, props) => props.renderCardActions;
const selectedScopeIdSelector = (_, props) => props.selectedScopeId;
const dataEntryIdSelector = (_, props) => props.dataEntryId;

// $FlowFixMe
export const makeGetSearchGroupWarning = () => createSelector(
searchGroupCountSelector,
onLinkSelector,
renderCardActionsSelector,
selectedScopeIdSelector,
dataEntryIdSelector,
(count: ?number, onLink: Function, selectedScopeId: string, dataEntryId: string) => {
(count: ?number, renderCardActions, selectedScopeId: string, dataEntryId: string) => {
if (!count) {
return null;
}
Expand All @@ -28,7 +28,7 @@ export const makeGetSearchGroupWarning = () => createSelector(
<SearchGroupDuplicate
dataEntryId={dataEntryId}
selectedScopeId={selectedScopeId}
onLink={onLink}
renderCardActions={renderCardActions}
/>
),
};
Expand Down
Loading

0 comments on commit 14058b1

Please sign in to comment.