Skip to content

Prettify frontend codebase #13

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

Merged
merged 2 commits into from
Jul 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion frontend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const environment = {
: isProduction
? ""
: MOCK_API_URL,
disableLogin,
disableLogin
};

const tabs = [StandardQueryEditorTab, TimebasedQueryEditorTab, FormsTab];
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/js/AppRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import type { TabT } from "./pane/types";
import AppRouter from "./app/AppRouter";

type PropsType = {
store: Object;
browserHistory: Object;
store: Record<string, any>;
browserHistory: Record<string, any>;
rightTabs: TabT[];
};

Expand Down
34 changes: 17 additions & 17 deletions frontend/src/js/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ import type {
PostLoginResponseT,
PostFormConfigsResponseT,
GetFormConfigsResponseT,
GetFormConfigResponseT,
GetFormConfigResponseT
} from "./types";

import fetchJson, { fetchJsonUnauthorized } from "./fetchJson";
import { transformQueryToApi } from "./apiHelper";
import { transformFormQueryToApi } from "./apiExternalFormsHelper";
import type {
FormConfigT,
BaseFormConfigT,
BaseFormConfigT
} from "js/external-forms/form-configs/reducer";

const PROTECTED_PREFIX = "/api";
Expand Down Expand Up @@ -62,15 +62,15 @@ export const getConcept = (
// Same signature as postFormQueries
export function postQueries(
datasetId: DatasetIdT,
query: Object,
query: Record<string, any>,
queryType: string
): Promise<PostQueriesResponseT> {
// Transform into backend-compatible format
const data = transformQueryToApi(query, queryType);

return fetchJson(getProtectedUrl(`/datasets/${datasetId}/queries`), {
method: "POST",
data,
data
});
}

Expand All @@ -87,7 +87,7 @@ export function postFormQueries(

return fetchJson(getProtectedUrl(`/datasets/${datasetId}/queries`), {
method: "POST",
data,
data
});
}

Expand All @@ -98,7 +98,7 @@ export function deleteQuery(
return fetchJson(
getProtectedUrl(`/datasets/${datasetId}/queries/${queryId}`),
{
method: "DELETE",
method: "DELETE"
}
);
}
Expand Down Expand Up @@ -140,21 +140,21 @@ export function deleteStoredQuery(
return fetchJson(
getProtectedUrl(`/datasets/${datasetId}/stored-queries/${queryId}`),
{
method: "DELETE",
method: "DELETE"
}
);
}

export function patchStoredQuery(
datasetId: DatasetIdT,
queryId: QueryIdT,
attributes: Object
attributes: Record<string, any>
): Promise<null> {
return fetchJson(
getProtectedUrl(`/datasets/${datasetId}/stored-queries/${queryId}`),
{
method: "PATCH",
data: attributes,
data: attributes
}
);
}
Expand All @@ -172,7 +172,7 @@ export function postPrefixForSuggestions(
),
{
method: "POST",
data: { text },
data: { text }
}
);
}
Expand All @@ -186,7 +186,7 @@ export function postConceptsListToResolve(
getProtectedUrl(`/datasets/${datasetId}/concepts/${conceptId}/resolve`),
{
method: "POST",
data: { concepts },
data: { concepts }
}
);
}
Expand All @@ -204,7 +204,7 @@ export function postFilterValuesResolve(
),
{
method: "POST",
data: { values },
data: { values }
}
);
}
Expand All @@ -221,8 +221,8 @@ export function postLogin(
method: "POST",
data: {
user,
password,
},
password
}
});
}

Expand All @@ -232,7 +232,7 @@ export function postFormConfig(
): Promise<PostFormConfigsResponseT> {
return fetchJson(getProtectedUrl(`/datasets/${datasetId}/form-configs`), {
method: "POST",
data,
data
});
}

