Skip to content

Commit

Permalink
feat: datatable rows hack
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim Fung committed Aug 10, 2020
1 parent 1a62365 commit 28e48d9
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 10 deletions.
14 changes: 12 additions & 2 deletions src/app/modules/querybuilder-module/fragments/results/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { DataTable } from 'app/components/datadisplay/DataTable';
import { DownloadButton } from './common/DownloadButton';
import { FormResetButton } from 'app/modules/querybuilder-module/common/FormResetButton';
import { RadioGroupTitle } from 'app/components/inputs/radiobuttons/RadioButtonGroup/common/RadioGroupTitle';
import { setRows } from 'app/state/models/QueryModel';
// import { setRows } from 'app/state/models/QueryModel';

const filename = () => new Date().toISOString().slice(0, 19);

Expand Down Expand Up @@ -111,14 +111,24 @@ export const DownloadFragment = () => {
<RadioGroup
defaultValue="50"
onChange={(e) => {
setRows(e);
switch (e.target.value) {
case '50':
document.cookie = 'rows=rows=50';
console.log(queryURL.concat('', 'rows=50'));
break;
case 'All':
document.cookie = 'rows=';
console.log(queryURL.replace('rows=50', ''));
break;
}
}}
row
>
<FormControlLabel
// type="primary"
// onChange=
value="50"
// checked
control={<Radio />}
label="50 activities"
/>
Expand Down
8 changes: 5 additions & 3 deletions src/app/state/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { Endpoint } from 'app/state/interfaces/Endpoint';
export const baseURL =
'https://iatidatastore.iatistandard.org/search/activity?'; //'https://test-datastore.iatistandard.org/search/activity?';

export const tableRows = 2500;

/* uncomment this in order to get data from API */
const NODE_ENV = 'production';

Expand Down Expand Up @@ -209,15 +211,15 @@ const api = <T>(endpoint: Endpoint): ApiModel<T> => ({
loading: false,
response: undefined,
error: undefined,
data: computed(state => state.response && state.response.data),
call: action(state => {
data: computed((state) => state.response && state.response.data),
call: action((state) => {
state.loading = true;
}),
success: action((state, payload) => {
state.loading = false;
state.response = payload;
}),
fetch: thunk(async actions => {
fetch: thunk(async (actions) => {
actions.call();
const response = await endpoint<T>();
actions.success({ data: response });
Expand Down
1 change: 1 addition & 0 deletions src/app/state/models/ApplicationStoreModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,5 @@ export interface ApplicationStoreModel {
secondaryReporter: SecondaryReporterInterface;
policyMarker: PolicyMarkerInterface;
tag: TagInterface;
rows: number;
}
20 changes: 16 additions & 4 deletions src/app/state/models/QueryModel.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
import { baseURL } from 'app/state/api';
import { action, Action } from 'easy-peasy';
import { baseURL, tableRows } from 'app/state/api';

export const ROWS = 2500;
import { action, Action, createStore, State, useStoreState } from 'easy-peasy';

document.cookie = 'rows=rows=50';

export const ROWS = document.cookie
.split('; ')
.find((row) => row.startsWith('rows'))
.split('=')[1];

export interface QueryModel {
url: string;
updateQuery: Action<QueryModel, string>;
rows?: number;
}

export const queryModel: QueryModel = {
url: `${baseURL}q=*:*&wt=json&rows=${ROWS}`,
url: `${baseURL}q=*:*&wt=json&rows=${
document.cookie
.split('; ')
.find((row) => row.startsWith('rows'))
.split('=')[1]
}`,
updateQuery: action((state, payload) => {
// eslint-disable-next-line
state.url = payload;
Expand Down
6 changes: 5 additions & 1 deletion src/app/state/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import policyMarker from '../interfaces/PolicyMarkerInterface';
import tag from 'app/state/interfaces/TagInterface';
import { queryModel } from 'app/state/models/QueryModel';

const applicationStore: ApplicationStoreModel = {
export const applicationStore: ApplicationStoreModel = {
organisationTypes: organisationTypes,
organisations: organisations,
sectors: sectors,
Expand Down Expand Up @@ -76,6 +76,10 @@ const applicationStore: ApplicationStoreModel = {
otherIdentifierType: otherIdentifierType,
policyMarker: policyMarker,
tag: tag,
rows: document.cookie
.split('; ')
.find((row) => row.startsWith('rows'))
.split('=')[1],
};

const appStore = createStore(applicationStore);
Expand Down

0 comments on commit 28e48d9

Please sign in to comment.