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

Commit 433daeb

Browse files
committed
marshall unmarshall options
1 parent 40c0bea commit 433daeb

File tree

4 files changed

+50
-6
lines changed

4 files changed

+50
-6
lines changed

src/cdm/DatabaseModel.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ import { Literal } from "obsidian-dataview/lib/data-model/value";
33
import { Cell } from "react-table";
44
import { LocalSettings } from "Settings"
55
import { BaseColumn, TableColumn, TableDataType } from "cdm/FolderModel";
6+
import { RowSelectOption } from "cdm/RowSelectModel";
67

78
/** database column */
89
export interface DatabaseColumn extends BaseColumn {
910
input: string;
11+
options?: RowSelectOption[];
1012
[key: string]: RowType;
1113
}
1214

src/components/portals/PopperSelectPortal.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ const PopperSelectPortal = (popperProps: PopperProps) => {
1515
// Selector reference state
1616
const [selectRef, setSelectRef] = useState(null);
1717
const [showSelect, setShowSelect] = useState(false);
18-
const [addSelectRef, setAddSelectRef] = useState(null);
1918
// Selector popper state
2019
const [selectPop, setSelectPop] = useState(null);
2120
const { styles, attributes } = usePopper(selectRef, selectPop);
@@ -136,7 +135,6 @@ const PopperSelectPortal = (popperProps: PopperProps) => {
136135
type="text"
137136
className="option-input"
138137
onBlur={handleOptionBlur}
139-
ref={setAddSelectRef}
140138
onKeyDown={handleOptionKeyDown}
141139
/>
142140
</div>

src/parsers/handlers/marshall/MarshallColumnsHandler.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import { DatabaseColumn } from 'cdm/DatabaseModel';
12
import { YamlHandlerResponse } from 'cdm/MashallModel';
3+
import { RowSelectOption } from 'cdm/RowSelectModel';
24
import { DataTypes, DEFAULT_COLUMN_CONFIG } from 'helpers/Constants';
35
import { AbstractYamlHandler } from 'parsers/handlers/marshall/AbstractYamlPropertyHandler';
46

@@ -30,9 +32,13 @@ export class MarshallColumnsHandler extends AbstractYamlHandler {
3032
Object.keys(yaml.columns)
3133
.forEach((key) => {
3234
const column = yaml.columns[key];
35+
/** BASE COLUMN INFO */
3336
if (!column.input) {
3437
this.addError(`There was not input in column ${key}`);
3538
yaml.columns[key].input = DataTypes.TEXT;
39+
} else {
40+
yaml.columns[key] = marshallParticularInputInfo(column);
41+
// PARTICULAR INPUT INFO
3642
}
3743
if (!column.accessor) {
3844
this.addError(`There was not accessor in column ${key}`);
@@ -46,6 +52,7 @@ export class MarshallColumnsHandler extends AbstractYamlHandler {
4652
this.addError(`There was not label in column ${key}`);
4753
yaml.columns[key].label = key;
4854
}
55+
/** CONFIG COLUMN INFO */
4956
if (!column.config && !(column.config instanceof Object)) {
5057
column.config = DEFAULT_COLUMN_CONFIG;
5158
yaml.columns[key] = column;
@@ -72,4 +79,22 @@ export class MarshallColumnsHandler extends AbstractYamlHandler {
7279
handlerResponse.yaml = yaml;
7380
return this.goNext(handlerResponse);
7481
}
82+
}
83+
84+
function marshallParticularInputInfo(column: DatabaseColumn): DatabaseColumn {
85+
switch (column.input) {
86+
case DataTypes.SELECT:
87+
if (!column.options || !Array.isArray(column.options)) {
88+
column.options = [];
89+
} else {
90+
column.options = column.options.filter((option: RowSelectOption) => {
91+
return option.backgroundColor
92+
&& option.label
93+
&& option.label !== ''
94+
&& option.backgroundColor !== '';
95+
});
96+
}
97+
break;
98+
}
99+
return column;
75100
}

src/parsers/handlers/unmarshall/UnmarshallColumnsHandler.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import { DatabaseColumn } from "cdm/DatabaseModel";
12
import { DiskHandlerResponse } from "cdm/MashallModel";
2-
import { YAML_INDENT } from "helpers/Constants";
3+
import { DataTypes, YAML_INDENT } from "helpers/Constants";
4+
import { Literal } from "obsidian-dataview/lib/data-model/value";
35
import { AbstractDiskHandler } from "parsers/handlers/unmarshall/AbstractDiskPropertyHandler";
46

57
export class UnmarshallColumnsHandler extends AbstractDiskHandler {
@@ -17,13 +19,14 @@ export class UnmarshallColumnsHandler extends AbstractDiskHandler {
1719
this.localDisk.push(`${YAML_INDENT.repeat(1)}${columnKey
1820
}:`);
1921
Object.keys(column)
20-
.filter(key => key !== 'config')
22+
.filter(key => typeof column[key] !== 'object')
2123
.forEach(key => {
22-
// Lvl3: column properties
24+
// Lvl3: literal column properties
2325
this.localDisk.push(`${YAML_INDENT.repeat(2)}${key}: ${column[key]}`);
2426
});
25-
this.localDisk.push(`${YAML_INDENT.repeat(2)}config:`);
2627

28+
this.localDisk.push(...unmarshallParticularInputInfo(column));
29+
this.localDisk.push(`${YAML_INDENT.repeat(2)}config:`);
2730
// Skip those columns that are metadata. They dont have config
2831
if (column.isMetadata) continue;
2932
// Lvl4: column config
@@ -34,3 +37,19 @@ export class UnmarshallColumnsHandler extends AbstractDiskHandler {
3437
return this.goNext(handlerResponse);
3538
}
3639
}
40+
41+
function unmarshallParticularInputInfo(column: DatabaseColumn): string[] {
42+
const particularInputString: string[] = [];
43+
switch (column.input) {
44+
case DataTypes.SELECT:
45+
// Lvl3: select column properties
46+
if (column.options && Array.isArray(column.options)) {
47+
particularInputString.push(`${YAML_INDENT.repeat(2)}options:`);
48+
column.options.forEach(option => {
49+
particularInputString.push(`${YAML_INDENT.repeat(3)}- {label: ${option.label}, backgroundColor: ${option
50+
.backgroundColor}`);
51+
});
52+
}
53+
}
54+
return particularInputString;
55+
}

0 commit comments

Comments
 (0)