Skip to content

Commit 7fd2751

Browse files
committed
test: update muxing model
1 parent a467fba commit 7fd2751

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/features/workspace/components/__tests__/workspace-muxing-model.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ test("render model overrides", async () => {
1010
expect(screen.getByText(/model muxing/i)).toBeVisible();
1111
expect(
1212
screen.getByText(
13-
/filters will be applied in order \(top to bottom\), empty filters will apply to all\./i,
13+
/select the model you would like to use in this workspace. This section applies only if you are using the MUX endpoint./i,
1414
),
1515
).toBeVisible();
1616
expect(

src/features/workspace/hooks/use-muxing-rules-form-workspace.ts

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { MuxMatcherType, MuxRule } from "@/api/generated";
22
import { useFormState } from "@/hooks/useFormState";
3-
import { useCallback, useEffect } from "react";
3+
import { isEqual } from "lodash";
4+
import { useCallback, useEffect, useRef } from "react";
45
import { v4 as uuidv4 } from "uuid";
56

67
export type PreferredMuxRule = MuxRule & { id: string };
@@ -22,14 +23,18 @@ export const useMuxingRulesFormState = (initialValues: MuxRule[]) => {
2223
rules: [{ ...DEFAULT_STATE, id: uuidv4() }],
2324
});
2425
const { values, updateFormValues, setInitialValues } = formState;
26+
const lastValuesRef = useRef(values.rules);
2527

2628
useEffect(() => {
27-
setInitialValues({
28-
rules:
29-
initialValues.length == 0
30-
? [DEFAULT_STATE]
31-
: initialValues.map((item) => ({ ...item, id: uuidv4() })),
32-
});
29+
const newValues =
30+
initialValues.length === 0
31+
? [DEFAULT_STATE]
32+
: initialValues.map((item) => ({ ...item, id: uuidv4() }));
33+
34+
if (!isEqual(lastValuesRef.current, newValues)) {
35+
lastValuesRef.current = newValues;
36+
setInitialValues({ rules: newValues });
37+
}
3338
}, [initialValues, setInitialValues]);
3439

3540
const addRule = useCallback(() => {

0 commit comments

Comments
 (0)