How to use the @ditojs/utils.labelize function in @ditojs/utils

To help you get started, we’ve selected a few @ditojs/utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ditojs / dito / packages / admin / src / utils / filter.js View on Github external
const comps = {}
  for (const filter of Object.values(filters || {})) {
    // Support both custom forms and default filter components, through the
    // `filterComponents` registry. Even for default filters, still use the
    // properties in `filter` as the base for `form`, so things like `label`
    // can be changed on the resulting form.
    const { filter: type, ...form } = filter
    const components = type
      ? filterComponents[type]?.(filter, api)
      : filter.components
    if (components) {
      form.components = {}
      // Convert labels to placeholders:
      for (const [key, component] of Object.entries(components)) {
        if (component) {
          const label = component.label || labelize(component.name || key)
          form.components[key] = {
            ...component,
            label: false,
            placeholder: label
          }
        }
      }
      comps[filter.name] = {
        label: form.label,
        type: 'object',
        default: () => ({}),
        form,
        inlined: true
      }
    } else {
      throw new Error(
github ditojs / dito / packages / admin / src / mixins / ResourceMixin.js View on Github external
}
      this.setLoading(true, settings)
      const { resource = this.resource, data, params } = options
      const request = { method, resource, data, params }
      try {
        const response = await this.rootComponent.request(request)
        // Pass both request and response to the callback, so they can be
        // exposed to further callbacks through ItemParams.
        callback(null, { request, response })
      } catch (error) {
        // If callback returns true, errors were already handled.
        const { response } = error
        if (!callback(error, { request, response })) {
          const data = response?.data
          if (data && isString(data.type)) {
            this.notify('error', labelize(data.type), data.message || error)
          } else {
            this.notify('error', 'Request Error', error)
          }
        }
      }
      this.setLoading(false, settings)
    },
github ditojs / dito / packages / admin / src / components / DitoSchema.vue View on Github external
},
                {}
              )
            })) {
              // We found some nested form to display at least parts fo the
              // errors. We can't display all errors at once, so we're done.
              // Don't call notifyErrors() yet, as we can only display it
              // once showValidationErrors() was called from DitoForm.mounted()
              return
            }
            // Keep removing the last part until we find a match.
            dataPathParts.pop()
          }
          // When the error can't be matched, add it to a list of unmatched
          // errors with decent message, to report at the end.
          const field = labelize(property)
          for (const err of errs) {
            const prefix = field
              ? `The field ${field}`
              : `The ${this.formLabel}`
            unmatched.push(`${prefix} ${err.message}`)
          }
        }
        first = false
      }
      if (!first) {
        this.notifyErrors(unmatched.join('\n'))
      }
    },
github ditojs / dito / packages / admin / src / mixins / DitoMixin.js View on Github external
getLabel(schema, name) {
      return schema
        ? this.getSchemaValue('label', { type: String, schema }) ||
          labelize(name || schema.name)
        : labelize(name) || ''
    },
github ditojs / dito / packages / admin / src / mixins / DitoMixin.js View on Github external
getButtonAttributes(name, button) {
      const verb = this.verbs[name] || name
      return {
        class: `dito-button-${verb}`,
        title: button?.text || labelize(verb)
      }
    },
github ditojs / dito / packages / admin / src / mixins / DitoMixin.js View on Github external
getLabel(schema, name) {
      return schema
        ? this.getSchemaValue('label', { type: String, schema }) ||
          labelize(name || schema.name)
        : labelize(name) || ''
    },