Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix aliases with commas in them. #179

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ node_modules
.env
.DS_Store
undefined
.vscode
.vscode
backups
Spaces.mdb
data.json
60 changes: 25 additions & 35 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/components/ContextView/ContextListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const ContextListView = (props: { plugin: MakeMDPlugin }) => {
const { schema } = useContext(MDBContext);
const [error, resetError] = useErrorBoundary();
if (error) console.log(error);

return schema ? (
schema.type == "flow" ? (
<FlowListView plugin={props.plugin}></FlowListView>
Expand Down
1 change: 1 addition & 0 deletions src/components/ContextView/DataTypeView/DataTypeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export const DataTypeView: React.FC<DataTypeViewProps> = (
></ContextCell>
);
} else if (fieldType.type == "fileprop") {

return <LookUpCell {...viewProps} file={file}></LookUpCell>;
} else if (fieldType.type == "number") {
return <NumberCell {...viewProps}></NumberCell>;
Expand Down
2 changes: 2 additions & 0 deletions src/components/ContextView/MDBContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ export const MDBProvider: React.FC<
) ?? [],
[tableData, schema, contextTable]
);

const sortedColumns = useMemo(() => {
return cols
.filter(
Expand Down Expand Up @@ -342,6 +343,7 @@ export const MDBProvider: React.FC<
const col = (table == "" ? tableData : contextTable[table])?.cols.find(
(f) => f.name == column
);

if (col)
saveFrontmatterValue(
props.plugin,
Expand Down
13 changes: 8 additions & 5 deletions src/dispatch/mdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export const insertContextColumn = async (
context: ContextInfo,
field: MDBField
): Promise<void> => {

let tagFileExists = abstractFileAtPathExists(app, context.dbPath);
if (!tagFileExists) {
tagFileExists = await createDefaultDB(plugin, context);
Expand Down Expand Up @@ -207,7 +207,9 @@ const fileToFM = (afile: TAbstractFile, cols: string[], plugin: MakeMDPlugin) =>
const fm = frontMatterForFile(file);
const fmKeys = frontMatterKeys(fm).filter((f) => cols.some((g) => f == g));
const rows = fmKeys.reduce(
(p, c) => ({ ...p, [c]: parseFrontMatter(c, fm[c]) }),
(p, c) => {
return ({ ...p, [c]: parseFrontMatter(c, fm[c]) })
},
{}
);
if (plugin.dataViewAPI()) {
Expand Down Expand Up @@ -246,6 +248,7 @@ export const onMetadataChange = async (
file: TAbstractFile,
contexts: ContextInfo[]
): Promise<void[]> => {
// console.log(contexts);
const promises = contexts.map((context) => {
return processContextFile(plugin, context, async (mdb, context) => {
const newDB = {
Expand Down Expand Up @@ -327,7 +330,7 @@ export const renameTagInContexts = async ( plugin: MakeMDPlugin,
export const addFileInContexts = async (plugin: MakeMDPlugin,
path: string,
contexts: ContextInfo[]): Promise<void[]> => {

const promises = contexts.map((context) => {
return processContextFile(plugin, context, async (mdb, context) => {
const newDB = insertRowsIfUnique(mdb, [{ File: path }]);
Expand All @@ -338,7 +341,7 @@ export const addFileInContexts = async (plugin: MakeMDPlugin,
})
});
return Promise.all(promises);

}

export const renameLinkInContexts = async (plugin: MakeMDPlugin,
Expand Down Expand Up @@ -406,7 +409,7 @@ export const removeFileInContexts = async (plugin: MakeMDPlugin,
saveContextToFrontmatter(path, mdb.cols, removeRow, plugin)
}
const newDB = removeRowForFile(mdb, path);

if (!_.isEqual(mdb, newDB))
{
await saveDB(plugin, context, newDB);}
Expand Down
13 changes: 7 additions & 6 deletions src/superstate/cacheParsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export const parseFileContetxs = (file: AFile, tags: string[], contextsCache: Ma
contexts.push(...tags.filter(t => contextsCache.has(t)))
if (file.parent != '/')
contexts.push(file.parent);
spaces.forEach(space =>
spaces.forEach(space =>
{
if (contextsCache.has(spaceContextPathFromName(space))) {
contexts.push(spaceContextPathFromName(space));
Expand All @@ -132,12 +132,12 @@ export const parseMetadata = (file: AFile, settings: MakeMDPluginSettings, conte
}
const tags : string[] = [];
const fileTags : string[] = tagsForCachedMetadata(metadataCache);

if (contextsCache.has(file.parent)) {
for (const def of contextsCache.get(file.parent).def) {
if (def.type == 'tag') {
tags.push(def.value);
}
}
}
}

Expand Down Expand Up @@ -169,7 +169,7 @@ export const parseMetadata = (file: AFile, settings: MakeMDPluginSettings, conte
}
let banner = '';
if (fm) {

const fmKeys = uniqCaseInsensitive(frontMatterKeys(fm));
const cols: Record<string, { type: string, name: string }> = fmKeys.reduce((p, c) => ({
...p, [c]: {
Expand All @@ -192,6 +192,7 @@ export const parseMetadata = (file: AFile, settings: MakeMDPluginSettings, conte
}
if (properties[settings.fmKeyAlias] && settings.spacesUseAlias) {
name = fm[settings.fmKeyAlias];
if (Array.isArray(name)) name = name[0];
}
}
const fileCache = {
Expand Down Expand Up @@ -239,8 +240,8 @@ export const parseMetadata = (file: AFile, settings: MakeMDPluginSettings, conte
let changed = true;

if (oldMetadata && _.isEqual(metadata, oldMetadata)) {

changed = false;
}
return {changed, cache: metadata }
}
}
12 changes: 6 additions & 6 deletions src/utils/contexts/mdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,15 +368,15 @@ export const connectContext = async (
tag: string,
source: string
) => {

};

export const disconnectContext = async (
plugin: MakeMDPlugin,
tag: string,
source: string
) => {

};

export const renameSpaceContextFile = async (
Expand All @@ -394,7 +394,7 @@ export const renameSpaceContextFile = async (
"/" + newSpaceDBPath
)
) {
await renameFile(plugin,
await renameFile(plugin,
getAbstractFileAtPath(app, context.dbPath),
newSpaceDBPath
);
Expand All @@ -413,7 +413,7 @@ export const renameSpaceContextFile = async (
});
}
}, app.workspace["rootSplit"]!);

};


Expand All @@ -434,7 +434,7 @@ export const renameTagContextFile = async (
".mdb"
)
) {
await renameFile(plugin,
await renameFile(plugin,
getAbstractFileAtPath(app, context.dbPath),
tagToTagPath(newTag) + ".mdb"
);
Expand All @@ -454,5 +454,5 @@ export const renameTagContextFile = async (
});
}
}, app.workspace["rootSplit"]!);

};
2 changes: 2 additions & 0 deletions src/utils/metadata/dv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export async function replaceValues(
input: string,
previousItemsCount: number = 0
): Promise<void> {

let file: TFile;
if (fileOrFilePath instanceof TFile) {
file = fileOrFilePath;
Expand All @@ -139,6 +140,7 @@ export async function replaceValues(
} = frontmatter
? frontmatter
: { position: { start: undefined, end: undefined } };

const newContent = content.map((line, i) => {
const encodedInput = encodeLink(input);
let encodedLine = encodeLink(line);
Expand Down
7 changes: 4 additions & 3 deletions src/utils/metadata/frontmatter/parseFrontMatter.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { serializeMultiDisplayString, serializeMultiString } from "utils/serializer";
import { MULTI_STRING_DELIMITER, serializeMultiDisplayString, serializeMultiString } from "utils/serializer";
import { detectYAMLType } from "./detectYAMLType";


export const parseFrontMatter = (field: string, value: any) => {
const YAMLtype = detectYAMLType(value, field);
// We need to always treat Aliases as an option-multi field, even if it's a string.
const YAMLtype = field === 'aliases' ? 'option-multi' : detectYAMLType(value, field);
switch (YAMLtype) {
case "object":
return JSON.stringify(value);
Expand All @@ -30,7 +31,7 @@ export const parseFrontMatter = (field: string, value: any) => {
case "option-multi":
case "link-multi":
if (typeof value === "string") {
return value;
return value.split(',').join(MULTI_STRING_DELIMITER);
}
return serializeMultiString(value
.map((v: any) => {
Expand Down
Loading