From e0d68dc1901bc8e521deb66af9e5524b8fc736c7 Mon Sep 17 00:00:00 2001 From: Stephanie Marker Date: Thu, 1 Mar 2018 11:07:43 -0500 Subject: [PATCH] Fix trusted sources mutation. (#42) --- .../src/components/Admin/TrustedSources.js | 32 +++++++------------ .../src/resolvers/Settings/mutations.js | 2 +- 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/project-fortis-interfaces/src/components/Admin/TrustedSources.js b/project-fortis-interfaces/src/components/Admin/TrustedSources.js index 81a7a5e1..89f33f2c 100644 --- a/project-fortis-interfaces/src/components/Admin/TrustedSources.js +++ b/project-fortis-interfaces/src/components/Admin/TrustedSources.js @@ -8,48 +8,38 @@ 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: , formatter: }, + {key: "pipelinekey", name: "Pipeline Key", editor: , formatter: }, {editable: true, filterable: true, sortable: true, key: "externalsourceid", name: "External Source Id"}, {editable: true, filterable: true, sortable: true, key: "displayname", name: "Name"}, ]; @@ -57,7 +47,7 @@ class TrustedSources extends React.Component { return getColumns(columnValues); } - getEnabledStreamsForDropdown = () => { + getStreamsForDropdown = () => { let dropdownOptions = []; this.props.enabledStreams.forEach((value, key) => { dropdownOptions.push({ @@ -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 { @@ -79,7 +69,7 @@ class TrustedSources extends React.Component { }; } - getDefaultLanguage() { + getDefaultLanguage = () => { return this.props.settings.properties.defaultLanguage; } diff --git a/project-fortis-services/src/resolvers/Settings/mutations.js b/project-fortis-services/src/resolvers/Settings/mutations.js index bdd7f5b5..9ade6d51 100644 --- a/project-fortis-services/src/resolvers/Settings/mutations.js +++ b/project-fortis-services/src/resolvers/Settings/mutations.js @@ -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,