Skip to content

Commit

Permalink
Fix trusted sources mutation. (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
Smarker authored and c-w committed Mar 1, 2018
1 parent b3aeb64 commit e0d68dc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 22 deletions.
32 changes: 11 additions & 21 deletions project-fortis-interfaces/src/components/Admin/TrustedSources.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,56 +8,46 @@ const { DropDownFormatter } = Formatters;
const TRANSLATED_NAME = "translatedname";

class TrustedSources extends React.Component {
constructor(props) {
super(props);

this.getEnabledStreamsForDropdown = this.getEnabledStreamsForDropdown.bind(this);
this.getTrustedSourcesColumns = this.getTrustedSourcesColumns.bind(this);
this.getTranslatableFields = this.getTranslatableFields.bind(this);
this.handleSave = this.handleSave.bind(this);
this.handleRemove = this.handleRemove.bind(this);
}

componentDidMount() {
this.props.flux.actions.ADMIN.notifyDataGridTrustedSourcesLoaded();
}

handleSave(rows) {
handleSave = rows => {
rows.forEach(row => row.rowKey = this.getRowKey(row));
this.props.flux.actions.ADMIN.save_trusted_sources(rows);
}

getRowKey(row) {
getRowKey = row => {
return `${row.pipelinekey},${row.externalsourceid}`;
}

handleRemove(rows) {
handleRemove = rows => {
const sourcesWithAllFieldsSet = this.filterSourcesWithUnsetFields(rows);
if (this.trustedSourcesToRemoveExist(sourcesWithAllFieldsSet)) {
this.props.flux.actions.ADMIN.remove_trusted_sources(sourcesWithAllFieldsSet);
}
}

filterSourcesWithUnsetFields(sources) {
filterSourcesWithUnsetFields = sources => {
return sources.filter(source => source.pipelinekey.length > 0 || source.externalsourceid.length > 0)
}

trustedSourcesToRemoveExist(sources) {
trustedSourcesToRemoveExist = sources => {
return sources.length > 0;
}

getTrustedSourcesColumns() {
const enabledStreams = this.getEnabledStreamsForDropdown();
getTrustedSourcesColumns = () => {
const streams = this.getStreamsForDropdown();
const columnValues = [
{key: "pipelinekey", name: "Pipeline Key", editor: <DropDownEditor options={enabledStreams}/>, formatter: <DropDownFormatter options={enabledStreams} value='Facebook'/>},
{key: "pipelinekey", name: "Pipeline Key", editor: <DropDownEditor options={streams}/>, formatter: <DropDownFormatter options={streams} value='Facebook'/>},
{editable: true, filterable: true, sortable: true, key: "externalsourceid", name: "External Source Id"},
{editable: true, filterable: true, sortable: true, key: "displayname", name: "Name"},
];

return getColumns(columnValues);
}

getEnabledStreamsForDropdown = () => {
getStreamsForDropdown = () => {
let dropdownOptions = [];
this.props.enabledStreams.forEach((value, key) => {
dropdownOptions.push({
Expand All @@ -70,7 +60,7 @@ class TrustedSources extends React.Component {
return dropdownOptions;
}

getTranslatableFields() {
getTranslatableFields = () => {
const defaultLanguage = this.getDefaultLanguage();
const alternateLanguage = this.props.settings.properties.supportedLanguages.find(supportedLanguage => supportedLanguage !== defaultLanguage);
return {
Expand All @@ -79,7 +69,7 @@ class TrustedSources extends React.Component {
};
}

getDefaultLanguage() {
getDefaultLanguage = () => {
return this.props.settings.properties.defaultLanguage;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ function addTrustedSources(args, res) { // eslint-disable-line no-unused-vars
externalsourceid,
displayname,
insertiontime
) VALUES (?,?,?,?,?,dateof(now()),?)`,
) VALUES (?,?,?,dateof(now()))`,
params: [
source.pipelinekey,
source.externalsourceid,
Expand Down

0 comments on commit e0d68dc

Please sign in to comment.