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 <craig.boger@microsoft.com>
This commit is contained in:
bogercraig 2023-09-01 14:46:49 -04:00 committed by GitHub
parent 1eb566ab57
commit d4c831ff91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 10 deletions

View File

@ -5,18 +5,18 @@ import DiscardIcon from "../../../../images/discard.svg";
import SaveIcon from "../../../../images/save-cosmos.svg"; import SaveIcon from "../../../../images/save-cosmos.svg";
import { AuthType } from "../../../AuthType"; import { AuthType } from "../../../AuthType";
import * as Constants from "../../../Common/Constants"; import * as Constants from "../../../Common/Constants";
import { getErrorMessage, getErrorStack } from "../../../Common/ErrorHandlingUtils";
import { getIndexTransformationProgress } from "../../../Common/dataAccess/getIndexTransformationProgress"; import { getIndexTransformationProgress } from "../../../Common/dataAccess/getIndexTransformationProgress";
import { readMongoDBCollectionThroughRP } from "../../../Common/dataAccess/readMongoDBCollection"; import { readMongoDBCollectionThroughRP } from "../../../Common/dataAccess/readMongoDBCollection";
import { updateCollection } from "../../../Common/dataAccess/updateCollection"; import { updateCollection } from "../../../Common/dataAccess/updateCollection";
import { updateOffer } from "../../../Common/dataAccess/updateOffer"; import { updateOffer } from "../../../Common/dataAccess/updateOffer";
import { getErrorMessage, getErrorStack } from "../../../Common/ErrorHandlingUtils";
import * as DataModels from "../../../Contracts/DataModels"; import * as DataModels from "../../../Contracts/DataModels";
import * as ViewModels from "../../../Contracts/ViewModels"; import * as ViewModels from "../../../Contracts/ViewModels";
import { Action, ActionModifiers } from "../../../Shared/Telemetry/TelemetryConstants"; import { Action, ActionModifiers } from "../../../Shared/Telemetry/TelemetryConstants";
import { trace, traceFailure, traceStart, traceSuccess } from "../../../Shared/Telemetry/TelemetryProcessor"; import { trace, traceFailure, traceStart, traceSuccess } from "../../../Shared/Telemetry/TelemetryProcessor";
import { userContext } from "../../../UserContext"; import { userContext } from "../../../UserContext";
import { MongoDBCollectionResource, MongoIndex } from "../../../Utils/arm/generatedClients/cosmos/types";
import * as AutoPilotUtils from "../../../Utils/AutoPilotUtils"; import * as AutoPilotUtils from "../../../Utils/AutoPilotUtils";
import { MongoDBCollectionResource, MongoIndex } from "../../../Utils/arm/generatedClients/cosmos/types";
import { CommandButtonComponentProps } from "../../Controls/CommandButton/CommandButtonComponent"; import { CommandButtonComponentProps } from "../../Controls/CommandButton/CommandButtonComponent";
import { useCommandBar } from "../../Menus/CommandBar/CommandBarComponentAdapter"; import { useCommandBar } from "../../Menus/CommandBar/CommandBarComponentAdapter";
import { SettingsTabV2 } from "../../Tabs/SettingsTabV2"; import { SettingsTabV2 } from "../../Tabs/SettingsTabV2";
@ -37,15 +37,15 @@ import {
AddMongoIndexProps, AddMongoIndexProps,
ChangeFeedPolicyState, ChangeFeedPolicyState,
GeospatialConfigType, GeospatialConfigType,
MongoIndexTypes,
SettingsV2TabTypes,
TtlType,
getMongoNotification, getMongoNotification,
getTabTitle, getTabTitle,
hasDatabaseSharedThroughput, hasDatabaseSharedThroughput,
isDirty, isDirty,
MongoIndexTypes,
parseConflictResolutionMode, parseConflictResolutionMode,
parseConflictResolutionProcedure, parseConflictResolutionProcedure,
SettingsV2TabTypes,
TtlType,
} from "./SettingsUtils"; } from "./SettingsUtils";
interface SettingsV2TabInfo { interface SettingsV2TabInfo {
@ -78,6 +78,8 @@ export interface SettingsComponentState {
timeToLiveBaseline: TtlType; timeToLiveBaseline: TtlType;
timeToLiveSeconds: number; timeToLiveSeconds: number;
timeToLiveSecondsBaseline: number; timeToLiveSecondsBaseline: number;
displayedTtlSeconds: string;
displayedTtlSecondsBaseline: string;
geospatialConfigType: GeospatialConfigType; geospatialConfigType: GeospatialConfigType;
geospatialConfigTypeBaseline: GeospatialConfigType; geospatialConfigTypeBaseline: GeospatialConfigType;
analyticalStorageTtlSelection: TtlType; analyticalStorageTtlSelection: TtlType;
@ -164,6 +166,8 @@ export class SettingsComponent extends React.Component<SettingsComponentProps, S
timeToLiveBaseline: undefined, timeToLiveBaseline: undefined,
timeToLiveSeconds: undefined, timeToLiveSeconds: undefined,
timeToLiveSecondsBaseline: undefined, timeToLiveSecondsBaseline: undefined,
displayedTtlSeconds: undefined,
displayedTtlSecondsBaseline: undefined,
geospatialConfigType: undefined, geospatialConfigType: undefined,
geospatialConfigTypeBaseline: undefined, geospatialConfigTypeBaseline: undefined,
analyticalStorageTtlSelection: undefined, analyticalStorageTtlSelection: undefined,
@ -369,6 +373,7 @@ export class SettingsComponent extends React.Component<SettingsComponentProps, S
throughput: this.state.throughputBaseline, throughput: this.state.throughputBaseline,
timeToLive: this.state.timeToLiveBaseline, timeToLive: this.state.timeToLiveBaseline,
timeToLiveSeconds: this.state.timeToLiveSecondsBaseline, timeToLiveSeconds: this.state.timeToLiveSecondsBaseline,
displayedTtlSeconds: this.state.displayedTtlSecondsBaseline,
geospatialConfigType: this.state.geospatialConfigTypeBaseline, geospatialConfigType: this.state.geospatialConfigTypeBaseline,
indexingPolicyContent: this.state.indexingPolicyContentBaseline, indexingPolicyContent: this.state.indexingPolicyContentBaseline,
indexesToAdd: [], indexesToAdd: [],
@ -479,6 +484,9 @@ export class SettingsComponent extends React.Component<SettingsComponentProps, S
private onTimeToLiveSecondsChange = (newTimeToLiveSeconds: number): void => private onTimeToLiveSecondsChange = (newTimeToLiveSeconds: number): void =>
this.setState({ timeToLiveSeconds: newTimeToLiveSeconds }); this.setState({ timeToLiveSeconds: newTimeToLiveSeconds });
private onDisplayedTtlChange = (newDisplayedTtlSeconds: string): void =>
this.setState({ displayedTtlSeconds: newDisplayedTtlSeconds });
private onGeoSpatialConfigTypeChange = (newGeoSpatialConfigType: GeospatialConfigType): void => private onGeoSpatialConfigTypeChange = (newGeoSpatialConfigType: GeospatialConfigType): void =>
this.setState({ geospatialConfigType: newGeoSpatialConfigType }); this.setState({ geospatialConfigType: newGeoSpatialConfigType });
@ -608,6 +616,8 @@ export class SettingsComponent extends React.Component<SettingsComponentProps, S
break; break;
} }
const displayedTtlSeconds: string = timeToLive === TtlType.On ? timeToLiveSeconds.toString() : "";
let analyticalStorageTtlSelection: TtlType; let analyticalStorageTtlSelection: TtlType;
let analyticalStorageTtlSeconds: number; let analyticalStorageTtlSeconds: number;
if (this.isAnalyticalStorageEnabled) { if (this.isAnalyticalStorageEnabled) {
@ -645,6 +655,8 @@ export class SettingsComponent extends React.Component<SettingsComponentProps, S
timeToLiveBaseline: timeToLive, timeToLiveBaseline: timeToLive,
timeToLiveSeconds: timeToLiveSeconds, timeToLiveSeconds: timeToLiveSeconds,
timeToLiveSecondsBaseline: timeToLiveSeconds, timeToLiveSecondsBaseline: timeToLiveSeconds,
displayedTtlSeconds: displayedTtlSeconds,
displayedTtlSecondsBaseline: displayedTtlSeconds,
analyticalStorageTtlSelection: analyticalStorageTtlSelection, analyticalStorageTtlSelection: analyticalStorageTtlSelection,
analyticalStorageTtlSelectionBaseline: analyticalStorageTtlSelection, analyticalStorageTtlSelectionBaseline: analyticalStorageTtlSelection,
analyticalStorageTtlSeconds: analyticalStorageTtlSeconds, analyticalStorageTtlSeconds: analyticalStorageTtlSeconds,
@ -986,6 +998,8 @@ export class SettingsComponent extends React.Component<SettingsComponentProps, S
timeToLiveSeconds: this.state.timeToLiveSeconds, timeToLiveSeconds: this.state.timeToLiveSeconds,
timeToLiveSecondsBaseline: this.state.timeToLiveSecondsBaseline, timeToLiveSecondsBaseline: this.state.timeToLiveSecondsBaseline,
onTimeToLiveSecondsChange: this.onTimeToLiveSecondsChange, onTimeToLiveSecondsChange: this.onTimeToLiveSecondsChange,
displayedTtlSeconds: this.state.displayedTtlSeconds,
onDisplayedTtlSecondsChange: this.onDisplayedTtlChange,
geospatialConfigType: this.state.geospatialConfigType, geospatialConfigType: this.state.geospatialConfigType,
geospatialConfigTypeBaseline: this.state.geospatialConfigTypeBaseline, geospatialConfigTypeBaseline: this.state.geospatialConfigTypeBaseline,
onGeoSpatialConfigTypeChange: this.onGeoSpatialConfigTypeChange, onGeoSpatialConfigTypeChange: this.onGeoSpatialConfigTypeChange,

View File

@ -20,6 +20,10 @@ describe("SubSettingsComponent", () => {
onTimeToLiveSecondsChange: () => { onTimeToLiveSecondsChange: () => {
return; return;
}, },
displayedTtlSeconds: "1000",
onDisplayedTtlSecondsChange: () => {
return;
},
geospatialConfigType: GeospatialConfigType.Geography, geospatialConfigType: GeospatialConfigType.Geography,
geospatialConfigTypeBaseline: GeospatialConfigType.Geography, geospatialConfigTypeBaseline: GeospatialConfigType.Geography,

View File

@ -15,13 +15,13 @@ import {
import { import {
ChangeFeedPolicyState, ChangeFeedPolicyState,
GeospatialConfigType, GeospatialConfigType,
getSanitizedInputValue,
IsComponentDirtyResult, IsComponentDirtyResult,
isDirty,
TtlOff, TtlOff,
TtlOn, TtlOn,
TtlOnNoDefault, TtlOnNoDefault,
TtlType, TtlType,
getSanitizedInputValue,
isDirty,
} from "../SettingsUtils"; } from "../SettingsUtils";
import { ToolTipLabelComponent } from "./ToolTipLabelComponent"; import { ToolTipLabelComponent } from "./ToolTipLabelComponent";
@ -34,6 +34,8 @@ export interface SubSettingsComponentProps {
timeToLiveSeconds: number; timeToLiveSeconds: number;
timeToLiveSecondsBaseline: number; timeToLiveSecondsBaseline: number;
onTimeToLiveSecondsChange: (newTimeToLiveSeconds: number) => void; onTimeToLiveSecondsChange: (newTimeToLiveSeconds: number) => void;
displayedTtlSeconds: string;
onDisplayedTtlSecondsChange: (newDisplayedTtlSeconds: string) => void;
geospatialConfigType: GeospatialConfigType; geospatialConfigType: GeospatialConfigType;
geospatialConfigTypeBaseline: GeospatialConfigType; geospatialConfigTypeBaseline: GeospatialConfigType;
@ -73,7 +75,14 @@ export class SubSettingsComponent extends React.Component<SubSettingsComponentPr
this.onComponentUpdate(); this.onComponentUpdate();
} }
componentDidUpdate(): void { componentDidUpdate(prevProps: SubSettingsComponentProps): void {
if (
(prevProps.timeToLive === TtlType.Off || prevProps.timeToLive === TtlType.OnNoDefault) &&
this.props.timeToLive === TtlType.On &&
this.props.timeToLiveBaseline !== TtlType.On
) {
this.props.onDisplayedTtlSecondsChange("");
}
this.onComponentUpdate(); this.onComponentUpdate();
} }
@ -93,7 +102,8 @@ export class SubSettingsComponent extends React.Component<SubSettingsComponentPr
public IsComponentDirty = (): IsComponentDirtyResult => { public IsComponentDirty = (): IsComponentDirtyResult => {
if ( if (
(this.props.timeToLive === TtlType.On && !this.props.timeToLiveSeconds) || (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 }; return { isSaveable: false, isDiscardable: true };
} else if ( } else if (
@ -138,6 +148,7 @@ export class SubSettingsComponent extends React.Component<SubSettingsComponentPr
newValue?: string newValue?: string
): void => { ): void => {
const newTimeToLiveSeconds = getSanitizedInputValue(newValue, Int32.Max); const newTimeToLiveSeconds = getSanitizedInputValue(newValue, Int32.Max);
this.props.onDisplayedTtlSecondsChange(newTimeToLiveSeconds.toString());
this.props.onTimeToLiveSecondsChange(newTimeToLiveSeconds); this.props.onTimeToLiveSecondsChange(newTimeToLiveSeconds);
}; };
@ -204,7 +215,7 @@ export class SubSettingsComponent extends React.Component<SubSettingsComponentPr
required required
min={1} min={1}
max={Int32.Max} max={Int32.Max}
value={this.props.timeToLiveSeconds?.toString()} value={this.props.displayedTtlSeconds}
onChange={this.onTimeToLiveSecondsChange} onChange={this.onTimeToLiveSecondsChange}
suffix="second(s)" suffix="second(s)"
/> />

View File

@ -150,12 +150,14 @@ exports[`SettingsComponent renders 1`] = `
"usageSizeInKB": [Function], "usageSizeInKB": [Function],
} }
} }
displayedTtlSeconds="5"
geospatialConfigType="Geometry" geospatialConfigType="Geometry"
geospatialConfigTypeBaseline="Geometry" geospatialConfigTypeBaseline="Geometry"
isAnalyticalStorageEnabled={false} isAnalyticalStorageEnabled={false}
onAnalyticalStorageTtlSecondsChange={[Function]} onAnalyticalStorageTtlSecondsChange={[Function]}
onAnalyticalStorageTtlSelectionChange={[Function]} onAnalyticalStorageTtlSelectionChange={[Function]}
onChangeFeedPolicyChange={[Function]} onChangeFeedPolicyChange={[Function]}
onDisplayedTtlSecondsChange={[Function]}
onGeoSpatialConfigTypeChange={[Function]} onGeoSpatialConfigTypeChange={[Function]}
onSubSettingsDiscardableChange={[Function]} onSubSettingsDiscardableChange={[Function]}
onSubSettingsSaveableChange={[Function]} onSubSettingsSaveableChange={[Function]}