Skip to content

Commit d82f969

Browse files
sim51jacomyal
authored andcommitted
[gephi-lite] refacto react-select
Same style than bootstrap field Creating a Select component which is a wrapper of react-select Using react-select even on simple select Review graph search components for react-select
1 parent 19ceb85 commit d82f969

22 files changed

+240
-182
lines changed

packages/gephi-lite/src/components/GraphAppearance/TransformationMethodPreview.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { makeGetValue } from "../../core/appearance/utils";
66

77
export const TransformationMethodPreview: FC<{ method?: TransformationMethod }> = ({ method }) => {
88
const getValue = makeGetValue(method);
9-
const size = 40;
9+
const size = 30;
1010
const margin = 2;
1111
return (
1212
<>

packages/gephi-lite/src/components/GraphAppearance/TransformationMethodSelect.tsx

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { FC } from "react";
1+
import { FC, useMemo } from "react";
22
import { useTranslation } from "react-i18next";
33

44
import { TransformationMethod } from "../../core/appearance/types";
5+
import { Select } from "../forms/Select";
56
import { TransformationMethodPreview } from "./TransformationMethodPreview";
67

78
export const TransformationMethodsSelect: FC<{
@@ -11,41 +12,52 @@ export const TransformationMethodsSelect: FC<{
1112
}> = ({ id, method, onChange }) => {
1213
const { t } = useTranslation();
1314

15+
const options = useMemo(
16+
() => [
17+
{ value: "", label: t("appearance.transformation_methods.linear").toString() },
18+
{ value: "pow-2", label: t("appearance.transformation_methods.pow-2").toString() },
19+
{ value: "pow-3", label: t("appearance.transformation_methods.pow-3").toString() },
20+
{ value: "pow-0.5", label: t("appearance.transformation_methods.sqrt").toString() },
21+
{ value: "log", label: t("appearance.transformation_methods.log").toString() },
22+
],
23+
[t],
24+
);
25+
26+
const value = useMemo(() => {
27+
const result =
28+
typeof method === "object" && "pow" in method ? `pow-${method.pow}` : method === "log" ? "log" : undefined;
29+
return { value: result, label: result };
30+
}, [method]);
31+
1432
return (
1533
<>
1634
<label htmlFor={id || "transformation-method"}>{t("appearance.transformation_methods.title")}</label>
1735
<div className="d-flex align-items-bottom ">
18-
<select
36+
<Select
1937
id={id || "transformation-method"}
20-
className="form-select me-2"
38+
className="me-2 flex-grow-1 form-control-sm"
39+
value={value}
40+
options={options}
2141
onChange={(e) => {
2242
let method: TransformationMethod | null = null;
23-
switch (e.target.value) {
24-
case "pow-2":
25-
method = { pow: 2 };
26-
break;
27-
case "pow-3":
28-
method = { pow: 3 };
29-
break;
30-
case "pow-0.5":
31-
method = { pow: 0.5 };
32-
break;
33-
case "log":
34-
method = "log";
43+
if (e) {
44+
switch (e.value) {
45+
case "pow-2":
46+
method = { pow: 2 };
47+
break;
48+
case "pow-3":
49+
method = { pow: 3 };
50+
break;
51+
case "pow-0.5":
52+
method = { pow: 0.5 };
53+
break;
54+
case "log":
55+
method = "log";
56+
}
3557
}
3658
onChange(method);
3759
}}
38-
value={
39-
typeof method === "object" && "pow" in method ? `pow-${method.pow}` : method === "log" ? "log" : undefined
40-
}
41-
>
42-
<option value="">{t("appearance.transformation_methods.linear")}</option>
43-
<option value="pow-2">{t("appearance.transformation_methods.pow-2")}</option>
44-
<option value="pow-3">{t("appearance.transformation_methods.pow-3")}</option>
45-
<option value="pow-0.5">{t("appearance.transformation_methods.sqrt")}</option>
46-
<option value="log">{t("appearance.transformation_methods.log")}</option>
47-
{/* <option disabled>{t("appearance.transformation_methods.spline")} TODO</option> */}
48-
</select>
60+
/>
4961

5062
<TransformationMethodPreview method={method} />
5163
</div>

packages/gephi-lite/src/components/GraphAppearance/color/ColorItem.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { ItemDataField } from "@gephi/gephi-lite-sdk";
22
import { isEqual } from "lodash";
33
import { FC, useMemo } from "react";
44
import { useTranslation } from "react-i18next";
5-
import Select from "react-select";
65

76
import { Color } from "../../../core/appearance/types";
87
import { DEFAULT_EDGE_COLOR, DEFAULT_NODE_COLOR, DEFAULT_SHADING_COLOR } from "../../../core/appearance/utils";
@@ -16,7 +15,7 @@ import { staticDynamicAttributeKey, staticDynamicAttributeLabel } from "../../..
1615
import { FieldModel } from "../../../core/graph/types";
1716
import { uniqFieldvaluesAsStrings } from "../../../core/graph/utils";
1817
import { ItemType } from "../../../core/types";
19-
import { DEFAULT_SELECT_PROPS } from "../../consts";
18+
import { Select } from "../../forms/Select";
2019
import { ColorFixedEditor } from "./ColorFixedEditor";
2120
import { ColorPartitionEditor } from "./ColorPartitionEditor";
2221
import { ColorRankingEditor } from "./ColorRankingEditor";
@@ -105,7 +104,6 @@ export const ColorItem: FC<{ itemType: ItemType }> = ({ itemType }) => {
105104
<h3 className="fs-5">{t("appearance.color.title")}</h3>
106105
<label htmlFor={`${itemType}-colorMode`}>{t("appearance.color.set_color_from")}</label>
107106
<Select<ColorOption>
108-
{...DEFAULT_SELECT_PROPS}
109107
id={`${itemType}-colorMode`}
110108
options={options}
111109
value={selectedOption}

packages/gephi-lite/src/components/GraphAppearance/color/ShadingColorEditor.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import { ItemDataField } from "@gephi/gephi-lite-sdk";
22
import { FC, useMemo } from "react";
33
import { useTranslation } from "react-i18next";
4-
import Select from "react-select";
54

65
import { ShadingColor } from "../../../core/appearance/types";
76
import { useGraphDataset } from "../../../core/context/dataContexts";
87
import { staticDynamicAttributeLabel } from "../../../core/graph/dynamicAttributes";
98
import { ItemType } from "../../../core/types";
109
import ColorPicker from "../../ColorPicker";
11-
import { DEFAULT_SELECT_PROPS } from "../../consts";
10+
import { Select } from "../../forms/Select";
1211

1312
type Option = { value: ItemDataField; label: string };
1413
function stringToOption(field: ItemDataField): Option {
@@ -42,7 +41,6 @@ export const ShadingColorEditor: FC<{
4241
{t("appearance.color.shading_attribute", { items: t(`graph.model.${itemType}`) })}
4342
</label>
4443
<Select<Option>
45-
{...DEFAULT_SELECT_PROPS}
4644
id={`${itemType}-shadingColorAttribute`}
4745
options={fieldOptions}
4846
value={stringToOption(color.field)}

packages/gephi-lite/src/components/GraphAppearance/label/LabelSizeItem.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { capitalize } from "lodash";
22
import { FC, useMemo } from "react";
33
import { useTranslation } from "react-i18next";
4-
import Select from "react-select";
54

65
import { DEFAULT_EDGE_LABEL_SIZE, DEFAULT_NODE_LABEL_SIZE } from "../../../core/appearance/utils";
76
import { useAppearance, useAppearanceActions } from "../../../core/context/dataContexts";
87
import { ItemType } from "../../../core/types";
9-
import { DEFAULT_SELECT_PROPS } from "../../consts";
8+
import { Select } from "../../forms/Select";
109
import { SliderInput } from "../../forms/TypedInputs";
1110

1211
export const LabelSizeItem: FC<{ itemType: ItemType }> = ({ itemType }) => {
@@ -32,7 +31,6 @@ export const LabelSizeItem: FC<{ itemType: ItemType }> = ({ itemType }) => {
3231
<div className="panel-block">
3332
<label htmlFor={`${itemType}-labelSizesMode`}>{t("appearance.labels.set_labels_size_from")}</label>
3433
<Select
35-
{...DEFAULT_SELECT_PROPS}
3634
id={`${itemType}-labelSizesMode`}
3735
options={labelSizeOptions}
3836
value={selectedOption}

packages/gephi-lite/src/components/GraphAppearance/label/StringAttrItem.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { ItemDataField } from "@gephi/gephi-lite-sdk";
22
import { FC, useCallback, useMemo } from "react";
33
import { useTranslation } from "react-i18next";
4-
import Select from "react-select";
54

65
import { StringAttr } from "../../../core/appearance/types";
76
import {
@@ -13,7 +12,7 @@ import {
1312
import { staticDynamicAttributeKey, staticDynamicAttributeLabel } from "../../../core/graph/dynamicAttributes";
1413
import { FieldModel } from "../../../core/graph/types";
1514
import { ItemType } from "../../../core/types";
16-
import { DEFAULT_SELECT_PROPS } from "../../consts";
15+
import { Select } from "../../forms/Select";
1716

1817
type LabelOption =
1918
| { value: string; type: "none" | "data" | "fixed"; field?: undefined; label: string }
@@ -72,8 +71,7 @@ export const StringAttrItem: FC<{ itemType: ItemType; itemKey: "images" | "label
7271
<div className="panel-block">
7372
<h3 className="fs-5">{t(`appearance.${itemKey}.title`)}</h3>
7473
<label htmlFor={`${itemType}-${itemKey}sMode`}>{t(`appearance.${itemKey}.set_labels_from`)}</label>
75-
<Select<LabelOption>
76-
{...DEFAULT_SELECT_PROPS}
74+
<Select<LabelOption | null>
7775
id={`${itemType}-labelsMode`}
7876
options={labelOptions}
7977
value={selectedLabelOption}

packages/gephi-lite/src/components/GraphAppearance/size/SizeItem.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { ItemDataField } from "@gephi/gephi-lite-sdk";
22
import { isEqual } from "lodash";
33
import { FC, useMemo } from "react";
44
import { useTranslation } from "react-i18next";
5-
import Select from "react-select";
65

76
import { Size } from "../../../core/appearance/types";
87
import { DEFAULT_EDGE_SIZE, DEFAULT_NODE_SIZE } from "../../../core/appearance/utils";
@@ -15,7 +14,7 @@ import {
1514
import { staticDynamicAttributeLabel } from "../../../core/graph/dynamicAttributes";
1615
import { FieldModel } from "../../../core/graph/types";
1716
import { ItemType } from "../../../core/types";
18-
import { DEFAULT_SELECT_PROPS } from "../../consts";
17+
import { Select } from "../../forms/Select";
1918
import { SizeFixedEditor } from "./SizeFixedEditor";
2019
import { SizeRankingEditor } from "./SizeRankingEditor";
2120

@@ -79,7 +78,6 @@ export const SizeItem: FC<{ itemType: ItemType }> = ({ itemType }) => {
7978
<h3 className="fs-5">{t("appearance.size.title")}</h3>
8079
<label htmlFor={`${itemType}-sizeMode`}>{t("appearance.size.set_size_from")}</label>
8180
<Select<SizeOption>
82-
{...DEFAULT_SELECT_PROPS}
8381
id={`${itemType}-sizeMode`}
8482
options={options}
8583
value={selectedOption}

packages/gephi-lite/src/components/GraphAppearance/zIndex/EdgesZIndexItem.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { ItemDataField } from "@gephi/gephi-lite-sdk";
22
import { FC, useMemo } from "react";
33
import { useTranslation } from "react-i18next";
4-
import Select from "react-select";
54

65
import {
76
useAppearance,
@@ -12,7 +11,7 @@ import {
1211
import { staticDynamicAttributeKey, staticDynamicAttributeLabel } from "../../../core/graph/dynamicAttributes";
1312
import { FieldModel } from "../../../core/graph/types";
1413
import { ItemType } from "../../../core/types";
15-
import { DEFAULT_SELECT_PROPS } from "../../consts";
14+
import { Select } from "../../forms/Select";
1615

1716
type LabelOption =
1817
| { value: string; type: "none"; field?: undefined; label: string }
@@ -54,8 +53,7 @@ export const EdgesZIndexItem: FC = () => {
5453
<h3 className="fs-5">{t(`appearance.zIndex.title`)}</h3>
5554
<p className="text-muted">{t(`appearance.zIndex.description`, { items: t("graph.model.edges") })}</p>
5655
<label htmlFor={`${itemType}-zIndexMode`}>{t(`appearance.zIndex.set_values_from`)}</label>
57-
<Select<LabelOption>
58-
{...DEFAULT_SELECT_PROPS}
56+
<Select<LabelOption | null>
5957
id={`${itemType}-zIndexMode`}
6058
options={labelOptions}
6159
value={selectedLabelOption}

packages/gephi-lite/src/components/GraphFilters/FilterCreator.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { capitalize } from "lodash";
33
import { FC, useEffect, useState } from "react";
44
import { useTranslation } from "react-i18next";
55
import { CgAddR } from "react-icons/cg";
6-
import Select from "react-select";
76

87
import {
98
useDynamicItemData,
@@ -16,7 +15,7 @@ import { FilterType } from "../../core/filters/types";
1615
import { staticDynamicAttributeKey, staticDynamicAttributeLabel } from "../../core/graph/dynamicAttributes";
1716
import { FieldModel } from "../../core/graph/types";
1817
import { ItemType } from "../../core/types";
19-
import { DEFAULT_SELECT_PROPS } from "../consts";
18+
import { Select } from "../forms/Select";
2019

2120
export interface FilterOption {
2221
value: string;
@@ -133,7 +132,6 @@ export const FilterCreator: FC = () => {
133132
<div>
134133
{t("filters.filter")}{" "}
135134
<Select
136-
{...DEFAULT_SELECT_PROPS}
137135
onChange={(o) => setFilterApplicationType(o?.value as ItemType | "topological")}
138136
options={[
139137
{ label: capitalize(t("graph.model.nodes").toString()), value: "nodes" },
@@ -146,7 +144,6 @@ export const FilterCreator: FC = () => {
146144
{t("filters.using")}
147145
{filterOptions.length > 0 && (
148146
<Select
149-
{...DEFAULT_SELECT_PROPS}
150147
value={selectedFilterOption}
151148
isClearable={true}
152149
onChange={(selectedOption) => {

packages/gephi-lite/src/components/GraphFilters/TermsFilter.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { useReadAtom } from "@ouestware/atoms";
33
import { countBy, flatMap, identity, sortBy, toPairs } from "lodash";
44
import { FC, useEffect, useState } from "react";
55
import { useTranslation } from "react-i18next";
6-
import Select from "react-select";
76

87
import { useFiltersActions, useGraphDataset } from "../../core/context/dataContexts";
98
import { TermsFilterType } from "../../core/filters/types";
@@ -14,7 +13,7 @@ import {
1413
mergeStaticDynamicData,
1514
staticDynamicAttributeLabel,
1615
} from "../../core/graph/dynamicAttributes";
17-
import { DEFAULT_SELECT_PROPS } from "../consts";
16+
import { Select } from "../forms/Select";
1817
import { FilteredGraphSummary } from "./FilteredGraphSummary";
1918

2019
const TermsFilterEditor: FC<{ filter: TermsFilterType }> = ({ filter }) => {
@@ -46,7 +45,6 @@ const TermsFilterEditor: FC<{ filter: TermsFilterType }> = ({ filter }) => {
4645
return (
4746
<div className="my-3 w-100">
4847
<Select
49-
{...DEFAULT_SELECT_PROPS}
5048
value={filter.terms ? Array.from(filter.terms).map((t) => ({ label: t, value: t })) : []}
5149
onChange={(options) => {
5250
const selectedValues = new Set(options.map((o) => o.value));

packages/gephi-lite/src/components/GraphFilters/TopologicalFilter.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export function TopologicalFilterEditor<ParametersType extends FilterParameter[]
2929
<div key={i} className="mt-1">
3030
<label className="form-check-label small">{p.label}</label>
3131
<GraphSearch
32+
className="form-control-sm"
3233
onChange={(option) => {
3334
if (option === null || "id" in option) {
3435
replaceCurrentFilter({

0 commit comments

Comments
 (0)