@bildvitta/quasar-ui-asteroid 3.9.0 → 3.10.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,5 @@
1
1
  import { decamelize } from 'humps'
2
2
  import { isEqual } from 'lodash'
3
- import { getNormalizedOptions } from '../helpers'
4
3
  import { getAction } from '@bildvitta/store-adapter'
5
4
 
6
5
  export default {
@@ -20,11 +19,11 @@ export default {
20
19
  type: String
21
20
  },
22
21
 
23
- useLazyLoading: {
22
+ fetching: {
24
23
  type: Boolean
25
24
  },
26
25
 
27
- fetching: {
26
+ useLazyLoading: {
28
27
  type: Boolean
29
28
  }
30
29
  },
@@ -38,12 +37,15 @@ export default {
38
37
 
39
38
  data () {
40
39
  return {
40
+ mx_cachedOptions: [],
41
+ mx_fetchCount: 0,
41
42
  mx_filteredOptions: [],
43
+ mx_foundDuplicatedOptions: [],
44
+ mx_fromSearch: false,
42
45
  mx_hasFetchError: false,
43
46
  mx_isFetching: false,
44
47
  mx_isScrolling: false,
45
48
  mx_search: '',
46
- mx_fetchCount: 0,
47
49
  mx_pagination: {
48
50
  page: 1,
49
51
  lastPage: null,
@@ -77,10 +79,6 @@ export default {
77
79
  return !!this.mx_filteredOptions.length
78
80
  },
79
81
 
80
- mx_isFilterByFuse () {
81
- return !this.useLazyLoading
82
- },
83
-
84
82
  mx_isMultiple () {
85
83
  return this.$attrs.multiple || this.$attrs.multiple === ''
86
84
  }
@@ -101,11 +99,24 @@ export default {
101
99
  methods: {
102
100
  async mx_filterOptionsByStore (search) {
103
101
  this.mx_resetFilter(search)
104
- await this.mx_setFetchOptions()
102
+
103
+ this.mx_fromSearch = !!search
104
+
105
+ const options = await this.mx_fetchOptions()
106
+
107
+ this.mx_resetOptions()
108
+
109
+ this.mx_filteredOptions.push(...options)
110
+
111
+ if (this.mx_cachedOptions.length && !search) this.mx_setInitialCachedOptions()
105
112
  },
106
113
 
107
- mx_resetFilter (search) {
114
+ mx_resetOptions () {
108
115
  this.mx_filteredOptions = []
116
+ this.mx_foundDuplicatedOptions = []
117
+ },
118
+
119
+ mx_resetFilter (search) {
109
120
  this.mx_search = search
110
121
  this.mx_pagination = {
111
122
  page: 1,
@@ -180,14 +191,8 @@ export default {
180
191
 
181
192
  this.$emit('fetch-options-success', data)
182
193
 
183
- return this.mx_handleOptions(results)
194
+ return this.mx_getNonDuplicatedOptions(results)
184
195
  } catch (error) {
185
- this.$qas.logger.group(
186
- `Mixin: searchFilterMixin - mx_fetchOptions -> exceção da action ${this.entity}/fetchFieldOptions`,
187
- [error],
188
- { error: true }
189
- )
190
-
191
196
  this.mx_hasFetchError = true
192
197
  this.$emit('fetch-options-error', error)
193
198
 
@@ -199,7 +204,48 @@ export default {
199
204
  },
200
205
 
201
206
  async mx_setFetchOptions () {
202
- this.mx_filteredOptions = await this.mx_fetchOptions()
207
+ const options = await this.mx_fetchOptions()
208
+
209
+ this.mx_filteredOptions.push(...options)
210
+ },
211
+
212
+ mx_setInitialCachedOptions () {
213
+ this.mx_cachedOptions.forEach(cachedOption => {
214
+ const hasOption = this.mx_filteredOptions.find(filteredOption => {
215
+ return filteredOption.value === cachedOption.value
216
+ })
217
+
218
+ if (!hasOption && this.mx_filteredOptions.length) {
219
+ this.mx_filteredOptions.unshift(cachedOption)
220
+ }
221
+ })
222
+ },
223
+
224
+ mx_getNonDuplicatedOptions (options = []) {
225
+ if (this.mx_fromSearch) {
226
+ this.mx_fromSearch = false
227
+
228
+ return options
229
+ }
230
+
231
+ if (!options.length) return []
232
+
233
+ const nonDuplicatedOptions = [...options]
234
+
235
+ this.mx_cachedOptions.forEach(cachedOption => {
236
+ if (this.mx_foundDuplicatedOptions.includes(cachedOption.value)) return
237
+
238
+ const duplicatedOptionIndex = nonDuplicatedOptions.findIndex(option => {
239
+ return option.value === cachedOption.value
240
+ })
241
+
242
+ if (~duplicatedOptionIndex) {
243
+ this.mx_foundDuplicatedOptions.push(cachedOption.value)
244
+ nonDuplicatedOptions.splice(duplicatedOptionIndex, 1)
245
+ }
246
+ })
247
+
248
+ return nonDuplicatedOptions
203
249
  },
204
250
 
205
251
  mx_canFetchOptions () {
@@ -210,18 +256,6 @@ export default {
210
256
  return hasMorePages && !this.mx_isFetching && !this.mx_isScrolling && this.useLazyLoading
211
257
  },
212
258
 
213
- mx_handleOptions (options) {
214
- if (this.labelKey && this.valueKey) {
215
- return getNormalizedOptions({
216
- options,
217
- label: this.labelKey,
218
- value: this.valueKey
219
- })
220
- }
221
-
222
- return options
223
- },
224
-
225
259
  mx_getMissingPropsMessage (prop) {
226
260
  return `A propriedade "${prop}" é obrigatória quando a propriedade "useLazyLoading" está ativa.`
227
261
  },
@@ -232,6 +266,15 @@ export default {
232
266
 
233
267
  mx_getNormalizedFuseResults (results = []) {
234
268
  return results.map(({ item }) => item)
269
+ },
270
+
271
+ mx_setCachedOptions (model) {
272
+ this.$watch(model, options => {
273
+ if (!options?.length) return
274
+
275
+ this.mx_filteredOptions = [...options]
276
+ this.mx_cachedOptions = [...options]
277
+ }, { immediate: true })
235
278
  }
236
279
  }
237
280
  }
package/src/vue-plugin.js CHANGED
@@ -13,12 +13,15 @@ import QasBtnDropdown from './components/btn-dropdown/QasBtnDropdown.vue'
13
13
  import QasCard from './components/card/QasCard.vue'
14
14
  import QasCheckboxGroup from './components/checkbox-group/QasCheckboxGroup.vue'
15
15
  import QasCopy from './components/copy/QasCopy.vue'
16
+ import QasDate from './components/date/QasDate.vue'
16
17
  import QasDateTimeInput from './components/date-time-input/QasDateTimeInput.vue'
17
18
  import QasDebugger from './components/debugger/QasDebugger.vue'
18
19
  import QasDelete from './components/delete/QasDelete.vue'
19
20
  import QasDialog from './components/dialog/QasDialog.vue'
20
21
  import QasDialogRouter from './components/dialog-router/QasDialogRouter.vue'
22
+ import QasEmptyResultText from './components/empty-result-text/QasEmptyResultText.vue'
21
23
  import QasField from './components/field/QasField.vue'
24
+ import QasSearchInput from './components/search-input/QasSearchInput.vue'
22
25
  import QasFilters from './components/filters/QasFilters.vue'
23
26
  import QasFormGenerator from './components/form-generator/QasFormGenerator.vue'
24
27
  import QasFormView from './components/form-view/QasFormView.vue'
@@ -93,12 +96,15 @@ function install (app) {
93
96
  app.component('QasCard', QasCard)
94
97
  app.component('QasCheckboxGroup', QasCheckboxGroup)
95
98
  app.component('QasCopy', QasCopy)
99
+ app.component('QasDate', QasDate)
96
100
  app.component('QasDateTimeInput', QasDateTimeInput)
97
101
  app.component('QasDebugger', QasDebugger)
98
102
  app.component('QasDelete', QasDelete)
99
103
  app.component('QasDialog', QasDialog)
100
104
  app.component('QasDialogRouter', QasDialogRouter)
105
+ app.component('QasEmptyResultText', QasEmptyResultText)
101
106
  app.component('QasField', QasField)
107
+ app.component('QasSearchInput', QasSearchInput)
102
108
  app.component('QasFilters', QasFilters)
103
109
  app.component('QasFormGenerator', QasFormGenerator)
104
110
  app.component('QasFormView', QasFormView)
@@ -174,12 +180,15 @@ export {
174
180
  QasCard,
175
181
  QasCheckboxGroup,
176
182
  QasCopy,
183
+ QasDate,
177
184
  QasDateTimeInput,
178
185
  QasDebugger,
179
186
  QasDelete,
180
187
  QasDialog,
181
188
  QasDialogRouter,
189
+ QasEmptyResultText,
182
190
  QasField,
191
+ QasSearchInput,
183
192
  QasFilters,
184
193
  QasFormGenerator,
185
194
  QasFormView,