Skip to content

Commit

Permalink
fix: review
Browse files Browse the repository at this point in the history
  • Loading branch information
eirikhaugstulen committed Feb 29, 2024
1 parent f72bce5 commit 59fb9ec
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 25 deletions.
10 changes: 5 additions & 5 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2024-02-27T15:15:55.309Z\n"
"PO-Revision-Date: 2024-02-27T15:15:55.309Z\n"
"POT-Creation-Date: 2024-02-29T10:05:58.402Z\n"
"PO-Revision-Date: 2024-02-29T10:05:58.402Z\n"

msgid "Choose one or more dates..."
msgstr "Choose one or more dates..."
Expand Down Expand Up @@ -889,6 +889,9 @@ msgstr "You don't have access to edit this event"
msgid "Edit event"
msgstr "Edit event"

msgid "View changelog"
msgstr "View changelog"

msgid "Event details"
msgstr "Event details"

Expand Down Expand Up @@ -1275,9 +1278,6 @@ msgstr "Event completed"
msgid "Back to all stages and events"
msgstr "Back to all stages and events"

msgid "View changelog"
msgstr "View changelog"

msgid "Schedule date info"
msgstr "Schedule date info"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// @flow
import React from 'react';
import React, { useState } from 'react';
import { useSelector } from 'react-redux';
import { dataEntryIds, dataEntryKeys } from 'capture-core/constants';
import { withStyles } from '@material-ui/core/';
import { spacers, IconFileDocument24, Button } from '@dhis2/ui';
import { spacers, IconFileDocument24, Button, IconMore16, FlyoutMenu, MenuItem } from '@dhis2/ui';
import { useQueryClient } from 'react-query';
import i18n from '@dhis2/d2-i18n';
import { ConditionalTooltip } from 'capture-core/components/Tooltips/ConditionalTooltip';
import { ViewEventSection } from '../Section/ViewEventSection.component';
Expand All @@ -13,19 +14,30 @@ import { ViewEventDataEntry } from '../../../WidgetEventEdit/ViewEventDataEntry/
import type { ProgramStage } from '../../../../metaData';
import { useCoreOrgUnit } from '../../../../metadataRetrieval/coreOrgUnit';
import { NoticeBox } from '../../../NoticeBox';
import { FEATURES, useFeature } from '../../../../../capture-core-utils';
import { EventChangelogWrapper } from '../../../WidgetEventEdit/EventChangelogWrapper';
import { OverflowButton } from '../../../Buttons';
import { ReactQueryAppNamespace } from '../../../../utils/reactQueryHelpers';
import { CHANGELOG_ENTITY_TYPES } from '../../../WidgetsChangelog';

