From 78485768fec8d5212075be26a5ca22db2d8e288f Mon Sep 17 00:00:00 2001 From: postrowinski
- {"(object)"}{" "} - {JSON.stringify( - attr.value, - null, - 4 - )} -- )} -
+ {"(object)"}{" "} + {JSON.stringify( + attr.value, + null, + 4 + )} ++ )} +
- {"(object)"}{" "} - {JSON.stringify( - attr.value, - null, - 4 - )} -- )} -
+ {"(object)"}{" "} + {JSON.stringify( + attr.value, + null, + 4 + )} ++ )} +
- {"(object)"}{" "} - {JSON.stringify( - attr.value, - null, - 4 - )} -- )} -
- {"(object)"}{" "} - {JSON.stringify( - attr.value, - null, - 4 - )} -- )} -
+ {"(object)"}{" "} + {JSON.stringify(attr.value, null, 4)} ++ )} +
{h} | ))}
---|
{
@@ -39,9 +46,9 @@ export default function SortedList(props) {
style={{ cursor: "pointer" }}
>
{h}
- {!unsortable.includes(h) && (
+ {!isNil(sortIcon(idx)) && (
| ||||||
---|---|---|---|---|---|---|
- {isDeleteButtonRender(cap) && (
- {
- ev.preventDefault();
- setCapabilitiesToDelete(cap);
- }}
- >
- |
- )}
- - {cap} - | -
-
- {capabilitiesList[cap] || "(no description)"}
-
-
- {profile.groups && (
-
-
- Got from:
-
- {profile.groups
- .filter((group) =>
- group.capabilities.includes(cap)
- )
- .map((group, index) => (
-
- |
-
- Here is the list of {profile.groups ? "account" : "group"}{" "} - superpowers: -
- {userHasCapabilities(Capability.manageUsers) && ( -+ Here is the list of {profile.groups ? "account" : "group"}{" "} + superpowers: +
+ {userHasCapabilities(Capability.manageUsers) && ( +User login | -Action | -
---|
User login | +Action | +
---|
Continue?
+ {isDeleteButtonRender(cap) && (
+ {
+ ev.preventDefault();
+ setCapabilitiesToDelete(cap);
+ }}
+ >
+ |
+ )}
+ + {cap} + | +
+
+ {capabilitiesList[cap] || "(no description)"}
+
+
+ {profile.groups && (
+
+
+ Got from:
+
+ {profile.groups
+ .filter((group) =>
+ group.capabilities.includes(cap)
+ )
+ .map(
+ (
+ group: Group,
+ index: number
+ ) => (
+
+ |
+
+ {renderTokens(token.tokens ?? [], options)} ++ ); + }, + paragraph(token: Token) { + return ( +
+ {renderTokens(token.tokens ?? [], options)} +
+ ); + }, + link(token: Token) { + if (token.href && token.href.startsWith("search#")) { + const query = token.href.slice("search#".length); + const search = + "?" + new URLSearchParams({ q: query }).toString(); + return ( + + {renderTokens(token.tokens ?? [], options)} + + ); + } + return ( + + {renderTokens(token.tokens ?? [], options)} + + ); + }, + list(token: Token) { + return ( +{token.text}
;
+ },
+ code(token: Token) {
+ return {token.text}; + }, + space() { + return []; + }, + }; + + return tokens.map((token: Token) => { + const renderer = renderers[token.type]; + if (!renderer) { + return [{`(No renderer for ${token.type})`}]; + } + return renderer(token); + }); +} diff --git a/mwdb/web/src/components/RichAttribute/MarkedMustache.jsx b/mwdb/web/src/components/RichAttribute/MarkedMustache.tsx similarity index 50% rename from mwdb/web/src/components/RichAttribute/MarkedMustache.jsx rename to mwdb/web/src/components/RichAttribute/MarkedMustache.tsx index 60641d11e..5af5aeec0 100644 --- a/mwdb/web/src/components/RichAttribute/MarkedMustache.jsx +++ b/mwdb/web/src/components/RichAttribute/MarkedMustache.tsx @@ -1,10 +1,11 @@ -import React from "react"; -import Mustache from "mustache"; -import { uniqueId } from "lodash"; -import { lexer, defaults, Tokenizer } from "marked"; -import { DataTable } from "@mwdb-web/commons/ui"; -import { escapeSearchValue } from "@mwdb-web/commons/helpers"; -import { Link } from "react-router-dom"; +import Mustache, { Context } from "mustache"; +import { marked, Tokenizer } from "marked"; +import { + escapeSearchValue, + Option, + renderTokens, + Token, +} from "@mwdb-web/commons/helpers"; /** * Markdown with Mustache templates for React @@ -18,18 +19,18 @@ import { Link } from "react-router-dom"; * - Removed HTML escaping on Marked level */ -function appendToLastElement(array, value) { +function appendToLastElement(array: string[], value: string) { // (["a", "b", "c"], "d") => ["a", "b", "cd"] return [...array.slice(0, -1), array[array.length - 1] + value]; } -function splitName(name) { +function splitName(name: string) { if (name === ".") // Special case for "this" return []; return name .split(/(? { + .reduce((acc: string[], current: string, index: number) => { const unescapedCurrent = current.replaceAll(/\\([.\\])/g, "$1"); if (index % 2) { // Last character is a dot, rest must be appended to last element @@ -42,7 +43,7 @@ function splitName(name) { }, []); } -function makeQuery(path, value, attributeKey) { +function makeQuery(path: string[], value: string, attributeKey: string) { if (path[0] !== "value" && path[0] !== "value*") /** * TODO: value* should be interpreted as attribute.
- {renderTokens(token.tokens, options)} -- ); - }, - paragraph(token) { - return ( -
- {renderTokens(token.tokens, options)} -
- ); - }, - link(token) { - if (token.href.startsWith("search#")) { - const query = token.href.slice("search#".length); - const search = - "?" + new URLSearchParams({ q: query }).toString(); - return ( - - {renderTokens(token.tokens, options)} - - ); - } - return ( - - {renderTokens(token.tokens, options)} - - ); - }, - list(token) { - return ( -{token.text}
;
- },
- code(token) {
- return {token.text}; - }, - space() { - return []; - }, - }; - return tokens.map((token) => { - const renderer = renderers[token.type]; - if (!renderer) { - return [{`(No renderer for ${token.type})`}]; - } - return renderer(token); - }); -} - -export function renderValue(template, value, options) { +export function renderValue(template: string, value: Object, options: Option) { const markdown = mustacheWriter.render(template, value); - const tokens = lexer(markdown, { - ...defaults, + const tokens = marked.lexer(markdown, { + ...marked.defaults, tokenizer: markedTokenizer, - }); + }) as Token[]; return