2019-11-07 04:59:40 +00:00
|
|
|
import { createSelector } from "reselect";
|
2019-11-25 05:07:27 +00:00
|
|
|
import { AppState } from "reducers";
|
|
|
|
|
import { ApplicationsReduxState } from "reducers/uiReducers/applicationsReducer";
|
|
|
|
|
import { ApplicationPayload } from "constants/ReduxActionConstants";
|
2020-01-20 08:07:00 +00:00
|
|
|
import Fuse from "fuse.js";
|
2020-03-09 05:46:32 +00:00
|
|
|
import { UserApplication } from "constants/userConstants";
|
2020-01-20 08:07:00 +00:00
|
|
|
|
|
|
|
|
const fuzzySearchOptions = {
|
|
|
|
|
keys: ["name"],
|
|
|
|
|
shouldSort: true,
|
|
|
|
|
threshold: 0.5,
|
|
|
|
|
location: 0,
|
|
|
|
|
distance: 100,
|
|
|
|
|
};
|
2019-11-07 04:59:40 +00:00
|
|
|
|
|
|
|
|
const getApplicationsState = (state: AppState) => state.ui.applications;
|
2020-01-20 08:07:00 +00:00
|
|
|
const getApplications = (state: AppState) =>
|
|
|
|
|
state.ui.applications.applicationList;
|
2020-03-09 05:46:32 +00:00
|
|
|
export const getCurrentApplication = (state: AppState): UserApplication => {
|
|
|
|
|
const appId = state.entities.pageList.applicationId;
|
|
|
|
|
const apps = state.ui.users.current
|
|
|
|
|
? state.ui.users.current.applications
|
|
|
|
|
: [];
|
|
|
|
|
const app = apps.find(app => app.id === appId);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
app || {
|
|
|
|
|
id: "",
|
|
|
|
|
name: "",
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
};
|
2020-01-20 08:07:00 +00:00
|
|
|
const getApplicationSearchKeyword = (state: AppState) =>
|
|
|
|
|
state.ui.applications.searchKeyword;
|
2020-02-03 12:19:10 +00:00
|
|
|
export const getIsDeletingApplication = (state: AppState) =>
|
|
|
|
|
state.ui.applications.deletingApplication;
|
2019-11-07 04:59:40 +00:00
|
|
|
|
|
|
|
|
export const getApplicationList = createSelector(
|
2020-01-20 08:07:00 +00:00
|
|
|
getApplications,
|
|
|
|
|
getApplicationSearchKeyword,
|
|
|
|
|
(
|
|
|
|
|
applications?: ApplicationPayload[],
|
|
|
|
|
keyword?: string,
|
|
|
|
|
): ApplicationPayload[] => {
|
|
|
|
|
if (
|
|
|
|
|
applications &&
|
|
|
|
|
applications.length > 0 &&
|
|
|
|
|
keyword &&
|
|
|
|
|
keyword.trim().length > 0
|
|
|
|
|
) {
|
|
|
|
|
const fuzzy = new Fuse(applications, fuzzySearchOptions);
|
|
|
|
|
return fuzzy.search(keyword) as ApplicationPayload[];
|
|
|
|
|
} else if (
|
|
|
|
|
applications &&
|
|
|
|
|
(keyword === undefined || keyword.trim().length === 0)
|
|
|
|
|
) {
|
|
|
|
|
return applications;
|
|
|
|
|
}
|
|
|
|
|
return [];
|
|
|
|
|
},
|
2019-11-07 04:59:40 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export const getIsFetchingApplications = createSelector(
|
|
|
|
|
getApplicationsState,
|
|
|
|
|
(applications: ApplicationsReduxState): boolean =>
|
|
|
|
|
applications.isFetchingApplications,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export const getIsCreatingApplication = createSelector(
|
|
|
|
|
getApplicationsState,
|
|
|
|
|
(applications: ApplicationsReduxState): boolean =>
|
|
|
|
|
applications.creatingApplication,
|
|
|
|
|
);
|
2019-11-21 10:52:49 +00:00
|
|
|
|
|
|
|
|
export const getCreateApplicationError = createSelector(
|
|
|
|
|
getApplicationsState,
|
|
|
|
|
(applications: ApplicationsReduxState): string | undefined =>
|
|
|
|
|
applications.createApplicationError,
|
|
|
|
|
);
|