project-booster-vue 8.124.0 → 8.125.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/package.json
CHANGED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
2
|
+
import { ref } from 'vue';
|
|
3
|
+
import { useStore } from 'vuex';
|
|
4
|
+
import axios from 'axios';
|
|
5
|
+
import { nestedAppDecorator } from '../../../.storybook/nested-app-decorator';
|
|
6
|
+
import { Anchor, Story, Preview, Meta, Props, ArgsTable, Source, Canvas } from '@storybook/addon-docs';
|
|
7
|
+
import store from '../../stores/store';
|
|
8
|
+
import PbScenario from './PbScenario';
|
|
9
|
+
|
|
10
|
+
<Meta
|
|
11
|
+
title="Project Booster/Scenario/PbScenario 🦠/ 🇷🇺 Russian playground"
|
|
12
|
+
argTypes={{
|
|
13
|
+
apiKey: {
|
|
14
|
+
name: 'Budget estimate API key',
|
|
15
|
+
defaultValue: 'xxx',
|
|
16
|
+
description: 'The API key to use for the budget estimate API.',
|
|
17
|
+
control: {
|
|
18
|
+
type: 'text',
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
apiBasePath: {
|
|
22
|
+
name: 'Budget estimate API base path',
|
|
23
|
+
defaultValue: 'https://api-prep.adeo.cloud/api-project-booster-internal-summary/v1/',
|
|
24
|
+
description: 'The base path to use for the budget estimate API.',
|
|
25
|
+
control: {
|
|
26
|
+
type: 'text',
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
subprojectFormUrl: {
|
|
30
|
+
name: 'The JSON scenario href',
|
|
31
|
+
defaultValue: 'https://storage.googleapis.com/pb-dev-adeo-disp-subproject-forms/demo-russia/LMRU_KITCHEN.json',
|
|
32
|
+
description: 'The JSON scenraio Url.',
|
|
33
|
+
control: {
|
|
34
|
+
type: 'text',
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
}}
|
|
38
|
+
decorators={[nestedAppDecorator(store, [{ path: '/steps/:stepCode/previous/:answers', component: PbScenario }])]}
|
|
39
|
+
parameters={{
|
|
40
|
+
layout: 'fullscreen',
|
|
41
|
+
}}
|
|
42
|
+
/>
|
|
43
|
+
|
|
44
|
+
export const answerGettersMappers = {
|
|
45
|
+
PbQuestion: ({ code }) => code,
|
|
46
|
+
PbRestitution: ({ code }) => code,
|
|
47
|
+
PbConclusion: ({ code }) => code,
|
|
48
|
+
PbSpaceInput: ({ space }) => parseFloat(space),
|
|
49
|
+
PbCitySearch: ({ city }) => city.inseeCode,
|
|
50
|
+
PbNameInput: ({ projectName }) => projectName,
|
|
51
|
+
PbDimensionsInput: ({ width, length }) => {
|
|
52
|
+
return { width: parseFloat(width), length: parseFloat(length) };
|
|
53
|
+
},
|
|
54
|
+
PbListSelect: ({ value }) => value,
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export const adaptAnswers = (answers, form) => {
|
|
58
|
+
let adaptedAnswers = [];
|
|
59
|
+
if (answers) {
|
|
60
|
+
adaptedAnswers = Object.entries(answers)
|
|
61
|
+
.filter(([code]) => !['PbRestitution'].includes(form[code]?.component))
|
|
62
|
+
.filter(([code]) => code !== 'SUBPROJECT_FORM_ID')
|
|
63
|
+
.map(([questionId, answerData]) => ({
|
|
64
|
+
questionId,
|
|
65
|
+
answers: answerData.map(answerGettersMappers[form[questionId].component]),
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
68
|
+
return adaptedAnswers;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export const TemplateSandbox = (args, { argTypes }) => {
|
|
72
|
+
return {
|
|
73
|
+
props: Object.keys(argTypes),
|
|
74
|
+
components: { PbScenario },
|
|
75
|
+
setup() {
|
|
76
|
+
const BASE_URL = args.apiBasePath;
|
|
77
|
+
axios.defaults.baseURL = BASE_URL;
|
|
78
|
+
axios.interceptors.request.use(
|
|
79
|
+
function (config) {
|
|
80
|
+
if (!config.url.includes('://') && config.url.indexOf('//') === -1) {
|
|
81
|
+
config.headers['X-ClientApiKey'] = args.apiKey;
|
|
82
|
+
config.url = config.url.replace('/api/', '/');
|
|
83
|
+
}
|
|
84
|
+
return config;
|
|
85
|
+
},
|
|
86
|
+
function (error) {
|
|
87
|
+
return Promise.reject(error);
|
|
88
|
+
},
|
|
89
|
+
);
|
|
90
|
+
const subprojectFormId = ref(args.subprojectFormId);
|
|
91
|
+
const store = useStore();
|
|
92
|
+
const showApp = ref(false);
|
|
93
|
+
const subprojectFormStructure = ref(null);
|
|
94
|
+
const runtimeOptions = ref({});
|
|
95
|
+
const handleEvent = ({ code, payload, context }) => {
|
|
96
|
+
if (['STEP-COMPLETED', 'PARTIAL-SELECT-UPDATE'].includes(code)) {
|
|
97
|
+
if (!!store.getters['estimates/getSessions'].estimatorId) {
|
|
98
|
+
const adaptedAnswers = adaptAnswers(context.answers, subprojectFormStructure.value);
|
|
99
|
+
store.dispatch('estimates/estimate', {
|
|
100
|
+
adaptedAnswers,
|
|
101
|
+
estimatorId: store.getters['estimates/getSessions'].estimatorId,
|
|
102
|
+
correlationId: store.getters['estimates/getSessions'].correlationId,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
const getSubprojectFormStructureFromJson = async () => {
|
|
108
|
+
try {
|
|
109
|
+
const result = await axios.get(args.subprojectFormUrl);
|
|
110
|
+
showApp.value = true;
|
|
111
|
+
return result.data;
|
|
112
|
+
} catch {
|
|
113
|
+
showApp.value = false;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
getSubprojectFormStructureFromJson().then((data) => {
|
|
117
|
+
subprojectFormStructure.value = data;
|
|
118
|
+
store.dispatch('estimates/initSessions', {
|
|
119
|
+
formId: subprojectFormId.value,
|
|
120
|
+
correlationId: uuidv4(),
|
|
121
|
+
estimatorId: subprojectFormStructure.value['__START__'].meta.estimatorId,
|
|
122
|
+
businessUnit: subprojectFormStructure.value['__START__'].meta.businessUnit,
|
|
123
|
+
subprojectFormStructure: subprojectFormStructure.value,
|
|
124
|
+
source: 'fake_source',
|
|
125
|
+
sourceDetail: 'fake_source_detail',
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
return {
|
|
129
|
+
args,
|
|
130
|
+
showApp,
|
|
131
|
+
subprojectFormStructure,
|
|
132
|
+
runtimeOptions,
|
|
133
|
+
handleEvent,
|
|
134
|
+
};
|
|
135
|
+
},
|
|
136
|
+
template: `<div>
|
|
137
|
+
<div v-if="showApp && subprojectFormStructure">
|
|
138
|
+
<pb-scenario
|
|
139
|
+
:scenarios="subprojectFormStructure"
|
|
140
|
+
:runtime-options="runtimeOptions"
|
|
141
|
+
min-height="100vh"
|
|
142
|
+
@scenario-event="handleEvent"
|
|
143
|
+
/>
|
|
144
|
+
</div>
|
|
145
|
+
<div v-if="!showApp">
|
|
146
|
+
L'application rencontre quelques difficultés, veuillez renouveler votre action ultérieurement
|
|
147
|
+
</div>
|
|
148
|
+
</div>`,
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
<Canvas>
|
|
153
|
+
<Story name="Kitchen" inline={false} height="758px" parameters={{ storyshots: { disable: true } }}>
|
|
154
|
+
{TemplateSandbox.bind({})}
|
|
155
|
+
</Story>
|
|
156
|
+
</Canvas>
|