Skip to content
This repository was archived by the owner on Jul 28, 2025. It is now read-only.

Commit 916983a

Browse files
committed
Merge branch '401-bug-select-cell-does-not-open-on-mobiles'
2 parents c64d2d3 + 263026a commit 916983a

File tree

6 files changed

+151
-231
lines changed

6 files changed

+151
-231
lines changed

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"@faker-js/faker": "7.5.0",
2222
"@rollup/plugin-commonjs": "22.0.2",
2323
"@rollup/plugin-json": "4.1.0",
24-
"@rollup/plugin-node-resolve": "14.0.1",
24+
"@rollup/plugin-node-resolve": "14.1.0",
2525
"@rollup/plugin-replace": "4.0.0",
2626
"@rollup/plugin-typescript": "8.5.0",
2727
"@testing-library/jest-dom": "5.16.5",
@@ -41,7 +41,7 @@
4141
"jest": "29.0.3",
4242
"jest-mock-extended": "3.0.1",
4343
"obsidian": "0.15.9",
44-
"rollup": "2.79.0",
44+
"rollup": "2.79.1",
4545
"rollup-plugin-terser": "7.0.2",
4646
"rollup-plugin-typescript2": "0.34.0",
4747
"ts-jest": "29.0.1",
@@ -50,8 +50,8 @@
5050
},
5151
"dependencies": {
5252
"@emotion/styled": "11.10.4",
53-
"@mui/icons-material": "5.10.3",
54-
"@mui/material": "5.10.5",
53+
"@mui/icons-material": "5.10.6",
54+
"@mui/material": "5.10.6",
5555
"@popperjs/core": "2.11.6",
5656
"@tanstack/match-sorter-utils": "8.1.1",
5757
"@tanstack/react-table": "8.5.13",

src/components/DefaultCell.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from "react";
22
import { InputType } from "helpers/Constants";
33
import { LOGGER } from "services/Logger";
44
import { RowDataType, TableColumn } from "cdm/FolderModel";
5-
import PopperSelectPortal from "components/portals/PopperSelectPortal";
5+
import SelectPortal from "components/portals/SelectPortal";
66
import CalendarPortal from "components/portals/CalendarPortal";
77
import CalendarTimePortal from "components/portals/CalendarTimePortal";
88
import CheckboxCell from "components/cellTypes/CheckboxCell";
@@ -55,7 +55,7 @@ export default function DefaultCell(
5555

5656
/** Selector option */
5757
case InputType.SELECT:
58-
return <PopperSelectPortal defaultCell={defaultCell} />;
58+
return <SelectPortal defaultCell={defaultCell} />;
5959

6060
/** Tags option */
6161
case InputType.TAGS:

src/components/portals/PopperSelectPortal.tsx

Lines changed: 0 additions & 216 deletions
This file was deleted.
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
import Relationship from "components/RelationShip";
2+
import { grey, randomColor } from "helpers/Colors";
3+
import React, { useState } from "react";
4+
import { CellComponentProps, RowSelectOption } from "cdm/ComponentsModel";
5+
import { TableColumn } from "cdm/FolderModel";
6+
import CreatableSelect from "react-select/creatable";
7+
import CustomTagsStyles from "components/styles/TagsStyles";
8+
import { c } from "helpers/StylesHelper";
9+
import { ActionMeta, OnChangeValue } from "react-select";
10+
11+
const SelectPortal = (popperProps: CellComponentProps) => {
12+
const { defaultCell } = popperProps;
13+
const { row, column, table } = defaultCell;
14+
const { tableState } = table.options.meta;
15+
const dataActions = tableState.data((state) => state.actions);
16+
17+
const selectPortalRow = tableState.data((state) => state.rows[row.index]);
18+
const columnsInfo = tableState.columns((state) => state.info);
19+
const configInfo = tableState.configState((state) => state.info);
20+
21+
const tableColumn = column.columnDef as TableColumn;
22+
23+
const [showSelect, setShowSelect] = useState(false);
24+
25+
const columnActions = table.options.meta.tableState.columns(
26+
(state) => state.actions
27+
);
28+
29+
function getColor() {
30+
const match = tableColumn.options.find(
31+
(option: { label: string }) =>
32+
option.label === selectPortalRow[tableColumn.key]
33+
);
34+
return (match && match.backgroundColor) || grey(200);
35+
}
36+
37+
const defaultValue = {
38+
label: selectPortalRow[tableColumn.key]?.toString(),
39+
value: selectPortalRow[tableColumn.key]?.toString(),
40+
color: getColor(),
41+
};
42+
43+
const multiOptions = tableColumn.options
44+
.sort((a, b) => a.label.localeCompare(b.label))
45+
.map((option: RowSelectOption) => ({
46+
value: option.label,
47+
label: option.label,
48+
color: option.backgroundColor,
49+
}));
50+
51+
const handleOnChange = (
52+
newValue: OnChangeValue<any, false>,
53+
actionMeta: ActionMeta<RowSelectOption>
54+
) => {
55+
const selection = newValue ? newValue.value : "";
56+
// Update on disk & memory
57+
dataActions.updateCell(
58+
row.index,
59+
tableColumn,
60+
selection,
61+
columnsInfo.getAllColumns(),
62+
configInfo.getLocalSettings(),
63+
true
64+
);
65+
// Add new option to column options
66+
67+
if (
68+
newValue.value &&
69+
!tableColumn.options.find((option) => option.label === newValue.value)
70+
) {
71+
columnActions.addOptionToColumn(
72+
tableColumn,
73+
newValue.value,
74+
randomColor()
75+
);
76+
}
77+
setShowSelect(false);
78+
};
79+
80+
function SelectComponent() {
81+
return (
82+
<div className={c("tags")}>
83+
<CreatableSelect
84+
defaultValue={defaultValue}
85+
isSearchable
86+
autoFocus
87+
isClearable
88+
menuPosition="fixed"
89+
styles={CustomTagsStyles}
90+
options={multiOptions}
91+
onBlur={() => setShowSelect(false)}
92+
onChange={handleOnChange}
93+
menuPortalTarget={activeDocument.body}
94+
menuPlacement="auto"
95+
menuShouldBlockScroll={true}
96+
className="react-select-container"
97+
classNamePrefix="react-select"
98+
key={`${tableColumn.key}-select-open`}
99+
/>
100+
</div>
101+
);
102+
}
103+
104+
return (
105+
<>
106+
{showSelect ? (
107+
SelectComponent()
108+
) : (
109+
/* Current value of the select */
110+
<div
111+
className="cell-padding d-flex cursor-default align-items-center flex-1"
112+
onClick={() => setShowSelect(true)}
113+
style={{ width: column.getSize() }}
114+
>
115+
{selectPortalRow[tableColumn.key] && (
116+
<Relationship
117+
value={selectPortalRow[tableColumn.key]?.toString()}
118+
backgroundColor={getColor()}
119+
/>
120+
)}
121+
</div>
122+
)}
123+
</>
124+
);
125+
};
126+
127+
export default SelectPortal;

0 commit comments

Comments
 (0)