Skip to content

World's first open-source enterprise world model.

An attribute can be created from the ontology table, and relation buttons say relation (#1225)

WaylandYang8b916974958f
diff --git a/web/src/i18n/en.ts b/web/src/i18n/en.ts
index 6676918f..7c80647a 100644
--- a/web/src/i18n/en.ts
+++ b/web/src/i18n/en.ts
@@ -1400,10 +1400,10 @@ export const en = {
axiomSymmetric: "Symmetric",
axiomAsymmetric: "Asymmetric",
axiomIrreflexive: "Irreflexive",
- tabProperties: "Properties",
+ tabProperties: "Relations",
newClass: "New class",
newSubClass: "New sub-class",
- newProperty: "New property",
+ newProperty: "New relation",
filter: "Filter…",
missesShort: "Unmatched",
uniquenessShort: "Overlaps",
@@ -1554,8 +1554,9 @@ export const en = {
/* 编辑弹窗(面板只展示,改动在弹窗里):标题与面板里的入口 */
edit: "Edit",
editClass: "Edit class",
- editProperty: "Edit property",
+ editProperty: "Edit relation",
editAttribute: "Edit attribute",
+ attributeHost: "Belongs to class",
connectTitle: "Connect a relationship",
connectOpen: "Connect an existing relationship…",
noDescription: "No description yet.",
diff --git a/web/src/i18n/zh.ts b/web/src/i18n/zh.ts
index cc493763..78dea684 100644
--- a/web/src/i18n/zh.ts
+++ b/web/src/i18n/zh.ts
@@ -1247,10 +1247,10 @@ export const zh: Strings = {
axiomSymmetric: "对称",
axiomAsymmetric: "反对称",
axiomIrreflexive: "非自反",
- tabProperties: "属性",
+ tabProperties: "关系",
newClass: "新建类",
newSubClass: "新建子类",
- newProperty: "新建属性",
+ newProperty: "新建关系",
filter: "筛选…",
missesShort: "未匹配",
uniquenessShort: "并存",
@@ -1376,6 +1376,7 @@ export const zh: Strings = {
editClass: "编辑类",
editProperty: "编辑关系",
editAttribute: "编辑属性",
+ attributeHost: "挂在哪个类",
connectTitle: "连接一个关系",
connectOpen: "用已有的关系连接…",
noDescription: "还没有描述。",
diff --git a/web/src/pages/Ontology.tsx b/web/src/pages/Ontology.tsx
index 6bd6876c..a7dd4784 100644
--- a/web/src/pages/Ontology.tsx
+++ b/web/src/pages/Ontology.tsx
@@ -128,7 +128,7 @@ type Edit =
// 从一个类出发新建关系时带上它的 id,domain 预填成它
initialDomain: string | null;
}
- | { kind: "attribute"; typeId: string; existing: RelationTypeView | null }
+ | { kind: "attribute"; typeId: string | null; existing: RelationTypeView | null }
| { kind: "connect"; cls: EntityTypeView }
| null;
@@ -582,6 +582,9 @@ export function Ontology() {
initialDomain: null,
})
}
+ onCreateAttribute={() =>
+ setEdit({ kind: "attribute", typeId: null, existing: null })
+ }
/>
) : (
<OntologySchemaGraph
@@ -787,6 +790,7 @@ export function Ontology() {
<AttributeDialog
kbId={kb.id}
typeId={edit.typeId}
+ allTypes={entity_types}
existing={edit.existing}
onClose={() => setEdit(null)}
onSaved={() => {
diff --git a/web/src/pages/ontologyDialogs.tsx b/web/src/pages/ontologyDialogs.tsx
index 22a586b2..c8883098 100644
--- a/web/src/pages/ontologyDialogs.tsx
+++ b/web/src/pages/ontologyDialogs.tsx
@@ -597,6 +597,7 @@ export function PropertyDialog({
export function AttributeDialog({
kbId,
typeId,
+ allTypes,
existing,
onClose,
onSaved,
@@ -604,7 +605,9 @@ export function AttributeDialog({
onError,
}: {
kbId: string;
- typeId: string;
+ /** null = 不是从某个类打开的(本体表格的属性页):弹窗里自己选挂在哪个类 */
+ typeId: string | null;
+ allTypes: EntityTypeView[];
existing: RelationTypeView | null;
onClose: () => void;
onSaved: () => void;
@@ -618,6 +621,8 @@ export function AttributeDialog({
// 单值 = functional:新值经时态引擎闭合旧值(属性历史的来源)。多数属性如此,默认开
const [single, setSingle] = useState(existing?.functional ?? true);
const [description, setDescription] = useState(existing?.description ?? "");
+ const [host, setHost] = useState(typeId ?? "");
+ const hostOpts = useMemo(() => parentOptions(allTypes, undefined), [allTypes]);
const save = useMutation({
mutationFn: async (): Promise<unknown> =>
@@ -635,7 +640,7 @@ export function AttributeDialog({
key,
label,
kind: "attribute",
- domains: [typeId],
+ domains: [host],
temporal: "state",
functional: single,
inverse_functional: false,
@@ -667,7 +672,7 @@ export function AttributeDialog({
closeLabel={S.ui.close}
saveLabel={S.ontology.save}
cancelLabel={S.ontology.cancel}
- canSave={!!label.trim() && (!!existing || !!key.trim())}
+ canSave={!!label.trim() && (!!existing || (!!key.trim() && !!host))}
busy={save.isPending}
onSave={() => save.mutate()}
onCancel={onClose}
@@ -682,6 +687,17 @@ export function AttributeDialog({
: undefined
}
>
+ {!existing && typeId === null && (
+ <Field label={S.ontology.attributeHost}>
+ <SearchSelect
+ value={host}
+ onChange={setHost}
+ options={hostOpts}
+ className="w-full"
+ placeholder={S.ontology.searchTypes}
+ />
+ </Field>
+ )}
{existing ? (
<Field label={S.ontology.label}>
<Input
diff --git a/web/src/pages/ontologyTables.tsx b/web/src/pages/ontologyTables.tsx
index cdba0e72..3c99453f 100644
--- a/web/src/pages/ontologyTables.tsx
+++ b/web/src/pages/ontologyTables.tsx
@@ -517,6 +517,7 @@ export function OntologyTables({
onSeeInstances,
onCreateClass,
onCreateProperty,
+ onCreateAttribute,
selected,
loading = false,
}: {
@@ -530,6 +531,8 @@ export function OntologyTables({
onCreateClass: () => void;
/** 建不带 domain 的关系,同上 */
onCreateProperty: () => void;
+ /** 属性必须挂在类上:从这里新建时,弹窗自己问挂在哪个类 */
+ onCreateAttribute: () => void;
/** 当前选中的那个类或属性。表里要标出来——**点一行开的是右边的面板,
* 行本身不留痕的话,翻两页之后就不知道正在看的是哪一个了**。
* 只收这两档:页面那个 `Sel` 还含 import / rules / schema 几种,
@@ -594,21 +597,28 @@ export function OntologyTables({
: counts.attributes,
)}
</GroupLabel>
- {/* 新建跟着当前这一档走(图那一档里的同一件事在左栏第一行)。
- 属性那一档不给:它必须挂在某个类下,而属性弹窗自己不挑宿主类
- (domain 由打开它的地方给定),所以它的入口在某个类的面板里 */}
- {tab !== "attributes" && (
- <Button
- variant="primary"
- size="sm"
- icon={<Plus size={12} />}
- // 本体还没到不给建:新类要挑父类,而父类清单此刻是空的
- disabled={loading}
- onClick={tab === "classes" ? onCreateClass : onCreateProperty}
- >
- {tab === "classes" ? S.ontology.newClass : S.ontology.newProperty}
- </Button>
- )}
+ {/* 新建跟着当前这一档走(图那一档里的同一件事在左栏第一行)。属性要挂在
+ 类上:从这里打开时弹窗会问挂在哪个类,从某个类的面板打开时就是那个类 */}
+ <Button
+ variant="primary"
+ size="sm"
+ icon={<Plus size={12} />}
+ // 本体还没到不给建:新类要挑父类,而父类清单此刻是空的
+ disabled={loading}
+ onClick={
+ tab === "classes"
+ ? onCreateClass
+ : tab === "properties"
+ ? onCreateProperty
+ : onCreateAttribute
+ }
+ >
+ {tab === "classes"
+ ? S.ontology.newClass
+ : tab === "properties"
+ ? S.ontology.newProperty
+ : S.ontology.newAttribute}
+ </Button>
</div>
<div className="u-scroll min-h-0 flex-1 overflow-y-auto px-8 pb-6">
{/* 表身出骨架,**表头不画**:列名是什么此刻还没定(三张表的列不一样),