Skip to content

Commit

Permalink
Merge branch 'feat/solutionversions' of https://github.com/weni-ai/co…
Browse files Browse the repository at this point in the history
…mmerce-webapp into staging
  • Loading branch information
acnormun committed Oct 14, 2024
2 parents 29df281 + ccc7dc5 commit 96cdaa1
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 52 deletions.
31 changes: 30 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
# Changelog
<!-- documentation: https://keepachangelog.com/en/1.1.0/ -->

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.1.1] - 2024-10-11

Release of the internally named version 1.0, integrating with the real API.


### Added

- Solutions modal images.


## [1.1.0] - 2024-10-10

Release of the internally named version 1.0, integrating with the real API.


### Added

- [Sentry](https://sentry.io/) integration.
- Unit tests for: `utils/index.ts`, `TreatUnhandledRejection.ts` and `HomeView.vue`

### Fixed

- Error when trying to integrate or edit a solution integration when the globals were empty.

## [1.0.0] - 2024-10-04

Expand All @@ -14,3 +42,4 @@ Release of the internally named version 1.0, integrating with the real API.
- [APIPhantom](https://github.com/weni-ai/APIPhantom) support.

[1.0.0]: https://github.com/weni-ai/commerce-webapp/compare/0.1.3...1.0.0
[1.1.0]: https://github.com/weni-ai/commerce-webapp/compare/1.0.0...1.1.0
6 changes: 6 additions & 0 deletions env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@ declare global {
declare const __APP_VERSION__: string;

type Solution = {
version: string;
uuid: string;
title: string;
description: string;
documentation: string;
tip: string;
globals: { [key: string]: { value: string } };
sectors: { [key: string]: { value: string[] } };
versions: {
version: string;
globals: { [key: string]: { value: string } };
sectors: { [key: string]: { value: string[] } };
}[];
};
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "commerce-webapp",
"version": "1.0.0",
"version": "1.1.1",
"author": "Weni <[email protected]>",
"private": true,
"type": "module",
Expand Down
30 changes: 29 additions & 1 deletion src/api/solutions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,31 @@ export default {
}: {
data: {
results: {
version?: string;
feature_uuid: string;
description: string;
disclaimer: string;
documentation_url: string;
globals?: string[];
initial_flow: {
initial_flow?: {
name: string;
uuid: string;
}[];
name: string;
sectors: string[];
versions?: {
version: string;
globals: string[];
sectors: string[];
}[];
}[];
};
} = await request.$http.get(
`/v2/feature/${authStore.projectUuid}/?category=${category}`,
);

return data.results.map((solution) => ({
version: solution.version || '',
uuid: solution.feature_uuid,
title: solution.name,
description: solution.description,
Expand All @@ -49,6 +56,27 @@ export default {
}),
{},
),
versions:
solution.versions &&
solution.versions.map((version) => ({
version: version.version,
globals: (version.globals || []).reduce(
(previous, current) => ({
...previous,
[current]: { value: '' },
}),
{},
),
sectors: version.sectors.reduce(
(previous, sectorName) => ({
...previous,
[sectorName]: {
value: [],
},
}),
{},
),
})),
}));
},

Expand Down
120 changes: 72 additions & 48 deletions src/components/solutions/DrawerSolution.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,33 +30,33 @@
</section>

<section class="form-elements">
<template v-if="solution?.globals">
<template v-if="currentVersion.globals">
<UnnnicFormElement
v-for="(field, index) in Object.keys(solution.globals)"
v-for="(field, index) in Object.keys(currentVersion.globals)"
:key="index"
:label="fieldLabel(field)"
>
<UnnnicInput
v-if="fieldType(field) === 'text'"
size="sm"
:data-test="field"
:modelValue="currentValueField(field).value"
:modelValue="currentValueField(field)?.value"
@update:model-value="
($event: string) => updateField(field, $event)
"
/>
</UnnnicFormElement>
</template>

<template v-if="solution?.sectors">
<template v-if="currentVersion.sectors">
<UnnnicFormElement
v-for="(sector, index) in Object.keys(solution.sectors)"
v-for="(sector, index) in Object.keys(currentVersion.sectors)"
:key="index"
:label="`Tags do ${sector}`"
>
<InputTags
:data-test="sector"
:modelValue="currentValueField(`tags:sector-${sector}`).value"
:modelValue="currentValueField(`tags:sector-${sector}`)?.value"
@update:model-value="updateField(`tags:sector-${sector}`, $event)"
/>
</UnnnicFormElement>
Expand Down Expand Up @@ -100,6 +100,8 @@ const props = defineProps<{
solution?: Solution;
}>();
const currentVersion = ref<any>({});
const { t } = useI18n();
const router = useRouter();
Expand All @@ -121,43 +123,51 @@ function close() {
}
async function save() {
const sectors = Object.keys(props.solution.sectors)
.map((sectorName) => ({
key: sectorName,
props: {
value: currentValueField(`tags:sector-${sectorName}`)?.value,
},
}))
.reduce((previous, { key, props }) => ({ ...previous, [key]: props }), {});
const globals = Object.keys(props.solution.globals)
.map((globalName) => ({
key: globalName,
props: {
value: currentValueField(globalName)?.value,
},
}))
.reduce((previous, { key, props }) => ({ ...previous, [key]: props }), {});
try {
isSaving.value = true;
await solutionsStore.integrateOrUpdate({
uuid: props.solution.uuid,
sectors,
globals,
});
close();
alertStore.add({
type: 'success',
text: t('solutions.integrate.status.created'),
});
router.push({ name: 'integrated-solutions' });
} finally {
isSaving.value = false;
if (props.solution) {
const sectors = Object.keys(props.solution.sectors)
.map((sectorName) => ({
key: sectorName,
props: {
value: currentValueField(`tags:sector-${sectorName}`)?.value,
},
}))
.reduce(
(previous, { key, props }) => ({ ...previous, [key]: props }),
{},
);
const globals = Object.keys(props.solution.globals)
.map((globalName) => ({
key: globalName,
props: {
value: currentValueField(globalName)?.value,
},
}))
.reduce(
(previous, { key, props }) => ({ ...previous, [key]: props }),
{},
);
try {
isSaving.value = true;
await solutionsStore.integrateOrUpdate({
uuid: props.solution.uuid,
sectors,
globals,
});
close();
alertStore.add({
type: 'success',
text: t('solutions.integrate.status.created'),
});
router.push({ name: 'integrated-solutions' });
} finally {
isSaving.value = false;
}
}
}
Expand All @@ -166,16 +176,16 @@ const types = ['tags'];
watch(
isOpen,
(isOpen) => {
if (isOpen && props.solution) {
Object.keys(props.solution.sectors).forEach((sectorName) => {
if (isOpen && currentVersion) {
Object.keys(currentVersion.value.sectors).forEach((sectorName) => {

Check failure on line 180 in src/components/solutions/DrawerSolution.vue

View workflow job for this annotation

GitHub Actions / Run tests and collect coverage

src/components/solutions/__tests__/DrawerSolution.spec.ts > DrawerSolution > when the solution is undefined and the drawer is open > emits close event

TypeError: Cannot convert undefined or null to object ❯ watch.immediate src/components/solutions/DrawerSolution.vue:180:14 ❯ callWithErrorHandling node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:200:19 ❯ callWithAsyncErrorHandling node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:207:17 ❯ baseWatchOptions.call node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:6062:47 ❯ job node_modules/@vue/reactivity/dist/reactivity.cjs.js:1829:18 ❯ Object.watch node_modules/@vue/reactivity/dist/reactivity.cjs.js:1865:7 ❯ doWatch node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:6090:34 ❯ Module.watch node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:6022:10 ❯ setup src/components/solutions/DrawerSolution.vue:176:1

Check failure on line 180 in src/components/solutions/DrawerSolution.vue

View workflow job for this annotation

GitHub Actions / Run tests and collect coverage

src/components/solutions/__tests__/DrawerSolution.spec.ts > DrawerSolution > when the solution does not have documentation > does not show the help box

TypeError: Cannot convert undefined or null to object ❯ watch.immediate src/components/solutions/DrawerSolution.vue:180:14 ❯ callWithErrorHandling node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:200:19 ❯ callWithAsyncErrorHandling node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:207:17 ❯ baseWatchOptions.call node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:6062:47 ❯ job node_modules/@vue/reactivity/dist/reactivity.cjs.js:1829:18 ❯ Object.watch node_modules/@vue/reactivity/dist/reactivity.cjs.js:1865:7 ❯ doWatch node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:6090:34 ❯ Module.watch node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:6022:10 ❯ setup src/components/solutions/DrawerSolution.vue:176:1

Check failure on line 180 in src/components/solutions/DrawerSolution.vue

View workflow job for this annotation

GitHub Actions / Run tests and collect coverage

src/components/solutions/__tests__/DrawerSolution.spec.ts > DrawerSolution > when the solution has documentation > shows the help box

TypeError: Cannot convert undefined or null to object ❯ watch.immediate src/components/solutions/DrawerSolution.vue:180:14 ❯ callWithErrorHandling node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:200:19 ❯ callWithAsyncErrorHandling node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:207:17 ❯ baseWatchOptions.call node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:6062:47 ❯ job node_modules/@vue/reactivity/dist/reactivity.cjs.js:1829:18 ❯ Object.watch node_modules/@vue/reactivity/dist/reactivity.cjs.js:1865:7 ❯ doWatch node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:6090:34 ❯ Module.watch node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:6022:10 ❯ setup src/components/solutions/DrawerSolution.vue:176:1

Check failure on line 180 in src/components/solutions/DrawerSolution.vue

View workflow job for this annotation

GitHub Actions / Run tests and collect coverage

src/components/solutions/__tests__/DrawerSolution.spec.ts > DrawerSolution > when the solution has documentation > when the user changes one global and one sector > when the drawer closes > emits close event

TypeError: Cannot convert undefined or null to object ❯ watch.immediate src/components/solutions/DrawerSolution.vue:180:14 ❯ callWithErrorHandling node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:200:19 ❯ callWithAsyncErrorHandling node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:207:17 ❯ baseWatchOptions.call node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:6062:47 ❯ job node_modules/@vue/reactivity/dist/reactivity.cjs.js:1829:18 ❯ Object.watch node_modules/@vue/reactivity/dist/reactivity.cjs.js:1865:7 ❯ doWatch node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:6090:34 ❯ Module.watch node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:6022:10 ❯ setup src/components/solutions/DrawerSolution.vue:176:1

Check failure on line 180 in src/components/solutions/DrawerSolution.vue

View workflow job for this annotation

GitHub Actions / Run tests and collect coverage

src/components/solutions/__tests__/DrawerSolution.spec.ts > DrawerSolution > when the solution has documentation > when the user changes one global and one sector > when the user clicks on cancel button > emits close event

TypeError: Cannot convert undefined or null to object ❯ watch.immediate src/components/solutions/DrawerSolution.vue:180:14 ❯ callWithErrorHandling node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:200:19 ❯ callWithAsyncErrorHandling node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:207:17 ❯ baseWatchOptions.call node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:6062:47 ❯ job node_modules/@vue/reactivity/dist/reactivity.cjs.js:1829:18 ❯ Object.watch node_modules/@vue/reactivity/dist/reactivity.cjs.js:1865:7 ❯ doWatch node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:6090:34 ❯ Module.watch node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:6022:10 ❯ setup src/components/solutions/DrawerSolution.vue:176:1

Check failure on line 180 in src/components/solutions/DrawerSolution.vue

View workflow job for this annotation

GitHub Actions / Run tests and collect coverage

src/components/solutions/__tests__/DrawerSolution.spec.ts > DrawerSolution > when the solution has documentation > when the user changes one global and one sector > when the user clicks on save button > calls integrateOrUpdate function from solutions store

TypeError: Cannot convert undefined or null to object ❯ watch.immediate src/components/solutions/DrawerSolution.vue:180:14 ❯ callWithErrorHandling node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:200:19 ❯ callWithAsyncErrorHandling node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:207:17 ❯ baseWatchOptions.call node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:6062:47 ❯ job node_modules/@vue/reactivity/dist/reactivity.cjs.js:1829:18 ❯ Object.watch node_modules/@vue/reactivity/dist/reactivity.cjs.js:1865:7 ❯ doWatch node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:6090:34 ❯ Module.watch node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:6022:10 ❯ setup src/components/solutions/DrawerSolution.vue:176:1

Check failure on line 180 in src/components/solutions/DrawerSolution.vue

View workflow job for this annotation

GitHub Actions / Run tests and collect coverage

src/components/solutions/__tests__/DrawerSolution.spec.ts > DrawerSolution > when the solution has documentation > when the user changes one global and one sector > when the user clicks on save button > emits close event

TypeError: Cannot convert undefined or null to object ❯ watch.immediate src/components/solutions/DrawerSolution.vue:180:14 ❯ callWithErrorHandling node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:200:19 ❯ callWithAsyncErrorHandling node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:207:17 ❯ baseWatchOptions.call node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:6062:47 ❯ job node_modules/@vue/reactivity/dist/reactivity.cjs.js:1829:18 ❯ Object.watch node_modules/@vue/reactivity/dist/reactivity.cjs.js:1865:7 ❯ doWatch node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:6090:34 ❯ Module.watch node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:6022:10 ❯ setup src/components/solutions/DrawerSolution.vue:176:1

Check failure on line 180 in src/components/solutions/DrawerSolution.vue

View workflow job for this annotation

GitHub Actions / Run tests and collect coverage

src/components/solutions/__tests__/DrawerSolution.spec.ts > DrawerSolution > when the solution has documentation > when the user changes one global and one sector > when the user clicks on save button > alerts that solution has been integrated

TypeError: Cannot convert undefined or null to object ❯ watch.immediate src/components/solutions/DrawerSolution.vue:180:14 ❯ callWithErrorHandling node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:200:19 ❯ callWithAsyncErrorHandling node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:207:17 ❯ baseWatchOptions.call node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:6062:47 ❯ job node_modules/@vue/reactivity/dist/reactivity.cjs.js:1829:18 ❯ Object.watch node_modules/@vue/reactivity/dist/reactivity.cjs.js:1865:7 ❯ doWatch node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:6090:34 ❯ Module.watch node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:6022:10 ❯ setup src/components/solutions/DrawerSolution.vue:176:1

Check failure on line 180 in src/components/solutions/DrawerSolution.vue

View workflow job for this annotation

GitHub Actions / Run tests and collect coverage

src/components/solutions/__tests__/DrawerSolution.spec.ts > DrawerSolution > when the solution has documentation > when the user changes one global and one sector > when the user clicks on save button > redirects to integrated-solutions page

TypeError: Cannot convert undefined or null to object ❯ watch.immediate src/components/solutions/DrawerSolution.vue:180:14 ❯ callWithErrorHandling node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:200:19 ❯ callWithAsyncErrorHandling node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:207:17 ❯ baseWatchOptions.call node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:6062:47 ❯ job node_modules/@vue/reactivity/dist/reactivity.cjs.js:1829:18 ❯ Object.watch node_modules/@vue/reactivity/dist/reactivity.cjs.js:1865:7 ❯ doWatch node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:6090:34 ❯ Module.watch node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:6022:10 ❯ setup src/components/solutions/DrawerSolution.vue:176:1
updateField(
`tags:sector-${sectorName}`,
clone(props.solution.sectors[sectorName].value),
clone(currentVersion.value.sectors[sectorName].value),
);
});
Object.keys(props.solution.globals).forEach((globalName) => {
updateField(globalName, props.solution.globals[globalName].value);
Object.keys(currentVersion.value.globals).forEach((globalName) => {
updateField(globalName, currentVersion.value.globals[globalName].value);
});
} else if (isOpen) {
nextTick(close);
Expand All @@ -184,6 +194,20 @@ watch(
{ immediate: true },
);
watch(
() => props.solution,
(newSolution) => {
if (newSolution) {
console.log('new solution', newSolution);
currentVersion.value =
newSolution.versions.find(
(item) => item.version === newSolution.version,
) || {};
}
},
{ immediate: true },
);
function currentValueField(field: string) {
const type = fieldType(field);
const label = fieldLabel(field);
Expand Down
7 changes: 6 additions & 1 deletion src/components/solutions/SolutionsGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ const solutionToIntegrate = reactive<{
title: string;
description: string;
tip: string;
versions?: {
version?: string;
globals?: string[];
sectors?: string[];
}[];
};
}>({
isOpen: false,
Expand Down Expand Up @@ -126,7 +131,7 @@ function openIntegrateSolutionModal(solution: Solution) {
function openDrawer(solution, values = {}) {
drawerSolution.isOpen = true;
drawerSolution.solution = solution;
drawerSolution.solution.values = values;
// drawerSolution.solution.values = values;
}
</script>

Expand Down

0 comments on commit 96cdaa1

Please sign in to comment.