Skip to content

Commit

Permalink
Added interface id prefix without package id to choices popup (digita…
Browse files Browse the repository at this point in the history
…l-asset#14941)

* added interface id prefix without package id to choices popup

CHANGELOG_BEGIN
CHANGELOG_END

* strong prefix
* format
  • Loading branch information
chunlokling-da authored Sep 6, 2022
1 parent fbe3d94 commit dbebbea
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 12 deletions.
8 changes: 2 additions & 6 deletions navigator/frontend/src/applets/contract/ContractComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { DamlLfValue } from "@da/ui-core/lib/api/DamlLfValue";
import {
shortenContractId,
shortenPartyId,
removePkgIdFromContractTypeId,
} from "@da/ui-core/lib/api/IdentifierShortening";
import * as React from "react";
import Link, { OwnProps } from "../../components/Link";
Expand Down Expand Up @@ -123,11 +124,6 @@ interface Props {
}

export default (props: Props): JSX.Element => {
const toInterfaceModuleAndEntity = (interfaceId: string): string => {
const matches = interfaceId.match(/^([^:@]+):([^:@]+)@([^:@]+)$/);
return matches ? `${matches[1]}:${matches[2]}` : interfaceId;
};

const { contract, choice, ifc, exercise, choiceLoading, error } = props;
const choices = contract.template.choices;
const isArchived = contract.archiveEvent !== null;
Expand Down Expand Up @@ -155,7 +151,7 @@ export default (props: Props): JSX.Element => {

const choicesEl = choices.map(({ name, inheritedInterface }) => {
const interfacePrefix = inheritedInterface
? toInterfaceModuleAndEntity(inheritedInterface) + ":"
? removePkgIdFromContractTypeId(inheritedInterface) + ":"
: "";
const fullChoiceName = `${interfacePrefix}${name}`;
const isAnyActive = choice !== undefined;
Expand Down
15 changes: 14 additions & 1 deletion navigator/frontend/src/applets/contracts/columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import Link from "../../components/Link";
import * as Routes from "../../routes";
import { Contract } from "./data";

import { removePkgIdFromContractTypeId } from "@da/ui-core/lib/api/IdentifierShortening";

export const columns: ContractColumn<Contract>[] = [
{
key: "id",
Expand Down Expand Up @@ -54,7 +56,18 @@ export const columns: ContractColumn<Contract>[] = [
choice: name,
ifc: inheritedInterface && encodeURIComponent(inheritedInterface),
}}>
<div>{name}</div>
<div>
{inheritedInterface ? (
<>
<strong>
{removePkgIdFromContractTypeId(inheritedInterface) + ":"}
</strong>{" "}
{name}{" "}
</>
) : (
name
)}
</div>
</Link>
)}
/>
Expand Down
4 changes: 2 additions & 2 deletions navigator/frontend/src/ui-core/src/ChoicesButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface Contract {
}

const List = styled.ul`
width: 160px;
min-width: 160px;
list-style: none;
padding: 15px;
margin: 0;
Expand Down Expand Up @@ -59,7 +59,7 @@ const Content = ({ contract, choices, renderLink }: ContentProps) => {
return (
<List>
{contract.template.choices.map(choice => (
<ListItem key={choice.name}>
<ListItem key={choice.inheritedInterface + choice.name}>
<Truncate>
{renderLink(contract.id, choice.name, choice.inheritedInterface)}
</Truncate>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { DamlLfValue } from "../api/DamlLfValue";
import * as DamlLfValueF from "../api/DamlLfValue";
import {
shortenContractId,
shortenTemplateId,
shortenContractTypeId,
} from "../api/IdentifierShortening";
import Autosuggest from "../Autosuggest";
import styled from "../theme";
Expand All @@ -28,7 +28,7 @@ function renderSuggestion(c: ParameterFormContract): JSX.Element {
return (
<Container>
<BigColumn>{shortenContractId(c.id)}</BigColumn>
<BigColumn>{shortenTemplateId(c.template.id)}</BigColumn>
<BigColumn>{shortenContractTypeId(c.template.id)}</BigColumn>
<BigColumn>{c.createEvent.transaction.effectiveAt}</BigColumn>
</Container>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,10 @@ export const shortenContractId = shortenHash;
// - just shorten the entire identifier to 12 characters
export const shortenPartyId = shortenPrefixedId("::");

export const shortenTemplateId = shortenPrefixedId("@");
export const shortenContractTypeId = shortenPrefixedId("@");

export function removePkgIdFromContractTypeId(id: string): string {
const separator = "@";
const parts = id.split(separator);
return parts.length === 2 ? parts[0] : id;
}

0 comments on commit dbebbea

Please sign in to comment.