Skip to content

Commit

Permalink
adds locale default to profile builder and editor
Browse files Browse the repository at this point in the history
  • Loading branch information
jhmullen committed Feb 6, 2019
1 parent a04f978 commit 90b6f14
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
19 changes: 9 additions & 10 deletions packages/cms/src/profile/ProfileBuilder.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -445,26 +445,24 @@ class ProfileBuilder extends Component {
*/
fetchVariables(slug, id, force, callback) {
const {variablesHash} = this.state;
const {locale} = this.props;
const {locale, localeDefault} = this.props;
const maybeCallback = () => {
if (callback) callback();
this.formatTreeVariables.bind(this)();
};
if (force || !variablesHash[slug]) {
if (id) {
axios.get(`/api/variables/${slug}/${id}`).then(en => {
const enVars = en.data;
axios.get(`/api/variables/${slug}/${id}?locale=${localeDefault}`).then(def => {
const defObj = {[localeDefault]: def.data};
if (!variablesHash[slug]) {
variablesHash[slug] = {en: enVars};
variablesHash[slug] = defObj;
}
else {
variablesHash[slug] = Object.assign(variablesHash[slug], {en: enVars});
variablesHash[slug] = Object.assign(variablesHash[slug], defObj);
}
if (locale) {
axios.get(`/api/variables/${slug}/${id}?locale=${locale}`).then(loc => {
const locVars = loc.data;
const locObj = {};
locObj[locale] = locVars;
const locObj = {[locale]: loc.data};
variablesHash[slug] = Object.assign(variablesHash[slug], locObj);
this.setState({variablesHash}, maybeCallback);
});
Expand All @@ -475,7 +473,7 @@ class ProfileBuilder extends Component {
});
}
else {
variablesHash[slug].en = {_genStatus: {}, _matStatus: {}};
variablesHash[slug][localeDefault] = {_genStatus: {}, _matStatus: {}};
if (locale) variablesHash[slug][locale] = {_genStatus: {}, _matStatus: {}};
this.setState({variablesHash}, maybeCallback);
}
Expand All @@ -488,7 +486,7 @@ class ProfileBuilder extends Component {
render() {

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

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

Expand Down Expand Up @@ -554,6 +552,7 @@ class ProfileBuilder extends Component {
? <Editor
id={currentNode.data.id}
locale={locale}
localeDefault={localeDefault}
masterSlug={currentNode.masterSlug}
preview={preview}
fetchVariables={this.fetchVariables.bind(this)}
Expand Down
14 changes: 7 additions & 7 deletions packages/cms/src/profile/ProfileEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class ProfileEditor extends Component {
render() {

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

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

Expand Down Expand Up @@ -159,12 +159,12 @@ class ProfileEditor extends Component {
.map(g => <GeneratorCard
key={g.id}
item={g}
locale="en"
locale={localeDefault}
preview={preview}
onSave={this.onSave.bind(this)}
onDelete={this.onDelete.bind(this)}
type="generator"
variables={variables.en}
variables={variables[localeDefault]}
/>)
}
</div>
Expand Down Expand Up @@ -199,11 +199,11 @@ class ProfileEditor extends Component {
<GeneratorCard
key={m.id}
item={m}
locale="en"
locale={localeDefault}
onSave={this.onSave.bind(this)}
onDelete={this.onDelete.bind(this)}
type="materializer"
variables={variables.en}
variables={variables[localeDefault]}
parentArray={minData.materializers}
onMove={this.onMove.bind(this)}
/>
Expand Down Expand Up @@ -237,11 +237,11 @@ class ProfileEditor extends Component {
>
<div className="cms-card-list cms-profile-header">
<TextCard
locale="en"
locale={localeDefault}
item={minData}
fields={["title", "subtitle"]}
type="profile"
variables={variables.en}
variables={variables[localeDefault]}
/>
{locale && <TextCard
locale={locale}
Expand Down
4 changes: 3 additions & 1 deletion packages/cms/src/story/StoryBuilder.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ class StoryBuilder extends Component {
render() {

const {nodes, currentNode, nodeToDelete} = this.state;
const {locale} = this.props;
const {locale, localeDefault} = this.props;

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

Expand Down Expand Up @@ -380,12 +380,14 @@ class StoryBuilder extends Component {
? <StoryEditor
id={currentNode.data.id}
locale={locale}
localeDefault={localeDefault}
reportSave={this.reportSave.bind(this)}
/>
: currentNode.itemType === "storytopic"
? <StoryTopicEditor
id={currentNode.data.id}
locale={locale}
localeDefault={localeDefault}
reportSave={this.reportSave.bind(this)}
/>
: null
Expand Down
2 changes: 1 addition & 1 deletion packages/cms/src/story/StoryEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class StoryEditor extends Component {
render() {

const {minData, showDate} = this.state;
const {locale} = this.props;
const {locale, localeDefault} = this.props;

if (!minData) return <Loading />;

Expand Down

0 comments on commit 90b6f14

Please sign in to comment.