Skip to content

Commit

Permalink
Refs #30633 - make other stopped clickable
Browse files Browse the repository at this point in the history
  • Loading branch information
MariaAga committed Aug 19, 2020
1 parent d3f07a6 commit 7f73ab6
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 44 deletions.
6 changes: 5 additions & 1 deletion app/services/foreman_tasks/dashboard_table_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ def scope
private

def scope_by(field)
@new_scope = @new_scope.where(field => @params[field]) if @params[field].present?
if (field == :result) && (@params[field] == 'other')
@new_scope = @new_scope.where(:result => ['cancelled', 'pending'])
elsif @params[field].present?
@new_scope = @new_scope.where(field => @params[field])
end
end

def scope_by_time
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Card } from 'patternfly-react';
import { Card, Button } from 'patternfly-react';
import classNames from 'classnames';
import { noop } from 'foremanReact/common/helpers';
import { translate as __ } from 'foremanReact/common/I18n';
Expand All @@ -13,6 +13,7 @@ import {
import {
TASKS_DASHBOARD_AVAILABLE_TIMES,
TASKS_DASHBOARD_AVAILABLE_QUERY_STATES,
TASKS_DASHBOARD_AVAILABLE_QUERY_RESULTS,
} from '../../../../TasksDashboardConstants';
import { getQueryValueText } from '../../../../TasksDashboardHelper';
import './StoppedTasksCard.scss';
Expand Down Expand Up @@ -57,10 +58,20 @@ const StoppedTasksCard = ({
</thead>
<tbody>{StoppedTable(data, query, time, updateQuery)}</tbody>
</table>
<React.Fragment>
<span>
<OtherInfo />
{otherCount}
</React.Fragment>
<Button
bsStyle="link"
onClick={() =>
updateQuery({
state: TASKS_DASHBOARD_AVAILABLE_QUERY_STATES.STOPPED,
result: TASKS_DASHBOARD_AVAILABLE_QUERY_RESULTS.OTHER,
})
}
>
{otherCount}
</Button>
</span>
</React.Fragment>
</Card.Body>
</Card>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,25 @@ const fixtures = {
},
};

Object.values(TASKS_DASHBOARD_AVAILABLE_QUERY_RESULTS).forEach(result => {
fixtures[`render ${result}-total selected`] = {
query: {
state: STOPPED,
result,
},
};
fixtures[`render ${result}-last selected`] = {
time: WEEK,
query: {
state: STOPPED,
result,
mode: LAST,
Object.values(TASKS_DASHBOARD_AVAILABLE_QUERY_RESULTS)
.filter(result => result !== TASKS_DASHBOARD_AVAILABLE_QUERY_RESULTS.OTHER)
.forEach(result => {
fixtures[`render ${result}-total selected`] = {
query: {
state: STOPPED,
result,
},
};
fixtures[`render ${result}-last selected`] = {
time: WEEK,
},
};
});
query: {
state: STOPPED,
result,
mode: LAST,
time: WEEK,
},
};
});

describe('StoppedTasksCard', () =>
testComponentSnapshotsWithFixtures(StoppedTasksCard, fixtures));
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,19 @@ exports[`StoppedTasksCard render error-last selected 1`] = `
</tr>
</tbody>
</table>
<OtherInfo />
0
<span>
<OtherInfo />
<Button
active={false}
block={false}
bsClass="btn"
bsStyle="link"
disabled={false}
onClick={[Function]}
>
0
</Button>
</span>
</CardBody>
</Card>
`;
Expand Down Expand Up @@ -312,8 +323,19 @@ exports[`StoppedTasksCard render error-total selected 1`] = `
</tr>
</tbody>
</table>
<OtherInfo />
0
<span>
<OtherInfo />
<Button
active={false}
block={false}
bsClass="btn"
bsStyle="link"
disabled={false}
onClick={[Function]}
>
0
</Button>
</span>
</CardBody>
</Card>
`;
Expand Down Expand Up @@ -471,8 +493,19 @@ exports[`StoppedTasksCard render selected 1`] = `
</tr>
</tbody>
</table>
<OtherInfo />
0
<span>
<OtherInfo />
<Button
active={false}
block={false}
bsClass="btn"
bsStyle="link"
disabled={false}
onClick={[Function]}
>
0
</Button>
</span>
</CardBody>
</Card>
`;
Expand Down Expand Up @@ -630,8 +663,19 @@ exports[`StoppedTasksCard render success-last selected 1`] = `
</tr>
</tbody>
</table>
<OtherInfo />
0
<span>
<OtherInfo />
<Button
active={false}
block={false}
bsClass="btn"
bsStyle="link"
disabled={false}
onClick={[Function]}
>
0
</Button>
</span>
</CardBody>
</Card>
`;
Expand Down Expand Up @@ -789,8 +833,19 @@ exports[`StoppedTasksCard render success-total selected 1`] = `
</tr>
</tbody>
</table>
<OtherInfo />
0
<span>
<OtherInfo />
<Button
active={false}
block={false}
bsClass="btn"
bsStyle="link"
disabled={false}
onClick={[Function]}
>
0
</Button>
</span>
</CardBody>
</Card>
`;
Expand Down Expand Up @@ -948,8 +1003,19 @@ exports[`StoppedTasksCard render warning-last selected 1`] = `
</tr>
</tbody>
</table>
<OtherInfo />
0
<span>
<OtherInfo />
<Button
active={false}
block={false}
bsClass="btn"
bsStyle="link"
disabled={false}
onClick={[Function]}
>
0
</Button>
</span>
</CardBody>
</Card>
`;
Expand Down Expand Up @@ -1107,8 +1173,19 @@ exports[`StoppedTasksCard render warning-total selected 1`] = `
</tr>
</tbody>
</table>
<OtherInfo />
0
<span>
<OtherInfo />
<Button
active={false}
block={false}
bsClass="btn"
bsStyle="link"
disabled={false}
onClick={[Function]}
>
0
</Button>
</span>
</CardBody>
</Card>
`;
Expand Down Expand Up @@ -1266,8 +1343,19 @@ exports[`StoppedTasksCard render with minimal props 1`] = `
</tr>
</tbody>
</table>
<OtherInfo />
0
<span>
<OtherInfo />
<Button
active={false}
block={false}
bsClass="btn"
bsStyle="link"
disabled={false}
onClick={[Function]}
>
0
</Button>
</span>
</CardBody>
</Card>
`;
Expand Down Expand Up @@ -1425,8 +1513,19 @@ exports[`StoppedTasksCard render with props 1`] = `
</tr>
</tbody>
</table>
<OtherInfo />
4
<span>
<OtherInfo />
<Button
active={false}
block={false}
bsClass="btn"
bsStyle="link"
disabled={false}
onClick={[Function]}
>
4
</Button>
</span>
</CardBody>
</Card>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const TASKS_DASHBOARD_AVAILABLE_QUERY_RESULTS = {
ERROR: 'error',
WARNING: 'warning',
SUCCESS: 'success',
OTHER: 'other',
};

export const TASKS_DASHBOARD_AVAILABLE_QUERY_MODES = {
Expand Down Expand Up @@ -44,6 +45,7 @@ export const TASKS_DASHBOARD_QUERY_VALUES_TEXT = {
[TASKS_DASHBOARD_AVAILABLE_QUERY_RESULTS.ERROR]: __('error'),
[TASKS_DASHBOARD_AVAILABLE_QUERY_RESULTS.WARNING]: __('warning'),
[TASKS_DASHBOARD_AVAILABLE_QUERY_RESULTS.SUCCESS]: __('success'),
[TASKS_DASHBOARD_AVAILABLE_QUERY_RESULTS.OTHER]: __('other'),
[TASKS_DASHBOARD_AVAILABLE_QUERY_MODES.LAST]: __('last'),
[TASKS_DASHBOARD_AVAILABLE_QUERY_MODES.OLDER]: __('older'),
[TASKS_DASHBOARD_AVAILABLE_TIMES.H24]: __('24h'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ export const selectTime = state =>
export const selectQuery = state => selectTasksDashboard(state).query || {};

export const calcStoppedOther = data =>
(data?.cancelled?.recent || 0) +
(data?.cancelled?.total || 0) +
(data?.pedning?.recent || 0) +
(data?.pedning?.total || 0);
(data?.cancelled?.total || 0) + (data?.pending?.total || 0);

export const selectTasksSummary = state => {
const { running, paused, stopped, scheduled } =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ const state = {
total: 7,
recent: 3,
},
cancelled: {
total: 5,
recent: 3,
},
pending: {
total: 11,
recent: 4,
},
},
},
scheduled: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,18 @@ Object {
},
"stopped": Object {
"by_result": Object {
"cancelled": Object {
"recent": 3,
"total": 5,
},
"error": Object {
"recent": 1,
"total": 9,
},
"pending": Object {
"recent": 4,
"total": 11,
},
"success": Object {
"recent": 3,
"total": 7,
Expand Down Expand Up @@ -58,7 +66,7 @@ Object {
"last": 1,
"total": 9,
},
"other": 0,
"other": 16,
"success": Object {
"last": 3,
"total": 7,
Expand Down

0 comments on commit 7f73ab6

Please sign in to comment.