2018-07-27 13:27:28 -07:00
|
|
|
import Component from '@ember/component';
|
2018-08-01 15:42:47 -07:00
|
|
|
import { get, set, computed } from '@ember/object';
|
2018-07-27 13:27:28 -07:00
|
|
|
import { task, TaskInstance } from 'ember-concurrency';
|
2018-08-01 15:42:47 -07:00
|
|
|
import ComputedProperty from '@ember/object/computed';
|
|
|
|
|
import { IChartDatum } from 'wherehows-web/typings/app/visualization/charts';
|
2018-07-27 13:27:28 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This is the container component for the dataset health tab. It should contain the health bar graphs and a table
|
|
|
|
|
* depicting the detailed health scores. Aside from fetching the data, it also handles click interactions between
|
|
|
|
|
* the graphs and the table in terms of filtering and displaying of data
|
|
|
|
|
*/
|
|
|
|
|
export default class DatasetHealthContainer extends Component {
|
|
|
|
|
/**
|
|
|
|
|
* The urn identifier for the dataset
|
|
|
|
|
* @type {string}
|
|
|
|
|
*/
|
|
|
|
|
urn: string;
|
|
|
|
|
|
2018-08-01 15:35:21 -07:00
|
|
|
/**
|
|
|
|
|
* Sets the classes for the rendered html element for the component
|
|
|
|
|
* @type {Array<string>}
|
|
|
|
|
*/
|
|
|
|
|
classNames = ['dataset-health'];
|
|
|
|
|
/**
|
|
|
|
|
* The current filter is used to set a filter for the table to show only items within a certain category or
|
|
|
|
|
* severity. It is set as a set of strings in order to support the idea of multiple filters in the future,
|
|
|
|
|
* even though our initial version will support only one filter at a time.
|
|
|
|
|
* @type {Array<string>}
|
|
|
|
|
*/
|
|
|
|
|
currentFilters: Set<string>;
|
2018-08-01 15:42:47 -07:00
|
|
|
|
2018-08-01 15:35:21 -07:00
|
|
|
constructor() {
|
|
|
|
|
super(...arguments);
|
|
|
|
|
set(this, 'currentFilters', new Set());
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-27 13:27:28 -07:00
|
|
|
didInsertElement() {
|
|
|
|
|
get(this, 'getContainerDataTask').perform();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
didUpdateAttrs() {
|
|
|
|
|
get(this, 'getContainerDataTask').perform();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* An async parent task to group all data tasks for this container component
|
|
|
|
|
* @type {Task<TaskInstance<Promise<any>>, (a?: any) => TaskInstance<TaskInstance<Promise<any>>>>}
|
|
|
|
|
*/
|
|
|
|
|
getContainerDataTask = task(function*(this: DatasetHealthContainer): IterableIterator<TaskInstance<Promise<any>>> {
|
2018-07-27 14:51:04 -07:00
|
|
|
// Do something in the future
|
2018-07-27 13:27:28 -07:00
|
|
|
});
|
2018-07-30 16:55:08 -07:00
|
|
|
|
2018-08-01 15:27:17 -07:00
|
|
|
actions = {
|
2018-08-01 15:42:47 -07:00
|
|
|
/**
|
2018-08-01 15:35:21 -07:00
|
|
|
* Triggered when the user clicks on one of the bars in the summary charts child component, will trigger
|
|
|
|
|
* a filter for whatever bar they select, unless it already is one in which case we will remove the filter
|
|
|
|
|
* @param this - Explicit this declaration for typescript
|
2018-08-01 15:42:47 -07:00
|
|
|
* @param filterDatum - Passed in to the action by the child component, contains the tag to be filtered for
|
2018-08-01 15:35:21 -07:00
|
|
|
*/
|
2018-08-01 15:42:47 -07:00
|
|
|
onFilterSelect(this: DatasetHealthContainer, filterDatum: IChartDatum): void {
|
2018-08-01 15:35:21 -07:00
|
|
|
const currentFilters = get(this, 'currentFilters');
|
2018-08-01 15:42:47 -07:00
|
|
|
const filterName = filterDatum.name;
|
|
|
|
|
|
|
|
|
|
if (currentFilters.has(filterName)) {
|
|
|
|
|
currentFilters.delete(filterName);
|
|
|
|
|
} else {
|
|
|
|
|
// This strange little logic here makes sure we have only one active filter at a time. Taking this away will
|
|
|
|
|
// essentially give us multiple filter support (if we decide to make such a UI for it)
|
|
|
|
|
currentFilters.clear();
|
|
|
|
|
currentFilters.add(filterName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.notifyPropertyChange('currentFilters');
|
2018-08-01 15:27:17 -07:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2018-07-30 16:55:08 -07:00
|
|
|
// Mock data for testing demo purposes, to be deleted once we have actual data and further development
|
|
|
|
|
testSeries = [{ name: 'Test1', value: 10 }, { name: 'Test2', value: 5 }, { name: 'Test3', value: 3 }];
|
2018-08-01 15:42:47 -07:00
|
|
|
fakeCategories: ComputedProperty<Array<IChartDatum>> = computed('currentFilters', function(
|
|
|
|
|
this: DatasetHealthContainer
|
|
|
|
|
): Array<IChartDatum> {
|
|
|
|
|
const baseCategories = [{ name: 'Compliance', value: 60 }, { name: 'Ownership', value: 40 }];
|
|
|
|
|
const currentFilters = get(this, 'currentFilters');
|
|
|
|
|
const hasFilters = Array.from(currentFilters).length > 0;
|
|
|
|
|
|
|
|
|
|
return baseCategories.map(datum => ({ ...datum, isFaded: hasFilters && !currentFilters.has(datum.name) }));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
fakeSeverity: ComputedProperty<Array<IChartDatum>> = computed('currentFilters', function(
|
|
|
|
|
this: DatasetHealthContainer
|
|
|
|
|
): Array<IChartDatum> {
|
|
|
|
|
const baseSeverities = [
|
|
|
|
|
{ name: 'Minor', value: 50, customColorClass: 'severity-chart__bar--minor' },
|
|
|
|
|
{ name: 'Warning', value: 30, customColorClass: 'severity-chart__bar--warning' },
|
|
|
|
|
{ name: 'Critical', value: 25, customColorClass: 'severity-chart__bar--critical' }
|
|
|
|
|
];
|
|
|
|
|
const currentFilters = get(this, 'currentFilters');
|
|
|
|
|
const hasFilters = Array.from(currentFilters).length > 0;
|
|
|
|
|
|
|
|
|
|
return baseSeverities.map(datum => ({ ...datum, isFaded: hasFilters && !currentFilters.has(datum.name) }));
|
|
|
|
|
});
|
2018-07-27 13:27:28 -07:00
|
|
|
}
|