Browse Source

enhancement: formula option UI

pull/1979/head
Wing-Kam Wong 2 years ago
parent
commit
389c8f9a1d
  1. 125
      packages/nc-gui/components/project/spreadsheet/components/editColumn/formulaOptions.vue

125
packages/nc-gui/components/project/spreadsheet/components/editColumn/formulaOptions.vue

@ -1,35 +1,28 @@
<template> <template>
<div class="formula-wrapper"> <div class="formula-wrapper">
<v-menu <v-text-field
v-model="autocomplete" ref="input"
bottom v-model="formula.value"
offset-y dense
nudge-bottom="-25px" outlined
allow-overflow class="caption"
> hide-details="auto"
<template #activator="_args"> label="Formula"
<!-- todo: autocomplete based on available functions and metadata --> :rules="[v => !!v || 'Required', v => parseAndValidateFormula(v)]"
<!-- <v-tooltip color="info" right>--> autocomplete="off"
<!-- <template #activator="{on}">--> @input="handleInputDeb"
<v-text-field @keydown.down.prevent="suggestionListDown"
ref="input" @keydown.up.prevent="suggestionListUp"
v-model="formula.value" @keydown.enter.prevent="selectText"
dense />
outlined <div class="hint">
class="caption" Hint: Use $ to reference columns, e.g: $column_name$. For more, please check out
hide-details="auto" <a href="https://docs.nocodb.com/setup-and-usages/formulas#available-formula-features" target="_blank">Formulas</a>.
label="Formula" </div>
persistent-hint <v-card v-if="suggestion" class="formula-suggestion">
hint="Hint: If you reference columns, use '$' to wrap the column name, e.g: $column_name$." <v-card-text>Suggestions</v-card-text>
:rules="[v => !!v || 'Required', v => parseAndValidateFormula(v)]" <v-divider />
autocomplete="off" <v-list ref="sugList" dense max-height="50vh" style="overflow: auto">
@input="handleInputDeb"
@keydown.down.prevent="suggestionListDown"
@keydown.up.prevent="suggestionListUp"
@keydown.enter.prevent="selectText"
/>
</template>
<v-list v-if="suggestion" ref="sugList" dense max-height="50vh" style="overflow: auto">
<v-list-item-group <v-list-item-group
v-model="selected" v-model="selected"
color="primary" color="primary"
@ -42,16 +35,59 @@
selectable selectable
@mousedown.prevent="appendText(it)" @mousedown.prevent="appendText(it)"
> >
<span <!-- Function -->
class="caption" <template v-if="it.type ==='function'">
:class="{ <v-list-item-content>
'primary--text text--lighten-2 font-weight-bold': it.type ==='function' <span
}" class="caption primary--text text--lighten-2 font-weight-bold"
>{{ it.text }}<span v-if="it.type ==='function'">(...)</span></span> >
{{ it.text }}(...)
</span>
</v-list-item-content>
<v-list-item-action>
<span class="caption">
Function
</span>
</v-list-item-action>
</template>
<!-- Column -->
<template v-if="it.type ==='column'">
<v-list-item-content>
<span
class="caption text--darken-3 font-weight-bold"
>
{{ it.text }}
</span>
</v-list-item-content>
<v-list-item-action>
<span class="caption">
Column
</span>
</v-list-item-action>
</template>
<!-- Operator -->
<template v-if="it.type ==='op'">
<v-list-item-content>
<span
class="caption indigo--text text--darken-3 font-weight-bold"
>
{{ it.text }}
</span>
</v-list-item-content>
<v-list-item-action>
<span class="caption">
Operator
</span>
</v-list-item-action>
</template>
</v-list-item> </v-list-item>
</v-list-item-group> </v-list-item-group>
</v-list> </v-list>
</v-menu> </v-card>
</div> </div>
</template> </template>
@ -87,7 +123,7 @@ export default {
type: 'function' type: 'function'
})), })),
...this.meta.columns.filter(c => !this.column || this.column.id !== c.id).map(c => ({ ...this.meta.columns.filter(c => !this.column || this.column.id !== c.id).map(c => ({
text: c.title, text: '$' + c.title + '$',
type: 'column', type: 'column',
c c
})), })),
@ -266,4 +302,17 @@ export default {
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
::v-deep {
.formula-suggestion .v-card__text {
font-size: 0.75rem;
padding: 8px;
text-align: center;
}
}
.hint {
font-size: 0.75rem;
line-height: normal;
padding: 10px 5px;
}
</style> </style>

Loading…
Cancel
Save