Merge pull request #772 from lowdefy/fix-card-title

Fix card title
This commit is contained in:
Gerrie van Wyk 2021-08-21 16:14:31 +02:00 committed by GitHub
commit 2ce90942fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 49 additions and 98 deletions

View File

@ -22,7 +22,11 @@ const CardBlock = ({ blockId, content, properties, methods }) => (
<Card
id={blockId}
title={
<RenderHtml html={content.title ? content.title() : properties.title} methods={methods} />
content.title ? (
content.title()
) : properties.title ? (
<RenderHtml html={properties.title} methods={methods} />
) : undefined
}
headStyle={methods.makeCssClass(properties.headerStyle, { styleObjectOnly: true })}
bodyStyle={methods.makeCssClass(properties.bodyStyle, { styleObjectOnly: true })}

View File

@ -110,8 +110,16 @@
"description": "Item label - supports html."
},
"value": {
"type": "string",
"description": "Value of item - supports html."
"oneOf": [
{
"type": "string",
"description": "Value of item - supports html."
},
{
"type": "number",
"description": "Value of item - supports html."
}
]
},
"span": {
"type": "integer",

View File

@ -94,41 +94,7 @@ Array [
"hoverable": undefined,
"id": "default",
"size": undefined,
"title": <RenderHtml
methods={
Object {
"makeCssClass": [MockFunction] {
"calls": Array [
Array [
undefined,
Object {
"styleObjectOnly": true,
},
],
Array [
undefined,
Object {
"styleObjectOnly": true,
},
],
],
"results": Array [
Object {
"type": "return",
"value": "{\\"options\\":{\\"styleObjectOnly\\":true}}",
},
Object {
"type": "return",
"value": "{\\"options\\":{\\"styleObjectOnly\\":true}}",
},
],
},
"registerEvent": [Function],
"registerMethod": [Function],
"triggerEvent": [Function],
}
}
/>,
"title": undefined,
"type": null,
},
Object {},

View File

@ -58,22 +58,6 @@ exports[`Render default - value[0] 1`] = `
className="ant-card ant-card-bordered"
id="default"
>
<div
className="ant-card-head"
style="{\\"options\\":{\\"styleObjectOnly\\":true}}"
>
<div
className="ant-card-head-wrapper"
>
<div
className="ant-card-head-title"
>
<div
className="{\\"style\\":[{\\"display\\":\\"inline-block\\"},null]}"
/>
</div>
</div>
</div>
<div
className="ant-card-body"
style="{\\"options\\":{\\"styleObjectOnly\\":true}}"

View File

@ -1407,39 +1407,9 @@ exports[`Test Schema properties.itemOptions.style 1`] = `true`;
exports[`Test Schema properties.itemOptions.style 2`] = `null`;
exports[`Test Schema properties.items html values 1`] = `false`;
exports[`Test Schema properties.items html values 1`] = `true`;
exports[`Test Schema properties.items html values 2`] = `
Array [
Object {
"dataPath": "/properties/items/2/value",
"keyword": "type",
"message": "should be string",
"params": Object {
"type": "string",
},
"schemaPath": "#/properties/properties/properties/items/oneOf/0/items/properties/value/type",
},
Object {
"dataPath": "/properties/items",
"keyword": "type",
"message": "should be object",
"params": Object {
"type": "object",
},
"schemaPath": "#/properties/properties/properties/items/oneOf/1/type",
},
Object {
"dataPath": "/properties/items",
"keyword": "oneOf",
"message": "should match exactly one schema in oneOf",
"params": Object {
"passingSchemas": null,
},
"schemaPath": "#/properties/properties/properties/items/oneOf",
},
]
`;
exports[`Test Schema properties.items html values 2`] = `null`;
exports[`Test Schema properties.items-list 1`] = `true`;

View File

@ -59,7 +59,7 @@ async function build(options) {
try {
let components = await buildRefs({ context });
await testSchema({ components, context });
context.getMeta = createGetMeta(context);
context.getMeta = createGetMeta({ components, context });
await validateApp({ components, context });
await validateConfig({ components, context });
await addDefaultPages({ components, context });

View File

@ -33,7 +33,9 @@ import createWriteMetaCache from './writeMetaCache';
import metaLocations from './metaLocations';
import fetchMetaUrl from './fetchMetaUrl';
function createGetMeta({ blocksServerUrl, cacheDirectory, types }) {
function createGetMeta({ components, context }) {
const { blocksServerUrl, cacheDirectory } = context;
const { types } = components;
const allMetaLocations = {
...metaLocations({ blocksServerUrl }),
...types,

View File

@ -69,6 +69,9 @@ const defaultMeta = {
},
};
const components = { types };
const context = { cacheDirectory: 'cacheDirectory' };
beforeEach(() => {
mockFetchMetaCache.mockReset();
mockWriteMetaCache.mockReset();
@ -76,7 +79,7 @@ beforeEach(() => {
});
test('getMeta cache returns from cache', async () => {
const getMeta = createGetMeta({ types, cacheDirectory: 'cacheDirectory' });
const getMeta = createGetMeta({ components, context });
mockFetchMetaCache.mockImplementation((location) => {
if (location && location.url === 'type1Url') {
return defaultMeta;
@ -88,7 +91,7 @@ test('getMeta cache returns from cache', async () => {
});
test('getMeta fetches from url and writes to cache', async () => {
const getMeta = createGetMeta({ types, cacheDirectory: 'cacheDirectory' });
const getMeta = createGetMeta({ components, context });
mockFetchMetaUrl.mockImplementation(({ location }) => {
if (location && location.url === 'type1Url') {
return defaultMeta;
@ -110,7 +113,7 @@ test('getMeta fetches from url and writes to cache', async () => {
});
test('getMeta uses locations from metaLocations', async () => {
const getMeta = createGetMeta({ types, cacheDirectory: 'cacheDirectory' });
const getMeta = createGetMeta({ components, context });
mockFetchMetaCache.mockImplementation((location) => {
if (location && location.url === 'defaultTypeUrl') {
return defaultMeta;
@ -122,28 +125,28 @@ test('getMeta uses locations from metaLocations', async () => {
});
test('getMeta type not in types', async () => {
const getMeta = createGetMeta({ types, cacheDirectory: 'cacheDirectory' });
const getMeta = createGetMeta({ components, context });
await expect(getMeta('Undefined')).rejects.toThrow(
'Block type "Undefined" is not defined. Specify type url in types array.'
);
});
test('getMeta undefined type', async () => {
const getMeta = createGetMeta({ types, cacheDirectory: 'cacheDirectory' });
const getMeta = createGetMeta({ components, context });
await expect(getMeta()).rejects.toThrow(
'Block type undefined is not defined. Specify type url in types array.'
);
});
test('getMeta meta not found in cache or url', async () => {
const getMeta = createGetMeta({ types, cacheDirectory: 'cacheDirectory' });
const getMeta = createGetMeta({ components, context });
await expect(getMeta('Type2')).rejects.toThrow(
'Block type "Type2" has invalid block meta at {"url":"type2Url"}.'
);
});
test('getMeta invalid meta', async () => {
const getMeta = createGetMeta({ types, cacheDirectory: 'cacheDirectory' });
const getMeta = createGetMeta({ components, context });
mockFetchMetaUrl.mockImplementation(() => ({ invalidMeta: true }));
await expect(getMeta('Type2')).rejects.toThrow(
'Block type "Type2" has invalid block meta at {"url":"type2Url"}.'
@ -151,7 +154,7 @@ test('getMeta invalid meta', async () => {
});
test('getMeta fetches from url and does not write to cache if location is localhost', async () => {
const getMeta = createGetMeta({ types, cacheDirectory: 'cacheDirectory' });
const getMeta = createGetMeta({ components, context });
mockFetchMetaUrl.mockImplementation(({ location }) => {
if (location && location.url === 'http://localhost:3003/meta/Block.json') {
return defaultMeta;
@ -165,7 +168,7 @@ test('getMeta fetches from url and does not write to cache if location is localh
});
test('getMeta meta is memoised when returned from cache', async () => {
const getMeta = createGetMeta({ types, cacheDirectory: 'cacheDirectory' });
const getMeta = createGetMeta({ components, context });
mockFetchMetaCache.mockImplementation((location) => {
if (location && location.url === 'defaultTypeUrl') {
return defaultMeta;
@ -184,7 +187,7 @@ test('getMeta meta is memoised when returned from cache', async () => {
});
test('getMeta meta is memoised when returned from cache', async () => {
const getMeta = createGetMeta({ types, cacheDirectory: 'cacheDirectory' });
const getMeta = createGetMeta({ components, context });
mockFetchMetaUrl.mockImplementation(({ location }) => {
if (location && location.url === 'defaultTypeUrl') {
return defaultMeta;
@ -211,3 +214,17 @@ test('getMeta meta is memoised when returned from cache', async () => {
],
]);
});
test('blocksServerUrl is passed to metaLoactions', async () => {
createGetMeta({
components,
context: { blocksServerUrl: 'blocksServerUrl', cacheDirectory: 'cacheDirectory' },
});
expect(metaLocations.mock.calls).toEqual([
[
{
blocksServerUrl: 'blocksServerUrl',
},
],
]);
});