Fix tooltips and linking

This commit is contained in:
Tom Russell 2018-10-05 18:41:12 +01:00
parent 3ea1e933ac
commit b716e8a509
4 changed files with 40 additions and 7 deletions

View File

@ -5,6 +5,7 @@ import queryString from 'query-string';
import ErrorBox from './error-box'; import ErrorBox from './error-box';
import InfoBox from './info-box'; import InfoBox from './info-box';
import Sidebar from './sidebar'; import Sidebar from './sidebar';
import Tooltip from './tooltip';
import { HelpIcon, CloseIcon, SaveIcon } from './icons'; import { HelpIcon, CloseIcon, SaveIcon } from './icons';
import CONFIG from './fields-config.json'; import CONFIG from './fields-config.json';
@ -29,7 +30,8 @@ const BuildingEdit = (props) => {
queryString.parse(props.location.search): queryString.parse(props.location.search):
{}; {};
return ( return (
<Sidebar title={`Edit Building`} back={`/building/${props.building_id}.html`}> <Sidebar title={`Edit Building`}
back={search.cat? `/building/${props.building_id}.html?cat=${search.cat}`: `/building//${props.building_id}.html`}>
{ {
CONFIG.map((conf_props) => { CONFIG.map((conf_props) => {
return <EditForm return <EditForm
@ -143,6 +145,10 @@ class EditForm extends Component {
el = <TextInput {...props} handleChange={this.handleChange} el = <TextInput {...props} handleChange={this.handleChange}
value={this.state[props.slug]} key={props.slug} /> value={this.state[props.slug]} key={props.slug} />
break; break;
case "text_list":
el = <TextListInput {...props} handleChange={this.handleChange}
value={this.state[props.slug]} key={props.slug} />
break;
case "number": case "number":
el = <NumberInput {...props} handleChange={this.handleChange} el = <NumberInput {...props} handleChange={this.handleChange}
value={this.state[props.slug]} key={props.slug} /> value={this.state[props.slug]} key={props.slug} />
@ -162,7 +168,7 @@ class EditForm extends Component {
(this.props.inactive)? (this.props.inactive)?
null : ( null : (
<div className="buttons-container"> <div className="buttons-container">
<Link to={`/building/${this.props.building_id}.html#${this.props.slug}`} <Link to={`/building/${this.props.building_id}.html?cat=${this.props.slug}`}
className="btn btn-secondary">Cancel</Link> className="btn btn-secondary">Cancel</Link>
<button type="submit" className="btn btn-primary">Save</button> <button type="submit" className="btn btn-primary">Save</button>
</div> </div>
@ -178,7 +184,7 @@ class EditForm extends Component {
const TextInput = (props) => ( const TextInput = (props) => (
<Fragment> <Fragment>
<label htmlFor={props.slug}>{props.title}</label> <Label slug={props.slug} title={props.title} tooltip={props.tooltip} />
<input className="form-control" type="text" <input className="form-control" type="text"
id={props.slug} name={props.slug} id={props.slug} name={props.slug}
value={props.value || ""} value={props.value || ""}
@ -187,9 +193,27 @@ const TextInput = (props) => (
</Fragment> </Fragment>
); );
const TextListInput = (props) => (
<Fragment>
<Label slug={props.slug} title={props.title} tooltip={props.tooltip} />
<select className="form-control"
id={props.slug} name={props.slug}
value={props.value || ""}
list={`${props.slug}_suggestions`}
onChange={props.handleChange}>
<option value="">Select a source</option>
{
props.options.map(option => (
<option value={option}>{option}</option>
))
}
</select>
</Fragment>
)
const NumberInput = (props) => ( const NumberInput = (props) => (
<Fragment> <Fragment>
<label htmlFor={props.slug}>{props.title}</label> <Label slug={props.slug} title={props.title} tooltip={props.tooltip} />
<input className="form-control" type="number" step={props.step} <input className="form-control" type="number" step={props.step}
id={props.slug} name={props.slug} id={props.slug} name={props.slug}
value={props.value || ""} value={props.value || ""}
@ -211,4 +235,11 @@ const LikeButton = (props) => (
</Fragment> </Fragment>
); );
const Label = (props) => (
<label htmlFor={props.slug}>
{props.title}
{ props.tooltip? <Tooltip text={ props.tooltip } /> : null }
</label>
)
export default BuildingEdit; export default BuildingEdit;

View File

@ -23,7 +23,7 @@ const BuildingView = (props) => {
} }
const search = (props.location && props.location.search)? queryString.parse(props.location.search): {}; const search = (props.location && props.location.search)? queryString.parse(props.location.search): {};
return ( return (
<Sidebar title={`View Building`} back="/map/date_year.html"> <Sidebar title={`View Building`} back={search.cat? `/map/${search.cat}.html` : "/map/age.html"}>
{ {
CONFIG.map(section_props => ( CONFIG.map(section_props => (
<DataSection <DataSection
@ -80,7 +80,7 @@ const DataSection = (props) => {
{ {
(match && !props.inactive)? (match && !props.inactive)?
<div className="buttons-container with-space"> <div className="buttons-container with-space">
<Link to={`/building/${props.building_id}/edit.html#${props.slug}`} className="btn btn-primary">Edit data</Link> <Link to={`/building/${props.building_id}/edit.html?cat=${props.slug}`} className="btn btn-primary">Edit data</Link>
</div> </div>
: null : null
} }

View File

@ -100,6 +100,7 @@
.icon-button.help:hover svg { .icon-button.help:hover svg {
color: rgb(0, 81, 255) color: rgb(0, 81, 255)
} }
.icon-button.tooltip-hint.active svg,
.icon-button.tooltip-hint:hover svg { .icon-button.tooltip-hint:hover svg {
color: rgb(255, 11, 245); color: rgb(255, 11, 245);
} }
@ -155,6 +156,7 @@
} }
.data-list dt, .data-list dt,
.data-section label { .data-section label {
display: block;
margin: 0.5em 0 0; margin: 0.5em 0 0;
font-size: 0.8333rem; font-size: 0.8333rem;
font-weight: normal; font-weight: normal;

View File

@ -23,7 +23,7 @@ class Tooltip extends Component {
console.log(this.state, this.props) console.log(this.state, this.props)
return ( return (
<div className="tooltip-wrap"> <div className="tooltip-wrap">
<button className="tooltip-hint icon-button" title={this.props.text} <button className={(this.state.active? "active ": "") + "tooltip-hint icon-button"} title={this.props.text}
onClick={this.handleClick}> onClick={this.handleClick}>
<InfoIcon /> <InfoIcon />
</button> </button>