mirror of
https://github.com/directus/directus.git
synced 2026-02-12 11:24:58 -05:00
Syntax fixes (#5367)
* Declare return types on functions And a very few other type related minor fixes * Minor syntax fixes * Remove unnecessary escape chars in regexes * Remove unnecessary awaits * Replace deprecated req.connection with req.socket * Replace deprecated upload with uploadOne * Remove unnecessary eslint-disable-next-line comments * Comment empty functions / catch or finally clauses * Fix irregular whitespaces * Add missing returns (null) * Remove unreachable code * A few logical fixes * Remove / Handle non-null assertions which are certainly unnecessary (e.g. in tests)
This commit is contained in:
@@ -1,21 +1,28 @@
|
||||
import { computed, Ref } from '@vue/composition-api';
|
||||
import { computed, ComputedRef, Ref } from '@vue/composition-api';
|
||||
import { render } from 'micromustache';
|
||||
import { getFieldsFromTemplate } from './get-fields-from-template';
|
||||
|
||||
type StringTemplate = {
|
||||
fieldsInTemplate: ComputedRef<string[]>;
|
||||
displayValue: ComputedRef<string | false>;
|
||||
};
|
||||
|
||||
export function renderStringTemplate(
|
||||
template: Ref<string | null> | string,
|
||||
item: Ref<Record<string, any> | undefined | null>
|
||||
) {
|
||||
): StringTemplate {
|
||||
const templateString = computed(() => (typeof template === 'string' ? template : template.value));
|
||||
|
||||
const fieldsInTemplate = computed(() => getFieldsFromTemplate(templateString.value));
|
||||
|
||||
const displayValue = computed(() => {
|
||||
if (!item.value || !templateString.value || !fieldsInTemplate.value) return;
|
||||
if (!item.value || !templateString.value || !fieldsInTemplate.value) return false;
|
||||
|
||||
try {
|
||||
return render(templateString.value, item.value, { propsExist: true });
|
||||
} catch {}
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
return { fieldsInTemplate, displayValue };
|
||||
|
||||
Reference in New Issue
Block a user