From a751f838218774f95a40d39007dd88180d680356 Mon Sep 17 00:00:00 2001 From: ay-bh Date: Tue, 29 Oct 2024 17:39:42 -0400 Subject: [PATCH] Convert Issue Tracker toggle to tabs with permission control --- .../issue_tracker/jsx/issueTrackerIndex.js | 71 +++++++++++++------ 1 file changed, 49 insertions(+), 22 deletions(-) diff --git a/modules/issue_tracker/jsx/issueTrackerIndex.js b/modules/issue_tracker/jsx/issueTrackerIndex.js index 80baf03d9c1..7557e658d63 100644 --- a/modules/issue_tracker/jsx/issueTrackerIndex.js +++ b/modules/issue_tracker/jsx/issueTrackerIndex.js @@ -1,6 +1,7 @@ import {createRoot} from 'react-dom/client'; import React, {Component} from 'react'; import PropTypes from 'prop-types'; +import {Tabs, TabPane} from 'Tabs'; import Loader from 'Loader'; import FilterableDataTable from 'FilterableDataTable'; @@ -21,12 +22,12 @@ class IssueTrackerIndex extends Component { data: {}, error: false, isLoaded: false, - view: 'normal', // 'normal' for FilterableDataTable, 'batch' for IssueTrackerBatchMode + activeTab: 'browse', }; this.fetchData = this.fetchData.bind(this); this.formatColumn = this.formatColumn.bind(this); - this.toggleView = this.toggleView.bind(this); + this.handleTabChange = this.handleTabChange.bind(this); } /** @@ -37,6 +38,21 @@ class IssueTrackerIndex extends Component { .then(() => this.setState({isLoaded: true})); } + /** + * Called by React when the component updates. + * @param {object} prevProps - Previous props + * @param {object} prevState - Previous state + */ + componentDidUpdate(prevProps, prevState) { + // If the activeTab has changed to 'browse', refetch data + if (prevState.activeTab !== 'browse' && this.state.activeTab === 'browse') { + this.setState({isLoaded: false}, () => { + this.fetchData() + .then(() => this.setState({isLoaded: true})); + }); + } + } + /** * Retrieve data from the provided URL and save it in state * Additionally add hiddenHeaders to global loris variable @@ -55,13 +71,12 @@ class IssueTrackerIndex extends Component { } /** - * Toggle between normal and batch mode + * Handle tab changes + * + * @param {string} newTab - The ID of the newly selected tab */ - toggleView() { - this.setState((prevState) => ({ - view: prevState.view === 'normal' ? 'batch' : 'normal', - })); - this.fetchData(); // Fetch fresh data when toggling views + handleTabChange(newTab) { + this.setState({activeTab: newTab}); } /** @@ -275,18 +290,29 @@ class IssueTrackerIndex extends Component { {label: 'New Issue', action: addIssue}, ]; + const tabList = [ + { + id: 'browse', + label: 'Browse Issues', + }, + ]; + + // Only display the Batch mode tab if user has the required permission + if (this.props.hasPermission('issue_tracker_developer')) { + tabList.push({ + id: 'batch', + label: 'Batch Edit', + }); + } + return ( -
-
- -
- {this.state.view === 'normal' ? ( + + - ) : ( + + - )} -
+ + ); } }