mediacube-ui 0.1.332 → 0.1.334

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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [0.1.334](https://github.com/MediaCubeCo/mcui/compare/v0.1.333...v0.1.334) (2024-11-14)
6
+
7
+ ### [0.1.333](https://github.com/MediaCubeCo/mcui/compare/v0.1.332...v0.1.333) (2024-11-14)
8
+
5
9
  ### [0.1.332](https://github.com/MediaCubeCo/mcui/compare/v0.1.331...v0.1.332) (2024-11-13)
6
10
 
7
11
  ### [0.1.331](https://github.com/MediaCubeCo/mcui/compare/v0.1.330...v0.1.331) (2024-11-12)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mediacube-ui",
3
- "version": "0.1.332",
3
+ "version": "0.1.334",
4
4
  "description": "Design system for Mediacube services",
5
5
  "author": "Mediacube",
6
6
  "private": false,
@@ -158,6 +158,7 @@ import McFilterTypeRelation from './McFilterTypeRelation/McFilterTypeRelation'
158
158
  import McFilterTypeText from './McFilterTypeText/McFilterTypeText'
159
159
  import McFilterTypeRange from './McFilterTypeRange/McFilterTypeRange'
160
160
  import McFilterTypeDate from './McFilterTypeDate/McFilterTypeDate'
161
+ import McFilterTypeSimple from './McFilterTypeSimple/McFilterTypeSimple'
161
162
  import McFilterTags from './McFilterTags/McFilterTags'
162
163
  import McChip from '../../elements/McChip/McChip'
163
164
 
@@ -169,6 +170,7 @@ export default {
169
170
  McFilterTypeText,
170
171
  McFilterTypeRange,
171
172
  McFilterTypeDate,
173
+ McFilterTypeSimple,
172
174
  McSvgIcon,
173
175
  McButton,
174
176
  McTitle,
@@ -200,7 +202,7 @@ export default {
200
202
  * [{
201
203
  name: Filter title,
202
204
  value: [String] - Filter value(key),
203
- type: [String] - Filter type(relation / date / text / fast / labels),
205
+ type: [String] - Filter type(relation / date / text / fast / labels / simple),
204
206
  options: [Array] - Filter options,
205
207
  getAjaxOne: [Function] - Method for get selected options when filter initialize,
206
208
  getAjaxOptions: [Function] - Method for get options by API,
@@ -131,7 +131,15 @@ export default {
131
131
  !_isEmpty(this.simpleValues) &&
132
132
  Object.entries(this.simpleValues).forEach(([key, value]) => {
133
133
  const filter = this.filters.find(f => f.value === key)
134
- if (filter && filter.type === 'fast') {
134
+ if (filter && filter.type === 'simple') {
135
+ tags.push({
136
+ id: _XEUtils.uniqueId(),
137
+ categoryName: filter?.name,
138
+ category: key,
139
+ ...filter,
140
+ title: filter.options.find(o => String(o.value) === String(value))?.name,
141
+ })
142
+ } else if (filter && filter.type === 'fast') {
135
143
  tags.push({
136
144
  id: _XEUtils.uniqueId(),
137
145
  categoryName: filter?.name,
@@ -0,0 +1,161 @@
1
+ <template>
2
+ <mc-field-select
3
+ v-model="selectedOptionValue"
4
+ :options="computedOptions"
5
+ :internal-search="!isAjax"
6
+ :placeholder="computedPlaceholder"
7
+ :loading="loading"
8
+ class="mc-filter-type-simple"
9
+ name="simple_select"
10
+ @search-change="handleSearchChange"
11
+ >
12
+ <div slot="header" class="mc-filter-type-simple__header">
13
+ <mc-title>{{ placeholders.simple }}</mc-title>
14
+ </div>
15
+ </mc-field-select>
16
+ </template>
17
+
18
+ <script>
19
+ import _uniqWith from 'lodash/uniqWith'
20
+ import _isEqual from 'lodash/isEqual'
21
+ import _debounce from 'lodash/debounce'
22
+ import _isEmpty from 'lodash/isEmpty'
23
+ import McTitle from '../../../elements/McTitle/McTitle'
24
+ import McFieldSelect from '../../../elements/McField/McFieldSelect/McFieldSelect'
25
+
26
+ export default {
27
+ name: 'McFilterTypeSimple',
28
+ components: {
29
+ McTitle,
30
+ McFieldSelect,
31
+ },
32
+ props: {
33
+ /**
34
+ * Значение
35
+ */
36
+ value: {
37
+ // type: [String, Number],
38
+ default: null,
39
+ },
40
+ /**
41
+ * Объект выбранного
42
+ * фильтра
43
+ */
44
+ filter: {
45
+ type: Object,
46
+ default: () => {},
47
+ },
48
+ /**
49
+ * Переводы локализаций
50
+ */
51
+ placeholders: {
52
+ type: Object,
53
+ required: true,
54
+ },
55
+ /**
56
+ * Текущее значение
57
+ * добавленных фильтров
58
+ */
59
+ currentValues: {
60
+ type: Object,
61
+ default: () => {},
62
+ },
63
+ asd: {
64
+ type: Object,
65
+ default: () => {},
66
+ },
67
+ },
68
+ data() {
69
+ return {
70
+ ajaxOptions: [],
71
+ loading: false,
72
+ }
73
+ },
74
+ computed: {
75
+ computedPlaceholder() {
76
+ return this.filter.placeholder || this.filter.is_text ? this.placeholders.enter : this.placeholders.choose
77
+ },
78
+ computedOptions() {
79
+ let options = this.isAjax ? this.ajaxOptions : this.filter.options || []
80
+
81
+ if (!_isEmpty(this.currentValues) && this.filter.value in this.currentValues) {
82
+ const category = this.currentValues[this.filter.value]
83
+ let selected = []
84
+ for (let [key, val] of Object.entries(category)) {
85
+ selected = [...selected, ...(Array.isArray(val) ? val : [[val]])]
86
+ }
87
+ options = options.filter(o => !selected.includes(String(o.value)))
88
+ }
89
+
90
+ return options
91
+ },
92
+ isAjax() {
93
+ return typeof this.filter.getAjaxOptions === 'function'
94
+ },
95
+ selectedOptionValue: {
96
+ get() {
97
+ let val = this.value
98
+ if (val) {
99
+ if (this.isAjax && val) {
100
+ this.addAjaxOption(val)
101
+ }
102
+ }
103
+ return val
104
+ },
105
+ set(val) {
106
+ this.setValue(val)
107
+ },
108
+ },
109
+ },
110
+ watch: {
111
+ filter() {
112
+ this.$nextTick(() => (this.ajaxOptions = []))
113
+ },
114
+ },
115
+ methods: {
116
+ async setAjaxOptions(value) {
117
+ this.loading = true
118
+ this.ajaxOptions = await this.filter.getAjaxOptions(value)
119
+ this.loading = false
120
+ },
121
+ async addAjaxOption(value) {
122
+ const option = await this.filter.getAjaxOne(value)
123
+ this.ajaxOptions = _uniqWith([...this.ajaxOptions, option], _isEqual)
124
+ },
125
+ handleSearchChange(value) {
126
+ if (!this.isAjax || !value) return
127
+ this.debounceHandler(this.setAjaxOptions.bind(null, value))
128
+ },
129
+ debounceHandler: _debounce(method => method(), 500),
130
+ setValue(value) {
131
+ /**
132
+ * Событие по изменению значения
133
+ */
134
+ this.$emit('input', value, this.computedOptions.find(o => String(o.value) === String(value))?.name)
135
+ },
136
+ },
137
+ }
138
+ </script>
139
+
140
+ <style lang="scss">
141
+ @import '../../../styles/mixins';
142
+ .mc-filter-type-simple {
143
+ $block-name: &;
144
+ width: 300px;
145
+ &__header {
146
+ display: flex;
147
+ align-items: center;
148
+ justify-content: space-between;
149
+ margin-bottom: -$space-50;
150
+ margin-top: -$space-50;
151
+ }
152
+ &__buttons {
153
+ display: flex;
154
+ @include child-indent-right($space-50);
155
+ .mc-button {
156
+ height: $size-300;
157
+ padding: $space-50 $space-150;
158
+ }
159
+ }
160
+ }
161
+ </style>