mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-17 21:06:04 +00:00
reduce schema manager query log to debug, fix useSearch
This commit is contained in:
@@ -333,7 +333,7 @@ export class SchemaManager {
|
|||||||
|
|
||||||
if (config.force) {
|
if (config.force) {
|
||||||
try {
|
try {
|
||||||
$console.log("[SchemaManager]", sql);
|
$console.debug("[SchemaManager]", sql);
|
||||||
await qb.execute();
|
await qb.execute();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new Error(`Failed to execute query: ${sql}: ${(e as any).message}`);
|
throw new Error(`Failed to execute query: ${sql}: ${(e as any).message}`);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { decodeSearch, encodeSearch, mergeObject } from "core/utils";
|
|||||||
import { isEqual, transform } from "lodash-es";
|
import { isEqual, transform } from "lodash-es";
|
||||||
import { useLocation, useSearch as useWouterSearch } from "wouter";
|
import { useLocation, useSearch as useWouterSearch } from "wouter";
|
||||||
import { type s, parse } from "core/object/schema";
|
import { type s, parse } from "core/object/schema";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useMemo, useState } from "react";
|
||||||
|
|
||||||
export type UseSearchOptions<Schema extends s.TAnySchema = s.TAnySchema> = {
|
export type UseSearchOptions<Schema extends s.TAnySchema = s.TAnySchema> = {
|
||||||
defaultValue?: Partial<s.StaticCoerced<Schema>>;
|
defaultValue?: Partial<s.StaticCoerced<Schema>>;
|
||||||
@@ -18,21 +18,24 @@ export function useSearch<Schema extends s.TAnySchema = s.TAnySchema>(
|
|||||||
const [value, setValue] = useState<s.StaticCoerced<Schema>>(
|
const [value, setValue] = useState<s.StaticCoerced<Schema>>(
|
||||||
options?.defaultValue ?? ({} as any),
|
options?.defaultValue ?? ({} as any),
|
||||||
);
|
);
|
||||||
const _defaults = mergeObject(
|
|
||||||
// @ts-ignore
|
const defaults = useMemo(() => {
|
||||||
schema.template({ withOptional: true }),
|
return mergeObject(
|
||||||
options?.defaultValue ?? {},
|
// @ts-ignore
|
||||||
);
|
schema.template({ withOptional: true }),
|
||||||
|
options?.defaultValue ?? {},
|
||||||
|
);
|
||||||
|
}, [JSON.stringify({ schema, dflt: options?.defaultValue })]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const initial =
|
const initial =
|
||||||
searchString.length > 0 ? decodeSearch(searchString) : (options?.defaultValue ?? {});
|
searchString.length > 0 ? decodeSearch(searchString) : (options?.defaultValue ?? {});
|
||||||
const v = parse(schema, Object.assign({}, _defaults, initial)) as any;
|
const v = parse(schema, Object.assign({}, defaults, initial)) as any;
|
||||||
setValue(v);
|
setValue(v);
|
||||||
}, [searchString, JSON.stringify(options?.defaultValue), location]);
|
}, [searchString, JSON.stringify(options?.defaultValue), location]);
|
||||||
|
|
||||||
function set<Update extends Partial<s.StaticCoerced<Schema>>>(update: Update): void {
|
function set<Update extends Partial<s.StaticCoerced<Schema>>>(update: Update): void {
|
||||||
const search = getWithoutDefaults(Object.assign({}, value, update), _defaults);
|
const search = getWithoutDefaults(Object.assign({}, value, update), defaults);
|
||||||
const prepared = options?.beforeEncode?.(search) ?? search;
|
const prepared = options?.beforeEncode?.(search) ?? search;
|
||||||
const encoded = encodeSearch(prepared, { encode: false });
|
const encoded = encodeSearch(prepared, { encode: false });
|
||||||
navigate(location + (encoded.length > 0 ? "?" + encoded : ""));
|
navigate(location + (encoded.length > 0 ? "?" + encoded : ""));
|
||||||
|
|||||||
Reference in New Issue
Block a user