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

Commit 51a8774

Browse files
committed
Merge branch 'style-compact'
2 parents 00b0d2a + 31b945a commit 51a8774

File tree

10 files changed

+77
-53
lines changed

10 files changed

+77
-53
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: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,11 @@ export default function DefaultCell(cellProperties: CellProps) {
173173
ref={editableMdRef}
174174
/>
175175
) : (
176-
<span ref={containerCellRef} onClick={handleEditableOnclick} />
176+
<span
177+
ref={containerCellRef}
178+
onClick={handleEditableOnclick}
179+
style={{ width: column.getSize() }}
180+
/>
177181
);
178182

179183
/** Number option */
@@ -187,7 +191,11 @@ export default function DefaultCell(cellProperties: CellProps) {
187191
className="text-align-right"
188192
/>
189193
) : (
190-
<span className="text-align-right" onClick={handleEditableOnclick}>
194+
<span
195+
className="text-align-right"
196+
onClick={handleEditableOnclick}
197+
style={{ width: column.getSize() }}
198+
>
191199
{(contextValue.value && contextValue.value.toString()) || ""}
192200
</span>
193201
);
@@ -209,7 +217,7 @@ export default function DefaultCell(cellProperties: CellProps) {
209217
return (
210218
<CalendarPortal
211219
intialState={tableData}
212-
column={column.columnDef as TableColumn}
220+
column={column}
213221
cellProperties={cellProperties}
214222
/>
215223
);
@@ -219,7 +227,7 @@ export default function DefaultCell(cellProperties: CellProps) {
219227
return (
220228
<CalendarTimePortal
221229
intialState={tableData}
222-
column={column.columnDef as TableColumn}
230+
column={column}
223231
cellProperties={cellProperties}
224232
/>
225233
);
@@ -231,7 +239,7 @@ export default function DefaultCell(cellProperties: CellProps) {
231239
<PopperSelectPortal
232240
dispatch={dataDispatch}
233241
row={row}
234-
column={column.columnDef as TableColumn}
242+
column={column}
235243
columns={columns}
236244
note={note}
237245
intialState={tableData}
@@ -244,7 +252,7 @@ export default function DefaultCell(cellProperties: CellProps) {
244252
<CellContext.Provider value={{ contextValue, setContextValue }}>
245253
<TagsPortal
246254
intialState={tableData}
247-
column={column.columnDef as TableColumn}
255+
column={column}
248256
columns={columns}
249257
dispatch={dataDispatch}
250258
cellProperties={cellProperties}

src/components/HeaderMenu.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { HeaderMenuProps } from "cdm/HeaderModel";
88
import header_action_button_section from "components/headerActions/HeaderActionButtonSection";
99
import { HeaderActionResponse } from "cdm/HeaderActionModel";
1010
import header_action_types_section from "components/headerActions/HeaderActiontypesSection";
11-
import { TableColumn } from "cdm/FolderModel";
11+
import { TableColumn, TableDataType } from "cdm/FolderModel";
1212

1313
const HeaderMenu = (headerMenuProps: HeaderMenuProps) => {
1414
const { table, header, column } = headerMenuProps.headerProps;
@@ -54,14 +54,6 @@ const HeaderMenu = (headerMenuProps: HeaderMenuProps) => {
5454
setLabelState(labelState);
5555
}, [labelState]);
5656

57-
useEffect(() => {
58-
// Throw event if inputRef changed to focus on when it exists
59-
if (inputRef) {
60-
inputRef.focus();
61-
inputRef.select();
62-
}
63-
}, [inputRef]);
64-
6557
/**
6658
* Array of action buttons asociated to the header
6759
*/
@@ -291,7 +283,7 @@ const HeaderMenu = (headerMenuProps: HeaderMenuProps) => {
291283
className="menu-item sort-button"
292284
onClick={() => {
293285
new ColumnModal(
294-
(table.options.meta as any).view,
286+
(table.options.meta as TableDataType).view,
295287
headerMenuProps
296288
).open();
297289
setExpanded(false);

src/components/modals/handlers/SelectedColumnOptionsHandler.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { randomColor } from "helpers/Colors";
66
import { ButtonComponent, Notice, Setting } from "obsidian";
77
import React from "react";
88
import ReactDOM from "react-dom";
9+
import { createRoot } from "react-dom/client";
910

1011
export class SelectedColumnOptionsHandler extends AbstractColumnHandler {
1112
settingTitle: string = "Column Options";
@@ -78,10 +79,8 @@ export class SelectedColumnOptionsHandler extends AbstractColumnHandler {
7879
columnSettingsManager.reset(columnHandlerResponse);
7980
});
8081
});
81-
82-
ReactDOM.render(
83-
<ColorPicker {...colorPickerProps} />,
84-
optionContainer.settingEl.createDiv()
82+
createRoot(optionContainer.settingEl.createDiv()).render(
83+
<ColorPicker {...colorPickerProps} />
8584
);
8685
});
8786

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: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,48 +9,56 @@ 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, TableDataType } from "cdm/FolderModel";
1213

1314
const TagsPortal = (tagsProps: TagsProps) => {
1415
const { intialState, column, dispatch, cellProperties, columns } = tagsProps;
15-
const { row } = cellProperties;
16+
const { row, table } = cellProperties;
17+
const tableColumn = column.columnDef as TableColumn;
18+
const state = table.options.meta as TableDataType;
1619
// Tags reference state
1720
const [showSelectTags, setShowSelectTags] = useState(false);
1821
// tags values state
1922
const [tagsState, setTagsState] = useState(
20-
Array.isArray(intialState.view.rows[row.index][column.key])
21-
? (intialState.view.rows[row.index][column.key] as Literal[])
23+
Array.isArray(intialState.view.rows[row.index][tableColumn.key])
24+
? (intialState.view.rows[row.index][tableColumn.key] as Literal[])
2225
: []
2326
);
2427

2528
/** Note info of current Cell */
2629
const note: NoteInfo = (cellProperties.row.original as any).__note__;
2730

2831
function getColor(tag: string) {
29-
const match = column.options.find(
32+
const match = tableColumn.options.find(
3033
(option: { label: string }) => option.label === tag
3134
);
3235
if (match) {
3336
return match.backgroundColor;
3437
} else {
3538
// In case of new tag, generate random color
3639
const color = randomColor();
37-
dispatch({
38-
columns: columns,
39-
option: tag,
40+
const newOption: RowSelectOption = {
41+
label: tag,
4042
backgroundColor: color,
41-
columnId: column.id,
42-
type: ActionTypes.ADD_OPTION_TO_COLUMN,
43+
};
44+
const currentColumn = state.columns.find(
45+
(col: TableColumn) => col.key === tableColumn.key
46+
);
47+
currentColumn.options.push(newOption);
48+
state.view.diskConfig.updateColumnProperties(column.id, {
49+
options: currentColumn.options,
4350
});
4451
return color;
4552
}
4653
}
54+
4755
const defaultValue = tagsState.map((tag: string) => ({
4856
label: tag,
4957
value: tag,
5058
color: getColor(tag),
5159
}));
5260

53-
const multiOptions = column.options.map((option: RowSelectOption) => ({
61+
const multiOptions = tableColumn.options.map((option: RowSelectOption) => ({
5462
value: option.label,
5563
label: option.label,
5664
color: option.backgroundColor,
@@ -63,7 +71,7 @@ const TagsPortal = (tagsProps: TagsProps) => {
6371
dispatch({
6472
type: ActionTypes.UPDATE_CELL,
6573
file: note.getFile(),
66-
key: column.key,
74+
key: tableColumn.key,
6775
value: arrayTags,
6876
row: cellProperties.row,
6977
columnId: column.id,
@@ -72,7 +80,7 @@ const TagsPortal = (tagsProps: TagsProps) => {
7280
newValue
7381
.filter(
7482
(tag: any) =>
75-
!column.options.find((option: any) => option.label === tag.value)
83+
!tableColumn.options.find((option: any) => option.label === tag.value)
7684
)
7785
.forEach((tag: any) => {
7886
dispatch({
@@ -118,6 +126,7 @@ const TagsPortal = (tagsProps: TagsProps) => {
118126
c("tags-container") + " cell-padding d-flex flex-wrap-wrap"
119127
}
120128
onClick={() => setShowSelectTags(true)}
129+
style={{ width: column.getSize() }}
121130
>
122131
{tagsState.map((tag: string) => (
123132
<div key={`key-${tag}`}>

0 commit comments

Comments
 (0)