From 8b4c81a3b81ac0529e4027111cb6fdc02e6e6900 Mon Sep 17 00:00:00 2001 From: nchamo Date: Sat, 7 Sep 2019 12:31:27 -0300 Subject: [PATCH] Load task button only if folderUrl is set --- plugins/cloudimport/public/TaskView.jsx | 18 +++--------------- plugins/cloudimport/templates/load_buttons.js | 16 ++++++++++++---- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/plugins/cloudimport/public/TaskView.jsx b/plugins/cloudimport/public/TaskView.jsx index fbc6bbd5..d84a913a 100644 --- a/plugins/cloudimport/public/TaskView.jsx +++ b/plugins/cloudimport/public/TaskView.jsx @@ -5,25 +5,13 @@ import GoToFolderButton from "./components/GoToFolderButton"; export default class TaskView extends Component { static propTypes = { - task: PropTypes.object.isRequired, - apiURL: PropTypes.string.isRequired, - } + folderUrl: PropTypes.string.isRequired, + } - state = { - folderUrl: null, - }; - - componentDidMount() { - $.getJSON(`${this.props.apiURL}/projects/${this.props.task.project}/tasks/${this.props.task.id}/checkforurl`) - .done(data => { - this.setState({folderUrl: data.folder_url}); - }) - } - render() { const { folderUrl, - } = this.state; + } = this.props; return ( {folderUrl ? diff --git a/plugins/cloudimport/templates/load_buttons.js b/plugins/cloudimport/templates/load_buttons.js index 0d419bd1..bc1f5190 100644 --- a/plugins/cloudimport/templates/load_buttons.js +++ b/plugins/cloudimport/templates/load_buttons.js @@ -12,9 +12,17 @@ PluginsAPI.Dashboard.addNewTaskButton( PluginsAPI.Dashboard.addTaskActionButton( ["cloudimport/build/TaskView.js"], function(args, ImportView) { - return React.createElement(ImportView, { - task: args.task, - apiURL: "{{ api_url }}", - }); + $.ajax({ + url: `{{ api_url }}/projects/${args.task.project}/tasks/${args.task.id}/checkforurl`, + dataType: 'json', + async: false, + success: function(data) { + if (data.folder_url) { + return React.createElement(ImportView, { + folderUrl: data.folder_url, + }); + } + } + }); } );