@legalplace/wizardx-core 4.34.0 → 4.35.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/App.js +11 -0
- package/dist/components/SmartScript.js +3 -2
- package/dist/componentsConnectors/connectPagination.d.ts +1 -0
- package/dist/componentsConnectors/connectPagination.js +5 -1
- package/dist/componentsConnectors/connectSummaryItem.js +3 -2
- package/dist/constants/autocomplete.d.ts +7 -0
- package/dist/constants/autocomplete.js +86 -0
- package/dist/helpers/activitiesHelper.d.ts +5 -0
- package/dist/helpers/activitiesHelper.js +86 -0
- package/dist/helpers/autocomplete.helper.d.ts +6 -0
- package/dist/helpers/autocomplete.helper.js +53 -0
- package/dist/helpers/autosave.helper.d.ts +15 -0
- package/dist/helpers/autosave.helper.js +75 -0
- package/dist/helpers/index.d.ts +1 -0
- package/dist/helpers/index.js +1 -0
- package/dist/helpers/inpiCitiesHelper.d.ts +11 -0
- package/dist/helpers/inpiCitiesHelper.js +116 -0
- package/dist/helpers/query.helper.d.ts +2 -0
- package/dist/helpers/query.helper.js +2 -0
- package/dist/libs/Formatter/FormatAddress.d.ts +1 -0
- package/dist/libs/Formatter/FormatAddress.js +11 -0
- package/dist/libs/PathReader.d.ts +1 -0
- package/dist/libs/PathReader.js +15 -3
- package/dist/libs/index.d.ts +1 -0
- package/dist/libs/index.js +1 -0
- package/dist/redux/sagas/saveData.js +1 -0
- package/dist/redux/sagas/setUserEmail.js +1 -1
- package/dist/service/autocomplete.manager.d.ts +7 -0
- package/dist/service/autocomplete.manager.js +141 -0
- package/dist/service/index.d.ts +1 -0
- package/dist/service/index.js +1 -0
- package/dist/types/autocomplete.type.d.ts +40 -0
- package/dist/types/autocomplete.type.js +10 -0
- package/package.json +10 -6
package/dist/App.js
CHANGED
|
@@ -17,6 +17,7 @@ import { PathReader } from "./libs/PathReader";
|
|
|
17
17
|
import { resetStateAction } from "./redux/actions/app";
|
|
18
18
|
import { callInitDataSmartscriptAction } from "./redux";
|
|
19
19
|
import { externalPartnerRedirectUrl } from "./helpers/redirectionConfig";
|
|
20
|
+
import { autoSave } from "./helpers/autosave.helper";
|
|
20
21
|
import { NOT_FOUND_PAGE_LINK } from "./constants/links.constant";
|
|
21
22
|
const RedirectHandler = () => {
|
|
22
23
|
const matchedPartner = Object.keys(externalPartnerRedirectUrl).find((partner) => window.location.origin.toLowerCase().includes(partner));
|
|
@@ -57,6 +58,16 @@ class WizardXCore extends React.Component {
|
|
|
57
58
|
componentDidMount() {
|
|
58
59
|
const { dispatch, getState } = getStore();
|
|
59
60
|
const state = getState();
|
|
61
|
+
let parent = null;
|
|
62
|
+
window.addEventListener("message", ({ data, source }) => {
|
|
63
|
+
if (parent === null || data.from === "BO") {
|
|
64
|
+
parent = source;
|
|
65
|
+
}
|
|
66
|
+
if (data.from && data.from === "BO") {
|
|
67
|
+
const variable = data.variables[0];
|
|
68
|
+
autoSave(variable, getStore());
|
|
69
|
+
}
|
|
70
|
+
});
|
|
60
71
|
dispatch(callInitDataSmartscriptAction());
|
|
61
72
|
if (!PathReader.isSmartScriptPath()) {
|
|
62
73
|
dispatch(fetchModelPrerequisitesAction(getConfig().permalink || state.app.meta.permalink, getConfig().prefix || state.app.meta.prefix || ""));
|
|
@@ -10,15 +10,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
11
11
|
import { useEffect, useState } from "react";
|
|
12
12
|
import { useParams } from "react-router-dom";
|
|
13
|
-
import queryString from "query-string";
|
|
14
13
|
import moment from "moment-business-days";
|
|
15
14
|
import { connect } from "react-redux";
|
|
16
15
|
import { getConfig } from "../config";
|
|
17
16
|
import { SmartScriptStore } from "../libs/SmartScriptStore";
|
|
18
17
|
import { smartScriptLoadedMessage } from "../constants/smartscript";
|
|
19
18
|
import { selectDataSmartscript } from "../redux";
|
|
19
|
+
import { getQueryStringValues } from "../helpers";
|
|
20
20
|
let initTriggersCallback = null;
|
|
21
21
|
const SmartScriptComponent = ({ inpiActivities = [] }) => {
|
|
22
|
+
var _a;
|
|
22
23
|
const [smartScriptLoaded, setSmartScriptLoaded] = useState(false);
|
|
23
24
|
const [isNewInstance, setIsNewInstance] = useState(true);
|
|
24
25
|
window.onInit = SmartScriptStore.onInit;
|
|
@@ -41,7 +42,7 @@ const SmartScriptComponent = ({ inpiActivities = [] }) => {
|
|
|
41
42
|
window.moment = moment;
|
|
42
43
|
const apiEndpoint = getConfig().apiEndpoint + (/\/$/.test(getConfig().apiEndpoint) ? "" : "/");
|
|
43
44
|
const { permalink, uniqid } = useParams();
|
|
44
|
-
const modelVersion =
|
|
45
|
+
const modelVersion = (_a = getQueryStringValues()) === null || _a === void 0 ? void 0 : _a.version;
|
|
45
46
|
useEffect(() => {
|
|
46
47
|
if (inpiActivities.length && !smartScriptLoaded) {
|
|
47
48
|
const src = `${apiEndpoint}wizard/contractv1/smartscript/${permalink}${uniqid ? `/${uniqid}` : ""}${modelVersion ? `?version=${modelVersion}` : ""}`;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { PathReader } from "../libs";
|
|
1
2
|
import { componentConnector } from "./connector/componentConnector";
|
|
2
|
-
const stateToProps = (selectors) => () => {
|
|
3
|
+
const stateToProps = (selectors) => (state) => {
|
|
3
4
|
const { selectIsFirstPage, selectCurrentPage, selectIsLastPage, selectIsLastWizardPage, selectAvailableSections, selectUserStatus, selectMandatorySection, selectCurrentSectionId, selectFirstUnfinishedSectionId, selectMandatoryIgnore, } = selectors;
|
|
4
5
|
const isFirstPage = selectIsFirstPage();
|
|
5
6
|
const currentPage = selectCurrentPage();
|
|
@@ -11,6 +12,8 @@ const stateToProps = (selectors) => () => {
|
|
|
11
12
|
const mandatoryIgnore = selectMandatoryIgnore();
|
|
12
13
|
const isCurrentSectionMandatoryValidated = selectMandatorySection(currentSection);
|
|
13
14
|
const firstUnfinishedSectionId = selectFirstUnfinishedSectionId(currentSection);
|
|
15
|
+
const pathReader = new PathReader(state);
|
|
16
|
+
const link = pathReader.getCurrentLinkPage();
|
|
14
17
|
return {
|
|
15
18
|
isFirstPage,
|
|
16
19
|
isLastPage,
|
|
@@ -22,6 +25,7 @@ const stateToProps = (selectors) => () => {
|
|
|
22
25
|
mandatoryIgnore,
|
|
23
26
|
isUserAuthenticated: userStatus === "authenticated",
|
|
24
27
|
currentPage,
|
|
28
|
+
link,
|
|
25
29
|
};
|
|
26
30
|
};
|
|
27
31
|
const dispatchToProps = (actions) => (dispatch) => ({
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import queryString from "query-string";
|
|
2
1
|
import { componentConnector } from "./connector/componentConnector";
|
|
3
2
|
import { PathReader } from "../libs/PathReader";
|
|
4
3
|
import { SectionValidity } from "../libs/SectionValidity";
|
|
4
|
+
import { getQueryStringValues } from "../helpers";
|
|
5
5
|
const stateToProps = (selectors) => (state, ownProps) => {
|
|
6
|
+
var _a;
|
|
6
7
|
const { selectSectionReference, selectAvailableSections, selectCurrentSectionId, selectMandatorySection, selectMandatoryIgnore, } = selectors;
|
|
7
8
|
const currentSection = selectCurrentSectionId();
|
|
8
9
|
const mandatoryIgnore = selectMandatoryIgnore();
|
|
@@ -14,7 +15,7 @@ const stateToProps = (selectors) => (state, ownProps) => {
|
|
|
14
15
|
const link = pathReader.parsePath(pageNumber);
|
|
15
16
|
const active = id === currentSection;
|
|
16
17
|
let disableClick = false;
|
|
17
|
-
if (
|
|
18
|
+
if (((_a = getQueryStringValues()) === null || _a === void 0 ? void 0 : _a.ignore) !== "true" &&
|
|
18
19
|
id > currentSection &&
|
|
19
20
|
mandatoryIgnore === false) {
|
|
20
21
|
const mandatoriesSections = selectAvailableSections().map((sectionId) => selectMandatorySection(sectionId));
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AutocompleteDatasetType } from "@legalplace/models-v3-types";
|
|
2
|
+
import type { IAutocompleteDatasetConfig } from "../types/autocomplete.type";
|
|
3
|
+
export declare const LegalStatusMapperConfig: Record<number, string>;
|
|
4
|
+
export declare const autocompleteDatasetConfig: Record<AutocompleteDatasetType, IAutocompleteDatasetConfig>;
|
|
5
|
+
export declare const ACCENTS_MAP: {
|
|
6
|
+
[key: string]: string;
|
|
7
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { DatasetTypeEnum } from "../types/autocomplete.type";
|
|
2
|
+
export const LegalStatusMapperConfig = {
|
|
3
|
+
5710: "SAS",
|
|
4
|
+
5720: "SASU",
|
|
5
|
+
5498: "EURL",
|
|
6
|
+
5499: "SARL",
|
|
7
|
+
6540: "SCI",
|
|
8
|
+
5485: "SELARL",
|
|
9
|
+
5785: "SELAS",
|
|
10
|
+
6599: "SC",
|
|
11
|
+
1000: "EI",
|
|
12
|
+
};
|
|
13
|
+
const AutocompleteDefaultDatasetConfig = {
|
|
14
|
+
timeoutLimit: 10000,
|
|
15
|
+
noResultPlaceholder: (value) => `Aucun résultat, utiliser <b>${value}</b> comme valeur`,
|
|
16
|
+
loadingPlaceholder: "Chargement...",
|
|
17
|
+
otherPlaceholder: (value) => `Aucun de ces choix, utiliser <b>${value}</b> comme valeur`,
|
|
18
|
+
linkedVariablesDisabledTooltip: "Complétez le champ ci-dessus pour modifier cette valeur",
|
|
19
|
+
};
|
|
20
|
+
export const autocompleteDatasetConfig = {
|
|
21
|
+
[DatasetTypeEnum.DATAGOUV_ADDRESSES]: Object.assign(Object.assign({}, AutocompleteDefaultDatasetConfig), { limit: 10, minInputLenght: 5, debounceDelay: 300, timeoutLimit: 10000, shouldDisableLinkedVariables: true, cannotChooseOther: false }),
|
|
22
|
+
[DatasetTypeEnum.DATAGOUV_CITIES]: Object.assign(Object.assign({}, AutocompleteDefaultDatasetConfig), { limit: 10, minInputLenght: 3, debounceDelay: 300, timeoutLimit: 10000, shouldDisableLinkedVariables: true, cannotChooseOther: false }),
|
|
23
|
+
[DatasetTypeEnum.PAPPERS]: Object.assign(Object.assign({}, AutocompleteDefaultDatasetConfig), { limit: 10, minInputLenght: 1, debounceDelay: 500, timeoutLimit: 10000, shouldDisableLinkedVariables: false, cannotChooseOther: false }),
|
|
24
|
+
[DatasetTypeEnum.ACTIVITIES]: Object.assign(Object.assign({}, AutocompleteDefaultDatasetConfig), { limit: 10, minInputLenght: 3, debounceDelay: 300, timeoutLimit: 10000, shouldDisableLinkedVariables: false, cannotChooseOther: false }),
|
|
25
|
+
[DatasetTypeEnum.KANOON_COLLECTIVE_AGREEMENTS]: Object.assign(Object.assign({}, AutocompleteDefaultDatasetConfig), { limit: 5, minInputLenght: 3, debounceDelay: 300, timeoutLimit: 10000, shouldDisableLinkedVariables: false, cannotChooseOther: false, noResultPlaceholder: (value) => `Aucun résultat, utiliser <b>${value}</b> comme valeur`, loadingPlaceholder: "Chargement...", otherPlaceholder: (value) => `Aucun de ces choix, utiliser <b>${value}</b> comme valeur`, linkedVariablesDisabledTooltip: "Veuillez sélectionner la convention collective" }),
|
|
26
|
+
[DatasetTypeEnum.DATAGOUV_ADDRESSES_V2]: Object.assign(Object.assign({}, AutocompleteDefaultDatasetConfig), { limit: 20, minInputLenght: 5, debounceDelay: 500, timeoutLimit: 10000, shouldDisableLinkedVariables: true, cannotChooseOther: false, otherPlaceholder: () => "<b>Aucun de ces choix</b><br>Entrer mon adresse manuellement", noResultPlaceholder: () => "<b>Aucun de ces choix</b><br>Entrer mon adresse manuellement" }),
|
|
27
|
+
[DatasetTypeEnum.DATAGOUV_CITIES_WITH_INPI]: Object.assign(Object.assign({}, AutocompleteDefaultDatasetConfig), { limit: 20, minInputLenght: 3, debounceDelay: 300, timeoutLimit: 10000, shouldDisableLinkedVariables: true, cannotChooseOther: true, noResultPlaceholder: () => "<b>Aucun résultat</b><br/> Veuillez vérifier l'orthographe de la ville ou insérer un code postal" }),
|
|
28
|
+
};
|
|
29
|
+
export const ACCENTS_MAP = {
|
|
30
|
+
Á: "A",
|
|
31
|
+
À: "A",
|
|
32
|
+
Â: "A",
|
|
33
|
+
Ä: "A",
|
|
34
|
+
Ã: "A",
|
|
35
|
+
Å: "A",
|
|
36
|
+
á: "a",
|
|
37
|
+
à: "a",
|
|
38
|
+
â: "a",
|
|
39
|
+
ä: "a",
|
|
40
|
+
ã: "a",
|
|
41
|
+
å: "a",
|
|
42
|
+
É: "E",
|
|
43
|
+
È: "E",
|
|
44
|
+
Ê: "E",
|
|
45
|
+
Ë: "E",
|
|
46
|
+
é: "e",
|
|
47
|
+
è: "e",
|
|
48
|
+
ê: "e",
|
|
49
|
+
ë: "e",
|
|
50
|
+
Í: "I",
|
|
51
|
+
Ì: "I",
|
|
52
|
+
Î: "I",
|
|
53
|
+
Ï: "I",
|
|
54
|
+
í: "i",
|
|
55
|
+
ì: "i",
|
|
56
|
+
î: "i",
|
|
57
|
+
ï: "i",
|
|
58
|
+
Ó: "O",
|
|
59
|
+
Ò: "O",
|
|
60
|
+
Ô: "O",
|
|
61
|
+
Ö: "O",
|
|
62
|
+
Õ: "O",
|
|
63
|
+
Ø: "O",
|
|
64
|
+
ó: "o",
|
|
65
|
+
ò: "o",
|
|
66
|
+
ô: "o",
|
|
67
|
+
ö: "o",
|
|
68
|
+
õ: "o",
|
|
69
|
+
ø: "o",
|
|
70
|
+
Ú: "U",
|
|
71
|
+
Ù: "U",
|
|
72
|
+
Û: "U",
|
|
73
|
+
Ü: "U",
|
|
74
|
+
ú: "u",
|
|
75
|
+
ù: "u",
|
|
76
|
+
û: "u",
|
|
77
|
+
ü: "u",
|
|
78
|
+
Ç: "C",
|
|
79
|
+
ç: "c",
|
|
80
|
+
Ñ: "N",
|
|
81
|
+
ñ: "n",
|
|
82
|
+
Ÿ: "Y",
|
|
83
|
+
ÿ: "y",
|
|
84
|
+
"-": " ",
|
|
85
|
+
"'": " ",
|
|
86
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { IActivities } from "../types/autocomplete.type";
|
|
2
|
+
export declare const api: import("axios").AxiosInstance;
|
|
3
|
+
export declare const getAllActivities: (signal?: AbortSignal | undefined) => Promise<import("axios").AxiosResponse<any, any>>;
|
|
4
|
+
export declare const initializeActivities: (signal?: AbortSignal | undefined) => Promise<void>;
|
|
5
|
+
export declare const searchInActivities: (inputValue: string, limit: number, signal?: AbortSignal | undefined) => Promise<Omit<IActivities, "keywords">[]>;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
11
|
+
var t = {};
|
|
12
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
13
|
+
t[p] = s[p];
|
|
14
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
15
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
16
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
17
|
+
t[p[i]] = s[p[i]];
|
|
18
|
+
}
|
|
19
|
+
return t;
|
|
20
|
+
};
|
|
21
|
+
import Fuse from "fuse.js";
|
|
22
|
+
import axios from "axios";
|
|
23
|
+
import { getConfig } from "../config";
|
|
24
|
+
let cachedActivities = null;
|
|
25
|
+
let initializationPromise = null;
|
|
26
|
+
export const api = axios.create({
|
|
27
|
+
withCredentials: true,
|
|
28
|
+
});
|
|
29
|
+
export const getAllActivities = (signal) => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
|
+
return api.get("/wizard/activities/all", {
|
|
31
|
+
baseURL: getConfig().apiEndpoint +
|
|
32
|
+
(/\/$/.test(getConfig().apiEndpoint) ? "" : "/"),
|
|
33
|
+
signal,
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
export const initializeActivities = (signal) => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
+
if (cachedActivities !== null) {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
if (initializationPromise !== null) {
|
|
41
|
+
return initializationPromise;
|
|
42
|
+
}
|
|
43
|
+
initializationPromise = (() => __awaiter(void 0, void 0, void 0, function* () {
|
|
44
|
+
try {
|
|
45
|
+
const response = yield getAllActivities(signal);
|
|
46
|
+
if (Array.isArray(response.data)) {
|
|
47
|
+
cachedActivities = response.data;
|
|
48
|
+
}
|
|
49
|
+
else if (response.data.result) {
|
|
50
|
+
cachedActivities = response.data.result;
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
cachedActivities = [];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
finally {
|
|
57
|
+
initializationPromise = null;
|
|
58
|
+
}
|
|
59
|
+
}))();
|
|
60
|
+
return initializationPromise;
|
|
61
|
+
});
|
|
62
|
+
export const searchInActivities = (inputValue, limit, signal) => __awaiter(void 0, void 0, void 0, function* () {
|
|
63
|
+
if (!cachedActivities) {
|
|
64
|
+
yield initializeActivities(signal);
|
|
65
|
+
}
|
|
66
|
+
if (!cachedActivities || !inputValue.trim()) {
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
69
|
+
const options = {
|
|
70
|
+
includeScore: true,
|
|
71
|
+
shouldSort: true,
|
|
72
|
+
threshold: 0.3,
|
|
73
|
+
keys: [
|
|
74
|
+
{ name: "label", weight: 4 },
|
|
75
|
+
{ name: "description", weight: 2 },
|
|
76
|
+
{ name: "keywords", weight: 2 },
|
|
77
|
+
{ name: "nafCode", weight: 3 },
|
|
78
|
+
],
|
|
79
|
+
};
|
|
80
|
+
const searchEngine = new Fuse(cachedActivities, options);
|
|
81
|
+
const searchResults = searchEngine.search(inputValue);
|
|
82
|
+
return searchResults.slice(0, limit).map(({ item }) => {
|
|
83
|
+
const { keywords: _keywords } = item, cleanedActivity = __rest(item, ["keywords"]);
|
|
84
|
+
return Object.assign(Object.assign({}, cleanedActivity), { primary: cleanedActivity.label, secondary: `Code NAF : ${cleanedActivity.nafCode}` });
|
|
85
|
+
});
|
|
86
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { AutocompleteDatasetType } from "@legalplace/models-v3-types";
|
|
2
|
+
export declare const handleDataGouvCitiesWithInpi: ({ inputValue, dataset, signal, }: {
|
|
3
|
+
inputValue: string;
|
|
4
|
+
dataset: AutocompleteDatasetType;
|
|
5
|
+
signal?: AbortSignal | undefined;
|
|
6
|
+
}) => Promise<Record<string, string | number | null | undefined>[]>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { DataGouvApi } from "@legalplace/data-gouv";
|
|
11
|
+
import { autocompleteDatasetConfig } from "../constants/autocomplete";
|
|
12
|
+
import { DatasetTypeEnum } from "../types/autocomplete.type";
|
|
13
|
+
import { initializeInpiCities, mixDataGouvAndInpiCities, } from "./inpiCitiesHelper";
|
|
14
|
+
export const handleDataGouvCitiesWithInpi = ({ inputValue, dataset, signal, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
yield initializeInpiCities();
|
|
16
|
+
if (inputValue.length < 3) {
|
|
17
|
+
return [];
|
|
18
|
+
}
|
|
19
|
+
const { limit, debounceDelay } = autocompleteDatasetConfig[dataset];
|
|
20
|
+
const debounceId = DatasetTypeEnum.DATAGOUV_CITIES_WITH_INPI;
|
|
21
|
+
const debounceTimerKey = `debounceTimer_${debounceId}`;
|
|
22
|
+
const windowWithTimers = window;
|
|
23
|
+
return new Promise((resolve) => {
|
|
24
|
+
if (windowWithTimers[debounceTimerKey]) {
|
|
25
|
+
clearTimeout(windowWithTimers[debounceTimerKey]);
|
|
26
|
+
}
|
|
27
|
+
windowWithTimers[debounceTimerKey] = setTimeout(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
|
+
try {
|
|
29
|
+
const api = new DataGouvApi();
|
|
30
|
+
const searchType = "municipality";
|
|
31
|
+
const searchPromise = api.searchAddress({
|
|
32
|
+
query: inputValue,
|
|
33
|
+
limit,
|
|
34
|
+
type: searchType,
|
|
35
|
+
autocomplete: true,
|
|
36
|
+
signal,
|
|
37
|
+
});
|
|
38
|
+
const localTimeoutPromise = new Promise((_, reject) => {
|
|
39
|
+
const localTimeoutId = setTimeout(() => {
|
|
40
|
+
clearTimeout(localTimeoutId);
|
|
41
|
+
reject(new Error("Local search timed out"));
|
|
42
|
+
}, autocompleteDatasetConfig[dataset].timeoutLimit);
|
|
43
|
+
});
|
|
44
|
+
const result = yield Promise.race([searchPromise, localTimeoutPromise]);
|
|
45
|
+
const processedResult = yield mixDataGouvAndInpiCities(result, inputValue, limit);
|
|
46
|
+
resolve(processedResult);
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
resolve([]);
|
|
50
|
+
}
|
|
51
|
+
}), debounceDelay);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AnyAction, EmptyObject, Store } from "redux";
|
|
2
|
+
import type { StateType } from "../types";
|
|
3
|
+
export declare const getRelatedParentsByVariableId: (variableId: number, index: number) => {
|
|
4
|
+
id: number;
|
|
5
|
+
value: Readonly<string | number>;
|
|
6
|
+
condition: boolean | undefined;
|
|
7
|
+
}[];
|
|
8
|
+
export declare const getAutoCompleteParentVariableId: (variableId: number, index: number, type?: string | undefined) => number | undefined;
|
|
9
|
+
export declare const autoSave: (variableData: {
|
|
10
|
+
variablesIds: number[];
|
|
11
|
+
updateValue: string;
|
|
12
|
+
index: number;
|
|
13
|
+
}, store: Store<EmptyObject & StateType, AnyAction> & {
|
|
14
|
+
dispatch: unknown;
|
|
15
|
+
}) => Promise<void>;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { saveDataAction, selectAutocompleteDataset, selectLinkedVariables, selectOptionReference, selectVariableConditionValue, selectVariableInputByIndex, selectVariableParents, selectVariablesReference, updateVariableAction, } from "../redux";
|
|
11
|
+
import { fetchAutocompleteDataFromInputValue } from "../service";
|
|
12
|
+
import { cleanString } from "../libs";
|
|
13
|
+
export const getRelatedParentsByVariableId = (variableId, index) => {
|
|
14
|
+
const parentOptionId = selectVariableParents(variableId)[0];
|
|
15
|
+
const optionData = selectOptionReference(parentOptionId);
|
|
16
|
+
const variablesSection = selectVariablesReference(optionData === null || optionData === void 0 ? void 0 : optionData.variables);
|
|
17
|
+
return variablesSection
|
|
18
|
+
.filter((variableItem) => variableItem.type === "autocomplete" &&
|
|
19
|
+
Object.values((variableItem === null || variableItem === void 0 ? void 0 : variableItem.linkedVariables) || []).includes(variableId))
|
|
20
|
+
.map((parentVariable) => ({
|
|
21
|
+
id: parentVariable.id,
|
|
22
|
+
value: selectVariableInputByIndex(parentVariable.id, index) || "",
|
|
23
|
+
condition: selectVariableConditionValue(parentVariable.id, index),
|
|
24
|
+
}));
|
|
25
|
+
};
|
|
26
|
+
export const getAutoCompleteParentVariableId = (variableId, index, type) => {
|
|
27
|
+
if (type === "autocomplete") {
|
|
28
|
+
return variableId;
|
|
29
|
+
}
|
|
30
|
+
const autoCompleteParents = getRelatedParentsByVariableId(variableId, index);
|
|
31
|
+
if (autoCompleteParents.length) {
|
|
32
|
+
const { id: idParent } = autoCompleteParents[0];
|
|
33
|
+
return idParent;
|
|
34
|
+
}
|
|
35
|
+
return undefined;
|
|
36
|
+
};
|
|
37
|
+
const getResultAutoComplete = (variableId, updateValue, index, store) => __awaiter(void 0, void 0, void 0, function* () {
|
|
38
|
+
const linkedVariables = selectLinkedVariables(variableId);
|
|
39
|
+
const autocompleteDataset = selectAutocompleteDataset(variableId);
|
|
40
|
+
const autocompleteResults = yield fetchAutocompleteDataFromInputValue({
|
|
41
|
+
dataset: autocompleteDataset,
|
|
42
|
+
inputValue: cleanString(updateValue),
|
|
43
|
+
attributes: Object.keys(linkedVariables || {}),
|
|
44
|
+
});
|
|
45
|
+
if (!autocompleteResults) {
|
|
46
|
+
window.parent.postMessage({ from: "WIZARD", data: "ERROR" }, "*");
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (autocompleteResults.length) {
|
|
50
|
+
const selectedValue = autocompleteResults[0];
|
|
51
|
+
yield store.dispatch(updateVariableAction(variableId, (selectedValue === null || selectedValue === void 0 ? void 0 : selectedValue.field) || (selectedValue === null || selectedValue === void 0 ? void 0 : selectedValue.primary) || updateValue, index));
|
|
52
|
+
Object.entries(linkedVariables || {}).forEach(([key, linkedVariableId]) => __awaiter(void 0, void 0, void 0, function* () {
|
|
53
|
+
yield store.dispatch(updateVariableAction(linkedVariableId, selectedValue[key] || "", index));
|
|
54
|
+
}));
|
|
55
|
+
store.dispatch(saveDataAction());
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
export const autoSave = (variableData, store) => __awaiter(void 0, void 0, void 0, function* () {
|
|
59
|
+
yield variableData.variablesIds.forEach((variableId, indexVariable) => __awaiter(void 0, void 0, void 0, function* () {
|
|
60
|
+
let contentVariable = variableData.updateValue;
|
|
61
|
+
if (variableData.variablesIds.length > 1) {
|
|
62
|
+
contentVariable = `${variableData.updateValue.split(",")[indexVariable] || ""}`.trim();
|
|
63
|
+
}
|
|
64
|
+
const variable = store.getState().references.variables[variableId];
|
|
65
|
+
const variableParentId = getAutoCompleteParentVariableId(variableId, variableData.index, variable === null || variable === void 0 ? void 0 : variable.type);
|
|
66
|
+
if (variableParentId) {
|
|
67
|
+
yield getResultAutoComplete(variableParentId, contentVariable, variableData.index, store);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
store.dispatch(updateVariableAction(variableId, contentVariable, variableData.index));
|
|
71
|
+
if (indexVariable === variableData.variablesIds.length - 1) {
|
|
72
|
+
store.dispatch(saveDataAction());
|
|
73
|
+
}
|
|
74
|
+
}));
|
|
75
|
+
});
|
package/dist/helpers/index.d.ts
CHANGED
package/dist/helpers/index.js
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { IGeoJSON } from "@legalplace/data-gouv";
|
|
2
|
+
interface IAddress {
|
|
3
|
+
postcode: string;
|
|
4
|
+
city: string;
|
|
5
|
+
citycode: string;
|
|
6
|
+
from?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function initializeInpiCities(): Promise<void>;
|
|
9
|
+
export declare function computeRelevance(address: IAddress, inputWords: string[]): number;
|
|
10
|
+
export declare function mixDataGouvAndInpiCities(dataGouvResult: IGeoJSON, inputValue: string, limit: number): Promise<Record<string, string | number>[]>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
11
|
+
var t = {};
|
|
12
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
13
|
+
t[p] = s[p];
|
|
14
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
15
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
16
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
17
|
+
t[p[i]] = s[p[i]];
|
|
18
|
+
}
|
|
19
|
+
return t;
|
|
20
|
+
};
|
|
21
|
+
import { getInpiCities } from "../service";
|
|
22
|
+
let cachedInpiCities = null;
|
|
23
|
+
let initializationPromise = null;
|
|
24
|
+
export function initializeInpiCities() {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
if (cachedInpiCities !== null) {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
if (initializationPromise !== null) {
|
|
30
|
+
return initializationPromise;
|
|
31
|
+
}
|
|
32
|
+
initializationPromise = (() => __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
try {
|
|
34
|
+
const [inpiCitiesEndpoint] = getInpiCities();
|
|
35
|
+
const inpiResponse = yield fetch(inpiCitiesEndpoint);
|
|
36
|
+
const inpiCities = yield inpiResponse.json();
|
|
37
|
+
cachedInpiCities = inpiCities.map((city) => ({
|
|
38
|
+
postcode: city.codePostal,
|
|
39
|
+
city: city.nomCommune,
|
|
40
|
+
citycode: city.codeCommune,
|
|
41
|
+
from: "INPI",
|
|
42
|
+
}));
|
|
43
|
+
}
|
|
44
|
+
finally {
|
|
45
|
+
initializationPromise = null;
|
|
46
|
+
}
|
|
47
|
+
}))();
|
|
48
|
+
return initializationPromise;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
export function computeRelevance(address, inputWords) {
|
|
52
|
+
let score = 0;
|
|
53
|
+
inputWords.forEach((word) => {
|
|
54
|
+
var _a, _b, _c;
|
|
55
|
+
if ((_a = address.city) === null || _a === void 0 ? void 0 : _a.toLowerCase().includes(word)) {
|
|
56
|
+
score += 3;
|
|
57
|
+
}
|
|
58
|
+
if ((_b = address.postcode) === null || _b === void 0 ? void 0 : _b.toLowerCase().includes(word)) {
|
|
59
|
+
score += 2;
|
|
60
|
+
}
|
|
61
|
+
if ((_c = address.citycode) === null || _c === void 0 ? void 0 : _c.toLowerCase().includes(word)) {
|
|
62
|
+
score += 1;
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
return score;
|
|
66
|
+
}
|
|
67
|
+
function addressKey(address) {
|
|
68
|
+
return address.postcode;
|
|
69
|
+
}
|
|
70
|
+
export function mixDataGouvAndInpiCities(dataGouvResult, inputValue, limit) {
|
|
71
|
+
var _a;
|
|
72
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
if (!cachedInpiCities) {
|
|
74
|
+
yield initializeInpiCities();
|
|
75
|
+
}
|
|
76
|
+
const inputLower = inputValue.toLowerCase();
|
|
77
|
+
const inputWords = inputLower.split(" ").filter((word) => word.length >= 3);
|
|
78
|
+
const addressesFromDataGouv = ((_a = dataGouvResult === null || dataGouvResult === void 0 ? void 0 : dataGouvResult.features) === null || _a === void 0 ? void 0 : _a.map(({ properties }) => {
|
|
79
|
+
const { postcode, city, citycode } = properties || {};
|
|
80
|
+
return {
|
|
81
|
+
postcode,
|
|
82
|
+
city,
|
|
83
|
+
citycode,
|
|
84
|
+
from: "DataGouv",
|
|
85
|
+
};
|
|
86
|
+
})) || [];
|
|
87
|
+
const addressesFromInpi = (cachedInpiCities || []).filter((city) => inputWords.some((word) => { var _a; return (_a = city.postcode) === null || _a === void 0 ? void 0 : _a.toLowerCase().includes(word); }) ||
|
|
88
|
+
inputWords.some((word) => { var _a; return (_a = city.city) === null || _a === void 0 ? void 0 : _a.toLowerCase().includes(word); }) ||
|
|
89
|
+
inputWords.some((word) => { var _a; return (_a = city.citycode) === null || _a === void 0 ? void 0 : _a.toLowerCase().includes(word); }));
|
|
90
|
+
const combinedAddressesMap = new Map();
|
|
91
|
+
addressesFromDataGouv.forEach((address) => {
|
|
92
|
+
var _a;
|
|
93
|
+
const key = addressKey(address);
|
|
94
|
+
if (!combinedAddressesMap.has(key) ||
|
|
95
|
+
((_a = combinedAddressesMap.get(key)) === null || _a === void 0 ? void 0 : _a.from) !== "DataGouv") {
|
|
96
|
+
combinedAddressesMap.set(key, address);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
addressesFromInpi.forEach((address) => {
|
|
100
|
+
const key = addressKey(address);
|
|
101
|
+
if (!combinedAddressesMap.has(key)) {
|
|
102
|
+
combinedAddressesMap.set(key, address);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
const combinedAddresses = Array.from(combinedAddressesMap.values());
|
|
106
|
+
const sortedAddresses = combinedAddresses
|
|
107
|
+
.map((address) => (Object.assign(Object.assign({}, address), { score: computeRelevance(address, inputWords) })))
|
|
108
|
+
.sort((a, b) => b.score - a.score)
|
|
109
|
+
.slice(0, limit)
|
|
110
|
+
.map((_a) => {
|
|
111
|
+
var { score: _score, from: _from } = _a, rest = __rest(_a, ["score", "from"]);
|
|
112
|
+
return (Object.assign(Object.assign({}, rest), { field: `${rest.city} ${rest.postcode}`, primary: rest.city, secondary: rest.postcode || "" }));
|
|
113
|
+
});
|
|
114
|
+
return sortedAddresses;
|
|
115
|
+
});
|
|
116
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const cleanString: (str?: string | undefined) => string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ACCENTS_MAP } from "../../constants/autocomplete";
|
|
2
|
+
export const cleanString = (str) => {
|
|
3
|
+
if (!str) {
|
|
4
|
+
return "";
|
|
5
|
+
}
|
|
6
|
+
const strToLowerCase = str.toLowerCase();
|
|
7
|
+
return strToLowerCase
|
|
8
|
+
.split("")
|
|
9
|
+
.map((c) => ACCENTS_MAP[c] || c)
|
|
10
|
+
.join("");
|
|
11
|
+
};
|
|
@@ -15,6 +15,7 @@ export declare class PathReader {
|
|
|
15
15
|
getPageUrlName(page: number): string;
|
|
16
16
|
getPageNumber(page: string): number;
|
|
17
17
|
getSectionId(page?: number): number;
|
|
18
|
+
getCurrentLinkPage(): string | undefined;
|
|
18
19
|
getPagination(): {
|
|
19
20
|
pages: (string | number)[][];
|
|
20
21
|
appStates: string[];
|
package/dist/libs/PathReader.js
CHANGED
|
@@ -6,6 +6,7 @@ import { getPluginsPageAppStates } from "../PluginLoader";
|
|
|
6
6
|
import { selectAvailableSections, selectAvailableAppStates, selectInstanceUniqid, selectMetaFetchStatus, } from "../redux/selectors/app";
|
|
7
7
|
import { selectSectionReference } from "../redux/selectors/references";
|
|
8
8
|
import Globals from "../Globals";
|
|
9
|
+
import { getQueryStringValues } from "../helpers";
|
|
9
10
|
export class PathReader {
|
|
10
11
|
constructor(state) {
|
|
11
12
|
this.currentPage = 1;
|
|
@@ -19,11 +20,12 @@ export class PathReader {
|
|
|
19
20
|
}
|
|
20
21
|
}
|
|
21
22
|
matchWithoutUniqId(state) {
|
|
23
|
+
var _a;
|
|
22
24
|
const matchSelector = createMatchSelector(getConfig().router.wizardPath);
|
|
23
25
|
const matchResult = matchSelector(state);
|
|
24
26
|
if (matchResult) {
|
|
25
27
|
const { permalink, page, view, prefix } = matchResult.params;
|
|
26
|
-
const modelVersion =
|
|
28
|
+
const modelVersion = (_a = getQueryStringValues()) === null || _a === void 0 ? void 0 : _a.version;
|
|
27
29
|
this.currentPrefix = prefix || "";
|
|
28
30
|
this.currentPermalink = Globals.permalink || permalink;
|
|
29
31
|
this.currentPage = this.getPageNumber(page);
|
|
@@ -35,11 +37,12 @@ export class PathReader {
|
|
|
35
37
|
}
|
|
36
38
|
}
|
|
37
39
|
matchWithUniqId(state) {
|
|
40
|
+
var _a;
|
|
38
41
|
const matchSelector = createMatchSelector(getConfig().router.wizardInstancePath);
|
|
39
42
|
const matchResult = matchSelector(state);
|
|
40
43
|
if (matchResult) {
|
|
41
44
|
const { permalink, page, uniqid, view, prefix } = matchResult.params;
|
|
42
|
-
const modelVersion =
|
|
45
|
+
const modelVersion = (_a = getQueryStringValues()) === null || _a === void 0 ? void 0 : _a.version;
|
|
43
46
|
this.currentPermalink = Globals.permalink || permalink;
|
|
44
47
|
this.currentPrefix = prefix || "";
|
|
45
48
|
this.currentPage = this.getPageNumber(page);
|
|
@@ -82,6 +85,13 @@ export class PathReader {
|
|
|
82
85
|
availableSectionsIndex = pageIndex - appStates.indexOf("wizard");
|
|
83
86
|
return availableSections[availableSectionsIndex];
|
|
84
87
|
}
|
|
88
|
+
getCurrentLinkPage() {
|
|
89
|
+
const { sectionId } = getQueryStringValues();
|
|
90
|
+
if (!sectionId)
|
|
91
|
+
return undefined;
|
|
92
|
+
const pageNumber = selectAvailableSections().indexOf(Number(sectionId)) + 1;
|
|
93
|
+
return this.parsePath(pageNumber);
|
|
94
|
+
}
|
|
85
95
|
getPagination() {
|
|
86
96
|
const availableAppStates = selectAvailableAppStates();
|
|
87
97
|
let pages = [];
|
|
@@ -134,9 +144,11 @@ export class PathReader {
|
|
|
134
144
|
if (modelVersion !== undefined) {
|
|
135
145
|
path += `?version=${modelVersion}`;
|
|
136
146
|
}
|
|
137
|
-
const queryParams =
|
|
147
|
+
const queryParams = getQueryStringValues();
|
|
138
148
|
if (queryParams.version !== undefined)
|
|
139
149
|
delete queryParams.version;
|
|
150
|
+
if (queryParams.sectionId !== undefined)
|
|
151
|
+
delete queryParams.sectionId;
|
|
140
152
|
const cleanQueryString = queryString.stringify(queryParams);
|
|
141
153
|
if (cleanQueryString.length > 0) {
|
|
142
154
|
path += modelVersion === undefined ? "?" : "&";
|
package/dist/libs/index.d.ts
CHANGED
package/dist/libs/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { call, put, takeLatest } from "redux-saga/effects";
|
|
2
2
|
import { getContractFunnelGAEvent, getUserInfos } from "@legalplace/lp-events";
|
|
3
3
|
import { getConfig } from "../../config";
|
|
4
|
-
import { selectPermalink, selectInstanceUniqid,
|
|
4
|
+
import { selectPermalink, selectInstanceUniqid, selectAvailableAppStates, selectDocumentModelVersion, selectDocumentTitle, } from "../selectors/app";
|
|
5
5
|
import { selectInputs } from "../selectors/inputs";
|
|
6
6
|
import { SET_USER_EMAIL } from "../constants/sagas/user";
|
|
7
7
|
import { setUserStatusAction, initUserAction } from "../actions/user";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AutocompleteDatasetType } from "@legalplace/models-v3-types";
|
|
2
|
+
export declare const fetchAutocompleteDataFromInputValue: ({ dataset, inputValue, attributes, signal, }: {
|
|
3
|
+
dataset: AutocompleteDatasetType;
|
|
4
|
+
inputValue: string;
|
|
5
|
+
attributes?: string[] | undefined;
|
|
6
|
+
signal?: AbortSignal | undefined;
|
|
7
|
+
}) => Promise<Record<string, string | number | null | undefined>[] | null>;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
11
|
+
var t = {};
|
|
12
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
13
|
+
t[p] = s[p];
|
|
14
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
15
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
16
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
17
|
+
t[p[i]] = s[p[i]];
|
|
18
|
+
}
|
|
19
|
+
return t;
|
|
20
|
+
};
|
|
21
|
+
import { DataGouvApi } from "@legalplace/data-gouv";
|
|
22
|
+
import { PappersApi, PappersSearchTargetsEnum } from "@legalplace/pappers";
|
|
23
|
+
import { DatasetTypeEnum } from "../types/autocomplete.type";
|
|
24
|
+
import { initializeActivities, searchInActivities, } from "../helpers/activitiesHelper";
|
|
25
|
+
import { autocompleteDatasetConfig, LegalStatusMapperConfig, } from "../constants/autocomplete";
|
|
26
|
+
import { handleDataGouvCitiesWithInpi } from "../helpers/autocomplete.helper";
|
|
27
|
+
export const fetchAutocompleteDataFromInputValue = ({ dataset, inputValue, attributes = [], signal, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
|
+
var _a, _b;
|
|
29
|
+
try {
|
|
30
|
+
if (dataset === DatasetTypeEnum.DATAGOUV_CITIES_WITH_INPI) {
|
|
31
|
+
return handleDataGouvCitiesWithInpi({
|
|
32
|
+
inputValue,
|
|
33
|
+
dataset,
|
|
34
|
+
signal,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
const errorTimeoutPromise = new Promise((_, reject) => {
|
|
38
|
+
setTimeout(() => {
|
|
39
|
+
reject(new Error("External source timed out"));
|
|
40
|
+
}, autocompleteDatasetConfig[dataset].timeoutLimit);
|
|
41
|
+
});
|
|
42
|
+
const { limit } = autocompleteDatasetConfig[dataset];
|
|
43
|
+
switch (dataset) {
|
|
44
|
+
case DatasetTypeEnum.DATAGOUV_ADDRESSES:
|
|
45
|
+
case DatasetTypeEnum.DATAGOUV_ADDRESSES_V2:
|
|
46
|
+
case DatasetTypeEnum.DATAGOUV_CITIES: {
|
|
47
|
+
const api = new DataGouvApi();
|
|
48
|
+
const searchType = dataset === DatasetTypeEnum.DATAGOUV_ADDRESSES ||
|
|
49
|
+
dataset === DatasetTypeEnum.DATAGOUV_ADDRESSES_V2
|
|
50
|
+
? "housenumber"
|
|
51
|
+
: "municipality";
|
|
52
|
+
const searchPromise = api.searchAddress({
|
|
53
|
+
query: inputValue,
|
|
54
|
+
limit,
|
|
55
|
+
type: searchType,
|
|
56
|
+
autocomplete: true,
|
|
57
|
+
signal,
|
|
58
|
+
});
|
|
59
|
+
const result = yield Promise.race([searchPromise, errorTimeoutPromise]);
|
|
60
|
+
return (((_b = (_a = result) === null || _a === void 0 ? void 0 : _a.features) === null || _b === void 0 ? void 0 : _b.map((feature) => {
|
|
61
|
+
const properties = feature.properties || {};
|
|
62
|
+
const { postcode, city, citycode, street, housenumber } = properties || {};
|
|
63
|
+
if (dataset === DatasetTypeEnum.DATAGOUV_ADDRESSES_V2) {
|
|
64
|
+
return {
|
|
65
|
+
field: `${housenumber ? `${housenumber} ` : ""}${street} ${postcode} ${city}`,
|
|
66
|
+
primary: `${housenumber ? `${housenumber} ` : ""}${street}`,
|
|
67
|
+
secondary: `${postcode} ${city}`,
|
|
68
|
+
numberAndStreet: `${housenumber ? `${housenumber} ` : ""}${street}`,
|
|
69
|
+
postcode,
|
|
70
|
+
city,
|
|
71
|
+
communal_code: citycode,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
if (dataset === DatasetTypeEnum.DATAGOUV_CITIES) {
|
|
75
|
+
return {
|
|
76
|
+
field: `${city}`,
|
|
77
|
+
primary: city,
|
|
78
|
+
secondary: postcode || "",
|
|
79
|
+
postcode,
|
|
80
|
+
communal_code: citycode,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
primary: `${housenumber ? `${housenumber} ` : ""}${street}`,
|
|
85
|
+
secondary: `${postcode || ""} ${city}`,
|
|
86
|
+
postcode,
|
|
87
|
+
city,
|
|
88
|
+
communal_code: citycode,
|
|
89
|
+
};
|
|
90
|
+
})) || []);
|
|
91
|
+
}
|
|
92
|
+
case DatasetTypeEnum.PAPPERS: {
|
|
93
|
+
const api = new PappersApi();
|
|
94
|
+
const searchPromise = api.searchCompany({
|
|
95
|
+
query: inputValue,
|
|
96
|
+
signal,
|
|
97
|
+
targets: [
|
|
98
|
+
PappersSearchTargetsEnum.SIREN,
|
|
99
|
+
PappersSearchTargetsEnum.COMPANY_NAME,
|
|
100
|
+
],
|
|
101
|
+
});
|
|
102
|
+
const result = yield Promise.race([searchPromise, errorTimeoutPromise]);
|
|
103
|
+
const { resultats_nom_entreprise: companyNameResults = [], resultats_siren: sirenResults = [], } = result;
|
|
104
|
+
const companyList = [...companyNameResults, ...sirenResults];
|
|
105
|
+
const uniqueSirenList = [];
|
|
106
|
+
const uniqueCompanyList = companyList.filter(({ siren }) => {
|
|
107
|
+
if (uniqueSirenList.includes(siren)) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
uniqueSirenList.push(siren);
|
|
111
|
+
return true;
|
|
112
|
+
});
|
|
113
|
+
const autocompleteResults = uniqueCompanyList.map((_a) => {
|
|
114
|
+
var _b;
|
|
115
|
+
var { siren, nom_entreprise: nomEntreprise, denomination, domaine_activite: domaineActivite, capital, date_creation_formate: dateCreationFormate, entreprise_cessee: entrepriseCessee, categorie_juridique: categorieJuridique, forme_juridique: formeJuridique, libelle_code_naf: libelleCodeNaf, siege: { adresse_ligne_1: adresseLigne1, code_postal: codePostal, ville, pays, } } = _a, rest = __rest(_a, ["siren", "nom_entreprise", "denomination", "domaine_activite", "capital", "date_creation_formate", "entreprise_cessee", "categorie_juridique", "forme_juridique", "libelle_code_naf", "siege"]);
|
|
116
|
+
const additionnalAttributes = {};
|
|
117
|
+
attributes.forEach((attr) => {
|
|
118
|
+
additionnalAttributes[attr] = rest[attr];
|
|
119
|
+
});
|
|
120
|
+
return Object.assign(Object.assign({}, additionnalAttributes), { primary: nomEntreprise, secondary: `${siren} · ${(_b = ville === null || ville === void 0 ? void 0 : ville[0]) === null || _b === void 0 ? void 0 : _b.toUpperCase()}${ville === null || ville === void 0 ? void 0 : ville.slice(1).toLowerCase()}`, company_activity: domaineActivite, company_capital: capital, company_ceased_business: entrepriseCessee, company_creation_date: dateCreationFormate, company_denomination: denomination, company_hq_address: adresseLigne1, company_hq_city: ville, company_hq_country: pays, company_hq_postcode: codePostal, company_legal_status: LegalStatusMapperConfig[Number(categorieJuridique)] ||
|
|
121
|
+
formeJuridique, company_naf_code: libelleCodeNaf, company_siren: siren });
|
|
122
|
+
});
|
|
123
|
+
return autocompleteResults;
|
|
124
|
+
}
|
|
125
|
+
case DatasetTypeEnum.ACTIVITIES: {
|
|
126
|
+
const searchPromise = (() => __awaiter(void 0, void 0, void 0, function* () {
|
|
127
|
+
yield initializeActivities(signal);
|
|
128
|
+
const results = yield searchInActivities(inputValue, limit);
|
|
129
|
+
return results;
|
|
130
|
+
}))();
|
|
131
|
+
const result = yield Promise.race([searchPromise, errorTimeoutPromise]);
|
|
132
|
+
return result;
|
|
133
|
+
}
|
|
134
|
+
default:
|
|
135
|
+
return [];
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
});
|
package/dist/service/index.d.ts
CHANGED
package/dist/service/index.js
CHANGED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export declare enum DatasetTypeEnum {
|
|
2
|
+
DATAGOUV_ADDRESSES = "datagouv_addresses",
|
|
3
|
+
DATAGOUV_ADDRESSES_V2 = "datagouv_addresses_v2",
|
|
4
|
+
DATAGOUV_CITIES = "datagouv_cities",
|
|
5
|
+
DATAGOUV_CITIES_WITH_INPI = "datagouv_cities_with_inpi",
|
|
6
|
+
PAPPERS = "pappers",
|
|
7
|
+
ACTIVITIES = "activities",
|
|
8
|
+
KANOON_COLLECTIVE_AGREEMENTS = "kanoon_collective_agreements"
|
|
9
|
+
}
|
|
10
|
+
export interface IAutocompleteDatasetConfig {
|
|
11
|
+
limit: number;
|
|
12
|
+
minInputLenght: number;
|
|
13
|
+
noResultPlaceholder: (value?: string) => string;
|
|
14
|
+
debounceDelay: number;
|
|
15
|
+
loadingPlaceholder: string;
|
|
16
|
+
otherPlaceholder: (value?: string) => string;
|
|
17
|
+
timeoutLimit: number;
|
|
18
|
+
shouldDisableLinkedVariables?: boolean;
|
|
19
|
+
linkedVariablesDisabledTooltip?: string;
|
|
20
|
+
cannotChooseOther?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export interface IActivities {
|
|
23
|
+
category: string;
|
|
24
|
+
label: string;
|
|
25
|
+
level1Id: string | number | null;
|
|
26
|
+
level2Id: string | number | null;
|
|
27
|
+
level3Id: string | number | null;
|
|
28
|
+
level4Id: string | number | null;
|
|
29
|
+
nafCode: string | number;
|
|
30
|
+
shouldAskIfCommercialPremises: string;
|
|
31
|
+
shouldAskIfAlcohol: string;
|
|
32
|
+
type: string;
|
|
33
|
+
comptaplaceEligibility: string;
|
|
34
|
+
comptaplaceCategory: string;
|
|
35
|
+
regulatedActivityProofNeeded: string;
|
|
36
|
+
description: string;
|
|
37
|
+
descriptionIfSellsAlcohol: string;
|
|
38
|
+
warningText: string;
|
|
39
|
+
keywords: string[];
|
|
40
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export var DatasetTypeEnum;
|
|
2
|
+
(function (DatasetTypeEnum) {
|
|
3
|
+
DatasetTypeEnum["DATAGOUV_ADDRESSES"] = "datagouv_addresses";
|
|
4
|
+
DatasetTypeEnum["DATAGOUV_ADDRESSES_V2"] = "datagouv_addresses_v2";
|
|
5
|
+
DatasetTypeEnum["DATAGOUV_CITIES"] = "datagouv_cities";
|
|
6
|
+
DatasetTypeEnum["DATAGOUV_CITIES_WITH_INPI"] = "datagouv_cities_with_inpi";
|
|
7
|
+
DatasetTypeEnum["PAPPERS"] = "pappers";
|
|
8
|
+
DatasetTypeEnum["ACTIVITIES"] = "activities";
|
|
9
|
+
DatasetTypeEnum["KANOON_COLLECTIVE_AGREEMENTS"] = "kanoon_collective_agreements";
|
|
10
|
+
})(DatasetTypeEnum || (DatasetTypeEnum = {}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@legalplace/wizardx-core",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.35.0",
|
|
4
4
|
"author": "Moncef Hammou (moncef@legalplace.fr)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -21,16 +21,20 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@appnest/masonry-layout": "^2.0.8",
|
|
23
23
|
"@cryptography/sha1": "^0.2.0",
|
|
24
|
+
"@legalplace/data-gouv": "^1.6.31",
|
|
24
25
|
"@legalplace/lp-events": "1.14.0",
|
|
25
26
|
"@legalplace/lplogic": "2.3.1",
|
|
26
27
|
"@legalplace/model-healthcheck": "^1.1.5",
|
|
27
|
-
"@legalplace/
|
|
28
|
+
"@legalplace/pappers": "^1.2.3",
|
|
29
|
+
"@legalplace/referencesparser": "^3.1.39",
|
|
28
30
|
"@legalplace/storybook": "2.355.0",
|
|
29
|
-
"@legalplace/typeorm-constants": "^3.
|
|
31
|
+
"@legalplace/typeorm-constants": "^3.60.0",
|
|
30
32
|
"@loadable/component": "^5.15.0",
|
|
31
33
|
"@redux-saga/core": "^1.1.3",
|
|
34
|
+
"axios": "^0.24.0",
|
|
32
35
|
"connected-react-router": "^6.8.0",
|
|
33
36
|
"crypto-js": "^4.1.1",
|
|
37
|
+
"fuse.js": "^7.0.0",
|
|
34
38
|
"history": "4.10.1",
|
|
35
39
|
"libphonenumber-js": "^1.10.19",
|
|
36
40
|
"lodash": "^4.17.21",
|
|
@@ -56,9 +60,9 @@
|
|
|
56
60
|
"devDependencies": {
|
|
57
61
|
"@legalplace/data-gouv": "^1.6.30",
|
|
58
62
|
"@legalplace/eslint-config": "^2.3.0",
|
|
59
|
-
"@legalplace/models-v3-types": "^5.13.
|
|
63
|
+
"@legalplace/models-v3-types": "^5.13.24",
|
|
60
64
|
"@legalplace/prettier-config": "^2.1.3",
|
|
61
|
-
"@legalplace/typeorm-entities": "^5.
|
|
65
|
+
"@legalplace/typeorm-entities": "^5.57.0",
|
|
62
66
|
"@swc-node/jest": "^1.3.2",
|
|
63
67
|
"@swc/core": "^1.2.93",
|
|
64
68
|
"@swc/jest": "^0.2.4",
|
|
@@ -96,5 +100,5 @@
|
|
|
96
100
|
"*.test.ts",
|
|
97
101
|
"*.test.tsx"
|
|
98
102
|
],
|
|
99
|
-
"gitHead": "
|
|
103
|
+
"gitHead": "89de8140aa28c769e781257746ca50377e05f5dd"
|
|
100
104
|
}
|