druxt-views 0.14.0 → 0.16.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,57 @@
1
1
  # druxt-views
2
2
 
3
+ ## 0.16.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [9161b38]
8
+ - druxt-router@0.24.0
9
+ - druxt-blocks@0.14.1
10
+ - druxt-entity@0.21.2
11
+
12
+ ## 0.16.0
13
+
14
+ ### Minor Changes
15
+
16
+ - e7b1533: Refactored DruxtModule fetch hooks
17
+
18
+ ### Patch Changes
19
+
20
+ - d80f5d4: Fixed issue with undefined wrapper in DruxtViewsFilter
21
+ - Updated dependencies [025315a]
22
+ - druxt-entity@0.21.0
23
+ - druxt-blocks@0.14.0
24
+ - druxt@0.13.0
25
+ - druxt-router@0.23.0
26
+
27
+ ## 0.15.0
28
+
29
+ ### Minor Changes
30
+
31
+ - c769243: Added support for Contextual filters (arguments)
32
+
33
+ ```vue
34
+ <DruxtView
35
+ :arguments="[1, 2, 3]"
36
+ displayid="block_1"
37
+ view-id="articles_aside"
38
+ />
39
+ ```
40
+
41
+ ### Patch Changes
42
+
43
+ - Updated dependencies [4504a2f]
44
+ - druxt@0.12.0
45
+ - druxt-router@0.22.0
46
+ - druxt-entity@0.20.0
47
+ - druxt-blocks@0.13.1
48
+
49
+ ## 0.14.1
50
+
51
+ ### Patch Changes
52
+
53
+ - b9e5839: Fixed missing templates in package
54
+
3
55
  ## 0.14.0
4
56
 
5
57
  ### Minor Changes
