Skip to content

Commit

Permalink
Merge pull request #234 from zimmerman-team/feat/2437/2476
Browse files Browse the repository at this point in the history
2437 2351
  • Loading branch information
stephanoshadjipetrou authored Nov 26, 2020
2 parents 9eba856 + d22b2f2 commit fd713ba
Show file tree
Hide file tree
Showing 15 changed files with 95 additions and 36 deletions.
2 changes: 1 addition & 1 deletion cypress/integration/qbOutputFormat.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('Query Builder - output format', function () {
it('should load the page', function () {
cy.visit('/querybuilder/output-format');
cy.get('[data-cy=covid-banner-close-btn]').click();
cy.get(':nth-child(3) > #navlink').click();
cy.get(':nth-child(3) > #Output_Format').click();
});

it('should show the correct text', function () {
Expand Down
6 changes: 5 additions & 1 deletion src/app/components/datadisplay/DataTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import sortBy from 'lodash/sortBy';
import get from 'lodash/get';
import axios from 'axios';
import { PagingState, CustomPaging } from '@devexpress/dx-react-grid';
import { ModuleStore } from 'app/modules/querybuilder-module/state/store';
import {
Grid,
PagingPanel,
Expand All @@ -20,6 +21,7 @@ import {
} from 'app/modules/querybuilder-module/fragments/results/model';
import { ROWS } from 'app/state/models/QueryModel';
import { NoDataCellComponent } from './common/nodatacellcomp';
import { getRetrievedItemsLabel } from 'app/modules/querybuilder-module/fragments/results/util';

export const DataTable = (props) => {
const [cols, setCols] = useState(
Expand All @@ -35,6 +37,8 @@ export const DataTable = (props) => {
const [pageSize, setPageSize] = useState(10);
const [tablePage, setTablePage] = useState(0);
const [loading, setLoading] = useState(false);
const store = ModuleStore.useStore();
const rowFormat = store.get('rowFormat');

useEffect(() => {
if (!props.defaultCols && docsData.length > 0) {
Expand Down Expand Up @@ -87,7 +91,7 @@ export const DataTable = (props) => {
>
<h3>
Datastore retrieved {props.allDataCount}{' '}
{props.allDataCount === 1 ? 'activity' : 'activities'} for you
{getRetrievedItemsLabel(rowFormat, props.allDataCount)} for you
</h3>
<Paper>
<Grid rows={docsData} columns={cols}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@ export const ValueContainer = (provided) => ({
fontWeight: 200,
});



export const MenuList = (provided, state) => ({
...provided,
height: '300px',
Expand Down
8 changes: 6 additions & 2 deletions src/app/components/inputs/selects/ConnectedSelect/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const customStyles = {
multiValueLabel: MultiValueLabel,
multiValueRemove: (provided: any) => ({ ...provided }),
menu: Menu,
placeholder: styles => ({...styles, color: 'black', opacity: '1'}),
placeholder: (styles) => ({ ...styles, color: 'black', opacity: '1' }),
};

export const ConnectedSelect = (props: any) => {
Expand All @@ -42,7 +42,11 @@ export const ConnectedSelect = (props: any) => {
`}
data-cy={props.data_cy}
>
<FieldInputLabel for={createID(props.label)} label={props.label} data-cy={'select-field-label'} />
<FieldInputLabel
for={createID(props.label)}
label={props.label}
data-cy={'select-field-label'}
/>
<Select
inputId={createID(props.label)}
data-cy={'select'}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* core */
import React from 'react';
/* third-party */
import get from 'lodash/get';
import Grid from '@material-ui/core/Grid';
/* project component */
import { ConnectedSelect } from 'app/components/inputs/selects/ConnectedSelect';
/* actions & store */
import { useStoreActions, useStoreState } from 'app/state/store';
import get from 'lodash/get';

type Props = {
label: string;
Expand All @@ -22,27 +22,6 @@ export function AddFilterModule(props: Props) {
get(state, `${props.dataKey}.data`, [])
);
const action = useStoreActions((actions) => actions[props.dataKey].fetch);
const label = props.label;
if (label === 'IATI version') {
return (
<Grid item xs={12} sm={12} md={4} key={props.label}>
<ConnectedSelect
label={props.label}
value={props.value}
options={values || []}
onChange={props.onChange}
onMenuOpen={() => {
if (values.length === 0) {
action();
}
}}
placeholder={props.placeholder}
getOptionValue={(option) => option.code}
getOptionLabel={(option) => `${option.code}`}
/>
</Grid>
);
}

return (
<Grid item xs={12} sm={12} md={4} key={props.label}>
Expand All @@ -58,7 +37,11 @@ export function AddFilterModule(props: Props) {
}}
placeholder={props.placeholder}
getOptionValue={(option) => option.code}
getOptionLabel={(option) => `${option.code}: ${option.name}`}
getOptionLabel={(option) =>
`${option.code}${
props.label === 'IATI version' ? '' : `: ${option.name}`
}`
}
/>
</Grid>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,24 @@ export const additionalFiltersPopData = [
<AddFilterModule
label="Tag"
dataKey="tag"
placeholder="All other identifier types"
placeholder="All options"
value={props.store.get('tag')}
onChange={(e) => props.store.set('tag')(e)}
/>
),
},
{
label: 'Tag vocabulary',
component: (props) => (
<AddFilterModule
label="Tag vocabulary"
dataKey="tagVocabulary"
placeholder="All options"
value={props.store.get('tagVocabulary')}
onChange={(e) => props.store.set('tagVocabulary')(e)}
/>
),
},
{
label: 'Policy marker',
component: (props) => (
Expand Down
11 changes: 7 additions & 4 deletions src/app/modules/querybuilder-module/fragments/results/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { DownloadButton } from 'app/modules/querybuilder-module/fragments/result
import { FormResetButton } from 'app/modules/querybuilder-module/common/FormResetButton';
import { RadioButton } from 'app/components/inputs/radiobuttons/RadioButton';
import { RadioGroupTitle } from 'app/components/inputs/radiobuttons/RadioButtonGroup/common/RadioGroupTitle';
import { getRetrievedItemsLabel } from './util';
// import { setRows } from 'app/state/models/QueryModel';

const filename = () => new Date().toISOString().slice(0, 19);
Expand Down Expand Up @@ -93,6 +94,8 @@ export const DownloadFragment = () => {
}
}, [allDataCount]);

const itemsLabel = getRetrievedItemsLabel(rowFormat);

return (
<Grid
container
Expand Down Expand Up @@ -145,14 +148,14 @@ export const DownloadFragment = () => {
{allDataCount > 50 && (
<FormControlLabel
value="50"
control={<RadioButton id={"activities_radio"} />}
label="50 activities"
control={<RadioButton id="activities_radio" />}
label={`50 ${itemsLabel}`}
/>
)}
<FormControlLabel
value={allDataCount.toString()}
control={<RadioButton id={"activities_radio_2"} />}
label={`${allDataCount} activities`}
control={<RadioButton id="activities_radio_2" />}
label={`${allDataCount} ${itemsLabel}`}
/>
</RadioGroup>
</Grid>
Expand Down
19 changes: 19 additions & 0 deletions src/app/modules/querybuilder-module/fragments/results/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,22 @@ export const cleanIframes = () => {
iframes[i].parentNode.removeChild(iframes[i]);
}
};

export const getRetrievedItemsLabel = (rowFormat: string, count?: number) => {
if (rowFormat === 'activity') {
if (count && count === 1) {
return 'activity';
}
return 'activities';
}
if (rowFormat === 'transaction') {
if (count && count === 1) {
return 'transaction';
}
return 'transactions';
}
if (count && count === 1) {
return 'budget';
}
return 'budgets';
};
10 changes: 10 additions & 0 deletions src/app/modules/querybuilder-module/state/effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,13 @@ export const withEffects: StoreEffect = (store) => {
})
: null;

const tagVocabulary =
store.get('tagVocabulary') && rowFormat === 'activity'
? store.get('tagVocabulary').map((item: ActivityStatusModel) => {
return item.code;
})
: null;

const defaultFlowType =
store.get('defaultFlowType') && rowFormat === 'activity'
? store.get('defaultFlowType').map((item: ActivityStatusModel) => {
Expand Down Expand Up @@ -807,6 +814,9 @@ export const withEffects: StoreEffect = (store) => {
? `policy_marker_code:(${policyMarker && policyMarker.join(' ')})`
: null,
get(tag, 'length', 0) ? `tag_code:(${tag && tag.join(' ')})` : null,
get(tagVocabulary, 'length', 0)
? `tag_vocabulary:(${tagVocabulary && tagVocabulary.join(' ')})`
: null,
];

const surl = constructSolrQuery(
Expand Down
2 changes: 2 additions & 0 deletions src/app/modules/querybuilder-module/state/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export type ModuleStoreModel = {
otherIdentifierType: ActivityStatusModel[];
policyMarker: ActivityStatusModel[];
tag: ActivityStatusModel[];
tagVocabulary: ActivityStatusModel[];
mustHaveDates: string;
startDateAfter: any;
startDateBefore: any;
Expand All @@ -70,6 +71,7 @@ const initialState = fromLocalStorage<ModuleStoreModel>({
sectors: [],
policyMarker: [],
tag: [],
tagVocabulary: [],
sectorCategories: [],
sectorVocabularies: [],
countries: [],
Expand Down
4 changes: 3 additions & 1 deletion src/app/state/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Endpoint } from 'app/state/interfaces/Endpoint';
export const baseURL =
'https://iatidatastore.iatistandard.org/search/activity?';
// export const baseURL =
// 'https://iatidatastore.iatistandard.org/search/activity?';
// 'https://test-datastore.iatistandard.org/search/activity?';

export const tableRows = 2500;

Expand Down Expand Up @@ -51,6 +51,8 @@ export const POLICY_MARKER = 'data/policy_marker.json';

export const TAG = 'data/tag.json';

export const TAG_VOCABULARY = 'api/codelists/TagVocabulary/?format=json';

export const ORGANISATIONS =
// @ts-ignore
NODE_ENV === 'development'
Expand Down
12 changes: 12 additions & 0 deletions src/app/state/interfaces/TagVocabularyInterface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ActivityStatusModel } from 'app/state/models';
import { getTagVocabularies } from 'app/state/services/api-service';
import api, { ApiModel } from 'app/state/api';

export interface TagVocabularyInterface
extends ApiModel<ActivityStatusModel[]> {}

const tagVocabulary: TagVocabularyInterface = {
...api(getTagVocabularies),
};

export default tagVocabulary;
2 changes: 2 additions & 0 deletions src/app/state/models/ApplicationStoreModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { TransactionReceiverOrgsInterface } from 'app/state/interfaces/Transacti
import { ParticipatingOrgsInterface } from 'app/state/interfaces/ParticipatingOrgsInterface';
import { SecondaryReporterInterface } from 'app/state/interfaces/SecondaryReporterInterface';
import { PolicyMarkerInterface } from 'app/state/interfaces/PolicyMarkerInterface';
import { TagVocabularyInterface } from 'app/state/interfaces/TagVocabularyInterface';

import { QueryModel } from 'app/state/models/QueryModel';
import { HierarchyInterface } from '../interfaces/HierarchyInterface';
Expand Down Expand Up @@ -74,4 +75,5 @@ export interface ApplicationStoreModel {
secondaryReporter: SecondaryReporterInterface;
policyMarker: PolicyMarkerInterface;
tag: TagInterface;
tagVocabulary: TagVocabularyInterface;
}
6 changes: 6 additions & 0 deletions src/app/state/services/api-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
TRANSACTION_RECEIVER_ORGS,
TRANSACTION_TIED_STATUS,
TRANSACTION_TYPE,
TAG_VOCABULARY,
} from 'app/state/api';

import { Endpoint } from 'app/state/interfaces/Endpoint';
Expand Down Expand Up @@ -82,6 +83,11 @@ export const getTag: Endpoint = (params: RequestInit = {}) =>
method: 'GET',
}).then((res) => res.json());

export const getTagVocabularies: Endpoint = (params: RequestInit = {}) =>
fetch(HOSTNAME + TAG_VOCABULARY, {
method: 'GET',
}).then((res) => res.json());

export const getRegions: Endpoint = (params: RequestInit = {}) =>
fetch(HOSTNAME + REGIONS, {
method: 'GET',
Expand Down
4 changes: 3 additions & 1 deletion src/app/state/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ import humanitarianScopeVocab from 'app/state/interfaces/HumanitarianScopeVocabI
import transactionHumanitarian from 'app/state/interfaces/TransactionHumanitarianInterface';
import otherIdentifierType from 'app/state/interfaces/OtherIdentifierTypeInterface';
import participatingOrgs from 'app/state/interfaces/ParticipatingOrgsInterface';
import policyMarker from '../interfaces/PolicyMarkerInterface';
import policyMarker from 'app/state/interfaces/PolicyMarkerInterface';
import tag from 'app/state/interfaces/TagInterface';
import tagVocabulary from 'app/state/interfaces/TagVocabularyInterface';
import { queryModel } from 'app/state/models/QueryModel';

export const applicationStore: ApplicationStoreModel = {
Expand Down Expand Up @@ -76,6 +77,7 @@ export const applicationStore: ApplicationStoreModel = {
otherIdentifierType: otherIdentifierType,
policyMarker: policyMarker,
tag: tag,
tagVocabulary: tagVocabulary,
};

const appStore = createStore(applicationStore);
Expand Down

0 comments on commit fd713ba

Please sign in to comment.