Expand All @@ -254,7 +254,7 @@ export function patchFormConfig(
getProtectedUrl(`/datasets/${datasetId}/form-configs/${formConfigId}`),
{
method: "PATCH",
data,
data
}
);
}
Expand All @@ -272,7 +272,7 @@ export function deleteFormConfig(
return fetchJson(
getProtectedUrl(`/datasets/${datasetId}/form-configs/${formConfigId}`),
{
method: "DELETE",
method: "DELETE"
}
);
}
2 changes: 1 addition & 1 deletion frontend/src/js/api/apiExternalFormsHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const transformFormQueryToApi = (
query: { form: string; formName: string },
queryType: string,
formQueryTransformation: Function
): Object => {
): Record<string, any> => {
const { form, formName } = query;

return {
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/js/api/apiHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,10 @@ const createExternal = (query: any) => {
// The query state already contains the query.
// But small additions are made (properties whitelisted), empty things filtered out
// to make it compatible with the backend API
export const transformQueryToApi = (query: Object, queryType: string) => {
export const transformQueryToApi = (
query: Record<string, any>,
queryType: string
) => {
switch (queryType) {
case "timebased":
return transformTimebasedQueryToApi(query);
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/js/api/fetchJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getStoredAuthToken } from "../authorization/helper";
export async function fetchJsonUnauthorized(
url: string,
request?: Partial<AxiosRequestConfig>,
rawBody: boolean = false
rawBody = false
) {
const finalRequest: AxiosRequestConfig = request
? {
Expand Down Expand Up @@ -50,7 +50,7 @@ export async function fetchJsonUnauthorized(
function fetchJson(
url: string,
request?: Partial<AxiosRequestConfig>,
rawBody: boolean = false
rawBody = false
) {
const authToken = getStoredAuthToken() || "";
const finalRequest = {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/js/app/AppRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import WithAuthToken from "../authorization/WithAuthToken";
import App from "./App";

type PropsType = {
history: Object;
history: Record<string, any>;
rightTabs: TabT[];
};

Expand Down
4 changes: 2 additions & 2 deletions frontend/src/js/app/LeftPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import { StateT } from "./reducers";

const LeftPane = () => {
const activeTab = useSelector<StateT, string>(
(state) => state.panes.left.activeTab
state => state.panes.left.activeTab
);
const selectedDatasetId = useSelector<StateT, DatasetIdT | null>(
(state) => state.datasets.selectedDatasetId
state => state.datasets.selectedDatasetId
);

return (
Expand Down
16 changes: 8 additions & 8 deletions frontend/src/js/app/reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,34 @@ import startup, { StartupStateT } from "../startup/reducer";
import { buildPanesReducer, PanesStateT } from "../pane/reducer";
import queryGroupModal from "../query-group-modal/reducer";
import previousQueries, {
PreviousQueriesStateT,
PreviousQueriesStateT
} from "../previous-queries/list/reducer";
import previousQueriesSearch, {
PreviousQueriesSearchStateT,
PreviousQueriesSearchStateT
} from "../previous-queries/search/reducer";
import previousQueriesFilter, {
PreviousQueriesFilterStateT,
PreviousQueriesFilterStateT
} from "../previous-queries/filter/reducer";
import uploadQueryResults from "../previous-queries/upload/reducer";
import deletePreviousQueryModal from "../previous-queries/delete-modal/reducer";
import snackMessage from "../snack-message/reducer";
import preview from "../preview/reducer";
import queryUploadConceptListModal from "../query-upload-concept-list-modal/reducer";
import uploadConceptListModal, {
UploadConceptListModalStateT,
UploadConceptListModalStateT
} from "../upload-concept-list-modal/reducer";

import { createQueryNodeEditorReducer } from "../query-node-editor/reducer";

import type { StandardQueryEditorStateT } from "../standard-query-editor";
import formConfigs, {
FormConfigsStateT,
FormConfigsStateT
} from "../external-forms/form-configs/reducer";
import formConfigsSearch, {
FormConfigsSearchStateT,
FormConfigsSearchStateT
} from "../external-forms/form-configs/search/reducer";
import formConfigsFilter, {
FormConfigsFilterStateT,
FormConfigsFilterStateT
} from "../external-forms/form-configs/filter/reducer";

// TODO: Introduce more StateTypes gradually
Expand Down Expand Up @@ -86,7 +86,7 @@ const buildAppReducer = (tabs: TabT[]) => {
...tabs.reduce((all, tab) => {
all[tab.key] = tab.reducer;
return all;
}, {}),
}, {})
});
};

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/js/authorization/WithAuthToken.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useDispatch } from "react-redux";
type PropsType = {
children: React.ReactNode;
location: {
search: Object;
search: Record<string, any>;
};
};

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/js/authorization/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { isLoginDisabled } from "../environment";
export function createUnauthorizedErrorMiddleware() {
const loginDisabled = isLoginDisabled();

return (store: Object) => (next: Function) => (action: any) => {
return (store: Record<string, any>) => (next: Function) => (action: any) => {
if (!loginDisabled && action.payload && action.payload.status === 401)
store.dispatch(push("/login"));

Expand Down
8 changes: 4 additions & 4 deletions frontend/src/js/button/PreviewButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import { openPreview } from "../preview/actions";
import IconButton from "./IconButton";

type PropsType = {
url: string,
isLoading: boolean,
onOpenPreview: (url: string) => void,
className?: string
url: string;
isLoading: boolean;
onOpenPreview: (url: string) => void;
className?: string;
};

const PreviewButton = ({
Expand Down
12 changes: 6 additions & 6 deletions frontend/src/js/common/actions/genericActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,26 @@ interface ErrorObject {
export const defaultError = (
type: string,
error: ErrorObject,
payload?: Object
payload?: Record<string, any>
): ActionT => ({
type,
error: true,
payload: {
message: error.message,
status: error.status,
...payload,
},
...payload
}
});

export const defaultSuccess = (
type: string,
results: any,
payload?: Object
payload?: Record<string, any>
): ActionT => ({
type,
payload: {
data: results,
receivedAt: Date.now(),
...payload,
},
...payload
}
});
4 changes: 2 additions & 2 deletions frontend/src/js/common/helpers/commonHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const compose = (...fns: Function[]) =>
v => v
);

export const objectWithoutKey = (key: string) => (obj: Object) => {
export const objectWithoutKey = (key: string) => (obj: Record<string, any>) => {
if (!obj.hasOwnProperty(key)) return obj;

const { [key]: deleted, ...rest } = obj;
Expand Down Expand Up @@ -69,7 +69,7 @@ export const toUpperCaseUnderscore = (str: string) => {
export const isObject = (item: any) =>
item && typeof item === "object" && !Array.isArray(item);

export const mergeDeep = (...elements: Object[]) => {
export const mergeDeep = (...elements: Record<string, any>[]) => {
return elements.filter(isObject).reduce((aggregate, current) => {
const nonObjectKeys = Object.keys(current).filter(
key => !isObject(current[key])
Expand Down
Loading