Skip to content

Commit

Permalink
feat(DecisionsList): add pivot value column (#457)
Browse files Browse the repository at this point in the history
* feat(api): add pivot_values to case detail

* feat(DecisionsList): add pivot value column
  • Loading branch information
balzdur authored May 27, 2024
1 parent 8e93e01 commit 3da1aa8
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 12 deletions.
1 change: 1 addition & 0 deletions packages/app-builder/public/locales/en/decisions.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"detail.scenario_name_runs_on": "<ScenarioName>{{scenarioName}}</ScenarioName> (runs on <TriggerObjectType>{{triggerObjectType}}</TriggerObjectType>)",
"detail.error": "An error as occured. Make sure the provided decision id is valid.",
"trigger_object.type": "Trigger object",
"pivot_value": "Pivot value",
"filters.has_case": "Presence of a case",
"filters.pivot_value": "Pivot value",
"filters.date_range.title": "creation date is:",
Expand Down
33 changes: 29 additions & 4 deletions packages/app-builder/src/components/Decisions/DecisionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
useState,
} from 'react';
import { useTranslation } from 'react-i18next';
import { Checkbox, Table, useVirtualTable } from 'ui-design-system';
import { Checkbox, Table, Tooltip, useVirtualTable } from 'ui-design-system';

import { Score } from './Score';

Expand All @@ -26,6 +26,7 @@ type Column =
| 'scenario_name'
| 'trigger_object_type'
| 'case'
| 'pivot_value'
| 'score'
| 'outcome';

Expand All @@ -44,6 +45,10 @@ export interface DecisionViewModel {
name: string;
status: TCaseStatus;
};
pivotValues: {
id?: string;
value?: string;
}[];
score: number;
outcome: TOutcome;
}
Expand Down Expand Up @@ -161,7 +166,7 @@ export function DecisionsList({
columnHelper.accessor((row) => row.scenario.version, {
id: 'scenario_version',
header: 'Vi',
size: 20,
size: 50,
cell: ({ getValue, row }) => (
<Link
to={getRoute('/scenarios/:scenarioId/i/:iterationId', {
Expand All @@ -178,12 +183,12 @@ export function DecisionsList({
columnHelper.accessor((row) => row.triggerObjectType, {
id: 'trigger_object_type',
header: t('decisions:trigger_object.type'),
size: 200,
size: 150,
}),
columnHelper.accessor((row) => row.case?.name ?? '-', {
id: 'case',
header: t('decisions:case'),
size: 200,
size: 150,
cell: ({ getValue, row }) =>
row.original.case ? (
<div className="flex w-fit flex-row items-center justify-center gap-1">
Expand All @@ -204,6 +209,26 @@ export function DecisionsList({
</span>
),
}),
columnHelper.accessor((row) => row.pivotValues, {
id: 'pivot_value',
header: t('decisions:pivot_value'),
size: 100,
cell: ({ getValue }) => {
const pivotValues = getValue() ?? [];
if (pivotValues.length === 0) return null;
return (
<div className="relative flex flex-col gap-1">
{pivotValues.map((pivotValue) => (
<Tooltip.Default key={pivotValue.id} content={pivotValue.value}>
<span className="text-grey-100 text-s line-clamp-1 text-ellipsis">
{pivotValue.value}
</span>
</Tooltip.Default>
))}
</div>
);
},
}),
columnHelper.accessor((row) => row.score, {
id: 'score',
header: t('decisions:score'),
Expand Down
10 changes: 10 additions & 0 deletions packages/app-builder/src/models/cases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ export interface CaseDetail
triggerObject: Record<string, unknown>;
triggerObjectType: string;
outcome: Outcome;
pivotValues: {
id?: string;
value?: string;
}[];
scenario: {
id: string;
name: string;
Expand All @@ -92,6 +96,12 @@ export function adaptCaseDetailDto({
triggerObject: decisionDto.trigger_object,
triggerObjectType: decisionDto.trigger_object_type,
outcome: decisionDto.outcome,
pivotValues: decisionDto.pivot_values.map(
({ pivot_id, pivot_value }) => ({
id: pivot_id ?? undefined,
value: pivot_value ?? undefined,
}),
),
scenario: {
id: decisionDto.scenario.id,
name: decisionDto.scenario.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ export default function Decisions() {
decisions={decisions}
selectable
selectionProps={selectionProps}
columnVisibility={{
pivot_value: false,
}}
/>
<CursorPaginationButtons
items={decisions}
Expand Down
21 changes: 13 additions & 8 deletions packages/marble-api/scripts/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3784,14 +3784,6 @@ components:
type: array
items:
type: object
required:
- id
- created_at
- trigger_object
- trigger_object_type
- outcome
- scenario
- score
properties:
id:
type: string
Expand All @@ -3805,6 +3797,10 @@ components:
type: string
outcome:
$ref: '#/components/schemas/Outcome'
pivot_values:
type: array
items:
$ref: '#/components/schemas/PivotValueDto'
scenario:
type: object
required:
Expand All @@ -3830,6 +3826,15 @@ components:
type: integer
error:
$ref: '#/components/schemas/Error'
required:
- id
- created_at
- trigger_object
- trigger_object_type
- outcome
- pivot_values
- scenario
- score
events:
type: array
items:
Expand Down
1 change: 1 addition & 0 deletions packages/marble-api/src/generated/marble-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ export type CaseDetailDto = Case & {
};
trigger_object_type: string;
outcome: Outcome;
pivot_values: PivotValueDto[];
scenario: {
id: string;
name: string;
Expand Down

0 comments on commit 3da1aa8

Please sign in to comment.