bbovenzi commented on code in PR #67054:
URL: https://github.com/apache/airflow/pull/67054#discussion_r3267401793
##########
airflow-core/src/airflow/ui/src/queries/useParamStore.ts:
##########
@@ -44,18 +44,77 @@ export const paramPlaceholder: ParamSpec = {
type FormStore = {
conf: string;
disabled: boolean;
+ initializeParamsDict: (newParamsDict: ParamsSpec) => void;
initialParamDict: ParamsSpec;
paramsDict: ParamsSpec;
setConf: (confString: string) => void;
setDisabled: (disabled: boolean) => void;
setInitialParamDict: (newParamsDict: ParamsSpec) => void;
- setParamsDict: (newParamsDict: ParamsSpec) => void;
+ setParamsDict: (newParamsDict: ParamsSpec, touchedKey?: string) => void;
+ touchedKeys: ReadonlySet<string>;
+};
+
+const getParsedConf = (confString: string): Record<string, unknown> =>
+ JSON.parse(confString) as Record<string, unknown>;
Review Comment:
We don't need this function. We should just call `JSON.parse` inline.
##########
airflow-core/src/airflow/ui/src/queries/useParamStore.ts:
##########
@@ -44,18 +44,77 @@ export const paramPlaceholder: ParamSpec = {
type FormStore = {
conf: string;
disabled: boolean;
+ initializeParamsDict: (newParamsDict: ParamsSpec) => void;
initialParamDict: ParamsSpec;
paramsDict: ParamsSpec;
setConf: (confString: string) => void;
setDisabled: (disabled: boolean) => void;
setInitialParamDict: (newParamsDict: ParamsSpec) => void;
- setParamsDict: (newParamsDict: ParamsSpec) => void;
+ setParamsDict: (newParamsDict: ParamsSpec, touchedKey?: string) => void;
+ touchedKeys: ReadonlySet<string>;
+};
+
+const getParsedConf = (confString: string): Record<string, unknown> =>
+ JSON.parse(confString) as Record<string, unknown>;
+
+export const buildParamsDictWithConfValues = (newParamsDict: ParamsSpec,
confString: string): ParamsSpec => {
Review Comment:
```suggestion
export const hydrateParams = (newParamsDict: ParamsSpec, confString:
string): ParamsSpec => {
```
##########
airflow-core/src/airflow/ui/src/queries/useParamStore.test.ts:
##########
@@ -0,0 +1,169 @@
+/*!
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import { act, renderHook } from "@testing-library/react";
+import { describe, expect, it } from "vitest";
+
+import type { ParamSchema, ParamsSpec } from "src/queries/useDagParams";
+import { buildParamsDictWithConfValues, useParamStore } from
"src/queries/useParamStore";
+
+const buildSchema = (type: ParamSchema["type"], title: string): ParamSchema =>
({
+ const: undefined,
+ description_md: undefined,
+ enum: undefined,
+ examples: undefined,
+ format: undefined,
+ items: undefined,
+ maximum: undefined,
+ maxLength: undefined,
+ minimum: undefined,
+ minLength: undefined,
+ section: undefined,
+ title,
+ type,
+ values_display: undefined,
+});
+
+const snowflakeExtraFields: ParamsSpec = {
+ account: {
+ description: null,
+ schema: buildSchema(["string", "null"], "Account"),
+ value: undefined,
+ },
+ insecure_mode: {
+ description: "Turns off OCSP certificate checks",
+ schema: buildSchema(["boolean", "null"], "Insecure Mode"),
+ value: false,
+ },
+};
+
+let namespaceId = 0;
+
+const renderParamStore = () => {
+ namespaceId += 1;
+
+ return renderHook(() => useParamStore(`use-param-store-${namespaceId}`));
+};
+
+const parseConf = (conf: string): Record<string, unknown> => JSON.parse(conf)
as Record<string, unknown>;
Review Comment:
We don't need `parseConf` just call `JSON.parse()`
##########
airflow-core/src/airflow/ui/src/queries/useParamStore.ts:
##########
@@ -44,18 +44,77 @@ export const paramPlaceholder: ParamSpec = {
type FormStore = {
conf: string;
disabled: boolean;
+ initializeParamsDict: (newParamsDict: ParamsSpec) => void;
initialParamDict: ParamsSpec;
paramsDict: ParamsSpec;
setConf: (confString: string) => void;
setDisabled: (disabled: boolean) => void;
setInitialParamDict: (newParamsDict: ParamsSpec) => void;
- setParamsDict: (newParamsDict: ParamsSpec) => void;
+ setParamsDict: (newParamsDict: ParamsSpec, touchedKey?: string) => void;
+ touchedKeys: ReadonlySet<string>;
+};
+
+const getParsedConf = (confString: string): Record<string, unknown> =>
+ JSON.parse(confString) as Record<string, unknown>;
+
+export const buildParamsDictWithConfValues = (newParamsDict: ParamsSpec,
confString: string): ParamsSpec => {
+ const parsedConf = getParsedConf(confString);
+ const paramsWithValues: Array<[string, ParamSpec]> = [];
+ const inParamsDict = new Set<string>(Object.keys(newParamsDict));
+
+ for (const [key, param] of Object.entries(newParamsDict)) {
+ paramsWithValues.push([
+ key,
+ {
+ description: param.description ?? null,
Review Comment:
```suggestion
description: param.description,
```
ParamSpec.description is already string | null
##########
airflow-core/src/airflow/ui/src/queries/useParamStore.ts:
##########
@@ -44,18 +44,77 @@ export const paramPlaceholder: ParamSpec = {
type FormStore = {
conf: string;
disabled: boolean;
+ initializeParamsDict: (newParamsDict: ParamsSpec) => void;
initialParamDict: ParamsSpec;
paramsDict: ParamsSpec;
setConf: (confString: string) => void;
setDisabled: (disabled: boolean) => void;
setInitialParamDict: (newParamsDict: ParamsSpec) => void;
- setParamsDict: (newParamsDict: ParamsSpec) => void;
+ setParamsDict: (newParamsDict: ParamsSpec, touchedKey?: string) => void;
+ touchedKeys: ReadonlySet<string>;
+};
+
+const getParsedConf = (confString: string): Record<string, unknown> =>
+ JSON.parse(confString) as Record<string, unknown>;
+
+export const buildParamsDictWithConfValues = (newParamsDict: ParamsSpec,
confString: string): ParamsSpec => {
+ const parsedConf = getParsedConf(confString);
+ const paramsWithValues: Array<[string, ParamSpec]> = [];
+ const inParamsDict = new Set<string>(Object.keys(newParamsDict));
+
+ for (const [key, param] of Object.entries(newParamsDict)) {
+ paramsWithValues.push([
+ key,
+ {
+ description: param.description ?? null,
+ schema: param.schema,
+ value: Object.hasOwn(parsedConf, key) ? parsedConf[key] : param.value,
+ },
+ ]);
+ }
+
+ for (const [key, value] of Object.entries(parsedConf)) {
+ if (!inParamsDict.has(key)) {
+ paramsWithValues.push([
+ key,
+ {
+ description: null,
+ schema: paramPlaceholder.schema,
+ value,
+ },
+ ]);
+ }
+ }
+
+ return Object.fromEntries(paramsWithValues);
Review Comment:
We're doing a ton of Object and Array manipulation in this function. It's
hard to follow. Please try to simplify it.
##########
airflow-core/src/airflow/ui/src/queries/useParamStore.ts:
##########
@@ -44,18 +44,77 @@ export const paramPlaceholder: ParamSpec = {
type FormStore = {
conf: string;
disabled: boolean;
+ initializeParamsDict: (newParamsDict: ParamsSpec) => void;
initialParamDict: ParamsSpec;
paramsDict: ParamsSpec;
setConf: (confString: string) => void;
setDisabled: (disabled: boolean) => void;
setInitialParamDict: (newParamsDict: ParamsSpec) => void;
- setParamsDict: (newParamsDict: ParamsSpec) => void;
+ setParamsDict: (newParamsDict: ParamsSpec, touchedKey?: string) => void;
+ touchedKeys: ReadonlySet<string>;
+};
+
+const getParsedConf = (confString: string): Record<string, unknown> =>
+ JSON.parse(confString) as Record<string, unknown>;
+
+export const buildParamsDictWithConfValues = (newParamsDict: ParamsSpec,
confString: string): ParamsSpec => {
+ const parsedConf = getParsedConf(confString);
+ const paramsWithValues: Array<[string, ParamSpec]> = [];
+ const inParamsDict = new Set<string>(Object.keys(newParamsDict));
+
+ for (const [key, param] of Object.entries(newParamsDict)) {
+ paramsWithValues.push([
+ key,
+ {
+ description: param.description ?? null,
+ schema: param.schema,
+ value: Object.hasOwn(parsedConf, key) ? parsedConf[key] : param.value,
+ },
+ ]);
+ }
+
+ for (const [key, value] of Object.entries(parsedConf)) {
+ if (!inParamsDict.has(key)) {
+ paramsWithValues.push([
+ key,
+ {
+ description: null,
+ schema: paramPlaceholder.schema,
+ value,
+ },
+ ]);
+ }
+ }
+
+ return Object.fromEntries(paramsWithValues);
+};
+
+export const buildConfFromTouchedParams = (
Review Comment:
```suggestion
export const serializeConf = (
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]