This repository has been archived by the owner on Aug 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
transform many components to React Functions
- Loading branch information
1 parent
4831623
commit 4c11546
Showing
83 changed files
with
2,025 additions
and
2,459 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,37 @@ | ||
import * as React from 'react' | ||
import * as React from 'react' | ||
import { ValueLine, EntityLine, EntityCombo } from '@framework/Lines' | ||
import { TypeContext } from '@framework/TypeContext' | ||
import { AlertEntity } from '../Signum.Entities.Alerts' | ||
|
||
export default class Alert extends React.Component<{ ctx: TypeContext<AlertEntity> }> { | ||
export default function Alert(p : { ctx: TypeContext<AlertEntity> }){ | ||
const e = p.ctx; | ||
|
||
render() { | ||
const ec = e.subCtx({ labelColumns: { sm: 2 } }); | ||
const sc = ec.subCtx({ formGroupStyle: "Basic" }); | ||
|
||
const e = this.props.ctx; | ||
|
||
const ec = e.subCtx({ labelColumns: { sm: 2 } }); | ||
const sc = ec.subCtx({ formGroupStyle: "Basic" }); | ||
|
||
|
||
return ( | ||
<div> | ||
{!ec.value.isNew && | ||
<div> | ||
<EntityLine ctx={ec.subCtx(e => e.createdBy)} readOnly={true} /> | ||
<ValueLine ctx={ec.subCtx(e => e.creationDate)} readOnly={true} /> | ||
</div> | ||
} | ||
{ec.value.target && <EntityLine ctx={ec.subCtx(n => n.target)} readOnly={true} />} | ||
<EntityLine ctx={ec.subCtx(n => n.recipient)} /> | ||
<hr /> | ||
<ValueLine ctx={ec.subCtx(n => n.title)} /> | ||
<EntityCombo ctx={ec.subCtx(n => n.alertType)} /> | ||
<ValueLine ctx={ec.subCtx(n => n.alertDate)} /> | ||
<ValueLine ctx={ec.subCtx(n => n.text)} valueHtmlAttributes={{ style: { height: "180px" } }} /> | ||
{ec.value.state == "Attended" && | ||
<div> | ||
<hr /> | ||
<ValueLine ctx={ec.subCtx(e => e.attendedDate)} readOnly={true} /> | ||
<EntityLine ctx={ec.subCtx(e => e.attendedBy)} readOnly={true} /> | ||
</div> | ||
} | ||
</div> | ||
); | ||
} | ||
return ( | ||
<div> | ||
{!ec.value.isNew && | ||
<div> | ||
<EntityLine ctx={ec.subCtx(e => e.createdBy)} readOnly={true} /> | ||
<ValueLine ctx={ec.subCtx(e => e.creationDate)} readOnly={true} /> | ||
</div> | ||
} | ||
{ec.value.target && <EntityLine ctx={ec.subCtx(n => n.target)} readOnly={true} />} | ||
<EntityLine ctx={ec.subCtx(n => n.recipient)} /> | ||
<hr /> | ||
<ValueLine ctx={ec.subCtx(n => n.title)} /> | ||
<EntityCombo ctx={ec.subCtx(n => n.alertType)} /> | ||
<ValueLine ctx={ec.subCtx(n => n.alertDate)} /> | ||
<ValueLine ctx={ec.subCtx(n => n.text)} valueHtmlAttributes={{ style: { height: "180px" } }} /> | ||
{ec.value.state == "Attended" && | ||
<div> | ||
<hr /> | ||
<ValueLine ctx={ec.subCtx(e => e.attendedDate)} readOnly={true} /> | ||
<EntityLine ctx={ec.subCtx(e => e.attendedBy)} readOnly={true} /> | ||
</div> | ||
} | ||
</div> | ||
); | ||
} |
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 |
---|---|---|
@@ -1,17 +1,14 @@ | ||
import * as React from 'react' | ||
import * as React from 'react' | ||
import { ValueLine } from '@framework/Lines' | ||
import { TypeContext } from '@framework/TypeContext' | ||
import { AlertTypeEntity } from '../Signum.Entities.Alerts' | ||
|
||
export default class AlertType extends React.Component<{ ctx: TypeContext<AlertTypeEntity> }> { | ||
|
||
render() { | ||
const ctx = this.props.ctx; | ||
const ctx4 = ctx.subCtx({ labelColumns: 2 }); | ||
return ( | ||
<div> | ||
<ValueLine ctx={ctx4.subCtx(n => n.name)} /> | ||
</div> | ||
); | ||
} | ||
export default function AlertType(p : { ctx: TypeContext<AlertTypeEntity> }){ | ||
const ctx = p.ctx; | ||
const ctx4 = ctx.subCtx({ labelColumns: 2 }); | ||
return ( | ||
<div> | ||
<ValueLine ctx={ctx4.subCtx(n => n.name)} /> | ||
</div> | ||
); | ||
} |
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 |
---|---|---|
@@ -1,23 +1,22 @@ | ||
import * as React from 'react' | ||
import { RoleEntity, AuthAdminMessage } from '../Signum.Entities.Authorization' | ||
import { ValueLine, EntityList, TypeContext } from '@framework/Lines' | ||
import { useForceUpdate } from '@framework/Hooks' | ||
|
||
export default class Role extends React.Component<{ ctx: TypeContext<RoleEntity> }> { | ||
export default function Role(p : { ctx: TypeContext<RoleEntity> }){ | ||
const forceUpdate = useForceUpdate(); | ||
|
||
render() { | ||
const ctx = this.props.ctx; | ||
return ( | ||
<div> | ||
<ValueLine ctx={ctx.subCtx(e => e.name)} /> | ||
<ValueLine ctx={ctx.subCtx(e => e.mergeStrategy)} unitText={this.rolesMessage()} onChange={() => this.forceUpdate()} /> | ||
<EntityList ctx={ctx.subCtx(e => e.roles)} onChange={() => this.forceUpdate()} /> | ||
</div> | ||
); | ||
} | ||
|
||
rolesMessage(): string { | ||
function rolesMessage() { | ||
return AuthAdminMessage.NoRoles.niceToString() + " ⇒ " + | ||
(this.props.ctx.value.mergeStrategy == "Union" ? AuthAdminMessage.Nothing : AuthAdminMessage.Everything).niceToString(); | ||
(p.ctx.value.mergeStrategy == "Union" ? AuthAdminMessage.Nothing : AuthAdminMessage.Everything).niceToString(); | ||
} | ||
const ctx = p.ctx; | ||
return ( | ||
<div> | ||
<ValueLine ctx={ctx.subCtx(e => e.name)} /> | ||
<ValueLine ctx={ctx.subCtx(e => e.mergeStrategy)} unitText={rolesMessage()} onChange={() => forceUpdate()} /> | ||
<EntityList ctx={ctx.subCtx(e => e.roles)} onChange={() => forceUpdate()} /> | ||
</div> | ||
); | ||
} | ||
|
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 |
---|---|---|
@@ -1,79 +1,67 @@ | ||
import * as React from 'react' | ||
import * as React from 'react' | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' | ||
import { AuthMessage, UserEntity } from '../Signum.Entities.Authorization' | ||
import { AuthMessage, UserEntity, UserState } from '../Signum.Entities.Authorization' | ||
import { Binding } from '@framework/Reflection' | ||
import { ValueLine, EntityLine, EntityCombo, FormGroup, TypeContext } from '@framework/Lines' | ||
|
||
export default class User extends React.Component<{ ctx: TypeContext<UserEntity> }, { withPassword: boolean }> { | ||
export default function User(p: { ctx: TypeContext<UserEntity> }) { | ||
|
||
constructor(props: any) { | ||
super(props); | ||
this.state = { withPassword: false }; | ||
} | ||
const ctx = p.ctx.subCtx({ labelColumns: { sm: 3 } }); | ||
const entity = p.ctx.value; | ||
|
||
render() { | ||
const ctx = this.props.ctx.subCtx({ labelColumns: { sm: 3 } }); | ||
const entity = this.props.ctx.value; | ||
return ( | ||
<div> | ||
<ValueLine ctx={ctx.subCtx(e => e.state, { readOnly: true })} /> | ||
<ValueLine ctx={ctx.subCtx(e => e.userName)} /> | ||
<DoublePassword ctx={new TypeContext<string>(ctx, undefined, undefined as any, Binding.create(ctx.value, v => v.newPassword))} isNew={entity.isNew} /> : | ||
<EntityLine ctx={ctx.subCtx(e => e.role)} /> | ||
<ValueLine ctx={ctx.subCtx(e => e.email)} /> | ||
<EntityCombo ctx={ctx.subCtx(e => e.cultureInfo)} /> | ||
<ValueLine ctx={ctx.subCtx(e => e.passwordNeverExpires)} /> | ||
<ValueLine ctx={ctx.subCtx(e => e.passwordSetDate)} /> | ||
</div> | ||
); | ||
} | ||
|
||
return ( | ||
<div> | ||
<ValueLine ctx={ctx.subCtx(e => e.state, { readOnly: true })} /> | ||
<ValueLine ctx={ctx.subCtx(e => e.userName)} /> | ||
{entity.isNew || this.state.withPassword ? | ||
<DoublePassword ctx={new TypeContext<string>(ctx, undefined, undefined as any, Binding.create(ctx.value, v => v.newPassword))} /> : | ||
!ctx.readOnly && this.renderButton(ctx) | ||
} | ||
<EntityLine ctx={ctx.subCtx(e => e.role)} /> | ||
<ValueLine ctx={ctx.subCtx(e => e.email)} /> | ||
<EntityCombo ctx={ctx.subCtx(e => e.cultureInfo)} /> | ||
<ValueLine ctx={ctx.subCtx(e => e.passwordNeverExpires)} /> | ||
<ValueLine ctx={ctx.subCtx(e => e.passwordSetDate)} /> | ||
</div> | ||
); | ||
} | ||
function DoublePassword(p: { ctx: TypeContext<string>, isNew: boolean }) { | ||
|
||
renderButton(ctx: TypeContext<UserEntity>) { | ||
return ( | ||
<FormGroup labelText={AuthMessage.NewPassword.niceToString()} ctx={ctx}> | ||
<a className="btn btn-light btn-sm" onClick={() => this.setState({ withPassword: true })}> | ||
<FontAwesomeIcon icon="key" /> {AuthMessage.ChangePassword.niceToString()} | ||
</a> | ||
</FormGroup> | ||
); | ||
} | ||
} | ||
const [withPassword, setWithPassword] = React.useState(p.isNew); | ||
|
||
class DoublePassword extends React.Component<{ ctx: TypeContext<string> }>{ | ||
if (!withPassword) { | ||
return <FormGroup labelText={AuthMessage.NewPassword.niceToString()} ctx={p.ctx}> | ||
<a className="btn btn-light btn-sm" onClick={() => setWithPassword(true)}> | ||
<FontAwesomeIcon icon="key" /> {AuthMessage.ChangePassword.niceToString()} | ||
</a> | ||
</FormGroup> | ||
} | ||
|
||
handlePasswordBlur = (event: React.SyntheticEvent<any>) => { | ||
|
||
const ctx = this.props.ctx; | ||
function handlePasswordBlur(e: React.SyntheticEvent<any>) { | ||
const ctx = p.ctx; | ||
|
||
if (this.newPass.value && this.newPass2.value && this.newPass.value != this.newPass2.value) { | ||
if (newPass.current!.value && newPass2.current!.value && newPass.current!.value != newPass2.current!.value) { | ||
ctx.error = AuthMessage.PasswordsAreDifferent.niceToString() | ||
} | ||
else { | ||
ctx.error = undefined; | ||
ctx.value = this.newPass.value; | ||
ctx.value = newPass.current!.value; | ||
} | ||
|
||
ctx.frame!.revalidate(); | ||
} | ||
|
||
newPass!: HTMLInputElement; | ||
newPass2!: HTMLInputElement; | ||
var newPass = React.useRef<HTMLInputElement>(null); | ||
var newPass2 = React.useRef<HTMLInputElement>(null); | ||
|
||
render() { | ||
return ( | ||
<div> | ||
<FormGroup ctx={this.props.ctx} labelText={AuthMessage.ChangePasswordAspx_NewPassword.niceToString()}> | ||
<input type="password" ref={p => this.newPass = p!} className={this.props.ctx.formControlClass} onBlur={this.handlePasswordBlur} /> | ||
</FormGroup> | ||
<FormGroup ctx={this.props.ctx} labelText={AuthMessage.ChangePasswordAspx_ConfirmNewPassword.niceToString()}> | ||
<input type="password" ref={p => this.newPass2 = p!} className={this.props.ctx.formControlClass} onBlur={this.handlePasswordBlur} /> | ||
</FormGroup> | ||
</div> | ||
); | ||
} | ||
return ( | ||
<div> | ||
<FormGroup ctx={p.ctx} labelText={AuthMessage.ChangePasswordAspx_NewPassword.niceToString()}> | ||
<input type="password" ref={newPass} className={p.ctx.formControlClass} onBlur={handlePasswordBlur} /> | ||
</FormGroup> | ||
<FormGroup ctx={p.ctx} labelText={AuthMessage.ChangePasswordAspx_ConfirmNewPassword.niceToString()}> | ||
<input type="password" ref={newPass2} className={p.ctx.formControlClass} onBlur={handlePasswordBlur} /> | ||
</FormGroup> | ||
</div> | ||
); | ||
} | ||
|
Oops, something went wrong.