Skip to content

Commit 10ea70d

Browse files
committed
[gephi-lite] Handles invalid and undefined values
This commit fixes #210 and #225. Details: - It is now possible to manually clear any cell in the data table - Invalid values are now rendered in the data table and the selection panel
1 parent 5d0c064 commit 10ea70d

File tree

6 files changed

+55
-12
lines changed

6 files changed

+55
-12
lines changed

packages/gephi-lite/src/components/common-icons.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ import {
7676
PiTrash,
7777
PiUser,
7878
PiWarning,
79+
PiWarningCircle,
7980
PiWarningOctagon,
8081
PiX,
8182
} from "react-icons/pi";
@@ -120,6 +121,7 @@ export const GraphIcon = PiGraph;
120121
export const GraphIconFill = PiGraphFill;
121122
export const GuessSettingsIcon = PiMagicWand;
122123
export const HomeIcon = PiHouseLine;
124+
export const InvalidDataIcon = PiWarningCircle;
123125
export const LassoIcon = PiLasso;
124126
export const LassoIconFill = PiLassoBold;
125127
export const LayoutsIcon = PiPolygon;

packages/gephi-lite/src/components/data/Attribute.tsx

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,30 @@ import { castScalarToModelValue, serializeModelValueToScalar } from "../../core/
2020
import { useDataCollection } from "../../hooks/useDataCollection";
2121
import { DEFAULT_LINKIFY_PROPS } from "../../utils/url";
2222
import ColorPicker, { InlineColorPicker } from "../ColorPicker";
23-
import { FieldModelIcon } from "../common-icons";
23+
import MessageTooltip from "../MessageTooltip";
24+
import { FieldModelIcon, InvalidDataIcon } from "../common-icons";
2425
import { BaseOption, CreatableSelect, optionize } from "../forms/Select";
2526

2627
/**
2728
* Render values:
2829
* **************
2930
*/
31+
export const InvalidAttributeRenderer: FC<{ value: Scalar; expectedType: FieldModelType }> = ({
32+
value,
33+
expectedType,
34+
}) => {
35+
const { t } = useTranslation("translation");
36+
return (
37+
<span className="invalid-value">
38+
<span>{value}</span>{" "}
39+
<MessageTooltip
40+
className="message-tooltip"
41+
message={t("graph.model.warnings.invalid_data", { value, type: expectedType })}
42+
icon={InvalidDataIcon}
43+
/>
44+
</span>
45+
);
46+
};
3047
export const AttributeRenderers: {
3148
[K in keyof FieldModelAbstraction]: FC<
3249
{
@@ -71,11 +88,13 @@ export const RenderKeywords = AttributeRenderers.keywords;
7188
export const RenderDate = AttributeRenderers.date;
7289
export const RenderColor = AttributeRenderers.color;
7390

74-
export const RenderItemAttribute: FC<{ field: FieldModelTypeSpec; value: Scalar }> = ({ field, value }) =>
75-
createElement(AttributeRenderers[field.type] as FC<{ value?: ModelValueType }>, {
76-
...field,
77-
value: castScalarToModelValue(value, field),
78-
});
91+
export const RenderItemAttribute: FC<{ field: FieldModelTypeSpec; value: Scalar }> = ({ field, value }) => {
92+
const castValue = castScalarToModelValue(value, field);
93+
const AttributeRenderer = AttributeRenderers[field.type] as FC<{ value?: ModelValueType }>;
94+
95+
if (!isNil(value) && isNil(castValue)) return <InvalidAttributeRenderer value={value} expectedType={field.type} />;
96+
return <AttributeRenderer {...field} value={castValue} />;
97+
};
7998

8099
/**
81100
* Edit values:

packages/gephi-lite/src/core/graph/fieldModel.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ export function serializeModelValueToScalar(
215215
fieldModel: FieldModelTypeSpec,
216216
originalScalar: Scalar,
217217
): Scalar {
218+
if (value === undefined) return undefined;
219+
218220
switch (fieldModel.type) {
219221
case "number":
220222
if (typeof value !== "number") return originalScalar;

packages/gephi-lite/src/locales/dev.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@
402402
"warnings": {
403403
"missing": "{{nbValues}} missing values",
404404
"wrong": "{{nbValues}} values are not quantitative",
405-
"allMissing": "No values in the graph"
405+
"invalid_data": "The value \"{{value}}\" cannot be interpreted as a \"{{type}}\" value."
406406
},
407407
"field": {
408408
"id": "Identifier",

packages/gephi-lite/src/styles/_data-table.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ $table-editable-columns-cell-hover-bg: color-mix(
138138
&.editable {
139139
padding: 0;
140140

141-
.tether-target {
141+
.tether-target:not(.message-tooltip) {
142142
width: 100%;
143143
padding: map.get($spacers, 1) 0;
144144
@extend .text-ellipsis;

packages/gephi-lite/src/styles/_data.scss

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,33 @@
4545
width: 0;
4646
height: 0;
4747
border-left: 0.3em solid transparent;
48-
border-left-width: 0.3em;
4948
border-right: 0.3em solid transparent;
50-
border-right-width: 0.3em;
5149
border-top: 0.6em solid red;
5250
flex-shrink: 0;
53-
border-left-width: 0.3em;
54-
border-right-width: 0.3em;
51+
}
52+
}
53+
}
54+
55+
.invalid-value {
56+
@extend .text-muted;
57+
@extend .gl-gap-1;
58+
font-style: italic;
59+
display: flex;
60+
justify-content: space-between;
61+
align-items: center;
62+
63+
span {
64+
@extend .text-truncate;
65+
flex-grow: 1;
66+
flex-shrink: 1;
67+
}
68+
69+
.message-tooltip {
70+
flex-grow: 0;
71+
flex-shrink: 0;
72+
73+
.gl-btn {
74+
@extend .text-dark;
5575
}
5676
}
5777
}

0 commit comments

Comments
 (0)