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

Release 2022-38 #4178

Merged
merged 23 commits into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
1cc4cfa
[no issue] Upgraded caniuse-lite (#4144)
rohan-bes Sep 6, 2022
b5e8a84
Merge pull request #4147 from beyondessential/master
IgorNadj Sep 6, 2022
c9a31cb
RN-484: Add ability for defining 'custom reports' in the report-serve…
rohan-bes Sep 6, 2022
fac0f48
RN-613: Export Selected Dashboard Only (#4130)
chris-pollard Sep 8, 2022
3bb1843
RN-515: Delete unused permission group (#4156)
chris-pollard Sep 9, 2022
09a19cd
RN-625 disable 1:many mapping dhis (#4126)
IgorNadj Sep 11, 2022
62a9701
RN-625 (2) Fix migration (#4161)
IgorNadj Sep 12, 2022
50ea2af
RN-614: Add 'Help centre' link to the User Menu (#4129)
rohan-bes Sep 12, 2022
7f526f6
[no-issue]: lesmis-server minor cleanups (#4165)
rohan-bes Sep 13, 2022
e87b307
MAUI-1105 lesmis modal scroll (#4135)
IgorNadj Sep 13, 2022
547fd07
[no-issue]: Fixed intermittent failure in dateRangePicker.test.js due…
rohan-bes Sep 13, 2022
a122f65
RN-601: Added ability to reference query parameters in viz-builder ex…
rohan-bes Sep 13, 2022
33afab4
RN-635: Introduce database locking mechanism to prevent change handle…
rohan-bes Sep 13, 2022
5ca76c3
MAUI-816: Change FETP individual entity type to fetp_graduate (#3981)
chris-pollard Sep 14, 2022
984503e
[no-issue]: Adjust padding on Sync message (#4169)
rohan-bes Sep 14, 2022
9e58433
RN-646 & RN-629 & RN-630: Added data-table-server (#4152)
rohan-bes Sep 15, 2022
a195574
[no-issue]: Reduce flakiness in sync queue related tests (#4170)
rohan-bes Sep 15, 2022
f91a571
RN-652: Added events data-table (#4172)
rohan-bes Sep 16, 2022
4edddd1
RN-632: Show Data-Tables in the Admin-Panel (#4175)
rohan-bes Sep 16, 2022
4aacba3
MAUI-859: Enable Project Creation (#4036)
chris-pollard Sep 16, 2022
7b15bde
RN-603 de dg multi mapping (#4158)
IgorNadj Sep 19, 2022
f080e66
(Hotfix) Fix kobo sync (#4180)
IgorNadj Sep 19, 2022
511980d
RN-506 lesmis favourite dashboard (#4167)
biaoli0 Sep 20, 2022
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
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"packages/api-client/**",
"packages/data-api/**",
"packages/data-lake-api/**",
"packages/data-table-server/**",
"packages/entity-server/**",
"packages/indicators/**",
"packages/lesmis-server/**",
Expand Down
2 changes: 2 additions & 0 deletions codeship-steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
command: './packages/devops/scripts/ci/testBackend.sh admin-panel-server'
- name: Test central-server
command: './packages/devops/scripts/ci/testBackend.sh central-server'
- name: Test data-table-server
command: './packages/devops/scripts/ci/testBackend.sh data-table-server'
- name: Test entity-server
command: './packages/devops/scripts/ci/testBackend.sh entity-server'
- name: Test lesmis-server
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,27 @@ describe('DashboardVisualisationExtractor', () => {
},
});
});

it('can get a draft report which uses a custom report', () => {
const extractor = new DashboardVisualisationExtractor(
{
code: 'viz',
data: { customReport: 'custom' },
presentation: {},
},
yup.object(),
draftReportValidator,
);

const report = extractor.getReport();

expect(report).toEqual({
code: 'viz',
config: {
customReport: 'custom',
},
});
});
});

describe('getReport() - legacyReport', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { QueryParameters, ApiConnection, RequestBody } from '@tupaia/server-boilerplate';

const { REPORT_API_URL = 'http://localhost:8030/v2' } = process.env;
const { REPORT_API_URL = 'http://localhost:8030/v1' } = process.env;

/**
* @deprecated use @tupaia/api-client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ export class DashboardVisualisationExtractor<
const { code, permissionGroup, data, presentation } = this.visualisation;
const validatedData = baseVisualisationDataValidator.validateSync(data);

if (validatedData.customReport) {
return {
config: {
customReport: validatedData.customReport,
},
code,
permissionGroup,
};
}

const { fetch: vizFetch, aggregate, transform } = validatedData;

const fetch = omitBy(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,10 @@
* Copyright (c) 2017 - 2021 Beyond Essential Systems Pty Ltd
*/

import { LegacyReport, Report} from '../types';
import { LegacyReport, Report } from '../types';
import { extractDataFromReport } from '../utils';
import { DashboardItem, DashboardViz, DashboardVizResource } from './types';

const getData = (report: Report) => {
const { config } = report;
const { fetch, transform } = config;
const { aggregations, ...restOfFetch } = fetch;
return { fetch: restOfFetch, aggregate: aggregations, transform };
};

const getLegacyData = (report: LegacyReport) => {
const { dataBuilder, config, dataServices } = report;
return { dataBuilder, config, dataServices };
Expand All @@ -24,20 +18,22 @@ const getPresentation = (dashboardItem: DashboardItem, report: Report | LegacyRe
const { type, name, ...config } = dashboardItemConfig;

const presentation: Record<string, unknown> = { type, ...config };
if (!dashboardItem.legacy) {
if (!dashboardItem.legacy && 'output' in reportConfig) {
presentation.output = reportConfig.output;
}

return presentation;
};

export function combineDashboardVisualisation(visualisationResource: DashboardVizResource): DashboardViz {
export function combineDashboardVisualisation(
visualisationResource: DashboardVizResource,
): DashboardViz {
const { dashboardItem, report } = visualisationResource;
const { id, code, config, legacy } = dashboardItem;
const { name } = config;
const data = dashboardItem.legacy
? getLegacyData(report as LegacyReport)
: getData(report as Report);
: extractDataFromReport(report as Report);
const presentation = getPresentation(dashboardItem, report);

const visualisation: Record<string, unknown> = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,33 @@
*/

import { ValidationError } from '@tupaia/utils';
import { LegacyReport, Report} from '../types';
import { LegacyReport, Report } from '../types';
import { extractDataFromReport } from '../utils';
import { MapOverlay, MapOverlayViz, MapOverlayVizResource } from './types';

// TODO: DRY
const getData = (report: Report) => {
const { config } = report;
const { fetch, transform } = config;
const { aggregations, ...restOfFetch } = fetch;
return { fetch: restOfFetch, aggregate: aggregations, transform };
};

const getPresentation = (mapOverlay: MapOverlay, report: Report | LegacyReport) => {
const { config: reportConfig } = report;
const { config } = mapOverlay;

const presentation = config;
if (!mapOverlay.legacy) {
if (!mapOverlay.legacy && 'output' in reportConfig) {
presentation.output = reportConfig.output;
}

return presentation;
};

export function combineMapOverlayVisualisation(visualisationResource: MapOverlayVizResource): MapOverlayViz {
export function combineMapOverlayVisualisation(
visualisationResource: MapOverlayVizResource,
): MapOverlayViz {
const { mapOverlay, report } = visualisationResource;

if (mapOverlay.legacy) {
throw new ValidationError('Legacy map overlay viz not supported');
}

const { config, permissionGroup: mapOverlayPermissionGroup, ...rest } = mapOverlay;
const data = getData(report);
const data = extractDataFromReport(report);
const presentation = getPresentation(mapOverlay, report);

const visualisation: Record<string, unknown> = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ const dateSpecsValidator = polymorphic({
string: yup.string().min(4),
});

export const configValidator = yup.object().shape({
const customReportConfigValidator = yup.object().shape({
customReport: yup.string().required(),
});

const standardConfigValidator = yup.object().shape({
fetch: yup
.object()
.shape(
Expand All @@ -70,3 +74,14 @@ export const configValidator = yup.object().shape({
transform: yup.array().required(),
output: yup.object(),
});

// TODO: Consolidate this and the validator in @tupaia/report-server in a common @tupaia/types package
export const configValidator = yup.lazy<
typeof standardConfigValidator | typeof customReportConfigValidator
>((config: unknown) => {
if (typeof config === 'object' && config && 'customReport' in config) {
return customReportConfigValidator;
}

return standardConfigValidator;
});
8 changes: 4 additions & 4 deletions packages/admin-panel-server/src/viz-builder/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Copyright (c) 2017 - 2021 Beyond Essential Systems Pty Ltd
*/

import { ReportConfig } from '@tupaia/report-server';
import { ReportConfig, StandardOrCustomReportConfig } from '@tupaia/report-server';

export type VizData = {
dataElements: ReportConfig['fetch']['dataElements'];
Expand All @@ -22,7 +22,7 @@ export enum PreviewMode {
export type Report = {
code: string;
permissionGroup: string;
config: ReportConfig;
config: StandardOrCustomReportConfig;
};

export type LegacyReport = {
Expand All @@ -47,7 +47,7 @@ export type CamelKeysToSnake<T extends Record<string, unknown>> = {
export type ExpandType<T> = T extends Record<string, unknown>
? T extends infer O
? {
[K in keyof O]: ExpandType<O[K]>;
}
[K in keyof O]: ExpandType<O[K]>;
}
: never
: T;
18 changes: 18 additions & 0 deletions packages/admin-panel-server/src/viz-builder/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Tupaia
* Copyright (c) 2017 - 2022 Beyond Essential Systems Pty Ltd
*/

import { Report } from './types';

// Used when combining the report and dashboardItem/mapOverlay
export const extractDataFromReport = (report: Report) => {
const { config } = report;
if ('customReport' in config) {
return { customReport: config.customReport };
}

const { fetch, transform } = config;
const { aggregations, ...restOfFetch } = fetch;
return { fetch: restOfFetch, aggregate: aggregations, transform };
};
18 changes: 16 additions & 2 deletions packages/admin-panel-server/src/viz-builder/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,24 @@ export const baseVisualisationValidator = yup.object().shape({
data: yup.object().required(),
});

export const baseVisualisationDataValidator = yup.object().shape({
const baseCustomReportDataValidator = yup.object().shape({
customReport: yup.string().required(),
});

const baseStandardReportDataValidator = yup.object().shape({
fetch: yup.object().required(),
});

export const baseVisualisationDataValidator = yup.lazy<
typeof baseStandardReportDataValidator | typeof baseCustomReportDataValidator
>((dataConfig: unknown) => {
if (typeof dataConfig === 'object' && dataConfig && 'customReport' in dataConfig) {
return baseCustomReportDataValidator;
}

return baseStandardReportDataValidator;
});

export const draftReportValidator = yup.object().shape({
code: yup.string().required('Requires "code" for the visualisation'),
config: configValidator,
Expand All @@ -24,4 +38,4 @@ export const legacyReportValidator = yup.object().shape({
dataBuilder: yup.string().required(),
config: yup.object().required(),
dataServices: yup.array().of(yup.object().shape({ isDataRegional: yup.boolean() })),
});
});
21 changes: 17 additions & 4 deletions packages/admin-panel/src/VizBuilderApp/components/Panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export const Panel = () => {
] = useVizConfig();

const {
visualisation: { data: finalData },
visualisation: { data: vizData },
} = useVisualisation();

const handleChange = (event, newValue) => {
Expand All @@ -108,6 +108,19 @@ export const Panel = () => {
return tab !== tabId && hasDataError;
};

const isCustomReport = 'customReport' in vizData;
// Custom report vizes don't support any configuration so just show the name
if (isCustomReport) {
return (
<Container>
<PanelNav>
<>Custom Report: {vizData.customReport}</>
<PlayButton />
</PanelNav>
</Container>
);
}

return (
<Container>
<PanelNav>
Expand All @@ -128,7 +141,7 @@ export const Panel = () => {
<TabPanel isSelected={tab === 0} Panel={PanelTabPanel}>
{jsonToggleEnabled ? (
<JsonEditor
value={finalData.fetch}
value={vizData.fetch}
onChange={value => setTabValue('fetch', value)}
onInvalidChange={handleInvalidChange}
/>
Expand All @@ -144,7 +157,7 @@ export const Panel = () => {
<TabPanel isSelected={tab === 1} Panel={PanelTabPanel}>
{jsonToggleEnabled ? (
<JsonEditor
value={finalData.aggregate}
value={vizData.aggregate}
onChange={value => setTabValue('aggregate', value)}
onInvalidChange={handleInvalidChange}
/>
Expand All @@ -161,7 +174,7 @@ export const Panel = () => {
<TabPanel isSelected={tab === 2} Panel={PanelTabPanel}>
{jsonToggleEnabled ? (
<JsonEditor
value={finalData.transform}
value={vizData.transform}
onChange={value => setTabValue('transform', value)}
onInvalidChange={handleInvalidChange}
/>
Expand Down
4 changes: 4 additions & 0 deletions packages/admin-panel/src/VizBuilderApp/context/VizConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ const useConfigStore = () => {
const setProject = value => dispatch({ type: SET_PROJECT, value });
const setTestData = value => dispatch({ type: SET_TEST_DATA, value });
const setVisualisation = value => {
if (!value.data.transform) {
return dispatch({ type: SET_VISUALISATION, value });
}

const { transform } = value.data;
const sanitisedTransform = transform.map(conf =>
typeof conf === 'string' ? { transform: conf, alias: true } : conf,
Expand Down
55 changes: 55 additions & 0 deletions packages/admin-panel/src/pages/resources/DataTablesPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Tupaia
* Copyright (c) 2017 - 2021 Beyond Essential Systems Pty Ltd
*/

import React from 'react';
import PropTypes from 'prop-types';
import { ResourcePage } from './ResourcePage';

const DATA_TABLES_ENDPOINT = 'dataTables';

const FIELDS = [
{
Header: 'Code',
source: 'code',
type: 'tooltip',
},
{
Header: 'Description',
source: 'description',
},
{
Header: 'Type',
source: 'type',
},
{
Header: 'Config',
source: 'config',
type: 'jsonTooltip',
editConfig: { type: 'jsonEditor' },
},
{
Header: 'Permission groups',
source: 'permission_groups',
type: 'tooltip',
editConfig: {
type: 'jsonArray',
},
},
];

const COLUMNS = [...FIELDS];

export const DataTablesPage = ({ getHeaderEl }) => (
<ResourcePage
title="Data-Tables"
endpoint={DATA_TABLES_ENDPOINT}
columns={COLUMNS}
getHeaderEl={getHeaderEl}
/>
);

DataTablesPage.propTypes = {
getHeaderEl: PropTypes.func.isRequired,
};
Loading