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

Commit 0b43311

Browse files
committed
tags migrated
1 parent f1924bd commit 0b43311

File tree

6 files changed

+46
-28
lines changed

6 files changed

+46
-28
lines changed

src/cdm/DatabaseModel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { RowType } from "cdm/RowTypeModel"
22
import { LocalSettings } from "cdm/SettingsModel";
33
import { Literal } from "obsidian-dataview/lib/data-model/value";
4-
import { TableOptions } from "@tanstack/react-table";
4+
import { Column, TableOptions } from "@tanstack/react-table";
55
import { BaseColumn, RowDataType, TableColumn, TableDataType } from "cdm/FolderModel";
66
import { RowSelectOption } from "cdm/ComponentsModel";
77

@@ -41,7 +41,7 @@ export type OptionSelect = {
4141
}
4242
export type BaseComponentProps = {
4343
intialState: TableDataType;
44-
column: TableColumn;
44+
column: Column<RowDataType, unknown>;
4545
}
4646

4747
export type SortedType = {

src/components/DefaultCell.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ export default function DefaultCell(cellProperties: CellProps) {
217217
return (
218218
<CalendarPortal
219219
intialState={tableData}
220-
column={column.columnDef as TableColumn}
220+
column={column}
221221
cellProperties={cellProperties}
222222
/>
223223
);
@@ -227,7 +227,7 @@ export default function DefaultCell(cellProperties: CellProps) {
227227
return (
228228
<CalendarTimePortal
229229
intialState={tableData}
230-
column={column.columnDef as TableColumn}
230+
column={column}
231231
cellProperties={cellProperties}
232232
/>
233233
);
@@ -239,7 +239,7 @@ export default function DefaultCell(cellProperties: CellProps) {
239239
<PopperSelectPortal
240240
dispatch={dataDispatch}
241241
row={row}
242-
column={column.columnDef as TableColumn}
242+
column={column}
243243
columns={columns}
244244
note={note}
245245
intialState={tableData}
@@ -252,7 +252,7 @@ export default function DefaultCell(cellProperties: CellProps) {
252252
<CellContext.Provider value={{ contextValue, setContextValue }}>
253253
<TagsPortal
254254
intialState={tableData}
255-
column={column.columnDef as TableColumn}
255+
column={column}
256256
columns={columns}
257257
dispatch={dataDispatch}
258258
cellProperties={cellProperties}

src/components/portals/CalendarPortal.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,19 @@ import NoteInfo from "services/NoteInfo";
66
import { Portal } from "@mui/material";
77
import { c } from "helpers/StylesHelper";
88
import { CalendarProps } from "cdm/ComponentsModel";
9-
import { TableDataType } from "cdm/FolderModel";
9+
import { TableColumn, TableDataType } from "cdm/FolderModel";
1010

1111
const CalendarPortal = (calendarProps: CalendarProps) => {
1212
const { column, cellProperties, intialState } = calendarProps;
1313
const { row, table } = cellProperties;
14+
const tableColumn = column.columnDef as TableColumn;
1415
const dataDispatch = (table.options.meta as TableDataType).dispatch;
1516
/** state of cell value */
1617
const [showDatePicker, setShowDatePicker] = useState(false);
1718
/** Note info of current Cell */
1819
const note: NoteInfo = row.original.__note__;
1920
const [calendarState, setCalendarState] = useState(
20-
intialState.view.rows[row.index][column.key]
21+
intialState.view.rows[row.index][tableColumn.key]
2122
);
2223

2324
function handleSpanOnClick(event: any) {
@@ -31,7 +32,7 @@ const CalendarPortal = (calendarProps: CalendarProps) => {
3132
dataDispatch({
3233
type: ActionTypes.UPDATE_CELL,
3334
file: note.getFile(),
34-
key: column.key,
35+
key: tableColumn.key,
3536
value: newValue.toFormat("yyyy-MM-dd"),
3637
row: row,
3738
columnId: column.id,
@@ -59,7 +60,11 @@ const CalendarPortal = (calendarProps: CalendarProps) => {
5960
placeholderText="Pick a date..."
6061
/>
6162
) : (
62-
<span className={`${c("calendar")}`} onClick={handleSpanOnClick}>
63+
<span
64+
className={`${c("calendar")}`}
65+
onClick={handleSpanOnClick}
66+
style={{ width: column.getSize() }}
67+
>
6368
{DateTime.isDateTime(calendarState)
6469
? (calendarState as unknown as DateTime).toFormat("yyyy-MM-dd")
6570
: null}

src/components/portals/CalendarTimePortal.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ import DatePicker from "react-datepicker";
55
import NoteInfo from "services/NoteInfo";
66
import { Portal } from "@mui/material";
77
import { CalendarProps } from "cdm/ComponentsModel";
8-
import { TableDataType } from "cdm/FolderModel";
8+
import { TableColumn, TableDataType } from "cdm/FolderModel";
99

1010
const CalendarTimePortal = (calendarTimeProps: CalendarProps) => {
1111
const { column, cellProperties, intialState } = calendarTimeProps;
1212
const { row, table } = cellProperties;
13+
const tableColumn = column.columnDef as TableColumn;
1314
const dataDispatch = (table.options.meta as TableDataType).dispatch;
1415
// Calendar state
1516
const [calendarTimeState, setCalendarTimeState] = useState(
16-
intialState.view.rows[row.index][column.key]
17+
intialState.view.rows[row.index][tableColumn.key]
1718
);
1819
/** state of cell value */
1920
const [showDatePicker, setShowDatePicker] = useState(false);
@@ -32,7 +33,7 @@ const CalendarTimePortal = (calendarTimeProps: CalendarProps) => {
3233
dataDispatch({
3334
type: ActionTypes.UPDATE_CELL,
3435
file: note.getFile(),
35-
key: column.key,
36+
key: tableColumn.key,
3637
value: DateTime.fromJSDate(date).toISO(),
3738
row: row,
3839
columnId: column.id,
@@ -47,7 +48,7 @@ const CalendarTimePortal = (calendarTimeProps: CalendarProps) => {
4748
return <Portal container={el}>{containerProps.children}</Portal>;
4849
};
4950

50-
return showDatePicker && !column.isMetadata ? (
51+
return showDatePicker && !tableColumn.isMetadata ? (
5152
<div className="calendar-time">
5253
<DatePicker
5354
dateFormat="yyyy-MM-dd h:mm aa"
@@ -66,7 +67,11 @@ const CalendarTimePortal = (calendarTimeProps: CalendarProps) => {
6667
/>
6768
</div>
6869
) : (
69-
<span className="calendar-time" onClick={handleSpanOnClick}>
70+
<span
71+
className="calendar-time"
72+
onClick={handleSpanOnClick}
73+
style={{ width: column.getSize() }}
74+
>
7075
{DateTime.isDateTime(calendarTimeState)
7176
? (calendarTimeState as DateTime).toFormat("yyyy-MM-dd h:mm a")
7277
: null}

src/components/portals/PopperSelectPortal.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { usePopper } from "react-popper";
88
import { PopperProps } from "cdm/ComponentsModel";
99
import { CellContext } from "components/contexts/CellContext";
1010
import CrossIcon from "components/img/CrossIcon";
11+
import { TableColumn } from "cdm/FolderModel";
1112

1213
const PopperSelectPortal = (popperProps: PopperProps) => {
1314
const { dispatch, row, column, columns, note, intialState } = popperProps;
@@ -24,6 +25,7 @@ const PopperSelectPortal = (popperProps: PopperProps) => {
2425
// Selector popper state
2526
const [domReady, setDomReady] = useState(false);
2627

28+
const tableColumn = column.columnDef as TableColumn;
2729
React.useEffect(() => {
2830
setDomReady(true);
2931
});
@@ -32,7 +34,7 @@ const PopperSelectPortal = (popperProps: PopperProps) => {
3234
dispatch({
3335
type: ActionTypes.UPDATE_OPTION_CELL,
3436
file: note.getFile(),
35-
key: column.key,
37+
key: tableColumn.key,
3638
value: "",
3739
row: row,
3840
columnId: column.id,
@@ -50,7 +52,7 @@ const PopperSelectPortal = (popperProps: PopperProps) => {
5052
dispatch({
5153
type: ActionTypes.UPDATE_OPTION_CELL,
5254
file: note.getFile(),
53-
key: column.key,
55+
key: tableColumn.key,
5456
value: option.label,
5557
row: row,
5658
columnId: column.id,
@@ -78,10 +80,12 @@ const PopperSelectPortal = (popperProps: PopperProps) => {
7880
}
7981
function addNewOption(e: any) {
8082
// check if option already exists
81-
const alreadyExist = column.options.find((option: { label: string }) => {
82-
if (option.label === e.target.value) {
83+
const alreadyExist = tableColumn.options.find(
84+
(option: { label: string }) => {
85+
if (option.label === e.target.value) {
86+
}
8387
}
84-
});
88+
);
8589
if (!alreadyExist) {
8690
dispatch({
8791
type: ActionTypes.ADD_OPTION_TO_COLUMN,
@@ -93,7 +97,7 @@ const PopperSelectPortal = (popperProps: PopperProps) => {
9397
}
9498

9599
function getColor() {
96-
const match = column.options.find(
100+
const match = tableColumn.options.find(
97101
(option: { label: string }) => option.label === contextValue.value
98102
);
99103
return (match && match.backgroundColor) || grey(200);
@@ -125,7 +129,7 @@ const PopperSelectPortal = (popperProps: PopperProps) => {
125129
className="d-flex flex-wrap-wrap"
126130
style={{ marginTop: "-0.5rem" }}
127131
>
128-
{column.options.map((option: any) => (
132+
{tableColumn.options.map((option: any) => (
129133
<div
130134
key={option.label}
131135
className="cursor-pointer"
@@ -198,6 +202,7 @@ const PopperSelectPortal = (popperProps: PopperProps) => {
198202
ref={setSelectRef}
199203
className="cell-padding d-flex cursor-default align-items-center flex-1"
200204
onClick={() => setShowSelect(true)}
205+
style={{ width: column.getSize() }}
201206
>
202207
{contextValue.value && (
203208
<Relationship

src/components/portals/TagsPortal.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,26 @@ import { c } from "helpers/StylesHelper";
99
import { Literal } from "obsidian-dataview/lib/data-model/value";
1010
import { ActionTypes } from "helpers/Constants";
1111
import NoteInfo from "services/NoteInfo";
12+
import { TableColumn } from "cdm/FolderModel";
1213

1314
const TagsPortal = (tagsProps: TagsProps) => {
1415
const { intialState, column, dispatch, cellProperties, columns } = tagsProps;
1516
const { row } = cellProperties;
17+
const tableColumn = column.columnDef as TableColumn;
1618
// Tags reference state
1719
const [showSelectTags, setShowSelectTags] = useState(false);
1820
// tags values state
1921
const [tagsState, setTagsState] = useState(
20-
Array.isArray(intialState.view.rows[row.index][column.key])
21-
? (intialState.view.rows[row.index][column.key] as Literal[])
22+
Array.isArray(intialState.view.rows[row.index][tableColumn.key])
23+
? (intialState.view.rows[row.index][tableColumn.key] as Literal[])
2224
: []
2325
);
2426

2527
/** Note info of current Cell */
2628
const note: NoteInfo = (cellProperties.row.original as any).__note__;
2729

2830
function getColor(tag: string) {
29-
const match = column.options.find(
31+
const match = tableColumn.options.find(
3032
(option: { label: string }) => option.label === tag
3133
);
3234
if (match) {
@@ -50,7 +52,7 @@ const TagsPortal = (tagsProps: TagsProps) => {
5052
color: getColor(tag),
5153
}));
5254

53-
const multiOptions = column.options.map((option: RowSelectOption) => ({
55+
const multiOptions = tableColumn.options.map((option: RowSelectOption) => ({
5456
value: option.label,
5557
label: option.label,
5658
color: option.backgroundColor,
@@ -63,7 +65,7 @@ const TagsPortal = (tagsProps: TagsProps) => {
6365
dispatch({
6466
type: ActionTypes.UPDATE_CELL,
6567
file: note.getFile(),
66-
key: column.key,
68+
key: tableColumn.key,
6769
value: arrayTags,
6870
row: cellProperties.row,
6971
columnId: column.id,
@@ -72,7 +74,7 @@ const TagsPortal = (tagsProps: TagsProps) => {
7274
newValue
7375
.filter(
7476
(tag: any) =>
75-
!column.options.find((option: any) => option.label === tag.value)
77+
!tableColumn.options.find((option: any) => option.label === tag.value)
7678
)
7779
.forEach((tag: any) => {
7880
dispatch({
@@ -118,6 +120,7 @@ const TagsPortal = (tagsProps: TagsProps) => {
118120
c("tags-container") + " cell-padding d-flex flex-wrap-wrap"
119121
}
120122
onClick={() => setShowSelectTags(true)}
123+
style={{ width: column.getSize() }}
121124
>
122125
{tagsState.map((tag: string) => (
123126
<div key={`key-${tag}`}>

0 commit comments

Comments
 (0)