Skip to content

Commit

Permalink
adds visual split and locale dropdown to builder
Browse files Browse the repository at this point in the history
  • Loading branch information
jhmullen committed Jan 31, 2019
1 parent cff3519 commit aee55df
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 12 deletions.
24 changes: 21 additions & 3 deletions packages/cms/src/Builder.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Builder extends Component {
currentTab: "profiles",
// formatters,
theme: "cms-light",
locale: "pt",

formatters: (props.formatters || []).reduce((acc, d) => {
const f = Function("n", "libs", "formatters", d.logic);
Expand Down Expand Up @@ -52,8 +53,12 @@ class Builder extends Component {
this.setState({theme: e.target.value});
}

handleLocaleSelect(e) {
this.setState({locale: e.target.value});
}

render() {
const {currentTab, theme} = this.state;
const {currentTab, theme, locale} = this.state;
const {isEnabled} = this.props;
const navLinks = ["profiles", "stories", "formatters"];

Expand All @@ -69,6 +74,19 @@ class Builder extends Component {
{navLink}
</button>
)}
<label className="cms-select-label cms-theme-select">second language: 
<select
className="cms-select"
name="select-theme"
id="select-theme"
value={locale}
onChange={this.handleLocaleSelect.bind(this)}
>
<option value="pt">pt</option>
<option value="es">es</option>
<option value="ru">ru</option>
</select>
</label>
<label className="cms-select-label cms-theme-select">theme: 
<select
className="cms-select"
Expand All @@ -82,8 +100,8 @@ class Builder extends Component {
</select>
</label>
</div>
{currentTab === "profiles" && <ProfileBuilder />}
{currentTab === "stories" && <StoryBuilder />}
{currentTab === "profiles" && <ProfileBuilder locale={locale}/>}
{currentTab === "stories" && <StoryBuilder locale={locale}/>}
{currentTab === "formatters" && <FormatterEditor />}
</div>
);
Expand Down
3 changes: 3 additions & 0 deletions packages/cms/src/api/cmsRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const profileReqProfileOnly = {

const storyReqStoryOnly = {
include: [
{association: "content"},
{association: "authors", attributes: ["id", "ordering"]},
{association: "descriptions", attributes: ["id", "ordering"]},
{association: "footnotes", attributes: ["id", "ordering"]}
Expand All @@ -58,6 +59,7 @@ const storyReqStoryOnly = {

const topicReqTopicOnly = {
include: [
{association: "content"},
{association: "subtitles", attributes: ["id", "ordering"]},
{association: "descriptions", attributes: ["id", "ordering"]},
{association: "visualizations", attributes: ["id", "ordering"]},
Expand All @@ -68,6 +70,7 @@ const topicReqTopicOnly = {

const storyTopicReqStoryTopicOnly = {
include: [
{association: "content"},
{association: "subtitles", attributes: ["id", "ordering"]},
{association: "descriptions", attributes: ["id", "ordering"]},
{association: "visualizations", attributes: ["id", "ordering"]},
Expand Down
31 changes: 31 additions & 0 deletions packages/cms/src/components/cards/Flag.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React, {Component} from "react";

class Flag extends Component {

constructor(props) {
super(props);
this.state = {

};
}

render() {

const {locale} = this.props;

const lookup = {
pt: "🇧🇷",
es: "🇪🇸",
ru: "🇷🇺"
};

return (
<div className="cms-flag">
{lookup[locale]}
</div>
);
}

}

export default Flag;
7 changes: 7 additions & 0 deletions packages/cms/src/components/cards/TextCard.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
padding: 1rem;
width: 18rem;
max-width: calc(100% - 2rem);

/* flag icon */
& .cms-flag {
position: absolute;
}
}


Expand Down Expand Up @@ -154,3 +159,5 @@
font-size: 24px;
}
}


11 changes: 7 additions & 4 deletions packages/cms/src/components/cards/TextCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import TextEditor from "../editors/TextEditor";
import PlainTextEditor from "../editors/PlainTextEditor";
import deepClone from "../../utils/deepClone";
import PropTypes from "prop-types";
import Flag from "./Flag";
import "./TextCard.css";

class TextCard extends Component {
Expand All @@ -28,10 +29,10 @@ class TextCard extends Component {
}

componentDidUpdate(prevProps) {
if (this.state.minData && (prevProps.variables !== this.props.variables || this.props.selectors !== prevProps.selectors)) {
if (this.state.minData && (JSON.stringify(prevProps.variables) !== JSON.stringify(this.props.variables) || JSON.stringify(this.props.selectors) !== JSON.stringify(prevProps.selectors))) {
this.formatDisplay.bind(this)();
}
if (prevProps.item.id !== this.props.item.id) {
if (prevProps.item.id !== this.props.item.id || prevProps.locale !== this.props.locale) {
this.hitDB.bind(this)();
}
}
Expand Down Expand Up @@ -79,9 +80,9 @@ class TextCard extends Component {
const {type, fields, plainfields, locale} = this.props;
const {minData} = this.state;
const payload = {id: minData.id};
const thisLocale = minData.content.find(c => c.lang === locale);
// For some reason, an empty quill editor reports its contents as <p><br></p>. Do not save
// this to the database - save an empty string instead.
const thisLocale = minData.content.find(c => c.lang === locale);
fields.forEach(field => thisLocale[field] = thisLocale[field] === "<p><br></p>" ? "" : thisLocale[field]);
if (plainfields) plainfields.forEach(field => thisLocale[field] = thisLocale[field] === "<p><br></p>" ? "" : thisLocale[field]);
payload.allowed = minData.allowed;
Expand Down Expand Up @@ -169,10 +170,12 @@ class TextCard extends Component {
{alertObj.message}
</Alert>

<Flag locale={locale} />

{/* title & edit toggle button */}
<h5 className="cms-card-header">
<button className="cms-button" onClick={this.openEditor.bind(this)}>
Edit <span className="pt-icon pt-icon-cog" />
Edit <span className="pt-icon pt-icon-cog" />
</button>
</h5>

Expand Down
2 changes: 2 additions & 0 deletions packages/cms/src/profile/ProfileBuilder.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ class ProfileBuilder extends Component {
render() {

const {nodes, currentNode, variablesHash, currentSlug, preview, profileModalOpen, cubeData, nodeToDelete} = this.state;
const {locale} = this.props;

if (!nodes) return <div>Loading</div>;

Expand Down Expand Up @@ -539,6 +540,7 @@ class ProfileBuilder extends Component {
{ currentNode
? <Editor
id={currentNode.data.id}
locale={locale}
masterSlug={currentNode.masterSlug}
preview={preview}
fetchVariables={this.fetchVariables.bind(this)}
Expand Down
14 changes: 10 additions & 4 deletions packages/cms/src/profile/ProfileEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ class ProfileEditor extends Component {
this.state = {
minData: null,
variables: null,
recompiling: true,
locale: "en"
recompiling: true
};
}

Expand Down Expand Up @@ -111,8 +110,8 @@ class ProfileEditor extends Component {

render() {

const {minData, recompiling, locale} = this.state;
const {children, variables, preview} = this.props;
const {minData, recompiling} = this.state;
const {children, variables, preview, locale} = this.props;

if (!minData || !variables) return <Loading />;

Expand Down Expand Up @@ -197,6 +196,13 @@ class ProfileEditor extends Component {
style={{backgroundImage: `url("/api/profile/${minData.slug}/${preview}/thumb")`}}
>
<div className="cms-card-list cms-profile-header">
<TextCard
locale="en"
item={minData}
fields={["title", "subtitle"]}
type="profile"
variables={variables}
/>
<TextCard
locale={locale}
item={minData}
Expand Down
65 changes: 64 additions & 1 deletion packages/cms/src/profile/TopicEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class TopicEditor extends Component {
render() {

const {minData, recompiling} = this.state;
const {variables, preview, children} = this.props;
const {variables, preview, children, locale} = this.props;

if (!minData || !variables) return <Loading />;

Expand Down Expand Up @@ -180,6 +180,15 @@ class TopicEditor extends Component {
<div className="cms-card-list">
<TextCard
item={minData}
locale="en"
fields={["title"]}
onSave={this.onSave.bind(this)}
type="topic"
variables={variables}
/>
<TextCard
item={minData}
locale={locale}
fields={["title"]}
onSave={this.onSave.bind(this)}
type="topic"
Expand All @@ -199,6 +208,24 @@ class TopicEditor extends Component {
<TextCard
key={s.id}
item={s}
locale="en"
fields={["subtitle"]}
type="topic_subtitle"
onDelete={this.onDelete.bind(this)}
variables={variables}
selectors={minData.selectors.map(s => Object.assign({}, s))}
parentArray={minData.subtitles}
onMove={this.onMove.bind(this)}
/>
)}
</div>
<hr />
<div className="cms-card-list">
{ minData.subtitles && minData.subtitles.map(s =>
<TextCard
key={s.id}
item={s}
locale={locale}
fields={["subtitle"]}
type="topic_subtitle"
onDelete={this.onDelete.bind(this)}
Expand Down Expand Up @@ -245,6 +272,24 @@ class TopicEditor extends Component {
<TextCard
key={s.id}
item={s}
locale="en"
fields={["title", "subtitle", "value", "tooltip"]}
type="topic_stat"
onDelete={this.onDelete.bind(this)}
variables={variables}
selectors={minData.selectors.map(s => Object.assign({}, s))}
parentArray={minData.stats}
onMove={this.onMove.bind(this)}
/>
)}
</div>
<hr/>
<div className="cms-card-list">
{ minData.stats && minData.stats.map(s =>
<TextCard
key={s.id}
item={s}
locale={locale}
fields={["title", "subtitle", "value", "tooltip"]}
type="topic_stat"
onDelete={this.onDelete.bind(this)}
Expand All @@ -268,6 +313,24 @@ class TopicEditor extends Component {
<TextCard
key={d.id}
item={d}
locale="en"
fields={["description"]}
type="topic_description"
onDelete={this.onDelete.bind(this)}
variables={variables}
selectors={minData.selectors.map(s => Object.assign({}, s))}
parentArray={minData.descriptions}
onMove={this.onMove.bind(this)}
/>
)}
</div>
<hr/>
<div className="cms-card-list">
{ minData.descriptions && minData.descriptions.map(d =>
<TextCard
key={d.id}
item={d}
locale={locale}
fields={["description"]}
type="topic_description"
onDelete={this.onDelete.bind(this)}
Expand Down

0 comments on commit aee55df

Please sign in to comment.