Skip to content

Commit

Permalink
Merge pull request #6002 from beyondessential/dev
Browse files Browse the repository at this point in the history
merge: update branch with latest dev
  • Loading branch information
avaek authored Nov 12, 2024
2 parents 52931e3 + 1b959cf commit 4eba288
Show file tree
Hide file tree
Showing 26 changed files with 199 additions and 36 deletions.
2 changes: 1 addition & 1 deletion packages/admin-panel/src/routes/surveys/optionSets.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const OPTION_SET_COLUMNS = [
type: 'export',
actionConfig: {
exportEndpoint: 'optionSets',
fileName: '{name}',
fileName: '{name}.xlsx',
},
},
{
Expand Down
4 changes: 2 additions & 2 deletions packages/admin-panel/src/routes/surveys/surveys.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ const SURVEY_FIELDS = {
options: SERVICE_TYPES,
setFieldsOnChange: (newValue, currentRecord = null) => {
const { dhisInstanceCode = 'regional' } = currentRecord
? currentRecord['data_group.config'] ?? {}
? (currentRecord['data_group.config'] ?? {})
: {};
const config = newValue === 'dhis' ? { dhisInstanceCode } : {};
return { 'data_group.config': config };
Expand Down Expand Up @@ -217,7 +217,7 @@ const SURVEY_COLUMNS = [
type: 'export',
actionConfig: {
exportEndpoint: 'surveys',
fileName: '{name}',
fileName: '{name}.xlsx',
},
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const COLUMNS = [
type: 'export',
actionConfig: {
exportEndpoint: 'dashboardVisualisation',
fileName: '{code}',
fileName: '{code}.json',
},
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const COLUMNS = [
type: 'export',
actionConfig: {
exportEndpoint: 'dataTable',
fileName: '{code}',
fileName: '{code}.json',
},
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ const COLUMNS = [
type: 'export',
actionConfig: {
exportEndpoint: 'mapOverlayVisualisation',
fileName: '{code}',
fileName: '{code}.json',
},
},
{
Expand Down
1 change: 1 addition & 0 deletions packages/data-api/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const sanitizeAnalyticsTableValue = (value: string, type: string) => {
switch (type) {
case 'Binary':
case 'Checkbox':
case 'Arithmetic':
case 'Number': {
const sanitizedValue = parseFloat(value);
return Number.isNaN(sanitizedValue) ? '' : sanitizedValue;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

var dbm;
var type;
var seed;

/**
* We receive the dbmigrate dependency from dbmigrate initially.
* This enables us to not have to rely on NODE_PATH.
*/
exports.setup = function (options, seedLink) {
dbm = options.dbmigrate;
type = dbm.dataType;
seed = seedLink;
};

exports.up = function (db) {
return db.runSql(
`ALTER TYPE public.entity_type ADD VALUE IF NOT EXISTS 'pacmossi_insecticide_test'`,
);
};

exports.down = function (db) {
return null;
};

exports._meta = {
version: 1,
};
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const CopySurveyUrlButton = () => {
}
arrow
enterDelay={500}
enterTouchDelay={500}
>
<Button aria-label="copy url to clipboard" onClick={copyPageUrl}>
<CopyIcon />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const downloadDashboardAsPdf = (
settings: TupaiaWebExportDashboardRequest.ReqBody['settings'] = {
exportWithLabels: false,
exportWithTable: false,
exportDescription: null,
separatePagePerItem: true,
},
) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ import { useDashboard } from '../utils';
import { ExportSubtitle } from './ExportSubtitle';
import { MailingListSection } from './MailingListSection';
import { Preview } from './Preview';
import { ExportDescriptionInput } from '../../ExportSettings/ExportDescriptionInput';

const ButtonGroup = styled.div`
padding-top: 2.5rem;
padding: 1rem 0;
width: 100%;
display: flex;
justify-content: flex-end;
Expand All @@ -31,7 +32,7 @@ const Wrapper = styled.div`
display: flex;
flex-direction: column;
flex-grow: 1;
width 100%;
width: 100%;
align-items: start;
section + section {
margin-top: 1.5rem;
Expand Down Expand Up @@ -104,9 +105,9 @@ const ExportSettingsInstructionsContainer = styled.div`
`;

const ExportSettingsWrapper = styled.div`
padding-block-end: 2rem;
padding-block-end: 0.8rem;
& + & {
padding-block-start: 1.5rem;
padding-block-start: 1rem;
border-top: 0.1rem solid ${({ theme }) => theme.palette.text.secondary};
}
&:last-child {
Expand All @@ -124,7 +125,8 @@ export const ExportConfig = ({ onClose, selectedDashboardItems }: ExportDashboar
const { data: project } = useProject(projectCode);
const { data: entity } = useEntity(projectCode, entityCode);
const { activeDashboard } = useDashboard();
const { exportWithLabels, exportWithTable, separatePagePerItem } = useExportSettings();
const { exportWithLabels, exportWithTable, exportDescription, separatePagePerItem } =
useExportSettings();

const exportFileName = `${project?.name}-${entity?.name}-${dashboardCode}-dashboard-export`;

Expand All @@ -139,6 +141,7 @@ export const ExportConfig = ({ onClose, selectedDashboardItems }: ExportDashboar
settings: {
exportWithLabels,
exportWithTable,
exportDescription,
separatePagePerItem,
},
});
Expand All @@ -164,6 +167,9 @@ export const ExportConfig = ({ onClose, selectedDashboardItems }: ExportDashboar
</ExportSettingsInstructionsContainer>
<ExportSetting>
<section>
<ExportSettingsWrapper>
<ExportDescriptionInput />
</ExportSettingsWrapper>
<ExportSettingsWrapper>
<DisplayFormatSettings />
</ExportSettingsWrapper>
Expand All @@ -178,6 +184,7 @@ export const ExportConfig = ({ onClose, selectedDashboardItems }: ExportDashboar
settings={{
exportWithTable,
exportWithLabels,
exportDescription,
separatePagePerItem,
}}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export const ExportDashboard = () => {
exportWithLabels: false,
exportWithTable: true,
exportWithTableDisabled: false,
exportDescription: '',
separatePagePerItem: true,
}}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ const PreviewContainer = styled.div`
overflow-x: hidden;
${A4Page} {
// simulate the margins of the printed page
padding-block-start: 5rem;
&:last-child {
padding-block-end: 5rem;
}
padding: 1cm 2.5cm 2cm;
}
`;

Expand Down Expand Up @@ -92,7 +89,11 @@ export const Preview = ({
)}
</PreviewHeaderContainer>
<PreviewContainer>
<DashboardPDFExport selectedDashboardItems={visualisationToPreview} isPreview={true} />
<DashboardPDFExport
selectedDashboardItems={visualisationToPreview}
isPreview={true}
pageIndex={page}
/>
</PreviewContainer>
</PreviewPanelContainer>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
* Tupaia
* Copyright (c) 2017 - 2024 Beyond Essential Systems Pty Ltd
*/

import React from 'react';
import styled from 'styled-components';
import { useExportSettings } from './ExportSettingsContext';
import { ExportSettingLabel } from './ExportSettingLabel';
import { TextField, OutlinedTextFieldProps } from '@material-ui/core';

const Wrapper = styled.div`
display: flex;
flex-direction: column;
`;

const ExportDescriptionInputArea = styled((props: OutlinedTextFieldProps) => (
<TextField {...props} />
))`
margin-block-start: 0.6rem;
.MuiInputBase-root {
border: 1px solid ${({ theme }) => theme.palette.text.secondary};
border-radius: 5px;
padding: 0.6rem 0.75rem 0.75rem;
background: none;
color: ${({ theme }) => theme.palette.text.primary};
font-size: 0.875rem;
line-height: 1.4;
&.Mui-error {
border: 1px solid ${({ theme }) => theme.palette.error.main};
}
&.Mui-focused {
border-color: ${({ theme }) => theme.palette.text.primary};
}
}
`;

const ExportDescription = styled.div<{
error: boolean;
}>`
display: flex;
align-self: end;
justify-content: space-between;
margin-top: 0.3rem;
color: ${({ error, theme }) => (error ? theme.palette.error.main : theme.palette.text.secondary)};
font-size: 0.75rem;
`;

const MAX_CHARACTERS = 250;

export const ExportDescriptionInput = () => {
const { exportDescription, updateExportDescription } = useExportSettings();
const showMaxCharsWarning = exportDescription.length >= MAX_CHARACTERS;

return (
<Wrapper>
<ExportSettingLabel as="legend">Description</ExportSettingLabel>
<ExportDescriptionInputArea
id="description"
multiline
rows={4}
value={exportDescription}
onChange={updateExportDescription}
variant="outlined"
error={showMaxCharsWarning}
inputProps={{ maxLength: MAX_CHARACTERS }}
placeholder="Enter description here"
/>
<ExportDescription error={showMaxCharsWarning}>
{showMaxCharsWarning && 'Character limit reached: '}
{exportDescription.length}/{MAX_CHARACTERS}
</ExportDescription>
</Wrapper>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ import styled from 'styled-components';
export const ExportSettingLabel = styled(Typography)`
color: ${({ theme }) => theme.palette.text.primary};
padding-inline-start: 0;
font-size: 1.125rem;
font-size: 1rem;
font-weight: ${({ theme }) => theme.typography.fontWeightMedium};
`;
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,46 @@ type ExportSettings = {
exportWithLabels: boolean;
exportWithTable: boolean;
exportWithTableDisabled: boolean;
exportDescription: string;
separatePagePerItem: boolean;
};

type ExportSettingsContextType = ExportSettings & {
setExportFormat: (value: ExportFormats) => void;
setExportWithLabels: (value: boolean) => void;
setExportWithTable: (value: boolean) => void;
setExportDescription: (value: string) => void;
setSeparatePagePerItem: (value: boolean) => void;
};

const defaultContext = {
const defaultContext: ExportSettingsContextType = {
exportFormat: ExportFormats.PNG,
exportWithLabels: false,
exportWithTable: true,
exportWithTableDisabled: false,
separatePagePerItem: true,
exportDescription: '',
setExportFormat: () => {},
setExportWithLabels: () => {},
setExportWithTable: () => {},
setExportDescription: () => {},
separatePagePerItem: true,
setSeparatePagePerItem: () => {},
} as ExportSettingsContextType;

// This is the context for the export settings
export const ExportSettingsContext = createContext(defaultContext);
export const ExportSettingsContext = createContext<ExportSettingsContextType>(defaultContext);

export const useExportSettings = () => {
const {
exportFormat,
exportWithLabels,
exportWithTable,
exportWithTableDisabled,
exportDescription,
setExportFormat,
setExportWithLabels,
setExportWithTable,
setExportDescription,
separatePagePerItem,
setSeparatePagePerItem,
} = useContext(ExportSettingsContext);
Expand All @@ -64,6 +70,10 @@ export const useExportSettings = () => {
setExportWithTable(e.target.checked);
};

const updateExportDescription = (e: ChangeEvent<HTMLInputElement>) => {
setExportDescription(e.target.value);
};

const updateSeparatePagePerItem = (e: ChangeEvent<HTMLInputElement>) => {
setSeparatePagePerItem(e.target.value === 'true');
};
Expand All @@ -72,6 +82,7 @@ export const useExportSettings = () => {
setExportFormat(dashboardItemType === 'matrix' ? ExportFormats.XLSX : ExportFormats.PNG);
setExportWithLabels(false);
setExportWithTable(true);
setExportDescription('');
setSeparatePagePerItem(true);
};

Expand All @@ -80,9 +91,11 @@ export const useExportSettings = () => {
exportWithLabels,
exportWithTable,
exportWithTableDisabled,
exportDescription,
updateExportFormat,
updateExportWithLabels,
updateExportWithTable,
updateExportDescription,
resetExportSettings,
separatePagePerItem,
updateSeparatePagePerItem,
Expand All @@ -105,6 +118,9 @@ export const ExportSettingsContextProvider = ({
const [exportWithTable, setExportWithTable] = useState<boolean>(
defaultSettings?.exportWithTable || true,
);
const [exportDescription, setExportDescription] = useState<string>(
defaultSettings?.exportDescription || '',
);
const [exportWithTableDisabled] = useState<boolean>(
defaultSettings?.exportWithTableDisabled || false,
);
Expand All @@ -120,9 +136,11 @@ export const ExportSettingsContextProvider = ({
exportWithLabels,
exportWithTable,
exportWithTableDisabled,
exportDescription,
setExportFormat,
setExportWithLabels,
setExportWithTable,
setExportDescription,
separatePagePerItem,
setSeparatePagePerItem,
}}
Expand Down
Loading

0 comments on commit 4eba288

Please sign in to comment.