Sha256: 09722717f5ba3b75eea44c987ba7243bc4f65d377c9854fd6753cf0bac91c5de

Contents?: true

Size: 1.54 KB

Versions: 91

Compression:

Stored size: 1.54 KB

Contents

import React from 'react';
import PropTypes from 'prop-types';
import { Row, Button, Label } from 'patternfly-react';
import { noop } from 'foremanReact/common/helpers';
import { translate as __ } from 'foremanReact/common/I18n';

import { getQueryKeyText, getQueryValueText } from '../../TasksDashboardHelper';
import { queryPropType } from '../../TasksDashboardPropTypes';
import './TasksLabelsRow.scss';

const TasksLabelsRow = ({ query, updateQuery }) => {
  const onDeleteClick = keyToDelete => {
    const { [keyToDelete]: deleted, ...queryWithoutDeleted } = query;
    updateQuery(queryWithoutDeleted);
  };

  const getLabelText = (key, value) => {
    const translatedKey = getQueryKeyText(key);
    const translatedValue = getQueryValueText(value);

    return `${translatedKey} = ${translatedValue}`;
  };

  const queryEntries = Object.entries(query);

  return (
    <Row className="tasks-labels-row">
      <span className="title">{__('Active Filters:')}</span>
      {queryEntries.map(([key, value]) => (
        <Label
          bsStyle="info"
          key={key}
          onRemoveClick={() => onDeleteClick(key)}
        >
          {getLabelText(key, value)}
        </Label>
      ))}
      {queryEntries.length > 0 && (
        <Button bsStyle="link" onClick={() => updateQuery({})}>
          {__('Clear All Filters')}
        </Button>
      )}
    </Row>
  );
};

TasksLabelsRow.propTypes = {
  query: queryPropType,
  updateQuery: PropTypes.func,
};

TasksLabelsRow.defaultProps = {
  query: {},
  updateQuery: noop,
};

export default TasksLabelsRow;

Version data entries

91 entries across 91 versions & 1 rubygems

Version Path
foreman-tasks-8.1.2 webpack/ForemanTasks/Components/TasksDashboard/Components/TasksLabelsRow/TasksLabelsRow.js
foreman-tasks-8.1.1 webpack/ForemanTasks/Components/TasksDashboard/Components/TasksLabelsRow/TasksLabelsRow.js
foreman-tasks-8.1.0 webpack/ForemanTasks/Components/TasksDashboard/Components/TasksLabelsRow/TasksLabelsRow.js
foreman-tasks-8.0.2 webpack/ForemanTasks/Components/TasksDashboard/Components/TasksLabelsRow/TasksLabelsRow.js
foreman-tasks-8.0.1 webpack/ForemanTasks/Components/TasksDashboard/Components/TasksLabelsRow/TasksLabelsRow.js
foreman-tasks-8.0.0 webpack/ForemanTasks/Components/TasksDashboard/Components/TasksLabelsRow/TasksLabelsRow.js
foreman-tasks-7.2.1 webpack/ForemanTasks/Components/TasksDashboard/Components/TasksLabelsRow/TasksLabelsRow.js
foreman-tasks-7.1.1 webpack/ForemanTasks/Components/TasksDashboard/Components/TasksLabelsRow/TasksLabelsRow.js
foreman-tasks-7.2.0 webpack/ForemanTasks/Components/TasksDashboard/Components/TasksLabelsRow/TasksLabelsRow.js
foreman-tasks-7.1.0 webpack/ForemanTasks/Components/TasksDashboard/Components/TasksLabelsRow/TasksLabelsRow.js
foreman-tasks-6.0.3 webpack/ForemanTasks/Components/TasksDashboard/Components/TasksLabelsRow/TasksLabelsRow.js
foreman-tasks-7.0.0 webpack/ForemanTasks/Components/TasksDashboard/Components/TasksLabelsRow/TasksLabelsRow.js
foreman-tasks-6.0.2 webpack/ForemanTasks/Components/TasksDashboard/Components/TasksLabelsRow/TasksLabelsRow.js
foreman-tasks-4.1.6 webpack/ForemanTasks/Components/TasksDashboard/Components/TasksLabelsRow/TasksLabelsRow.js
foreman-tasks-5.2.3 webpack/ForemanTasks/Components/TasksDashboard/Components/TasksLabelsRow/TasksLabelsRow.js
foreman-tasks-6.0.1 webpack/ForemanTasks/Components/TasksDashboard/Components/TasksLabelsRow/TasksLabelsRow.js
foreman-tasks-5.2.2 webpack/ForemanTasks/Components/TasksDashboard/Components/TasksLabelsRow/TasksLabelsRow.js
foreman-tasks-6.0.0 webpack/ForemanTasks/Components/TasksDashboard/Components/TasksLabelsRow/TasksLabelsRow.js
foreman-tasks-5.2.1 webpack/ForemanTasks/Components/TasksDashboard/Components/TasksLabelsRow/TasksLabelsRow.js
foreman-tasks-5.3.0 webpack/ForemanTasks/Components/TasksDashboard/Components/TasksLabelsRow/TasksLabelsRow.js