Skip to content

Commit 083b1f8

Browse files
author
Herve Tribouilloy
committed
Added fixes for typescript + corrected response type on an API call
1 parent 047245e commit 083b1f8

11 files changed

Lines changed: 19 additions & 43 deletions

File tree

vite_project/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vite_project/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "widget-intent-discovery",
33
"private": true,
4-
"version": "1.0.1",
4+
"version": "1.3.0",
55
"type": "module",
66
"scripts": {
77
"dev": "vite",

vite_project/src/components/AttributeLayer/AttributeSelectorLayer.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { AttributeTile } from "./AttributeTile.tsx";
55
import { useTranslationState } from "../../state/Translation/useTranslationState.ts";
66
import type { IntentDiscoveryDataConfig } from "../../domain/intent-discovery.types.ts";
77
import { useInteractionState } from "../../state/Interaction/useInteractionState.ts";
8-
import {NoResult} from "../global/NoResult.tsx";
98
import {useIntentState} from "../../state/Intent/useIntentState.ts";
109
import type {MagentoLayeredNavigation} from "../../hooks/domain/useLayeredNavigation.tsx";
1110
import type {MergedAttribute} from "../../hooks/infra/useMagentoLayeredData.tsx";
@@ -36,8 +35,6 @@ export const AttributeSelectorLayer = ({
3635

3736
const isDisabled = intentState.status === "suggestionProcessing"
3837

39-
if (!attributeLayerData?.totalCount) return <NoResult />;
40-
4138
return (
4239
<div className={`step-finder ${isDisabled ? 'step-finder--disabled' : ''}`}>
4340
{visibleAttributes.map((attr) => {

vite_project/src/components/IntentDiscovery/AttributeLayer.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import type {IntentControllerState} from "../../domain/intent.types.ts";
44
import {useAskAi} from "../../hooks/domain/useAiInterpretation.tsx";
55
import {AttributeSelectorLayer} from "../AttributeLayer/AttributeSelectorLayer.tsx";
66
import {IntentExplanation} from "../AttributeLayer/IntentExplanation.tsx";
7-
import {SearchSpinnerOverlay} from "../global/SearchSpinnerOverlay.tsx";
87
import {useIntentState} from "../../state/Intent/useIntentState.ts";
98
import {useAnalyseSearch} from "../../hooks/domain/useAnalyseSearch.tsx";
109
import type {CategoryData} from "../../types/infra/magento/category.types.ts";
@@ -68,7 +67,7 @@ export const AttributeLayer = ({
6867
askAi()
6968
}
7069

71-
if (loading) return <SearchSpinnerOverlay />
70+
if (loading) return null
7271

7372
return (
7473
<div className="finder">

vite_project/src/components/IntentDiscovery/IntentReadiness/Warning.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,13 @@ export const Warning = ({
3737

3838
// 4. Not enough results (below threshold)
3939
if (coveragePct < 100) {
40-
if (coveragePct < 50) {
41-
message = "Add more detail or refine your preferences"
42-
}
43-
4440
if (coveragePct < 80) {
4541
message = "Getting closer — refine a bit more"
4642
}
4743

48-
message = "Almost there — just a bit more detail"
44+
if (coveragePct < 50) {
45+
message = "Add more detail or refine your preferences"
46+
}
4947
}
5048

5149
// 5. Enough results but too broad

vite_project/src/integration/intent/IntentEngine.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,7 @@ export class IntentEngine {
6666
}
6767

6868
private notify() {
69-
// IMPORTANT: emit a new reference so React state updates reliably
70-
const snapshot: IntentEngineState = {
71-
intentText: this.state.intentText,
72-
categoryScore: { ...this.state.categoryScore },
73-
attributeScore: Object.fromEntries(
74-
Object.entries(this.state.attributeScore).map(([k, v]) => [k, { ...(v as any) }])
75-
),
76-
productScore: { ...this.state.productScore },
77-
priceAffinity: { ...this.state.priceAffinity },
78-
status: this.state.status
79-
};
80-
69+
const snapshot: IntentEngineState = structuredClone(this.state);
8170
for (const listener of this.listeners) listener(snapshot);
8271
}
8372

vite_project/src/integration/intent/types.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ export type IntentEngineState = {
2020
intentInterpreted: boolean;
2121
intentInterpretationReady: boolean;
2222
searchReady: boolean;
23-
initialTotalAggregations: number;
24-
totalFilteredAggregations: number;
2523
}
2624

2725
export type IntentSignal =

vite_project/src/services/layeredNavigation/fetchBase.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const baseCache = new Map()
1010
// products: {items: GraphqlProduct[]}
1111
// }
1212

13-
type ProductsResponse = {
13+
export type ProductsResponse = {
1414
products: MagentoProducts
1515
}
1616

vite_project/src/services/layeredNavigation/fetchFiltered.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import {
2-
LAYERER_ATTRIBUTE_DATA,
3-
type MagentoProducts,
4-
type ProductsResponse
2+
LAYERER_ATTRIBUTE_DATA
53
} from "../../hooks/infra/useMagentoLayeredData.tsx";
64
import {getAttributesFilter} from "./buildFilter.ts";
75
import type {GraphqlClient} from "../../lib/graphql.ts";
86
import type {IntentEngineState} from "../../integration/intent/types.ts";
7+
import type {MagentoProducts, ProductsResponse} from "./fetchBase.ts";
98

109
const filteredCache = new Map()
1110

vite_project/src/state/Intent/IntentState.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ const initialState: IntentEngineState = {
1010
attributeScore: {},
1111
productScore: {},
1212
priceAffinity: {},
13-
status: 'idle'
13+
status: 'idle',
14+
recommendations: [],
15+
resultCount: 0,
16+
intentInterpreted: false,
17+
intentInterpretationReady: false,
18+
searchReady: false
1419
};
1520
export function loadIntentState(): IntentEngineState {
1621
try {

0 commit comments

Comments
 (0)