Skip to content

Commit

Permalink
updates selectorusage to work with stories
Browse files Browse the repository at this point in the history
  • Loading branch information
jhmullen committed Oct 11, 2021
1 parent ee52abd commit a683573
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 18 deletions.
2 changes: 1 addition & 1 deletion packages/cms/src/api/cmsRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ const sortStorySection = (db, storysection) => {
storysection.stats = flatSort(db.storysection_stat, storysection.stats);
storysection.descriptions = flatSort(db.storysection_description, storysection.descriptions);
// ordering is nested in section_selector - bubble for top-level sorting
storysection.selectors = bubbleSortSelectors(db.storysection_selector, storysection.selectors);
storysection.selectors = bubbleSortSelectors(db.storysection_selector, storysection.selectors, "storysection_selector");
return storysection;
};

Expand Down
37 changes: 26 additions & 11 deletions packages/cms/src/components/interface/SelectorUsage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import scaffoldDynamic from "../../utils/selectors/scaffoldDynamic";
import {newEntity, deleteEntity, swapEntity} from "../../actions/profiles";
import {setStatus} from "../../actions/status";

import {SELECTOR_TYPES} from "../../utils/consts/cms";

import "./SelectorUsage.css";

class SelectorUsage extends Component {
Expand All @@ -22,13 +24,19 @@ class SelectorUsage extends Component {
}

removeItem(id) {
const {minData} = this.props;
this.props.deleteEntity("section_selector", {section_id: minData.id, selector_id: id});
const {minData, type} = this.props;
const payload = type === SELECTOR_TYPES.STORYSECTION_SELECTOR
? {storysection_id: minData.id, story_selector_id: id}
: {section_id: minData.id, selector_id: id};
this.props.deleteEntity(type, payload);
}

addItem(id) {
const {minData} = this.props;
this.props.newEntity("section_selector", {section_id: minData.id, selector_id: id});
const {minData, type} = this.props;
const payload = type === SELECTOR_TYPES.STORYSECTION_SELECTOR
? {storysection_id: minData.id, story_selector_id: id}
: {section_id: minData.id, selector_id: id};
this.props.newEntity(type, payload);
}

onChange(name, e) {
Expand All @@ -40,7 +48,8 @@ class SelectorUsage extends Component {
}

swapSelector(id) {
this.props.swapEntity("section_selector", id);
const {type} = this.props;
this.props.swapEntity(type, id);
}

render() {
Expand All @@ -59,7 +68,7 @@ class SelectorUsage extends Component {
if (selector.dynamic) {
if (validateDynamic(variables[selector.dynamic]) === "valid") {
return {...selector, options: scaffoldDynamic(variables[selector.dynamic])};
}
}
else return {...selector, options: []};
}
else return selector;
Expand Down Expand Up @@ -103,12 +112,12 @@ class SelectorUsage extends Component {
</ul>
: <p className="u-font-xs">All available selectors have been activated</p>
}
{(showMore || inactiveSelectors.length > inactiveSelectorsVisible.length) &&
<Button
{(showMore || inactiveSelectors.length > inactiveSelectorsVisible.length) &&
<Button
fontSize="xxs"
onClick={() => this.setState({showMore: !this.state.showMore})}
>
{showMore ? "Hide Full List" : "Show Full List..."}
{showMore ? "Hide Full List" : "Show Full List..."}
</Button>
}
</div>
Expand Down Expand Up @@ -184,10 +193,16 @@ class SelectorUsage extends Component {
}
}

const mapStateToProps = state => ({
SelectorUsage.defaultProps = {
type: SELECTOR_TYPES.SECTION_SELECTOR
};

const mapStateToProps = (state, ownProps) => ({
variables: state.cms.variables,
status: state.cms.status,
allSelectors: state.cms.profiles.find(p => p.id === state.cms.status.currentPid).selectors
allSelectors: ownProps.type === SELECTOR_TYPES.STORYSECTION_SELECTOR
? state.cms.stories.find(p => p.id === state.cms.status.currentStoryPid).selectors
: state.cms.profiles.find(p => p.id === state.cms.status.currentPid).selectors
});

const mapDispatchToProps = dispatch => ({
Expand Down
4 changes: 2 additions & 2 deletions packages/cms/src/db/section.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = function(sequelize, db) {
type: {
type: db.STRING,
defaultValue: "TextViz"
},
},
ordering: db.INTEGER,
allowed: {
type: db.STRING,
Expand All @@ -36,7 +36,7 @@ module.exports = function(sequelize, db) {
type: db.STRING,
defaultValue: ""
}
},
},
{
tableName: "canon_cms_section",
freezeTableName: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/cms/src/db/storysection_selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = function(sequelize, db) {
primaryKey: true,
autoIncrement: true
},
section_id: {
storysection_id: {
type: db.INTEGER,
onDelete: "cascade",
references: {
Expand Down
5 changes: 4 additions & 1 deletion packages/cms/src/profile/SectionEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import ProfileRenderer from "../components/ProfileRenderer.jsx";
import {newEntity, updateEntity} from "../actions/profiles";
import {setStatus} from "../actions/status";

import {PARENT_TYPES, SELECTOR_TYPES} from "../utils/consts/cms";

import "./SectionEditor.css";

const buttonGroupProps = {
Expand Down Expand Up @@ -269,7 +271,7 @@ class SectionEditor extends Component {
key={s.id}
minData={s}
fields={["subtitle"]}
type="section_subtitle"
type={"section_subtitle"}
showReorderButton={minData.subtitles[minData.subtitles.length - 1].id !== s.id}
/>
)}
Expand All @@ -280,6 +282,7 @@ class SectionEditor extends Component {
<Deck title="Selector activation" entity="selectorUsage">
<SelectorUsage
key="selector-usage"
type={SELECTOR_TYPES.SECTION_SELECTOR}
minData={minData}
/>
</Deck>
Expand Down
1 change: 1 addition & 0 deletions packages/cms/src/story/StorySectionEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Deck from "../components/interface/Deck";
import TextCard from "../components/cards/TextCard";
import Loading from "components/Loading";
import VisualizationCard from "../components/cards/VisualizationCard";
import SelectorUsage from "../components/interface/SelectorUsage";
import deepClone from "../utils/deepClone";

import {newEntity, updateEntity} from "../actions/profiles";
Expand Down
6 changes: 6 additions & 0 deletions packages/cms/src/utils/consts/cms.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,11 @@ module.exports = {
MATERIALIZER: "materializer",
STORY_GENERATOR: "story_generator",
STORY_MATERIALIZER: "story_materializer"
},

SELECTOR_TYPES: {
SECTION_SELECTOR: "section_selector",
STORYSECTION_SELECTOR: "storysection_selector"
}

};
6 changes: 4 additions & 2 deletions packages/cms/src/utils/sequelize/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ const storyReqFull = {
{association: "subtitles", include: [{association: "content", separate: true}], separate: true},
{association: "descriptions", include: [{association: "content", separate: true}], separate: true},
{association: "stats", include: [{association: "content", separate: true}], separate: true},
{association: "visualizations", separate: true}
{association: "visualizations", separate: true},
{association: "selectors"}
]
}
]
Expand All @@ -63,7 +64,8 @@ const storysectionReqFull = {
{association: "subtitles", include: [{association: "content", separate: true}], separate: true},
{association: "descriptions", include: [{association: "content", separate: true}], separate: true},
{association: "stats", include: [{association: "content", separate: true}], separate: true},
{association: "visualizations", separate: true}
{association: "visualizations", separate: true},
{association: "selectors"}
]
};

Expand Down

0 comments on commit a683573

Please sign in to comment.