Skip to content

Commit

Permalink
Remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
Etheryte committed Oct 23, 2023
1 parent 2defae3 commit d6045bf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 262 deletions.
88 changes: 14 additions & 74 deletions web/html/src/manager/visualization/hierarchy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class Hierarchy extends React.Component<Props, State> {
.data()
.map((e) => e.managed_groups || [])
.reduce((a, b) => a.concat(b));
const systemGroups = [NO_GROUP_LABEL, "foo", "bar", ...treeSystemGroups];
const systemGroups = [NO_GROUP_LABEL, ...treeSystemGroups];
this.setState({ tree, systemGroups });

d3.select(window).on("resize", function () {
Expand Down Expand Up @@ -185,72 +185,6 @@ class Hierarchy extends React.Component<Props, State> {
}
);

// TODO: Remove
// Partitioning by checkin time
function partitionByCheckin(datetime) {
tree.partitioning().get()["user-partitioning"] = (d) => {
if (DEPRECATED_unsafeEquals(d.data.checkin, undefined)) {
return "";
}
const firstPartition = d.data.checkin < datetime.getTime();
d.data.partition = firstPartition;
return firstPartition ? "stroke-red non-checking-in" : "stroke-green checking-in";
};
tree.refresh();
}
// TODO: Remove
function clearPartitioning() {
tree.partitioning().get()["user-partitioning"] = (d) => {
return "";
};
tree.refresh();
}
// TODO: Remove
UI.addCheckinTimePartitioningSelect("#partitioning-tab", partitionByCheckin, clearPartitioning);

// Partitioning by patch existence
const hasPatchesPartitioning = d3.select("#partitioning-tab").append("div").attr("class", "filter");

// TODO: Remove
hasPatchesPartitioning
.append("div")
.attr("class", "filter-title")
.text(t("Partition systems based on whether there are patches for them:"));

// TODO: Remove
function applyPatchesPartitioning() {
tree.partitioning().get()["user-partitioning"] = (d) => {
if (!Utils.isSystemType(d) || DEPRECATED_unsafeEquals(d.data.patch_counts, undefined)) {
return "";
}
const firstPartition = d.data.patch_counts.filter((pc) => pc > 0).length > 0;
d.data.partition = firstPartition;
return firstPartition ? "stroke-red unpatched" : "stroke-green patched";
};
tree.refresh();
}

const patchesPartitioningButtons = hasPatchesPartitioning.append("div").attr("class", "btn-group");
UI.addButton(patchesPartitioningButtons, "Apply", applyPatchesPartitioning);
UI.addButton(patchesPartitioningButtons, "Clear", clearPartitioning);

// TODO: Remove this
// Grouping UI (based on the preprocessor type)
if (tree.preprocessor().groupingConfiguration) {
// we have a processor responding to groupingConfiguration
UI.addGroupSelector(
d3.select("#partitioning-tab"),
tree
.data()
.map((e) => e.managed_groups || [])
.reduce((a, b) => a.concat(b)),
(data) => {
tree.preprocessor().groupingConfiguration(data);
tree.refresh();
}
);
}

this.setState({
hasGroupingFilter: !!tree.preprocessor().groupingConfiguration,
});
Expand Down Expand Up @@ -356,9 +290,7 @@ class Hierarchy extends React.Component<Props, State> {
</li>
</ul>
<div id="filtering-tab" className="filter-tab active"></div>
<div id="partitioning-tab" className="filter-tab"></div>
{/* TODO: Remove the old tab and update logic */}
<div>
<div id="partitioning-tab" className="filter-tab">
<div className="filter">
<div className="filter-title">{t("Partition systems by given check-in time:")}</div>
<div className="input-group">
Expand Down Expand Up @@ -416,12 +348,13 @@ class Hierarchy extends React.Component<Props, State> {
if (!tree) {
return;
}

const selectedSystemGroups = [...this.state.selectedSystemGroups];
selectedSystemGroups[index] = value || [];
this.setState({ selectedSystemGroups });
// TODO: Data is the new systemGroupingLevels
// tree.preprocessor().groupingConfiguration(data);
// tree.refresh();

tree.preprocessor().groupingConfiguration(selectedSystemGroups);
tree.refresh();
}}
//
/>
Expand All @@ -432,10 +365,17 @@ class Hierarchy extends React.Component<Props, State> {
className="toggle-grouping-level"
title={t("Remove this level")}
onClick={() => {
const tree = this.state.tree;
if (!tree) {
return;
}

const selectedSystemGroups = [...this.state.selectedSystemGroups];
selectedSystemGroups.splice(index, 1);
this.setState({ selectedSystemGroups });
console.log(selectedSystemGroups);

tree.preprocessor().groupingConfiguration(selectedSystemGroups);
tree.refresh();
}}
>
<i className="fa fa-close"></i>
Expand Down
189 changes: 1 addition & 188 deletions web/html/src/manager/visualization/ui/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,63 +27,6 @@ function addFilter(targetSelection, caption, placeholder, onInputCallback) {
});
}

// Add a checkin-time partitioning selector (date- and timepicker + 'Apply'
// button)
//
// params:
// - anchorId - id of element in DOM where the UI will be added
// - applyCallback - applyCallback receiving picked time and date after user clicks
// the 'Apply' button
// - clearCallback - clearCallback will be executed when the user clicks the "Clear" button
function addCheckinTimePartitioningSelect(anchorId, applyCallback, clearCallback) {
const checkinTimePartitioning = d3.select(anchorId).append("div").attr("class", "filter");

checkinTimePartitioning
.append("div")
.attr("class", "filter-title")
.text(t("Partition systems by given check-in time:"));

const inputGroup = checkinTimePartitioning.append("div").attr("class", "input-group");

inputGroup.append("input").attr("type", "text").attr("class", "partitioning-datepicker input-group-addon");

inputGroup.append("input").attr("type", "text").attr("class", "partitioning-timepicker input-group-addon");

jQuery(anchorId + " .partitioning-datepicker").datepicker({
autoclose: true,
format: "yyyy-mm-dd",
});
// TODO: If you touch this code, please use `localizedMoment()` here instead
// eslint-disable-next-line local-rules/no-raw-date
jQuery(anchorId + " .partitioning-datepicker").datepicker("setDate", new Date());
jQuery(anchorId + " .partitioning-timepicker").timepicker({ timeFormat: "H:i:s", maxTime: "23:30:00" });
// TODO: If you touch this code, please use `localizedMoment()` here instead
// eslint-disable-next-line local-rules/no-raw-date
jQuery(anchorId + " .partitioning-timepicker").timepicker("setTime", new Date());

const checkinPartitioningButtons = checkinTimePartitioning.append("div").attr("class", "btn-group");
addButton(checkinPartitioningButtons, "Apply", () => {
const date = jQuery(anchorId + " .partitioning-datepicker").datepicker("getDate");
const time = jQuery(anchorId + " .partitioning-timepicker").timepicker("getTime");
// TODO: If you touch this code, please use `localizedMoment()` here instead
// eslint-disable-next-line local-rules/no-raw-date
const datetime = new Date(
date.getFullYear(),
date.getMonth(),
date.getDate(),
time.getHours(),
time.getMinutes(),
time.getSeconds()
);
applyCallback(datetime);
});
addButton(checkinPartitioningButtons, "Clear", () => {
clearCallback();
});

return checkinTimePartitioning;
}

// Add a checkbox to given selection
//
// params:
Expand Down Expand Up @@ -112,136 +55,6 @@ function addCheckbox(targetSelection, caption, icon, classes, callback) {
.html((icon ? '<i class="fa ' + icon + '"></i>' : "") + caption);
}

// Simple JS component for selecting groups
//
// Adds an 'Add a grouping level' button, clicking on it appends a new
// multiselect box in the UI. In each of these select boxes, the user can
// specify multiple groups. Selected options are internally stored in the
// 'data' array in the format:
// [['grp1', 'grp2'], // selected groups on the 1st level
// ['grp1', 'grp2'] // selected groups on the 2nd level
// ]
//
// After a selection is changed, 'onChange' will be called with the new data as
// a parameter.
//
// In addition, each selectbox is accompanied by a 'Remove this level' button
// that deletes it from the UI, adjusts the data and fires the onChange
// callback.
//
// input
// - groups: array of possible group names (['grp1', 'grp2'])
// - element: where to hook the UI
// methods
// - onChange: setter/getter for a function that is called after a selection
// is changed or a select box on one level is collapsed
function groupSelector(groups, element) {
const NO_GROUP_LABEL = "** NO GROUP **";
const data: any[] = [];
let onChange = function (data) {
// Do nothing
};
groups = Array.from(new Set(groups));

function appendAdder() {
element
.append("a")
.attr("href", "#")
.attr("class", "toggle-grouping-level")
.text(t("Add a grouping level"))
.on("click", (d) => {
data.push([]);
update();
})
.append("i")
.attr("class", "fa fa-plus");
}

function update() {
const updateSection = element.selectAll(".grpCriterion").data(data, (d, i) => i);

updateSection.exit().remove();

const divEnter = updateSection.enter().append("div").attr("class", "grpCriterion");

const selectEnter = divEnter
.append("select")
.attr("class", "apply-select2js-on-this")
.attr("multiple", "multiple")
.attr("style", "width: 250px");

selectEnter
.selectAll("option")
.data(groups)
.enter()
.append("option")
.attr("value", (d) => d)
.text((d) => d);

selectEnter.append("option").attr("value", NO_GROUP_LABEL).text(NO_GROUP_LABEL);

//HACK: usage of JQuery here is needed to apply the select2js plugin
jQuery("select.apply-select2js-on-this").each(function (i) {
var select = jQuery(this);
// apply select2js only one time
if (!select.hasClass("select2js-applied")) {
select.addClass("select2js-applied");
var select2js = select.select2({ placeholder: t("Select a system group") });
select2js.on("change", function (event) {
data[i] = select.val() || [];
onChange(data);
});

divEnter
.append("a")
.attr("href", "#")
.attr("class", "toggle-grouping-level")
.attr("title", "Remove this level")
.on("click", function () {
data.splice(i, 1);
onChange(data);
update();
})
.append("i")
.attr("class", "fa fa-close");
} else {
// if data is changed, e.g. a level is removed,
// we need to keep aligned data and selected values
if (data[i] != null && data[i].length > 0) {
select.val(data[i]).trigger("change");
}
}
});
}

function my() {
appendAdder();
}

my.onChange = function (callback) {
return arguments.length ? ((onChange = callback), my) : onChange;
};

return my;
}

// Add a group selector (see comment for groupSelector)
//
// params:
// - targetSelection - selection where to append the element to
// - groups - all possible groups to appear in the select boxes
// - callback - function called after the state of UI changes (either user
// select a group from the selectbox or they remove the select box for a
// grouping level)
function addGroupSelector(targetSelection, groups, callback) {
const groupingDiv = targetSelection.append("div").attr("class", "filter");
groupingDiv.append("div").attr("class", "filter-title").text(t("Split into groups"));

let mySel = groupSelector(groups, groupingDiv);
mySel.onChange(callback);
mySel();
}

// Add a button with a caption
//
// params:
Expand Down Expand Up @@ -270,4 +83,4 @@ function svgTextStyle(container) {
textStyle.append("feComposite").attr("in", "SourceGraphic");
}

export { addFilter, addCheckinTimePartitioningSelect, addCheckbox, addGroupSelector, addButton, svgTextStyle };
export { addFilter, addCheckbox, addButton, svgTextStyle };

0 comments on commit d6045bf

Please sign in to comment.