Skip to content

Commit

Permalink
1270 hide detail relations section for template entities (#2036)
Browse files Browse the repository at this point in the history
* Add isTemplate condition into getEntityRelationRules method

* Add no relations text

* Integrate isTemplate parameter where needed
  • Loading branch information
adammertel authored Apr 19, 2024
1 parent 6da2e80 commit 7e0022d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export const EntityTag: React.FC<EntityTag> = ({
? entity.data.text
: undefined
}
isTemplate={entity.isTemplate}
partOfSpeech={entity.data.pos}
itemsCount={statementsCount}
position={tooltipPosition}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ interface EntityTooltip {

referenceElement: HTMLDivElement | null;
customTooltipAttributes?: { partLabel?: string };
isTemplate?: boolean;
}
export const EntityTooltip: React.FC<EntityTooltip> = ({
// entity
Expand All @@ -82,6 +83,7 @@ export const EntityTooltip: React.FC<EntityTooltip> = ({
//
referenceElement,
customTooltipAttributes,
isTemplate = false,
}) => {
const [tooltipData, setTooltipData] = useState<
EntityTooltipNamespace.IResponse | false
Expand Down Expand Up @@ -214,7 +216,8 @@ export const EntityTooltip: React.FC<EntityTooltip> = ({

const filteredTypes = getEntityRelationRules(
entityClass,
RelationEnums.TooltipTypes
RelationEnums.TooltipTypes,
isTemplate
);

const relationsCount: number[] = filteredTypes.map((t) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { getEntityRelationRules } from "utils/utils";
import { EntityDetailInverseRelations } from "./EntityDetailInverseRelations/EntityDetailInverseRelations";
import { StyledRelationsGrid } from "./EntityDetailRelationsStyles";
import { EntityDetailRelationTypeBlock } from "./EntityDetailRelationTypeBlock/EntityDetailRelationTypeBlock";
import { StyledEditorEmptyState } from "pages/Main/containers/StatementEditorBox/StatementEditorBoxStyles";
import { BsInfoCircle } from "react-icons/bs";

interface EntityDetailRelations {
entity: IResponseDetail;
Expand Down Expand Up @@ -48,7 +50,8 @@ export const EntityDetailRelations: React.FC<EntityDetailRelations> = ({
useEffect(() => {
const filteredTypes = getEntityRelationRules(
entity.class,
RelationEnums.EntityDetailTypes
RelationEnums.EntityDetailTypes,
entity.isTemplate
);
setFilteredRelationTypes(filteredTypes);
}, [entity]);
Expand All @@ -58,6 +61,14 @@ export const EntityDetailRelations: React.FC<EntityDetailRelations> = ({
return (
<>
<StyledRelationsGrid>
{filteredRelationTypes.length === 0 && (
<>
<StyledEditorEmptyState>
<BsInfoCircle size="20" style={{ marginRight: "5px" }} />
This entity cannot have any relations
</StyledEditorEmptyState>
</>
)}
{filteredRelationTypes.map((relationType, key) => {
const selectedRelations = relations[relationType]?.connections;

Expand Down
21 changes: 20 additions & 1 deletion packages/client/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,28 @@ export const getRelationTreeDepth = (

export const getEntityRelationRules = (
entityClass: EntityEnums.Class,
relationTypes?: RelationEnums.Type[]
relationTypes?: RelationEnums.Type[],
isTemplate: boolean = false
) => {
const typesToFilter = relationTypes ? relationTypes : RelationEnums.AllTypes;

// A and C entity classes cannot have any relations, other classes might have only Classification and Related
if (isTemplate) {
if (
entityClass === EntityEnums.Class.Action ||
entityClass === EntityEnums.Class.Concept
) {
return [];
} else {
return typesToFilter.filter((rule) => {
return (
rule === RelationEnums.Type.Classification ||
rule === RelationEnums.Type.Related
);
});
}
}

return typesToFilter.filter((rule) => {
if (
!Relation.RelationRules[rule]?.allowedEntitiesPattern.length &&
Expand Down

0 comments on commit 7e0022d

Please sign in to comment.