@ouestfrance/sipa-bms-ui 8.8.1 → 8.9.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ouestfrance/sipa-bms-ui",
3
- "version": "8.8.1",
3
+ "version": "8.9.0",
4
4
  "author": "Ouest-France BMS",
5
5
  "license": "ISC",
6
6
  "scripts": {
@@ -58,11 +58,10 @@
58
58
  </template>
59
59
 
60
60
  <script lang="ts" setup>
61
- import { computed, ref, useTemplateRef } from 'vue';
61
+ import { computed, Ref, ref } from 'vue';
62
62
  import { ChevronDown, ChevronUp, X } from 'lucide-vue-next';
63
63
  import BmsTag from './BmsTag.vue';
64
64
  import { InputOption } from '@/models';
65
- import _ from 'lodash';
66
65
  import { searchString } from '@/helpers';
67
66
  import { FieldComponentProps } from '@/plugins/field/field-component.model';
68
67
  import RawSelect from './RawSelect.vue';
@@ -77,7 +76,8 @@ const props = withDefaults(defineProps<Props>(), {
77
76
  disabled: false,
78
77
  required: false,
79
78
  });
80
- const inputElement = useTemplateRef('inputElement');
79
+
80
+ const inputElement: Ref<HTMLElement | null> = ref(null);
81
81
 
82
82
  const isDatalistOpen = ref(false);
83
83
 
@@ -32,13 +32,12 @@
32
32
 
33
33
  <script lang="ts" setup>
34
34
  import { ChevronDown, ChevronUp } from 'lucide-vue-next';
35
- import { computed, Ref, ref, useTemplateRef } from 'vue';
35
+ import { computed, Ref, ref } from 'vue';
36
36
  import _ from 'lodash';
37
37
  import { InputOption } from '@/models';
38
38
  import { FieldComponentProps } from '@/plugins/field/field-component.model';
39
39
  import RawSelect from './RawSelect.vue';
40
40
  import { onClickOutside } from '@vueuse/core';
41
- import { v4 as uuid } from 'uuid';
42
41
 
43
42
  export interface Props extends FieldComponentProps {
44
43
  options: InputOption[];
@@ -56,7 +55,8 @@ const props = withDefaults(defineProps<Props>(), {
56
55
  });
57
56
 
58
57
  const modelValue = defineModel<any>('modelValue', { required: true });
59
- const inputElement = useTemplateRef('inputElement');
58
+
59
+ const inputElement: Ref<HTMLElement | null> = ref(null);
60
60
 
61
61
  const isDatalistOpen = ref(props.open);
62
62
 
@@ -0,0 +1,74 @@
1
+ import BmsServerAutocomplete from '@/components/form/BmsServerAutocomplete.vue';
2
+ import { http, HttpResponse } from 'msw';
3
+
4
+ export default {
5
+ title: 'Composants/form/ServerAutocomplete',
6
+ component: BmsServerAutocomplete,
7
+ argTypes: {
8
+ disableSearch: {
9
+ control: { type: 'boolean' },
10
+ },
11
+ headers: {},
12
+ },
13
+ };
14
+
15
+ const mswRequestHandler = () =>
16
+ http.get('https://fakeapi.com/items', () =>
17
+ HttpResponse.json([
18
+ {
19
+ label: 'Label 1',
20
+ value: '1',
21
+ },
22
+ {
23
+ label: 'Label 2',
24
+ value: '2',
25
+ },
26
+ ]),
27
+ );
28
+
29
+ const Template = (args) => ({
30
+ components: {
31
+ BmsServerAutocomplete,
32
+ },
33
+ setup() {
34
+ return { args };
35
+ },
36
+ template: `
37
+ <BmsServerAutocomplete v-bind="args">
38
+ </BmsServerAutocomplete>
39
+ `,
40
+ });
41
+
42
+ export const Default = Template.bind({});
43
+ Default.parameters = {
44
+ msw: {
45
+ handlers: [mswRequestHandler()],
46
+ },
47
+ };
48
+ Default.args = {
49
+ label: 'My autocomplete field',
50
+ modelValue: '',
51
+ url: 'https://fakeapi.com/items',
52
+ };
53
+
54
+ export const WithRequest = Template.bind({});
55
+ WithRequest.args = {
56
+ label: 'My autocomplete field',
57
+ modelValue: '',
58
+ request: () => {
59
+ return new Promise((resolve) =>
60
+ resolve({
61
+ data: [
62
+ {
63
+ label: 'Label 1',
64
+ value: '1',
65
+ },
66
+ {
67
+ label: 'Label 2',
68
+ value: '2',
69
+ },
70
+ ],
71
+ }),
72
+ );
73
+ },
74
+ };
@@ -0,0 +1,143 @@
1
+ <template>
2
+ <RawAutocomplete
3
+ v-model="modelValue"
4
+ :options="options"
5
+ :open="open"
6
+ :label="label"
7
+ :optional="optional"
8
+ :disabled="disabled"
9
+ :errors="errors"
10
+ :captions="captions"
11
+ :required="required"
12
+ :helperText="helperText"
13
+ :placeholder="placeholder"
14
+ :small="small"
15
+ :canAddNewOption="false"
16
+ @input="onInput"
17
+ @select="(option: any) => emits('select', option)"
18
+ >
19
+ <template #icon-start v-if="currentOptionIcon">
20
+ <span
21
+ class="icon"
22
+ v-if="typeof currentOptionIcon === 'string'"
23
+ v-html="currentOptionIcon"
24
+ ></span>
25
+ <component v-else :is="currentOptionIcon" />
26
+ </template>
27
+ <template #icon-end>
28
+ <BmsLoader v-if="loading" :size="16" />
29
+ </template>
30
+ <template #option="{ option }: { option: any }">
31
+ <template v-if="option.icon">
32
+ <span
33
+ class="icon datalist-icon"
34
+ v-if="typeof option.icon === 'string'"
35
+ v-html="option.icon"
36
+ ></span>
37
+
38
+ <component class="icon datalist-icon" v-else :is="option.icon" />
39
+ </template>
40
+ {{ option.label }}
41
+ </template>
42
+ </RawAutocomplete>
43
+ </template>
44
+
45
+ <script setup lang="ts">
46
+ import { computed, onMounted, ref, watch } from 'vue';
47
+ import RawAutocomplete from './RawAutocomplete.vue';
48
+ import { InputOption } from '@/models';
49
+ import { FieldComponentProps } from '@/plugins/field/field-component.model';
50
+ import BmsLoader from '../feedback/BmsLoader.vue';
51
+
52
+ export interface Props extends FieldComponentProps {
53
+ url?: string;
54
+ request?: (
55
+ abortController: AbortController,
56
+ inputValue?: string,
57
+ url?: string,
58
+ ) => Promise<{ data: InputOption[] }>;
59
+
60
+ modelValue?: string;
61
+ placeholder?: string;
62
+ open?: boolean;
63
+ }
64
+
65
+ const props = withDefaults(defineProps<Props>(), {
66
+ open: false,
67
+ request: async (controller: AbortController, url?: string) => {
68
+ if (!url) {
69
+ throw 'URL must be defined';
70
+ }
71
+
72
+ const response = await fetch(url, {
73
+ method: 'GET',
74
+ signal: controller.signal,
75
+ });
76
+
77
+ const data = await response.json();
78
+ return { data };
79
+ },
80
+ });
81
+
82
+ const modelValue = defineModel<string>('modelValue', {
83
+ default: null,
84
+ });
85
+ const emits = defineEmits<{
86
+ addNewOption: [newOption: string];
87
+ select: [option: InputOption];
88
+ }>();
89
+
90
+ const options = ref<InputOption[]>([]);
91
+ const loading = ref(true);
92
+ const controller = ref<AbortController>();
93
+
94
+ const loadData = async (search: string) => {
95
+ loading.value = true;
96
+ try {
97
+ if (controller.value) {
98
+ controller.value.abort();
99
+ }
100
+ controller.value = new AbortController();
101
+ loading.value = true;
102
+
103
+ const { data } = await props.request(controller.value, search, props.url);
104
+
105
+ options.value = data;
106
+ } catch (e) {
107
+ console.error(e);
108
+ } finally {
109
+ loading.value = false;
110
+ }
111
+ };
112
+
113
+ onMounted(() => loadData(''));
114
+ const onInput = (e: InputEvent) => {
115
+ loadData((e.target as HTMLInputElement)?.value);
116
+ };
117
+
118
+ const currentOptionIcon = computed(() => {
119
+ const option = options.value.find((o) => o.value === modelValue.value);
120
+ if (!option || typeof option === 'string') return undefined;
121
+ return option.icon;
122
+ });
123
+ </script>
124
+
125
+ <style scoped lang="scss">
126
+ .icon {
127
+ height: 1em;
128
+ width: 1em;
129
+
130
+ &.datalist-icon {
131
+ margin: 0 0.5em;
132
+ }
133
+
134
+ :deep(svg) {
135
+ height: 100%;
136
+ width: 100%;
137
+
138
+ * {
139
+ fill: currentColor !important;
140
+ }
141
+ }
142
+ }
143
+ </style>
@@ -53,7 +53,7 @@
53
53
  <script setup lang="ts">
54
54
  import { searchString } from '@/helpers/string.helper';
55
55
  import FieldDatalist from '@/plugins/field/FieldDatalist.vue';
56
- import { computed, ref, useTemplateRef, watch } from 'vue';
56
+ import { computed, Ref, ref, watch } from 'vue';
57
57
  import RawInputText from '@/components/form/RawInputText.vue';
58
58
  import { InputOption, InputType } from '@/models';
59
59
  import { ChevronDown, ChevronUp, X } from 'lucide-vue-next';
@@ -72,11 +72,12 @@ export interface Props extends FieldComponentProps {
72
72
  const props = withDefaults(defineProps<Props>(), {
73
73
  modelValue: null,
74
74
  open: false,
75
+ canAddNewOption: false,
75
76
  });
76
77
 
77
78
  const modelValue = defineModel<string | null>('modelValue', { required: true });
78
79
 
79
- const rawInput = useTemplateRef('rawInput');
80
+ const rawInput: Ref<HTMLElement | null> = ref(null);
80
81
 
81
82
  const emits = defineEmits<{
82
83
  addNewOption: [newOption: string];
@@ -50,6 +50,7 @@
50
50
  transformValueForComponent(filter?.valueFrom, filter.type)
51
51
  "
52
52
  :valueTo="transformValueForComponent(filter?.valueTo, filter.type)"
53
+ :autocompleteRequest="filter?.autocompleteRequest"
53
54
  :options="getFilterOptions(filter) as any"
54
55
  @input="
55
56
  (e: InputEvent) =>
@@ -95,6 +96,7 @@ import _cloneDeep from 'lodash/cloneDeep';
95
96
  import BmsIconButton from '../button/BmsIconButton.vue';
96
97
  import BmsBetweenInput from '@/components/form/BmsBetweenInput.vue';
97
98
  import { isBetweenFilter } from '@/composables/search.helper';
99
+ import BmsServerAutocomplete from '../form/BmsServerAutocomplete.vue';
98
100
 
99
101
  const route = useRoute();
100
102
 
@@ -156,6 +158,8 @@ const getFilterComponent = (type: FilterType) => {
156
158
  return BmsInputDateTime;
157
159
  case 'autocomplete':
158
160
  return BmsAutocomplete;
161
+ case 'autocompleteServer':
162
+ return BmsServerAutocomplete;
159
163
  case 'select':
160
164
  return BmsSelect;
161
165
  case 'betweenNumber':
@@ -1,4 +1,4 @@
1
- import { InputType } from './form.model';
1
+ import { InputOption, InputType } from './form.model';
2
2
  import { Sort, SortFunction } from './sort.model';
3
3
 
4
4
  export enum ColumnType {
@@ -34,6 +34,7 @@ export type FilterType =
34
34
  | 'inputDate'
35
35
  | 'boolean'
36
36
  | 'autocomplete'
37
+ | 'autocompleteServer'
37
38
  | 'betweenNumber'
38
39
  | 'betweenDate'
39
40
  | 'betweenDateTime';
@@ -48,6 +49,10 @@ export interface Filter {
48
49
  valueTo?: any;
49
50
  selectOptions?: { label: string; value: any }[];
50
51
  autocompleteOptions?: string[] | { label: string; value: string }[];
52
+ autocompleteRequest?: (
53
+ abortController: AbortController,
54
+ url?: string,
55
+ ) => Promise<{ data: InputOption[] }>;
51
56
  customFilter?: Function;
52
57
  }
53
58
 
@@ -39,6 +39,12 @@
39
39
  :options="optionsLabelValue"
40
40
  />
41
41
  <br />
42
+ Valeur: {{ autocompleteText }}
43
+ <BmsServerAutocomplete
44
+ label="Autocomplete avec un appel API"
45
+ :request="autocompleteRequest"
46
+ v-model="autocompleteText"
47
+ />
42
48
  </template>
43
49
 
44
50
  <script setup lang="ts">
@@ -49,12 +55,10 @@ import { ref } from 'vue';
49
55
  import BmsButton from '@/components/button/BmsButton.vue';
50
56
  import BmsSelect from '@/components/form/BmsSelect.vue';
51
57
  import BmsMultiSelect from '@/components/form/BmsMultiSelect.vue';
52
- import FieldDatalist from '@/plugins/field/FieldDatalist.vue';
53
- import RawAutocomplete from '@/components/form/RawAutocomplete.vue';
54
- import BmsInputText from '@/components/form/BmsInputText.vue';
55
58
 
56
59
  const select = ref('');
57
60
  const multiSelect = ref([]);
61
+ import BmsServerAutocomplete from '@/components/form/BmsServerAutocomplete.vue';
58
62
 
59
63
  const optionsLabelValue = ref(
60
64
  range(0, 30).map((i) =>
@@ -69,6 +73,7 @@ const optionsText = ref(
69
73
  range(0, 30).map((i) => (Math.random() > 0.5 ? `toto-${i}` : `titi-${i}`)),
70
74
  );
71
75
  const inputText = ref('');
76
+ const autocompleteText = ref('');
72
77
 
73
78
  const optionsIcon = ref(
74
79
  range(0, 30).map((i) =>
@@ -82,4 +87,12 @@ const inputValueIcon = ref('');
82
87
  const onAddNewOption = (newOption: string) => {
83
88
  optionsLabelValue.value.push({ label: newOption, value: newOption });
84
89
  };
90
+
91
+ const autocompleteRequest = (
92
+ abortController: AbortController,
93
+ searchString?: string,
94
+ ) =>
95
+ fetch(`http://localhost:3000/pokemon-types?search=${searchString}`).then(
96
+ (res) => res.json(),
97
+ );
85
98
  </script>
@@ -1,5 +1,4 @@
1
1
  <template>
2
- {{ filters }}
3
2
  <bms-server-table
4
3
  v-model:selectedItems="selectedItems"
5
4
  v-model:selectMode="selectMode"
@@ -14,8 +13,6 @@
14
13
  :total="totalItems"
15
14
  @saveFilter="onSaveFilter"
16
15
  @deleteSavedFilter="onDeleteSavedFilter"
17
- @filterInput="onFilterInput"
18
- @filterChange="onFilterChange"
19
16
  >
20
17
  <template #default="{ row }: { row: any }">
21
18
  <td>
@@ -41,7 +38,7 @@
41
38
  </template>
42
39
 
43
40
  <script lang="ts" setup>
44
- import { Filter, SavedFilter, SelectMode } from '@/models';
41
+ import { Filter, InputType, SavedFilter, SelectMode } from '@/models';
45
42
  import axios from 'axios';
46
43
  import { computed, Ref, ref } from 'vue';
47
44
  import { isEmptyStringOrNotDefined } from '@/helpers';
@@ -52,27 +49,19 @@ const serverHeaders = [
52
49
  { label: 'Type', key: 'type' },
53
50
  ];
54
51
 
55
- const typeOptions = ref([
56
- 'Grass',
57
- 'Poison',
58
- 'Fire',
59
- 'Flying',
60
- 'Water',
61
- 'Bug',
62
- 'Normal',
63
- 'Electric',
64
- 'Ground',
65
- 'Fairy',
66
- 'Fighting',
67
- 'Psychic',
68
- 'Rock',
69
- 'Steel',
70
- 'Ice',
71
- 'Ghost',
72
- 'Dragon',
73
- ]);
52
+ const pokemonTypeAutocompleteRequest = async (
53
+ abortController: AbortController,
54
+ ) => {
55
+ const { data } = await axios.get('http://localhost:3000/pokemon-types', {
56
+ signal: abortController.signal,
57
+ });
58
+
59
+ return {
60
+ data,
61
+ };
62
+ };
74
63
 
75
- const filters = computed(() => [
64
+ const filters: Filter[] = [
76
65
  {
77
66
  label: 'Name',
78
67
  key: 'name',
@@ -82,15 +71,15 @@ const filters = computed(() => [
82
71
  label: 'Number',
83
72
  key: 'idBetween',
84
73
  type: 'betweenNumber',
85
- inputType: 'number',
74
+ inputType: InputType.NUMBER,
86
75
  },
87
76
  {
88
77
  label: 'Type',
89
78
  key: 'type',
90
- type: 'autocomplete',
91
- autocompleteOptions: typeOptions.value,
79
+ type: 'autocompleteServer',
80
+ autocompleteRequest: pokemonTypeAutocompleteRequest,
92
81
  },
93
- ]);
82
+ ];
94
83
 
95
84
  const savedFilters: Ref<SavedFilter[]> = ref<SavedFilter[]>([]);
96
85
  const selectedItems = ref<any[]>([]);
@@ -106,33 +95,6 @@ const onDeleteSavedFilter = (savedFilter: SavedFilter) => {
106
95
  (filter) => filter.id !== savedFilter.id,
107
96
  );
108
97
  };
109
-
110
- const onFilterInput = ({
111
- filterKey,
112
- e,
113
- }: {
114
- filterKey: string;
115
- e: InputEvent;
116
- }) => {
117
- typeOptions.value = [];
118
- console.log(
119
- `user filtered key ${filterKey} with val ${(e.target as HTMLInputElement)?.value}`,
120
- );
121
- };
122
-
123
- const onFilterChange = ({
124
- filterKey,
125
- e,
126
- }: {
127
- filterKey: string;
128
- e: InputEvent;
129
- }) => {
130
- typeOptions.value = [];
131
- console.log(
132
- `user filtered key ${filterKey} changed with val ${(e.target as HTMLInputElement)?.value}`,
133
- );
134
- };
135
-
136
98
  const customFetchData = async (
137
99
  params: any,
138
100
  abortController: AbortController,
@@ -170,22 +132,4 @@ const customFetchData = async (
170
132
  data,
171
133
  };
172
134
  };
173
-
174
- const customQueryBuilder = (
175
- size: number,
176
- _: number,
177
- page: number,
178
- search: string,
179
- ) => {
180
- const params: any = {
181
- size: '' + size,
182
- page: '' + (page + 1),
183
- };
184
-
185
- if (search) {
186
- params['beer_name'] = search;
187
- }
188
-
189
- return params;
190
- };
191
135
  </script>
@@ -8,6 +8,30 @@ app.use(cors());
8
8
 
9
9
  const port = 3000;
10
10
 
11
+ app.get('/pokemon-types', (req, res) => {
12
+ res.send({
13
+ data: [
14
+ { label: 'Grass', value: 'Grass' },
15
+ { label: 'Poison', value: 'Poison' },
16
+ { label: 'Fire', value: 'Fire' },
17
+ { label: 'Flying', value: 'Flying' },
18
+ { label: 'Water', value: 'Water' },
19
+ { label: 'Bug', value: 'Bug' },
20
+ { label: 'Normal', value: 'Normal' },
21
+ { label: 'Electric', value: 'Electric' },
22
+ { label: 'Ground', value: 'Ground' },
23
+ { label: 'Fairy', value: 'Fairy' },
24
+ { label: 'Fighting', value: 'Fighting' },
25
+ { label: 'Psychic', value: 'Psychic' },
26
+ { label: 'Rock', value: 'Rock' },
27
+ { label: 'Steel', value: 'Steel' },
28
+ { label: 'Ice', value: 'Ice' },
29
+ { label: 'Ghost', value: 'Ghost' },
30
+ { label: 'Dragon', value: 'Dragon' },
31
+ ],
32
+ });
33
+ });
34
+
11
35
  app.get('/pokemons', (req, res) => {
12
36
  let data = pokemons;
13
37
  let total = 0;