MCPcopy
hub / github.com/determined-ai/determined / Wrapper

Function Wrapper

webui/react/src/hooks/useTypedParams.test.tsx:76–116  ·  view source on GitHub ↗
({ params }: { params: t.TypeOf<typeof codec> })

Source from the content-addressed store, hash-verified

74const setupTest = (params: t.TypeOf<typeof codec>) => {
75 const outerRef: { current: null | ReturnType<typeof useTypedParams> } = { current: null };
76 const Wrapper = ({ params }: { params: t.TypeOf<typeof codec> }) => {
77 // set up queryparams for usersettingsprovider
78 const querySettings = useMemo(() => {
79 const pairs = Object.entries(params).reduce(
80 (memo, [k, v]) => {
81 if (Array.isArray(v)) {
82 v.forEach((sv) => {
83 if (sv !== null) {
84 const stringValue = sv instanceof Object ? JSON.stringify(sv) : sv.toString();
85 memo.push([k, stringValue]);
86 }
87 });
88 } else if (v instanceof Object) {
89 memo.push([k, JSON.stringify(v)]);
90 } else {
91 memo.push([k, `${v}`]);
92 }
93 return memo;
94 },
95 [] as [string, string][],
96 );
97 return new URLSearchParams(pairs);
98 }, [params]);
99
100 const Inner = () => {
101 const result = useTypedParams(codec, {});
102 useLayoutEffect(() => {
103 outerRef.current = result;
104 });
105 return null;
106 };
107
108 return (
109 <UserSettings.Provider
110 value={{ isLoading: false, querySettings, state: observable(NotLoaded) }}>
111 <BrowserRouter>
112 <Inner />
113 </BrowserRouter>
114 </UserSettings.Provider>
115 );
116 };
117 const renderResult = render(<Wrapper params={params} />);
118 return {
119 hookRef: outerRef,

Callers

nothing calls this directly

Calls 4

reduceMethod · 0.45
forEachMethod · 0.45
toStringMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected