From d4c831ff91620e2a530504906f7ecd50706d5cf7 Mon Sep 17 00:00:00 2001 From: bogercraig <124094535+bogercraig@users.noreply.github.com> Date: Fri, 1 Sep 2023 14:46:49 -0400 Subject: [PATCH] Users/bogercraig/blank ttl default value (#1596) * Initial rough of keeping textfield blank. Still need to disable save button. * Rough implementation with state moved up to settings component. Allows for discarding of new TTL when TTL is already enabled. * Updating unit tests to include new display variable. * Brought formatting back from master. * Updating unit test snapshots. * Ran prettier and renormalized modified files. * Correct lint issues. * Undo prettier changes to add collection code and testing snapshot. * Restoring AddCollectionPanel to match master. Not modifying snapshot. --------- Co-authored-by: Craig Boger --- .../Controls/Settings/SettingsComponent.tsx | 24 +++++++++++++++---- .../SubSettingsComponent.test.tsx | 4 ++++ .../SubSettingsComponent.tsx | 21 ++++++++++++---- .../SettingsComponent.test.tsx.snap | 2 ++ 4 files changed, 41 insertions(+), 10 deletions(-) diff --git a/src/Explorer/Controls/Settings/SettingsComponent.tsx b/src/Explorer/Controls/Settings/SettingsComponent.tsx index ee3393ee9..d38ce0b22 100644 --- a/src/Explorer/Controls/Settings/SettingsComponent.tsx +++ b/src/Explorer/Controls/Settings/SettingsComponent.tsx @@ -5,18 +5,18 @@ import DiscardIcon from "../../../../images/discard.svg"; import SaveIcon from "../../../../images/save-cosmos.svg"; import { AuthType } from "../../../AuthType"; import * as Constants from "../../../Common/Constants"; +import { getErrorMessage, getErrorStack } from "../../../Common/ErrorHandlingUtils"; import { getIndexTransformationProgress } from "../../../Common/dataAccess/getIndexTransformationProgress"; import { readMongoDBCollectionThroughRP } from "../../../Common/dataAccess/readMongoDBCollection"; import { updateCollection } from "../../../Common/dataAccess/updateCollection"; import { updateOffer } from "../../../Common/dataAccess/updateOffer"; -import { getErrorMessage, getErrorStack } from "../../../Common/ErrorHandlingUtils"; import * as DataModels from "../../../Contracts/DataModels"; import * as ViewModels from "../../../Contracts/ViewModels"; import { Action, ActionModifiers } from "../../../Shared/Telemetry/TelemetryConstants"; import { trace, traceFailure, traceStart, traceSuccess } from "../../../Shared/Telemetry/TelemetryProcessor"; import { userContext } from "../../../UserContext"; -import { MongoDBCollectionResource, MongoIndex } from "../../../Utils/arm/generatedClients/cosmos/types"; import * as AutoPilotUtils from "../../../Utils/AutoPilotUtils"; +import { MongoDBCollectionResource, MongoIndex } from "../../../Utils/arm/generatedClients/cosmos/types"; import { CommandButtonComponentProps } from "../../Controls/CommandButton/CommandButtonComponent"; import { useCommandBar } from "../../Menus/CommandBar/CommandBarComponentAdapter"; import { SettingsTabV2 } from "../../Tabs/SettingsTabV2"; @@ -37,15 +37,15 @@ import { AddMongoIndexProps, ChangeFeedPolicyState, GeospatialConfigType, + MongoIndexTypes, + SettingsV2TabTypes, + TtlType, getMongoNotification, getTabTitle, hasDatabaseSharedThroughput, isDirty, - MongoIndexTypes, parseConflictResolutionMode, parseConflictResolutionProcedure, - SettingsV2TabTypes, - TtlType, } from "./SettingsUtils"; interface SettingsV2TabInfo { @@ -78,6 +78,8 @@ export interface SettingsComponentState { timeToLiveBaseline: TtlType; timeToLiveSeconds: number; timeToLiveSecondsBaseline: number; + displayedTtlSeconds: string; + displayedTtlSecondsBaseline: string; geospatialConfigType: GeospatialConfigType; geospatialConfigTypeBaseline: GeospatialConfigType; analyticalStorageTtlSelection: TtlType; @@ -164,6 +166,8 @@ export class SettingsComponent extends React.Component this.setState({ timeToLiveSeconds: newTimeToLiveSeconds }); + private onDisplayedTtlChange = (newDisplayedTtlSeconds: string): void => + this.setState({ displayedTtlSeconds: newDisplayedTtlSeconds }); + private onGeoSpatialConfigTypeChange = (newGeoSpatialConfigType: GeospatialConfigType): void => this.setState({ geospatialConfigType: newGeoSpatialConfigType }); @@ -608,6 +616,8 @@ export class SettingsComponent extends React.Component { onTimeToLiveSecondsChange: () => { return; }, + displayedTtlSeconds: "1000", + onDisplayedTtlSecondsChange: () => { + return; + }, geospatialConfigType: GeospatialConfigType.Geography, geospatialConfigTypeBaseline: GeospatialConfigType.Geography, diff --git a/src/Explorer/Controls/Settings/SettingsSubComponents/SubSettingsComponent.tsx b/src/Explorer/Controls/Settings/SettingsSubComponents/SubSettingsComponent.tsx index f3d82a17a..ffebfcc55 100644 --- a/src/Explorer/Controls/Settings/SettingsSubComponents/SubSettingsComponent.tsx +++ b/src/Explorer/Controls/Settings/SettingsSubComponents/SubSettingsComponent.tsx @@ -15,13 +15,13 @@ import { import { ChangeFeedPolicyState, GeospatialConfigType, - getSanitizedInputValue, IsComponentDirtyResult, - isDirty, TtlOff, TtlOn, TtlOnNoDefault, TtlType, + getSanitizedInputValue, + isDirty, } from "../SettingsUtils"; import { ToolTipLabelComponent } from "./ToolTipLabelComponent"; @@ -34,6 +34,8 @@ export interface SubSettingsComponentProps { timeToLiveSeconds: number; timeToLiveSecondsBaseline: number; onTimeToLiveSecondsChange: (newTimeToLiveSeconds: number) => void; + displayedTtlSeconds: string; + onDisplayedTtlSecondsChange: (newDisplayedTtlSeconds: string) => void; geospatialConfigType: GeospatialConfigType; geospatialConfigTypeBaseline: GeospatialConfigType; @@ -73,7 +75,14 @@ export class SubSettingsComponent extends React.Component { if ( (this.props.timeToLive === TtlType.On && !this.props.timeToLiveSeconds) || - (this.props.analyticalStorageTtlSelection === TtlType.On && !this.props.analyticalStorageTtlSeconds) + (this.props.analyticalStorageTtlSelection === TtlType.On && !this.props.analyticalStorageTtlSeconds) || + (this.props.timeToLive === TtlType.On && this.props.displayedTtlSeconds === "") ) { return { isSaveable: false, isDiscardable: true }; } else if ( @@ -138,6 +148,7 @@ export class SubSettingsComponent extends React.Component { const newTimeToLiveSeconds = getSanitizedInputValue(newValue, Int32.Max); + this.props.onDisplayedTtlSecondsChange(newTimeToLiveSeconds.toString()); this.props.onTimeToLiveSecondsChange(newTimeToLiveSeconds); }; @@ -204,7 +215,7 @@ export class SubSettingsComponent extends React.Component diff --git a/src/Explorer/Controls/Settings/__snapshots__/SettingsComponent.test.tsx.snap b/src/Explorer/Controls/Settings/__snapshots__/SettingsComponent.test.tsx.snap index bdad7d1f7..5e905e786 100644 --- a/src/Explorer/Controls/Settings/__snapshots__/SettingsComponent.test.tsx.snap +++ b/src/Explorer/Controls/Settings/__snapshots__/SettingsComponent.test.tsx.snap @@ -150,12 +150,14 @@ exports[`SettingsComponent renders 1`] = ` "usageSizeInKB": [Function], } } + displayedTtlSeconds="5" geospatialConfigType="Geometry" geospatialConfigTypeBaseline="Geometry" isAnalyticalStorageEnabled={false} onAnalyticalStorageTtlSecondsChange={[Function]} onAnalyticalStorageTtlSelectionChange={[Function]} onChangeFeedPolicyChange={[Function]} + onDisplayedTtlSecondsChange={[Function]} onGeoSpatialConfigTypeChange={[Function]} onSubSettingsDiscardableChange={[Function]} onSubSettingsSaveableChange={[Function]}