diff --git a/package-lock.json b/package-lock.json index 85b4acc..9b463e2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4566,7 +4566,7 @@ "version": "3.0.2", "license": "MIT", "dependencies": { - "fill-range": "^7.0.1" + "fill-range": "^7.1.1" }, "engines": { "node": ">=8" @@ -6868,8 +6868,9 @@ } }, "node_modules/fill-range": { - "version": "7.0.1", - "license": "MIT", + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", + "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", "dependencies": { "to-regex-range": "^5.0.1" }, diff --git a/src/Candidate.js b/src/Candidate.js index 1adaf14..c3d606d 100644 --- a/src/Candidate.js +++ b/src/Candidate.js @@ -15,11 +15,37 @@ export default class Candidate extends React.Component { } renderDescription() { - let description = this.props.candidate.description; - if (description !== undefined) { - return (
Description
{description}
); - } - } + const description = this.props.candidate?.description; + + if (description) { + return ( +
+
Description
+
+ {description?.values?.length > 0 && + Array.isArray(description?.values) + ? description.values.map((value, index) => ( + + + {value.str} + + + {value.lang} + + + )) + : typeof description === "string" && ( + + {description} + + )} +
+
+ ); + } + + return null; + } renderTypes() { let types = this.props.candidate.type; @@ -45,10 +71,29 @@ export default class Candidate extends React.Component { } render() { - let candidate = this.props.candidate; - return ( + let candidate = this.props.candidate; + const nameValues = candidate?.name?.values; + const hasValues = nameValues?.length > 0; + const mainTitle = hasValues ? nameValues[0]?.str : candidate?.name; + const lang = hasValues ? nameValues[0]?.lang : ""; + return ( + {mainTitle} + {hasValues && ( + {lang} + )} + + } + active={candidate.match} + > + +
{candidate?.name?.values?.slice(1)?.map(value=>{ + return {value?.str}{value?.lang} + })}
+
{this.props.candidate.score} -
ID
{this.renderDescription()} diff --git a/src/TestBench.js b/src/TestBench.js index 30d7270..1bbcded 100644 --- a/src/TestBench.js +++ b/src/TestBench.js @@ -19,11 +19,11 @@ import PreviewRenderer from './PreviewRenderer.js'; import DataExtensionTab from './DataExtensionTab.js'; import JSONTree from 'react-json-tree'; import { getSchema } from './JsonValidator.js'; -import { jsonTheme } from './utils.js'; +import { jsonTheme, specVersions } from './utils.js'; export default class TestBench extends React.Component { - constructor() { - super(); + constructor(props) { + super(props); this.state = { reconQuery: '', @@ -36,6 +36,12 @@ export default class TestBench extends React.Component { }; } + componentDidUpdate(prevProps, prevState) { + if (prevProps?.service?.endpoint !== this.props.service.endpoint) { + this.formulateReconQuery(this.props.service.manifest.versions) + } +} + onReconQueryChange = (e) => { this.setState({ reconQuery: e.currentTarget.value @@ -113,11 +119,11 @@ export default class TestBench extends React.Component { } this.setState({reconResults: 'fetching'}); let fetcher = this.props.service.postFetcher(); - fetcher({url:this.props.service.endpoint,queries:JSON.stringify({q0: this.formulateReconQuery()})}) + fetcher({url:this.props.service.endpoint,queries:JSON.stringify(this.formulateReconQuery(this.props.service.manifest.versions)),manifestVersion:this.props.service.manifest.versions}) .then(result => result.json()) .then(result => this.setState({ - reconResults: result.q0.result, + reconResults: result?.results?.[0]?.candidates ?? result?.q0?.result ?? [], reconResponseValidationErrors: this.validateServiceResponse('reconciliation-result-batch', result) })) .catch(e => { @@ -189,33 +195,58 @@ export default class TestBench extends React.Component { } } - formulateReconQuery() { - let query = { - query: this.state.reconQuery, - }; - if (this.state.reconType === 'custom-type' && this.state.reconCustomType !== undefined) { - query.type = this.state.reconCustomType.id; - } else if (this.state.reconType !== 'no-type') { - query.type = this.state.reconType; - } - if (this.state.reconProperties.length > 0) { - query.properties = this.state.reconProperties - .filter(m => m !== undefined && m.property && m.value) - .map(m => {return {pid: m.property.id, v: m.value}}) - } - if (!isNaN(parseInt(this.state.reconLimit))) { - query.limit = parseInt(this.state.reconLimit); - } - return query; - } + formulateReconQuery(manifestVersion) { + const isCustomType = this.state.reconType === "custom-type" && this.state.reconCustomType !== undefined; + const isNotNoType = this.state.reconType !== "no-type"; + const hasReconProperties = this.state.reconProperties.length > 0; + const reconLimit = parseInt(this.state.reconLimit); + const isLimitValid = !isNaN(reconLimit); + + const buildConditions = () => { + let conditions = [{ matchType: "name", v: this.state.reconQuery }]; + if (hasReconProperties) { + const properties = this.state.reconProperties + .filter(m => m && m.property && m.value) + .map(m => ({ matchType: "property", pid: m.property.id, v: m.value })); + conditions = conditions.concat(properties); + } + return conditions; + }; + + const buildQuery = () => { + const query = { query: this.state.reconQuery }; + if (isCustomType) query.type = this.state.reconCustomType.id; + else if (isNotNoType) query.type = this.state.reconType; + if (hasReconProperties) { + query.properties = this.state.reconProperties + .filter(m => m && m.property && m.value) + .map(m => ({ pid: m.property.id, v: m.value })); + } + if (isLimitValid) query.limit = reconLimit; + return query; + }; + + if (manifestVersion?.includes(specVersions["0.3"])) { + return { + queries: [{ + ...(isCustomType ? { type: this.state.reconCustomType.id } : isNotNoType ? { type: this.state.reconType } : {}), + ...(isLimitValid && { limit: this.state.reconLimit }), + conditions: buildConditions() + }] + }; + } else { + return { q0: buildQuery() }; + } +} formulateQueryUrl() { let baseUrl = this.props.service.endpoint; if (!baseUrl) { return '#'; } + let params = { - queries: JSON.stringify({q0: this.formulateReconQuery()}) + queries: JSON.stringify( this.formulateReconQuery(this.props.service.manifest.versions)) }; let url = new URL(baseUrl); Object.keys(params).forEach(key => url.searchParams.append(key, params[key])); @@ -311,7 +342,7 @@ export default class TestBench extends React.Component { ''} shouldExpandNode={(keyName, data, level) => true} hideRoot={true} /> diff --git a/src/style.css b/src/style.css index 6034fe4..19eda31 100644 --- a/src/style.css +++ b/src/style.css @@ -86,3 +86,25 @@ div .radio label { .candidateValue { margin-left: 1.5em; } + +.candidateMultilingualNames{ + display: grid; + margin-left: 1.5em; +} + +.candidate-main-title{ + display: flex; + gap:8px +} + +.candidate-main-title-lang-bold,.candidate-main-title-str-bold{ + font-weight: bold; +} + +.candidate-main-title-lang-bold,.candidate-main-title-lang{ + color:#ababab +} + +.candidate-description-wrapper{ + margin-left: 1.5em; +} \ No newline at end of file diff --git a/src/utils.js b/src/utils.js index a48fce1..f01e0d1 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,6 +1,12 @@ import fetchJsonp from 'fetch-jsonp'; +export const specVersions={ +"0.1":"0.1", +"0.2":"0.2", +"0.3":"0.3", +"draft":"draft", +} const addParams = (baseUrl, params) => { let url = new URL(baseUrl); if (params) { @@ -30,17 +36,45 @@ export const postJsonpParams = ({url,queries}) => { } -export const postParams = ({url,queries}) => { - return fetch(url, { - method:"POST", - headers: { - 'Content-Type': 'application/x-www-form-urlencoded' - }, - body: new URLSearchParams({ - queries - }) -}); -} +export const postParams = ({ + url, + queries, + manifestVersion = [specVersions["0.2"]], + }) => { + let currentManifestVersion = specVersions["0.2"]; + if(manifestVersion?.includes(specVersions["0.3"])) currentManifestVersion = specVersions["0.3"]; + switch (currentManifestVersion) { + + case "0.2": + return fetch(url, { + method: "POST", + headers: { + "Content-Type": "application/x-www-form-urlencoded", + }, + body: new URLSearchParams({ + queries, + }), + }); + case "0.3": + return fetch(url, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body:queries, + }); + default: + return fetch(url, { + method: "POST", + headers: { + "Content-Type": "application/x-www-form-urlencoded", + }, + body: new URLSearchParams({ + queries, + }), + }); + } + }; export const jsonTheme = { scheme: 'monokai',