Skip to content

Commit

Permalink
Aligning field type icons with the Properties for consistency (#679)
Browse files Browse the repository at this point in the history
  • Loading branch information
Acylation committed Oct 4, 2023
1 parent 5f82c36 commit 9d757c1
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 36 deletions.
5 changes: 4 additions & 1 deletion src/lib/stores/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
"boolean": "Checkbox",
"date": "Date",
"unknown": "Unknown data type",
"repeated": "Repeated field"
"repeated": "Repeated field",
"list": "List",
"tags": "Tags",
"Aliases": "Aliases"
},
"datasources": {
"folder": "Folder",
Expand Down
5 changes: 4 additions & 1 deletion src/lib/stores/translations/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
"boolean": "复选框",
"date": "日期",
"unknown": "未知",
"repeated": "周期"
"repeated": "周期",
"list": "列表",
"tags": "标签",
"aliases": "别名"
},
"datasources": {
"folder": "文件夹",
Expand Down
9 changes: 1 addition & 8 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import isoWeek from "dayjs/plugin/isoWeek";
import localizedFormat from "dayjs/plugin/localizedFormat";
import { either, task, taskEither } from "fp-ts";
import { pipe } from "fp-ts/lib/function";
import { Plugin, TFile, TFolder, WorkspaceLeaf, addIcon } from "obsidian";
import { Plugin, TFile, TFolder, WorkspaceLeaf } from "obsidian";
import "obsidian-dataview";
import { createDataRecord, createProject } from "src/lib/dataApi";
import { api } from "src/lib/stores/api";
Expand Down Expand Up @@ -48,13 +48,6 @@ export default class ProjectsPlugin extends Plugin {
this.activateView();
});

// Add an icon for text fields. Remove once Obsidian has a decent
// alternative.
addIcon(
"text",
`<g transform="matrix(1,0,0,1,2,2)"><path d="M20,32L28,32L28,24L41.008,24L30.72,72L20,72L20,80L52,80L52,72L42.992,72L53.28,24L68,24L68,32L76,32L76,16L20,16L20,32Z" /></g>`
);

this.registerView(
VIEW_TYPE_PROJECTS,
(leaf) => new ProjectsView(leaf, this)
Expand Down
5 changes: 3 additions & 2 deletions src/ui/views/Table/components/DataGrid/GridHeader.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
import type { Menu } from "obsidian";
import { GridCell, TextLabel } from "./GridCell";
import { fieldIcon, menuOnContextMenu, type GridColDef } from "./data-grid";
import { fieldIcon } from "src/ui/views/helpers";
import { menuOnContextMenu, type GridColDef } from "./dataGrid";
import GridCellGroup from "./GridCellGroup.svelte";
import { DataFieldType } from "src/lib/data";
import { DataFieldType } from "src/lib/dataframe/dataframe";
import { i18n } from "src/lib/stores/i18n";
export let columns: GridColDef[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import { DataFieldType } from "src/lib/dataframe/dataframe";
import { i18n } from "src/lib/stores/i18n";
import { get } from "svelte/store";
import { fieldIcon, type GridColDef } from "../dataGrid";
import { fieldIcon } from "src/ui/views/helpers";
import type { GridColDef } from "../dataGrid";
import { TextLabel } from "../GridCell";
type GridColDefWithId = GridColDef & { readonly id: string };
Expand All @@ -27,7 +28,13 @@
style:width={`${column.width}px`}
>
{#if column.repeated}
<Icon name="list" tooltip={get(i18n).t(`data-types.repeated`) ?? ""} />
{#if column.field == "tags"}
<Icon name="tags" tooltip={get(i18n).t(`data-types.tags`) ?? ""} />
{:else if column.field == "aliases"}
<Icon name="forward" tooltip={get(i18n).t(`data-types.aliases`) ?? ""} />
{:else}
<Icon name="list" tooltip={get(i18n).t(`data-types.list`) ?? ""} />
{/if}
{:else}
<Icon
name={fieldIcon(column.type ?? DataFieldType.Unknown)}
Expand Down
19 changes: 1 addition & 18 deletions src/ui/views/Table/components/DataGrid/dataGrid.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import type { Menu } from "obsidian";
import {
DataFieldType,
type DataField,
} from "../../../../../lib/dataframe/dataframe";
import type { DataFieldType, DataField } from "src/lib/dataframe/dataframe";

export type GridValidRowModel = { [key: string]: any };
export type GridRowModel<R extends GridValidRowModel = GridValidRowModel> = R;
Expand All @@ -23,20 +20,6 @@ export interface GridRowProps {
readonly row: GridRowModel;
}

export function fieldIcon(field: DataFieldType): string {
switch (field) {
case DataFieldType.String:
return "text";
case DataFieldType.Number:
return "hash";
case DataFieldType.Boolean:
return "check";
case DataFieldType.Date:
return "calendar-days";
}
return "alert-triangle";
}

export function menuOnContextMenu(event: MouseEvent, menu: Menu): void {
const contextMenuFunc = (event: MouseEvent) => {
window.removeEventListener("contextmenu", contextMenuFunc);
Expand Down
8 changes: 4 additions & 4 deletions src/ui/views/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ export function fieldIcon(field: DataFieldType): string {
case DataFieldType.String:
return "text";
case DataFieldType.Number:
return "hash";
return "binary";
case DataFieldType.Boolean:
return "check";
return "check-square";
case DataFieldType.Date:
return "calendar-days";
return "calendar";
}
return "info";
return "file-question";
}

export function fieldToSelectableValue(field: DataField): {
Expand Down

0 comments on commit 9d757c1

Please sign in to comment.