Skip to content

Commit 66b0913

Browse files
fix on rule snooze & improvement
1 parent 24027b1 commit 66b0913

3 files changed

Lines changed: 25 additions & 36 deletions

File tree

packages/app-builder/src/components/CaseManager/PivotsPanel/PivotsPanelContent.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,11 @@ type PivotObjectDetailsProps = {
334334
dataModel: DataModelWithTableOptions;
335335
pivotObject: PivotObject;
336336
};
337-
function PivotObjectDetails({ tableModel, dataModel, pivotObject }: PivotObjectDetailsProps) {
337+
export function PivotObjectDetails({
338+
tableModel,
339+
dataModel,
340+
pivotObject,
341+
}: PivotObjectDetailsProps) {
338342
const { t } = useTranslation(['common', 'cases']);
339343
const { data, relatedObjects } = pivotObject.pivotObjectData;
340344
const filteredRelatedObjects = relatedObjects.filter((r) => !!r.relatedObjectDetail?.metadata);

packages/app-builder/src/components/CaseManager/SnoozePanel/SnoozePanel.tsx

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { casesI18n } from '@app-builder/components/Cases';
22
import { AddRuleSnooze } from '@app-builder/components/Cases/AddRuleSnooze';
3-
import { ClientObjectDataList } from '@app-builder/components/DataModelExplorer/ClientObjectDataList';
4-
import { OutcomeBadge } from '@app-builder/components/Decisions';
53
import { Nudge } from '@app-builder/components/Nudge';
64
import { RuleGroup } from '@app-builder/components/Scenario/Rules/RuleGroup';
75
import { ScoreModifier } from '@app-builder/components/Scenario/Rules/ScoreModifier';
@@ -18,6 +16,7 @@ import { Button, cn, Tabs, TabsContent, TabsList, TabsTrigger } from 'ui-design-
1816
import { Icon } from 'ui-icons';
1917

2018
import { DrawerContext } from '../Drawer/Drawer';
19+
import { PivotObjectDetails } from '../PivotsPanel/PivotsPanelContent';
2120

2221
const findDataFromPivotValue = (pivots: PivotObject[], pivotValue: string) => {
2322
return pivots.find((p) => p.pivotValue === pivotValue);
@@ -60,28 +59,20 @@ export const SnoozePanel = ({
6059
<Tabs className="flex w-full flex-col" defaultValue={Object.keys(rulesByPivot)[0]}>
6160
<TabsList className="mb-6 w-fit">
6261
{Object.keys(rulesByPivot).map((pivotValue) => {
63-
const client = findDataFromPivotValue(pivotObjects ?? [], pivotValue);
64-
65-
const clientName =
66-
client?.pivotObjectData.data &&
67-
'name' in client.pivotObjectData.data &&
68-
typeof client.pivotObjectData.data['name'] === 'string'
69-
? client.pivotObjectData.data['name']
70-
: pivotValue;
71-
7262
return (
7363
<TabsTrigger
7464
key={`trigger-${pivotValue}`}
7565
value={pivotValue}
7666
className="gap-2"
7767
>
78-
<span className="font-medium">{clientName}</span>
68+
<span className="font-medium">{pivotValue}</span>
7969
</TabsTrigger>
8070
);
8171
})}
8272
</TabsList>
8373
{Dict.entries(rulesByPivot).map(([pivotValue, rules]) => {
8474
const client = findDataFromPivotValue(pivotObjects ?? [], pivotValue);
75+
console.log('client', client);
8576
const table = dataModelWithTableOptions.find(
8677
(t) => t.name === client?.pivotObjectName,
8778
);
@@ -92,12 +83,15 @@ export const SnoozePanel = ({
9283
key={`content-${pivotValue}`}
9384
value={pivotValue}
9485
>
95-
{table && client?.pivotObjectData.data ? (
96-
<ClientObjectDataList
97-
className="bg-grey-98 border-grey-95 rounded-sm border p-2"
98-
tableModel={table}
99-
data={client.pivotObjectData.data}
100-
/>
86+
{table && client ? (
87+
<div className="border-grey-90 flex flex-col gap-v2-md border p-v2-md bg-grey-background-light rounded-v2-lg">
88+
<div className="capitalize font-semibold">{table.name}</div>
89+
<PivotObjectDetails
90+
tableModel={table}
91+
dataModel={dataModelWithTableOptions}
92+
pivotObject={client}
93+
/>
94+
</div>
10195
) : null}
10296
<div className="border-grey-90 bg-grey-100 relative w-full rounded-lg border">
10397
<div className="text-2xs text-grey-50 relative grid grid-cols-[150px_120px_1fr_1fr_0.5fr_0.5fr_150px] font-normal">
@@ -123,10 +117,10 @@ export const SnoozePanel = ({
123117
<span className="p-2">{t('cases:decisions.rule.name_and_score')}</span>
124118
<span className="p-2">{t('cases:decisions.rule.description')}</span>
125119
<span className="p-2">{t('cases:decisions.rule.rule_group')}</span>
126-
<span className="p-2">{t('cases:decisions.outcome')}</span>
127120
<span className="p-2">{t('cases:decisions.rule.snooze_until')}</span>
128121
</div>
129122
{rules.map((r) => {
123+
console.log(r);
130124
const formattedHitAt = (
131125
<span
132126
className={cn('text-grey-50 text-xs', { 'opacity-30': r.isSnoozed })}
@@ -195,12 +189,6 @@ export const SnoozePanel = ({
195189
/>
196190
) : null}
197191
</div>
198-
<div className="border-grey-90 flex min-h-full items-center border-r p-2">
199-
<OutcomeBadge
200-
className={cn({ 'opacity-30': r.isSnoozed })}
201-
outcome={r.outcome}
202-
/>
203-
</div>
204192
<div className="flex min-h-full items-center p-2">
205193
{r.isSnoozed ? (
206194
<span className="opacity-30">

packages/app-builder/src/routes/_builder+/cases+/$caseId+/_index.tsx

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
mergeDataModelWithTableOptions,
1818
type TableModelWithOptions,
1919
} from '@app-builder/models';
20+
import { isRuleExecutionHit } from '@app-builder/models/decision';
2021
import { useEnqueueCaseReviewMutation } from '@app-builder/queries/ask-case-review';
2122
import { initServerServices } from '@app-builder/services/init.server';
2223
import { badRequest } from '@app-builder/utils/http/http-responses';
@@ -99,13 +100,14 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
99100
cases.getMostRecentCaseReview({ caseId }),
100101
]);
101102

102-
const dataModelWithTableOptions = (await Promise.all(
103+
const dataModelWithTableOptionsRaw = (await Promise.all(
103104
dataModel.map<Promise<TableModelWithOptions>>((table) =>
104105
dataModelRepository.getDataModelTableOptions(table.id).then((options) => {
105106
return mergeDataModelWithTableOptions(table, options);
106107
}),
107108
),
108109
)) satisfies DataModelWithTableOptions;
110+
const dataModelWithTableOptions = dataModelWithTableOptionsRaw as DataModelWithTableOptions;
109111

110112
const decisionsPromise = Promise.all(
111113
currentCase.decisions.map(async (d) => ({
@@ -169,9 +171,8 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
169171
map(details, (d) =>
170172
pipe(
171173
d.rules,
172-
filter((r) => r.outcome === 'hit'),
173174
map((r) => ({
174-
...omit(r, ['outcome', 'evaluation']),
175+
...omit(r, ['evaluation']),
175176
isSnoozed: snoozes.find(
176177
(s) => s.pivotValue === pivotValue && r.ruleId === s.ruleId,
177178
)
@@ -180,13 +181,9 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
180181
hitAt: d.createdAt,
181182
decisionId: d.id,
182183
ruleGroup: scenarioRules.find((sr) => sr.id === r.ruleId)?.ruleGroup,
183-
outcome: d.outcome,
184-
start: snoozes.find(
185-
(s) => s.ruleId === r.ruleId && s.createdFromDecisionId === d.id,
186-
)?.startsAt as string,
187-
end: snoozes.find(
188-
(s) => s.ruleId === r.ruleId && s.createdFromDecisionId === d.id,
189-
)?.endsAt as string,
184+
start: snoozes.find((s) => s.ruleId === r.ruleId)?.startsAt as string,
185+
end: snoozes.find((s) => s.ruleId === r.ruleId)?.endsAt as string,
186+
scoreModifier: isRuleExecutionHit(r) ? r.scoreModifier : 0,
190187
})),
191188
),
192189
),

0 commit comments

Comments
 (0)