const getStyles = () => ({
container: {
flexGrow: 2,
flexBasis: 0,
},
content: {
dataEntryContent: {
display: 'flex',
gap: spacers.dp8,
},
dataEntryContainer: {
flexGrow: 1,
},
headerContainer: {
display: 'flex',
width: '100%',
alignItems: 'center',
justifyContent: 'space-between',
},
actionsContainer: {
flexShrink: 0,
},
Expand All @@ -38,12 +50,14 @@ const getStyles = () => ({

type Props = {
showEditEvent: ?boolean,
eventId: string,
onOpenEditEvent: (orgUnit: Object) => void,
programStage: ProgramStage,
eventAccess: { read: boolean, write: boolean },
classes: {
container: string,
content: string,
headerContainer: string,
dataEntryContent: string,
dataEntryContainer: string,
actionsContainer: string,
button: string,
Expand All @@ -54,13 +68,23 @@ type Props = {
const EventDetailsSectionPlain = (props: Props) => {
const {
classes,
eventId,
onOpenEditEvent,
showEditEvent,
programStage,
eventAccess,
...passOnProps } = props;
const orgUnitId = useSelector(({ viewEventPage }) => viewEventPage.loadedValues?.orgUnit?.id);
const { orgUnit, error } = useCoreOrgUnit(orgUnitId);
const queryClient = useQueryClient();
const supportsChangelog = useFeature(FEATURES.changelogs);
const [changeLogIsOpen, setChangeLogIsOpen] = useState(false);
const [actionsIsOpen, setActionsIsOpen] = useState(false);

const onSaveExternal = () => {
const queryKey = [ReactQueryAppNamespace, 'changelog', CHANGELOG_ENTITY_TYPES.EVENT, eventId];
queryClient.removeQueries(queryKey);
};

if (error) {
return error.errorComponent;
Expand All @@ -76,6 +100,7 @@ const EventDetailsSectionPlain = (props: Props) => {
dataEntryId={dataEntryIds.SINGLE_EVENT}
formFoundation={formFoundation}
orgUnit={orgUnit}
onSaveExternal={onSaveExternal}
{...passOnProps}
/> :
// $FlowFixMe[cannot-spread-inexact] automated comment
Expand Down Expand Up @@ -112,6 +137,26 @@ const EventDetailsSectionPlain = (props: Props) => {
</Button>
</ConditionalTooltip>
</div>}
{supportsChangelog && (
<OverflowButton
open={actionsIsOpen}
onClick={() => setActionsIsOpen(prev => !prev)}
secondary
small
icon={<IconMore16 />}
component={(
<FlyoutMenu dense maxWidth="250px">
<MenuItem
label={i18n.t('View changelog')}
onClick={() => {
setChangeLogIsOpen(true);
setActionsIsOpen(false);
}}
/>
</FlyoutMenu>
)}
/>
)}
</div>
);
};
Expand All @@ -120,14 +165,26 @@ const EventDetailsSectionPlain = (props: Props) => {
return orgUnit ? (
<div className={classes.container}>
<ViewEventSection
header={<ViewEventSectionHeader text={i18n.t('Event details')} icon={IconFileDocument24} />}
header={(
<div className={classes.headerContainer}>
<ViewEventSectionHeader text={i18n.t('Event details')} icon={IconFileDocument24} />
{renderActionsContainer()}
</div>
)}
>
<div className={classes.content}>
<div className={classes.dataEntryContainer}>
{renderDataEntryContainer()}
{renderActionsContainer()}
</div>
{showEditEvent && <NoticeBox formId={`${dataEntryIds.SINGLE_EVENT}-${dataEntryKeys.EDIT}`} /> }
</ViewEventSection>
{supportsChangelog && changeLogIsOpen && (
<EventChangelogWrapper
isOpen
setIsOpen={setChangeLogIsOpen}
eventId={eventId}
formFoundation={programStage.stageForm}
/>
)}
</div>
) : null;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {

const mapStateToProps = (state: ReduxState) => ({
showEditEvent: state.viewEventPage.eventDetailsSection && state.viewEventPage.eventDetailsSection.showEditEvent,
eventId: state.viewEventPage.eventId,
programId: state.currentSelections.programId,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const mapDispatchToProps = (dispatch: ReduxDispatch, props): any => ({
onSave: (orgUnit: OrgUnit) => (eventId: string, dataEntryId: string, formFoundation: RenderFoundation) => {
const { onSaveExternal } = props;
window.scrollTo(0, 0);
onSaveExternal && onSaveExternal(eventId);
onSaveExternal && onSaveExternal();
dispatch(requestSaveEditEventDataEntry(eventId, dataEntryId, formFoundation, orgUnit));
},
onCancel: () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ const WidgetProfilePlain = ({
{i18n.t('Edit')}
</Button>
)}
{supportsChangelog && (
{!readOnlyMode && supportsChangelog && (
<OverflowButton
open={actionsIsOpen}
onClick={() => setActionsIsOpen(prev => !prev)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,11 @@ export const ChangelogComponent = ({

<ModalActions>
<ButtonStrip>
<Button onClick={() => setIsOpen(false)}>
Close
<Button
onClick={() => setIsOpen(false)}
secondary
>
{i18n.t('Close')}
</Button>
</ButtonStrip>
</ModalActions>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
// @flow
import React from 'react';
import { DataTableCell, DataTableRow } from '@dhis2/ui';
import { withStyles } from '@material-ui/core/styles';
import { ChangelogChangeCell } from './ChangelogChangeCell';
import type { ChangelogRecord } from '../../Changelog/Changelog.types';

type Props = {|
record: ChangelogRecord,
|}

const styles = {

};

const ChangelogTableRowPLain = ({ record }: Props) => (
export const ChangelogTableRow = ({ record }: Props) => (
<DataTableRow>
<DataTableCell>
{record.date}
Expand All @@ -32,5 +27,3 @@ const ChangelogTableRowPLain = ({ record }: Props) => (
</DataTableCell>
</DataTableRow>
);

export const ChangelogTableRow = withStyles(styles)(ChangelogTableRowPLain);
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ export const useChangelogData = ({
params: {
page,
pageSize,
...{ sortDirection: sortDirection === DEFAULT_SORT_DIRECTION ? undefined : sortDirection },
...{
order: sortDirection === DEFAULT_SORT_DIRECTION ? undefined : `createdAt:${sortDirection}`,
},
},
},
{
Expand Down

0 comments on commit 59fb9ec

Please sign in to comment.