Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function resolveNameForTitleMap({ schema, properties, value }) {
if (schema.titleMap) {
// Here we add a field side by side with the value
// to keep the title associated to the value
const info = schema.titleMap.find(titleMap => titleMap.value === value);
const parentKey = schema.key.slice();
const key = parentKey.pop();
const nameKey = `$${key}_name`;
const parentValue = getValue(properties, { key: parentKey });
if (info) {
parentValue[nameKey] = info.name;
} else {
delete parentValue[nameKey];
}
}
}
return;
}
// Here we add a field side by side with the value
// to keep the title associated to the value
const valueIsArray = Array.isArray(value);
const uniformValue = valueIsArray ? value : [value];
const names = uniformValue
.map(nextValue => schema.titleMap.find(titleMap => titleMap.value === nextValue))
.map(entry => entry && entry.name);
const parentKey = schema.key.slice();
const key = parentKey.pop();
const nameKey = `$${key}_name`;
const parentValue = getValue(properties, { key: parentKey });
if (names.some(name => name !== undefined)) {
parentValue[nameKey] = valueIsArray ? names : names[0];
} else {
delete parentValue[nameKey];
}
}
function resolveName(value) {
// create schema to get entry name from internal properties
const key = Array.from(props.schema.key);
key[key.length - 1] = `$${key[key.length - 1]}_name`;
const nameSchema = { ...props.schema, key };
return getValue(props.properties, nameSchema) || value;
}
function updateProperties({ body, trigger, properties }) {
const targetPath = trigger.options[0].path;
const schema = { key: targetPath.split('.') };
const value = trigger.options[0].type === 'object' ? body : body.data;
return {
properties: mutateValue(properties, schema, value),
};
}
function getNewErrors(errors, schema, errorMessage) {
if (errorMessage) {
return addError(errors, schema, errorMessage);
} else if (getError(errors, schema) !== undefined) {
return removeError(errors, schema);
}
return errors;
}
function getNewErrors(errors, schema, errorMessage) {
if (errorMessage) {
return addError(errors, schema, errorMessage);
} else if (getError(errors, schema) !== undefined) {
return removeError(errors, schema);
}
return errors;
}
function getNewErrors(errors, schema, errorMessage) {
if (errorMessage) {
return addError(errors, schema, errorMessage);
} else if (getError(errors, schema) !== undefined) {
return removeError(errors, schema);
}
return errors;
}
function getNewErrors(errors, schema, errorMessage) {
if (errorMessage) {
return addError(errors, schema, errorMessage);
} else if (getError(errors, schema) !== undefined) {
return removeError(errors, schema);
}
return errors;
}
function getNewErrors(errors, schema, errorMessage) {
if (errorMessage) {
return addError(errors, schema, errorMessage);
} else if (getError(errors, schema) !== undefined) {
return removeError(errors, schema);
}
return errors;
}
function getNewErrors(errors, schema, errorMessage) {
if (errorMessage) {
return addError(errors, schema, errorMessage);
} else if (getError(errors, schema) !== undefined) {
return removeError(errors, schema);
}
return errors;
}