fix UI bugs

This commit is contained in:
Shawn Erquhart 2018-07-25 05:34:19 -04:00
parent e764df68b2
commit 439920c652
3 changed files with 37 additions and 54 deletions

View File

@ -47,9 +47,7 @@ const AppHeaderContent = styled.div`
`; `;
const AppHeaderButton = styled.button` const AppHeaderButton = styled.button`
border: 0; ${buttons.button};
cursor: pointer;
background-color: transparent;
color: #7b8290; color: #7b8290;
font-size: 16px; font-size: 16px;
font-weight: 500; font-weight: 500;
@ -103,8 +101,6 @@ export default class Header extends React.Component {
displayUrl: PropTypes.string, displayUrl: PropTypes.string,
}; };
static activeClassName = `${uuid()}-active`;
handleCreatePostClick = (collectionName) => { handleCreatePostClick = (collectionName) => {
const { onCreateEntryClick } = this.props; const { onCreateEntryClick } = this.props;
if (onCreateEntryClick) { if (onCreateEntryClick) {
@ -132,7 +128,7 @@ export default class Header extends React.Component {
<nav> <nav>
<AppHeaderNavLink <AppHeaderNavLink
to="/" to="/"
activeClassName={Header.activeClassName} activeClassName="header-link-active"
isActive={(match, location) => location.pathname.startsWith('/collections/')} isActive={(match, location) => location.pathname.startsWith('/collections/')}
> >
<Icon type="page"/> <Icon type="page"/>
@ -140,7 +136,7 @@ export default class Header extends React.Component {
</AppHeaderNavLink> </AppHeaderNavLink>
{ {
hasWorkflow hasWorkflow
? <AppHeaderNavLink to="/workflow" activeClassName={Header.activeClassName}> ? <AppHeaderNavLink to="/workflow" activeClassName="header-link-active">
<Icon type="workflow"/> <Icon type="workflow"/>
Workflow Workflow
</AppHeaderNavLink> </AppHeaderNavLink>

View File

@ -97,8 +97,6 @@ export default class Sidebar extends React.Component {
collections: ImmutablePropTypes.orderedMap.isRequired, collections: ImmutablePropTypes.orderedMap.isRequired,
}; };
static sidebarLinkActiveClassName = `${uuid()}-sidebar-active`;
state = { query: this.props.searchTerm || '' }; state = { query: this.props.searchTerm || '' };
renderLink = collection => { renderLink = collection => {
@ -107,7 +105,7 @@ export default class Sidebar extends React.Component {
<SidebarNavLink <SidebarNavLink
key={collectionName} key={collectionName}
to={`/collections/${collectionName}`} to={`/collections/${collectionName}`}
activeClassName={Sidebar.sidebarLinkActiveClassName} activeClassName="sidebar-active"
> >
<Icon type="write"/> <Icon type="write"/>
{collection.get('label')} {collection.get('label')}

View File

@ -1,55 +1,49 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { css } from 'react-emotion'; import { injectGlobal, css } from 'react-emotion';
import Autosuggest from 'react-autosuggest'; import Autosuggest from 'react-autosuggest';
import uuid from 'uuid/v4'; import uuid from 'uuid/v4';
import { List, Map } from 'immutable'; import { List, Map } from 'immutable';
import { debounce } from 'lodash'; import { debounce } from 'lodash';
import { Loader, components } from 'netlify-cms-ui-default'; import { Loader, components } from 'netlify-cms-ui-default';
/** injectGlobal`
* Create a classname for use as a descendant selector. This is generally .react-autosuggest__container {
* discouraged in Emotion because composition will break the resulting
* classnames, but we won't be using composition here.
*/
const styles = {
suggestionsContainer: css`
display: none;
`,
};
/**
* react-autosuggest theme spec:
* https://github.com/moroshko/react-autosuggest#theme-optional
*/
const theme = {
container: css`
position: relative; position: relative;
`, }
containerOpen: css`
${styles.suggestionsContainer} { .react-autosuggest__suggestions-container {
${components.dropdownList} display: none;
position: absolute; }
display: block;
top: 51px; .react-autosuggest__container--open .react-autosuggest__suggestions-container {
width: 100%; ${components.dropdownList}
z-index: 2; position: absolute;
} display: block;
`, top: 51px;
suggestion: css` width: 100%;
${components.drodpownItem}; z-index: 2;
cursor: pointer; }
padding: 10px 20px;
`, .react-autosuggest__suggestion {
suggestionsList: css` ${components.dropdownItem}
}
.react-autosuggest__suggestions-list {
margin: 0; margin: 0;
padding: 0; padding: 0;
list-style-type: none; list-style-type: none;
`, }
suggestionHighlighted: css`
.react-autosuggest__suggestion {
cursor: pointer;
padding: 10px 20px;
}
.react-autosuggest__suggestion--focused {
background-color: #ddd; background-color: #ddd;
`, }
}; `
function escapeRegexCharacters(str) { function escapeRegexCharacters(str) {
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
@ -93,15 +87,12 @@ export default class RelationControl extends React.Component {
} }
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
console.log(`receiving`);
console.log(nextProps.queryHits && nextProps.queryHits.get(this.controlID));
if (this.didInitialSearch) return; if (this.didInitialSearch) return;
if (nextProps.queryHits !== this.props.queryHits && nextProps.queryHits.get && nextProps.queryHits.get(this.controlID)) { if (nextProps.queryHits !== this.props.queryHits && nextProps.queryHits.get && nextProps.queryHits.get(this.controlID)) {
this.didInitialSearch = true; this.didInitialSearch = true;
const suggestion = nextProps.queryHits.get(this.controlID); const suggestion = nextProps.queryHits.get(this.controlID);
if (suggestion && suggestion.length === 1) { if (suggestion && suggestion.length === 1) {
const val = this.getSuggestionValue(suggestion[0]); const val = this.getSuggestionValue(suggestion[0]);
console.log(`accepting ${val}`);
this.props.onChange(val, { [nextProps.field.get('collection')]: { [val]: suggestion[0].data } }); this.props.onChange(val, { [nextProps.field.get('collection')]: { [val]: suggestion[0].data } });
} }
} }
@ -121,7 +112,6 @@ export default class RelationControl extends React.Component {
const { field } = this.props; const { field } = this.props;
const collection = field.get('collection'); const collection = field.get('collection');
const searchFields = field.get('searchFields').toJS(); const searchFields = field.get('searchFields').toJS();
console.log(`querying ${value}`);
this.props.query(this.controlID, collection, searchFields, value); this.props.query(this.controlID, collection, searchFields, value);
}, 500); }, 500);
@ -182,7 +172,6 @@ export default class RelationControl extends React.Component {
renderSuggestion={this.renderSuggestion} renderSuggestion={this.renderSuggestion}
inputProps={inputProps} inputProps={inputProps}
focusInputOnSuggestionClick={false} focusInputOnSuggestionClick={false}
theme={theme}
/> />
<Loader active={isFetching === this.controlID} /> <Loader active={isFetching === this.controlID} />
</div> </div>