@@ -27,6 +27,20 @@ export default {
27
27
  * Vue.js Properties.
28
28
  */
29
29
  props: {
30
+ /**
31
+ * Views contextual filters.
32
+ *
33
+ * @type {array}
34
+ * @default []
35
+ *
36
+ * @example
37
+ * <DruxtView :arguments="[1, 2, 3]" display-id="block_1" view-id="articles_aside" />
38
+ */
39
+ arguments: {
40
+ type: Array,
41
+ default: () => [],
42
+ },
43
+
30
44
  /**
31
45
  * The View Display ID.
32
46
  *
@@ -99,55 +113,6 @@ export default {
99
113
  }
100
114
  },
101
115
 
102
- /** */
103
- async fetch() {
104
- let component = { ...this.component }
105
-
106
- // Fetch View.
107
- if (!this.view && (this.uuid || this.viewId)) {
108
- if (this.uuid) {
109
- this.view = await this.getResource({
110
- type: this.type,
111
- id: this.uuid,
112
- })
113
- } else {
114
- const collection = await this.getCollection({ type: this.type, query: new DrupalJsonApiParams().addFilter('drupal_internal__id', this.viewId) })
115
- this.view = { data: collection.data[0] }
116
- }
117
-
118
- // Build wrapper component object.
119
- const options = this.getModuleComponents()
120
- component = {
121
- is: (((options.filter(o => o.global) || [])[0] || {}).name || 'DruxtWrapper'),
122
- options: options.map(o => o.name) || [],
123
- }
124
- }
125
-
126
- // Get scoped slots.
127
- component.slots = Object.keys(this.getScopedSlots())
128
-
129
- // Get wrapper component data to merge with module settings.
130
- const wrapperData = await this.getWrapperData(component.is)
131
- component.settings = merge(this.$druxt.settings.views, wrapperData.druxt || {}, { arrayMerge: (dest, src) => src })
132
-
133
- // Fetch JSON:API Views resource.
134
- const viewId = this.viewId || (((this.view || {}).data || {}).attributes || {}).drupal_internal__id
135
- if (viewId) {
136
- const query = this.getQuery(component.settings)
137
- this.resource = await this.getResults({
138
- viewId,
139
- displayId: this.displayId,
140
- query: stringify(query)
141
- })
142
- }
143
-
144
- // Build wrapper component propsData.
145
- component = { ...component, ...this.getModulePropsData(wrapperData.props) }
146
-
147
- // Set component data.
148
- this.component = component
149
- },
150
-
151
116
  fetchKey(getCounter) {
152
117
  const parts = ['DruxtView', this.viewId || this.uuid, this.displayId].filter((o) => o)
153
118
  return [...parts, getCounter(parts.join(':'))].join(':')
@@ -378,6 +343,13 @@ export default {
378
343
  query.page = this.model.page
379
344
  }
380
345
 
346
+ // Contextual filters.
347
+ if (this.arguments.length) {
348
+ for (const index in this.arguments) {
349
+ query[`views-argument[${index}]`] = this.arguments[index]
350
+ }
351
+ }
352
+
381
353
  // Exposed filters.
382
354
  if (Object.entries(this.model.filter || {}).length) {
383
355
  query['views-filter'] = this.model.filter
@@ -419,6 +391,38 @@ export default {
419
391
  */
420
392
  componentOptions: ({ displayId, uuid, viewId }) => ([[viewId || uuid, displayId]]),
421
393
 
394
+ /**
395
+ * Fetch View configuration resource.
396
+ */
397
+ async fetchConfig() {
398
+ if (!this.view && (this.uuid || this.viewId)) {
399
+ if (this.uuid) {
400
+ this.view = await this.getResource({
401
+ type: this.type,
402
+ id: this.uuid,
403
+ })
404
+ } else {
405
+ const collection = await this.getCollection({ type: this.type, query: new DrupalJsonApiParams().addFilter('drupal_internal__id', this.viewId) })
406
+ this.view = { data: collection.data[0] }
407
+ }
408
+ }
409
+ },
410
+
411
+ /**
412
+ * Fetch JSON:API Views results.
413
+ */
414
+ async fetchData(settings) {
415
+ const viewId = this.viewId || (((this.view || {}).data || {}).attributes || {}).drupal_internal__id
416
+ if (viewId) {
417
+ const query = this.getQuery(settings)
418
+ this.resource = await this.getResults({
419
+ viewId,
420
+ displayId: this.displayId,
421
+ query: stringify(query)
422
+ })
423
+ }
424
+ },
425
+
422
426
  /**
423
427
  * Provides propsData for the DruxtWrapper.
424
428
  *
@@ -434,6 +438,16 @@ export default {
434
438
  view: vm.view
435
439
  }),
436
440
 
441
+ /**
442
+ * Component settings.
443
+ */
444
+ settings: ({ $druxt }, wrapperSettings) => {
445
+ const settings = merge($druxt.settings.views || {}, wrapperSettings, { arrayMerge: (dest, src) => src })
446
+ return {
447
+ query: settings.query || {},
448
+ }
449
+ },
450
+
437
451
  /**
438
452
  * Provides the scoped slots object for the Module render function.
439
453
  *
@@ -1,8 +1,8 @@
1
1
  <template>
2
2
  <component
3
- :is="wrapper.component"
3
+ :is="(wrapper || {}).component || 'div'"
4
4
  v-if="!$fetchState.pending"
5
- v-bind="wrapper.propsData"
5
+ v-bind="(wrapper || {}).propsData"
6
6
  >
7
7
  <component
8
8
  :is="component.is"
@@ -7,7 +7,7 @@ import { DruxtEntityContextMixin } from 'druxt-entity';
7
7
 
8
8
  async function DruxtViewsStorybook({ stories }) {
9
9
  const { addTemplate, options } = this;
10
- const druxt = new DruxtClient(options.druxt.baseUrl, options.druxt);
10
+ const druxt = new DruxtClient(options.druxt.baseUrl, { ...options.druxt, proxy: { api: false } });
11
11
  const resourceType = "view--view";
12
12
  const query = new DrupalJsonApiParams().addFilter("status", 1).addFields(resourceType, ["display", "description", "drupal_internal__id", "label"]);
13
13
  const collections = await druxt.getCollectionAll(resourceType, query);
@@ -16,7 +16,7 @@ const md5__default = /*#__PURE__*/_interopDefaultLegacy(md5);
16
16
 
17
17
  async function DruxtViewsStorybook({ stories }) {
18
18
  const { addTemplate, options } = this;
19
- const druxt$1 = new druxt.DruxtClient(options.druxt.baseUrl, options.druxt);
19
+ const druxt$1 = new druxt.DruxtClient(options.druxt.baseUrl, { ...options.druxt, proxy: { api: false } });
20
20
  const resourceType = "view--view";
21
21
  const query = new drupalJsonapiParams.DrupalJsonApiParams().addFilter("status", 1).addFields(resourceType, ["display", "description", "drupal_internal__id", "label"]);
22
22
  const collections = await druxt$1.getCollectionAll(resourceType, query);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "druxt-views",
3
- "version": "0.14.0",
3
+ "version": "0.16.1",
4
4
  "description": "Drupal Views components for Druxt with support for filters, pagination and sorting.",
5
5
  "keywords": [
6
6
  "cms",
@@ -38,16 +38,17 @@
38
38
  "module": "dist/druxt-views.esm.js",
39
39
  "files": [
40
40
  "dist",
41
- "nuxt"
41
+ "nuxt",
42
+ "templates"
42
43
  ],
43
44
  "dependencies": {
44
45
  "axios": "^0.21.1",
45
46
  "deepmerge": "^4.2.2",
46
47
  "drupal-jsonapi-params": "^1.1.12",
47
- "druxt": "^0.11.0",
48
- "druxt-blocks": "^0.13.0",
49
- "druxt-entity": "^0.19.0",
50
- "druxt-router": "^0.21.0",
48
+ "druxt": "^0.13.0",
49
+ "druxt-blocks": "^0.14.1",
50
+ "druxt-entity": "^0.21.2",
51
+ "druxt-router": "^0.24.0",
51
52
  "md5": "^2.3.0"
52
53
  },
53
54
  "optionalDependencies": {
@@ -0,0 +1,42 @@
1
+ import DruxtView from 'druxt-views/dist/components/DruxtView.vue'
2
+
3
+ export default {
4
+ title: <%= devalue(options.title) %>,
5
+ component: DruxtView,
6
+ argTypes: {
7
+ displayId: {
8
+ control: {
9
+ type: 'select',
10
+ options: [<%= options.displays.map(({ id }) => `'${id}'`).join(', ') %>]
11
+ },
12
+ },
13
+ },
14
+ parameters: {
15
+ docs: {
16
+ description: {
17
+ component: <%= options.description ? devalue(options.description) : '" "' %>
18
+ }
19
+ }
20
+ }
21
+ }
22
+
23
+ const Template = (args, { argTypes }) => ({
24
+ props: Object.keys(args),
25
+ template: '<DruxtView v-bind="$props" v-on="$props" />',
26
+ })
27
+
28
+ <% for (display of options.displays) { %>
29
+ export const <%= display.id.charAt(0).toUpperCase() + display.id.slice(1) %> = Template.bind({})
30
+ <%= display.id.charAt(0).toUpperCase() + display.id.slice(1) %>.args = {
31
+ displayId: '<%= display.id %>',
32
+ viewId: '<%= options.viewId %>',
33
+ }
34
+ <%= display.id.charAt(0).toUpperCase() + display.id.slice(1) %>.storyName = '<%= display.display_title %>'
35
+ <%= display.id.charAt(0).toUpperCase() + display.id.slice(1) %>.parameters = {
36
+ docs: {
37
+ source: {
38
+ code: '<DruxtView display-id="<%= display.id %>" view-id="<%= options.viewId %>" />'
39
+ }
40
+ }
41
+ }
42
+ <% } %>
@@ -0,0 +1,3 @@
1
+ import { DruxtViewsStore } from 'druxt-views'
2
+
3
+ export default DruxtViewsStore