-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create & edit Decimal128 values (#1292)
* Keeping original uuid bahaviour, and will no longer check propertyName for 'object id' PKs. * Removed comment * Bumped realm to 10.0.0-alpha.9 * Introduced parseDecimal128 & reused StringCell for editing * Introduced Decimal128Control for object creation, with default value: 0 * Reordered primitives array, to list decimal under double * Release notes updated: Decimal128 create/edit * Naming * PR suggestions * handle prefix on eventhandler * Removed console from testing
- Loading branch information
1 parent
577c7ce
commit b98247f
Showing
8 changed files
with
128 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,6 +66,7 @@ | |
} | ||
|
||
&__ObjectIdControl, | ||
&__Decimal128Control, | ||
&__StringControl, | ||
&__DateControl, | ||
&__NummericControl { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
src/ui/RealmBrowser/Content/CreateObjectDialog/types/Decimal128Control.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
//////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Copyright 2020 Realm Inc. | ||
// | ||
// Licensed 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 React from 'react'; | ||
import { Decimal128 } from 'bson'; | ||
import { Button, Input, InputGroup, InputGroupAddon } from 'reactstrap'; | ||
|
||
import { IBaseControlProps } from './TypeControl'; | ||
import { parseDecimal128 } from '../../../parsers'; | ||
|
||
interface IDecimal128ControlState { | ||
internalValue: string | null; | ||
} | ||
|
||
export class Decimal128Control extends React.PureComponent< | ||
IBaseControlProps<Decimal128 | null>, | ||
IDecimal128ControlState | ||
> { | ||
state: IDecimal128ControlState = { | ||
internalValue: this.props.value?.toString() ?? null, | ||
}; | ||
|
||
render() { | ||
const { children, property, value } = this.props; | ||
const { internalValue } = this.state; | ||
|
||
return ( | ||
<InputGroup className="CreateObjectDialog__Decimal128Control"> | ||
<Input | ||
className="CreateObjectDialog__Decimal128Control__Input" | ||
onChange={this.inputChangeEventHandler} | ||
placeholder={value === null ? 'null' : ''} | ||
value={internalValue ?? ''} | ||
required={!property.optional} | ||
invalid={(!!internalValue || !property.optional) && value === null} | ||
/> | ||
{internalValue && property.optional && ( | ||
<InputGroupAddon addonType="append"> | ||
<Button size="sm" onClick={this.handleClearValue}> | ||
<i className="fa fa-close" /> | ||
</Button> | ||
</InputGroupAddon> | ||
)} | ||
{children} | ||
</InputGroup> | ||
); | ||
} | ||
|
||
private inputChangeEventHandler = (e: React.ChangeEvent<HTMLInputElement>) => | ||
this.changeHandler(e.target.value); | ||
|
||
private handleClearValue = () => this.changeHandler(null); | ||
|
||
private changeHandler = (value: string | null) => { | ||
const { property, onChange } = this.props; | ||
|
||
this.setState({ internalValue: value }); | ||
|
||
let parsedDecimal: Decimal128 | null = null; | ||
|
||
if (value) { | ||
try { | ||
parsedDecimal = parseDecimal128(value, property); | ||
} catch (err) { | ||
// tslint:disable-next-line:no-console | ||
console.warn(err.message); | ||
} | ||
} | ||
|
||
onChange(parsedDecimal); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters