Skip to content

Commit

Permalink
Convert dashboard to functional (#534)
Browse files Browse the repository at this point in the history
* Convert Dashboard to functional component

it would be shorter to list what didn't change.

Everything changes?

useEffect replacing compnentDidMount
No more weird handling of filter values, let API filtering do it's job
Cleaned up small behaviors around button enabling

State use makes way more sense now

dashboard_id is sanely synced when direct navigation via URL

don't wait for promise repsonse to set modal open state
  • Loading branch information
mshriver authored Jan 9, 2025
1 parent 7214327 commit 326b0cc
Show file tree
Hide file tree
Showing 8 changed files with 451 additions and 579 deletions.
4 changes: 2 additions & 2 deletions frontend/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ const compat = new FlatCompat({

export default [
{
files: ['src/*', 'cypress/*'],
ignores: ['node_modules/*'],
files: ['src/*', 'cypress/*', 'bin/*'],
ignores: ['node_modules/*', 'build/*'],
},
...compat.extends(
'eslint:recommended',
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import ElementWrapper from './components/elementWrapper';

import { Navigate, Route, Routes } from 'react-router-dom';

import { Dashboard } from './dashboard';
import Dashboard from './dashboard';
import { ReportBuilder } from './report-builder';
import { RunList } from './run-list';
import { Run } from './run';
Expand Down Expand Up @@ -48,12 +48,12 @@ export class App extends React.Component {
<Route
path="dashboard/:dashboard_id"
element={
<ElementWrapper routeElement={Dashboard} eventEmitter={this.eventEmitter} />
<Dashboard />
}
/>
<Route
path="dashboard/*"
element={<ElementWrapper routeElement={Dashboard} eventEmitter={this.eventEmitter} />}
element={<Dashboard />}
/>


Expand Down
13 changes: 10 additions & 3 deletions frontend/src/components/ibutsu-header.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,12 @@ export class IbutsuHeader extends React.Component {
}

onProjectSelect = (_event, value) => {
const { primaryObject, setPrimaryObject, setPrimaryType } = this.context;
const {
primaryObject,
setPrimaryObject,
setPrimaryType,
setDefaultDashboard,
} = this.context;
if (primaryObject?.id === value?.id) {
this.setState({
isProjectSelectorOpen: false,
Expand All @@ -227,8 +232,10 @@ export class IbutsuHeader extends React.Component {
return;
}
// update context
setPrimaryObject(value)
setPrimaryType('project')
setPrimaryObject(value);
setPrimaryType('project');
setDefaultDashboard(value.default_dashboard_id);

// update state
this.setState({
selectedProject: value,
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const IbutsuSidebar = (props) => {
});
setViews(data.widgets)})
.catch(error => console.log(error));
}
}

const { primaryType, primaryObject } = context;
if ( primaryType == 'project' && primaryObject ) {
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/components/user-dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ export class UserDropdown extends React.Component {
};

logout = () => {
const { setPrimaryObject, setActiveDashboard } = this.context;
const { setPrimaryObject } = this.context;
setPrimaryObject();
setActiveDashboard();
AuthService.logout();
window.location = '/';
}
Expand Down
Loading

0 comments on commit 326b0cc

Please sign in to comment.