Replies: 2 comments 4 replies
-
In case it doesn't exist, I can fix my use case it with the following function. export async function obtainColumnsFromRows(
view: DatabaseView,
ddbbConfig: LocalSettings,
filters: FilterSettings,
tableColumns: TableColumn[]
): Promise<Record<string, DatabaseColumn>> {
const columns: Record<string, DatabaseColumn> = {};
const rows = await obtainAllPossibleRows(
view.file.parent.path,
ddbbConfig,
filters,
tableColumns
);
// Obtain unique keys from source
const keys = rows.reduce((acc, row) => {
const keys = Object.keys(row).map((key) => key);
// Remove duplicates
return [...new Set([...acc, ...keys])];
}, [] as string[]);
const uppercaseFields: string[] = [];
let lowercaseFields: string[] = [];
keys.forEach((key) => {
if (containsUpper(key)) {
uppercaseFields.push(key);
} else {
lowercaseFields.push(key);
}
});
const uppercaseFieldsToFilter = uppercaseFields.map((ucf) =>
ucf.toLowerCase()
);
lowercaseFields = lowercaseFields.filter(
(field) => !uppercaseFieldsToFilter.contains(field)
);
const uniqueKeys = [...new Set([...uppercaseFields, ...lowercaseFields])];
// Add keys to columns
uniqueKeys
// Check metadata columns to not be added
.filter((key) => validateColumnKey(key))
.forEach((key, index) => {
columns[key] = {
input: InputType.TEXT,
accessorKey: key,
label: key,
key: key,
position: index,
config: DEFAULT_COLUMN_CONFIG,
};
});
return columns;
} |
Beta Was this translation helpful? Give feedback.
1 reply
-
I can confirm this issue. If you add a YAML header which uses It's probably somewhere an issue with the Dataview API (lovely plugin btw, thanks!). |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have a function on dbfolder plugin where you can obtain all possible fields. To evict duplicates, I was mapping the results to lowercase because if the field has the first char on uppercase, the API also returns lowercase one.
Is there an option to do not duplicate that result?
Thanks in advance
I leave an example with the lowercase map removed:
RafaelGB/obsidian-db-folder#269
Beta Was this translation helpful? Give feedback.
All reactions