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";
|
2020-06-17 10:19:56 +00:00
|
|
|
import {
|
|
|
|
|
ApplicationPayload,
|
|
|
|
|
OrganizationDetails,
|
|
|
|
|
} from "constants/ReduxActionConstants";
|
2020-01-20 08:07:00 +00:00
|
|
|
import Fuse from "fuse.js";
|
|
|
|
|
|
|
|
|
|
const fuzzySearchOptions = {
|
2020-09-16 11:50:47 +00:00
|
|
|
keys: ["applications.name", "organization.name"],
|
2020-01-20 08:07:00 +00:00
|
|
|
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-10-06 15:10:21 +00:00
|
|
|
export const getCurrentApplication = (
|
|
|
|
|
state: AppState,
|
|
|
|
|
): ApplicationPayload | undefined => {
|
|
|
|
|
return state.ui.applications.currentApplication;
|
2020-03-09 05:46:32 +00:00
|
|
|
};
|
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;
|
2020-09-01 07:16:54 +00:00
|
|
|
export const getIsDuplicatingApplication = (state: AppState) =>
|
|
|
|
|
state.ui.applications.duplicatingApplication;
|
2020-09-16 11:50:47 +00:00
|
|
|
export const getIsSavingAppName = (state: AppState) =>
|
|
|
|
|
state.ui.applications.isSavingAppName;
|
2020-06-17 10:19:56 +00:00
|
|
|
export const getUserApplicationsOrgs = (state: AppState) => {
|
|
|
|
|
return state.ui.applications.userOrgs;
|
|
|
|
|
};
|
2019-11-07 04:59:40 +00:00
|
|
|
|
2020-04-14 12:34:14 +00:00
|
|
|
export const getImportedCollections = (state: AppState) =>
|
|
|
|
|
state.ui.importedCollections.importedCollections;
|
|
|
|
|
|
|
|
|
|
export const getProviders = (state: AppState) => state.ui.providers.providers;
|
|
|
|
|
export const getProvidersLoadingState = (state: AppState) =>
|
|
|
|
|
state.ui.providers.isFetchingProviders;
|
|
|
|
|
export const getProviderTemplates = (state: AppState) =>
|
|
|
|
|
state.ui.providers.providerTemplates;
|
|
|
|
|
export const getProvidersTemplatesLoadingState = (state: AppState) =>
|
|
|
|
|
state.ui.providers.isFetchingProviderTemplates;
|
|
|
|
|
|
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
|
|
|
);
|
|
|
|
|
|
2020-06-17 10:19:56 +00:00
|
|
|
export const getUserApplicationsOrgsList = createSelector(
|
|
|
|
|
getUserApplicationsOrgs,
|
|
|
|
|
getApplicationSearchKeyword,
|
|
|
|
|
(applicationsOrgs?: [], keyword?: string): OrganizationDetails[] => {
|
|
|
|
|
if (
|
|
|
|
|
applicationsOrgs &&
|
|
|
|
|
applicationsOrgs.length > 0 &&
|
|
|
|
|
keyword &&
|
|
|
|
|
keyword.trim().length > 0
|
|
|
|
|
) {
|
|
|
|
|
const fuzzy = new Fuse(applicationsOrgs, fuzzySearchOptions);
|
|
|
|
|
let organizationList = fuzzy.search(keyword) as OrganizationDetails[];
|
|
|
|
|
organizationList = organizationList.map(org => {
|
|
|
|
|
const applicationFuzzy = new Fuse(org.applications, {
|
|
|
|
|
...fuzzySearchOptions,
|
|
|
|
|
keys: ["name"],
|
|
|
|
|
});
|
|
|
|
|
const applications = applicationFuzzy.search(keyword) as [];
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
...org,
|
|
|
|
|
applications,
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return organizationList;
|
|
|
|
|
} else if (
|
|
|
|
|
applicationsOrgs &&
|
|
|
|
|
(keyword === undefined || keyword.trim().length === 0)
|
|
|
|
|
) {
|
|
|
|
|
return applicationsOrgs;
|
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
|
);
|