Skip to content

Commit

Permalink
21064: Fixed a bug that caused time_series attributes not in the form…
Browse files Browse the repository at this point in the history
… to be lost on update (#8)
  • Loading branch information
lancegliser authored Jul 26, 2024
1 parent d8f5692 commit 08859f1
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
44 changes: 43 additions & 1 deletion src/components/FeatureAttributes/utils/forms.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,50 @@
import { FeatureAttributes } from "@howso/openapi-client";
import type { FeatureAttributes } from "@howso/openapi-client";
import {
InferFeatureAttributeFormValues,
getInferFeatureAttributeParamsFormValuesOnSubmit,
getInferFeatureAttributesFromFormData,
} from "./forms";
import type { InferFeatureAttributesParams } from "../types";

describe("getInferFeatureAttributeParamsFormValuesOnSubmit", () => {
it("should not reset the time feature property on submit", () => {
const feature = "test";
const params: InferFeatureAttributesParams = {
features: {
[feature]: {
type: "continuous",
data_type: "number",
significant_digits: undefined,
decimal_places: undefined,
date_time_format: "",
time_series: {
type: "rate",
time_feature: true,
},
},
},
};

const data: InferFeatureAttributeFormValues = {
...params.features?.[feature],
reserved: {
boundingMode: "auto",
isDateTime: true,
},
};
// Remove the time_series.time_feature property as it is not part of the form's elements
delete data.time_series?.time_feature;

const updatedParams = getInferFeatureAttributeParamsFormValuesOnSubmit({
data,
feature,
params,
});
expect(updatedParams.features?.[feature].time_series).toStrictEqual(
params.features?.[feature].time_series,
);
});
});

describe("getFeatureAttributesFromFormData", () => {
it("should remove empty values", () => {
Expand Down
8 changes: 8 additions & 0 deletions src/components/FeatureAttributes/utils/forms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ const getParamsWithUpdatedFeatureAttributes = (
[feature]: {
...params.features?.[feature],
...attributes,
time_series:
params.features?.[feature].time_series || attributes.time_series
? ({
type: "rate",
...params.features?.[feature].time_series,
...attributes.time_series,
} satisfies FeatureAttributes["time_series"])
: undefined,
},
},
});

0 comments on commit 08859f1

Please sign in to comment.