Commit 609a22b1 authored by Nicolas Chauvat's avatar Nicolas Chauvat
Browse files

Refactor the display of "evaluated views" in sidebar

parent 801bf0255517
......@@ -19,7 +19,7 @@
******************************************************************************/
import React = require("react");
import { application, definition } from "@logilab/libview";
import { application, definition, implementation } from "@logilab/libview";
import { ResourceData } from "../data";
export interface CurrentTabViewsProps {
......@@ -29,12 +29,40 @@ export interface CurrentTabViewsProps {
onClickBack: () => void;
}
const RenderingEvaluationComponent = (props: application.RenderingEvaluation) =>
<div key={"evaluation-" + "0"} className="row">
<div className="col-12">
<span
title="Priority for this view"
className= {
props.priority === implementation.VIEW_PRIORITY_INAPPROPRIATE
? "badge badge-warning"
: "badge badge-primary"
}
style={{ marginRight: "5pt" }}
>
{props.priority === implementation.VIEW_PRIORITY_INAPPROPRIATE
? "disabled" : props.priority}
</span>
<span>{props.viewId}</span>
</div>
</div>;
export class CurrentTabViews extends React.Component<CurrentTabViewsProps, {}> {
constructor(props: CurrentTabViewsProps) {
super(props);
}
render() {
if (this.props.data.rendering === null) {
return <span>not data to render</span>;
}
/* const validViews = this.props.data.rendering.evaluations.filter(
(evaluation: application.RenderingEvaluation) =>
evaluation.viewId in this.props.registry.descriptors);
const disabledViewIds = Object.keys(this.props.registry.descriptors).filter(
(viewId: string) => !(viewId in validViews));
*/
return (
<div className="container-fluid">
{this.props.displayBack ? (
......@@ -63,61 +91,9 @@ export class CurrentTabViews extends React.Component<CurrentTabViewsProps, {}> {
</div>
</div>
<hr />
{this.props.data.rendering === null ? (
<span />
) : (
this.props.data.rendering.evaluations.map(
(evaluation: application.RenderingEvaluation, index: number) => {
let view = this.props.registry.descriptors[evaluation.viewId];
if (view === undefined) return null;
return (
<div key={"evaluation-" + index} className="row">
<div className="col-12">
<span
title="Priority for this view"
className="badge badge-primary"
style={{ marginRight: "5pt" }}
>
{evaluation.priority}
</span>
<span>{view.name}</span>
</div>
</div>
);
}
)
)}
<hr />
{Object.keys(this.props.registry.descriptors)
.map((viewId: string, index: number) => {
if (
this.props.data.rendering === null ||
this.props.data.rendering.evaluations.find(
(value: application.RenderingEvaluation) =>
value.viewId === viewId
)
) {
return null;
}
let view = this.props.registry.descriptors[viewId];
if (view === undefined) return null;
return (
<div key={"view-" + index} className="row">
<div className="col-12">
<span
title="Priority for this view"
className="badge badge-secondary"
style={{ marginRight: "5pt" }}
>
{"disabled"}
</span>
<span>{view.name}</span>
</div>
</div>
);
})
.filter((value: any) => value !== null)}
</div>
<span />
{this.props.data.rendering.evaluations.map(eva => <RenderingEvaluationComponent {...eva} />)}
</div>
);
}
}
......@@ -176,7 +176,6 @@ function evaluateViewsFor(
priority: implementations[id].priorityFor(store, target)
};
})
.filter((a: RenderingEvaluation) => a.priority >= 0)
.sort(
(x: RenderingEvaluation, y: RenderingEvaluation) =>
y.priority - x.priority
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment