Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions public/locales/de-DE/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@
"deployment-id": "Deployment-ID",
"decision-requirements-id": "Entscheidungsanforderungs-Definitions-ID",
"history-ttl": "Verlaufs-Aufbewahrungsdauer",
"history-ttl-updated": "Verlaufs-Aufbewahrungsdauer aktualisiert.",
"sort": {
"name": "Name",
"key": "Schlüssel",
Expand Down
1 change: 1 addition & 0 deletions public/locales/en-US/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@
"deployment-id": "Deployment ID",
"decision-requirements-id": "Decision Requirements Definition ID",
"history-ttl": "History Time To Live",
"history-ttl-updated": "History time to live updated.",
"sort": {
"name": "Name",
"key": "Key",
Expand Down
1 change: 1 addition & 0 deletions public/locales/es-ES/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@
"deployment-id": "ID de despliegue",
"decision-requirements-id": "ID de definición de requisitos de decisión",
"history-ttl": "Tiempo de vida del historial",
"history-ttl-updated": "Tiempo de vida del historial actualizado.",
"sort": {
"name": "Nombre",
"key": "Clave",
Expand Down
1 change: 1 addition & 0 deletions public/locales/fr-FR/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@
"deployment-id": "ID de déploiement",
"decision-requirements-id": "ID de définition des exigences de décision",
"history-ttl": "Durée de conservation de l'historique",
"history-ttl-updated": "Durée de conservation de l'historique mise à jour.",
"sort": {
"name": "Nom",
"key": "Clé",
Expand Down
1 change: 1 addition & 0 deletions public/locales/nl-NL/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@
"deployment-id": "Deployment-ID",
"decision-requirements-id": "Beslissingsvereisten-definitie-ID",
"history-ttl": "Bewaartermijn geschiedenis",
"history-ttl-updated": "Bewaartermijn geschiedenis bijgewerkt.",
"sort": {
"name": "Naam",
"key": "Sleutel",
Expand Down
11 changes: 10 additions & 1 deletion src/api/resources/decision.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GET, GET_TEXT } from '../helper.jsx'
import { GET, PUT } from '../helper.jsx'


const get_decision_definition = (state, id) =>
Expand All @@ -13,11 +13,20 @@ const get_decision_definitions = (state, params = {}) => {
const get_dmn_xml = (state, id) =>
GET(`/decision-definition/${id}/xml`, state, state.api.decision.dmn)

const update_history_ttl = (state, id, historyTimeToLive) =>
PUT(
`/decision-definition/${id}/history-time-to-live`,
{ historyTimeToLive },
state,
state.api.decision.update_history_ttl,
)


const decision = {
get_decision_definition,
get_decision_definitions,
get_dmn_xml,
update_history_ttl,
}

export default decision
13 changes: 12 additions & 1 deletion src/api/resources/decision.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { describe, it, vi, beforeEach } from "vitest";
vi.mock("../helper.jsx", () => ({
GET: vi.fn(),
GET_TEXT: vi.fn(),
PUT: vi.fn(),
}));

import { GET } from "../helper.jsx";
import { GET, PUT } from "../helper.jsx";
import { create_mock_state, expect_api_call } from "../../test/helpers.js";
import decision from "./decision.js";

Expand Down Expand Up @@ -41,4 +42,14 @@ describe("api/resources/decision", () => {
signal: state.api.decision.dmn,
});
});

it("update_history_ttl() PUTs the history time to live", () => {
decision.update_history_ttl(state, "dec-1", 30);
expect_api_call(PUT, {
url: "/decision-definition/dec-1/history-time-to-live",
body: { historyTimeToLive: 30 },
state,
signal: state.api.decision.update_history_ttl,
});
});
});
34 changes: 30 additions & 4 deletions src/pages/Decisions.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useContext, useEffect } from 'preact/hooks'
import { useSignal, useSignalEffect } from '@preact/signals'
import { useTranslation } from 'react-i18next'
import { AppState } from '../state.js'
import { useLocation, useRoute } from 'preact-iso'
Expand Down Expand Up @@ -170,9 +171,24 @@ const DecisionsList = () => {

const DecisionDetails = () => {
const state = useContext(AppState),
{ api: { decision: { definition, dmn } } } = state,
{ params: { decision_id } } = useRoute(),
[t] = useTranslation()
{ api: { decision: { definition, dmn, update_history_ttl } } } = state,
[t] = useTranslation(),
history_ttl = useSignal('')

useSignalEffect(() => {
history_ttl.value = definition.value?.data?.historyTimeToLive ?? ''
})

const submit_history_ttl = async (e, id) => {
e.preventDefault()
const raw = history_ttl.peek()
await engine_rest.decision.update_history_ttl(
state,
id,
raw === '' ? null : Number(raw),
)
void engine_rest.decision.get_decision_definition(state, id)
}

return <div id="decision-details">
<RequestState
Expand All @@ -182,7 +198,6 @@ const DecisionDetails = () => {
const {
id, key, name, version, versionTag, tenantId, deploymentId,
decisionRequirementsDefinitionId, historyTimeToLive,
resource
} = definition.value.data

return <div>
Expand All @@ -207,6 +222,17 @@ const DecisionDetails = () => {
<dt>{t("decisions.history-ttl")}</dt>
<dd>{historyTimeToLive}</dd>
</dl>
<RequestState
signal={update_history_ttl}
on_nothing={() => <></>}
on_success={() => <p class="success">{t("decisions.history-ttl-updated")}</p>} />
<form class="history-ttl-form" onSubmit={(e) => submit_history_ttl(e, id)}>
<label for="decision-history-ttl">{t("decisions.history-ttl")}</label>
<input id="decision-history-ttl" name="historyTimeToLive" type="number" min="0" step="1"
value={history_ttl.value}
onInput={(e) => (history_ttl.value = e.currentTarget.value)} />
<button type="submit">{t("common.save")}</button>
</form>
</div>
}} />

Expand Down
50 changes: 49 additions & 1 deletion src/pages/Decisions.test.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
import { h } from "preact";
import { render, cleanup } from "@testing-library/preact";
import { render, cleanup, fireEvent } from "@testing-library/preact";

// Spy all engine_rest API functions but keep RequestState/RESPONSE_STATE real.
vi.mock("../api/engine_rest.jsx", async (importOriginal) => {
Expand Down Expand Up @@ -79,4 +79,52 @@ describe("DecisionsPage", () => {
const { getByTestId } = renderPage(state);
expect(getByTestId("dmn-viewer").textContent).toBe("<dmn>xml</dmn>");
});

it("updates the decision definition history time to live", async () => {
mockParams = { decision_id: "d1" };
signal_response(state.api.decision.definition, {
id: "d1",
key: "risk",
name: "Risk",
version: 1,
historyTimeToLive: 30,
});
const { container, getByLabelText } = renderPage(state);

fireEvent.input(getByLabelText("decisions.history-ttl"), {
target: { value: "45" },
});
fireEvent.submit(container.querySelector("form.history-ttl-form"));
await Promise.resolve();

expect(engine_rest.decision.update_history_ttl).toHaveBeenCalled();
const call = engine_rest.decision.update_history_ttl.mock.lastCall;
expect(call[0]).toBe(state);
expect(call[1]).toBe("d1");
expect(call[2]).toBe(45);
});

it("clears the decision definition history time to live with an empty value", async () => {
mockParams = { decision_id: "d1" };
signal_response(state.api.decision.definition, {
id: "d1",
key: "risk",
name: "Risk",
version: 1,
historyTimeToLive: 30,
});
const { container, getByLabelText } = renderPage(state);

fireEvent.input(getByLabelText("decisions.history-ttl"), {
target: { value: "" },
});
fireEvent.submit(container.querySelector("form.history-ttl-form"));
await Promise.resolve();

expect(engine_rest.decision.update_history_ttl).toHaveBeenCalled();
const call = engine_rest.decision.update_history_ttl.mock.lastCall;
expect(call[0]).toBe(state);
expect(call[1]).toBe("d1");
expect(call[2]).toBeNull();
});
});
1 change: 1 addition & 0 deletions src/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ const createAppState = () => {
definitions: signal(null),
definition: signal(null),
dmn: signal(null),
update_history_ttl: signal(null),
saved_filters: signal(null),
},
history: {
Expand Down