Skip to content

Commit f3519fd

Browse files
committed
Rework item actions as object actions
1 parent cc4f3c8 commit f3519fd

File tree

10 files changed

+89
-43
lines changed

10 files changed

+89
-43
lines changed

docs/actions.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,17 @@ The following actions are available:
5757

5858
- `stac-map`: Allows to open items through stac-map at <https://developmentseed.org/stac-map/>.
5959

60-
All actions for items are stored in the folder [`src/actions/items`](../src/actions/items) if you want to inspect them.
60+
All actions for items are stored in the folder [`src/actions/objects`](../src/actions/objects) if you want to inspect them.
6161

62-
The actions can be enabled by adding them to the [`itemActions.config.js`](../itemActions.config.js) file.
62+
The actions can be enabled by adding them to the [`objectActions.config.js`](../objectActions.config.js) file.
6363
Open the file and you'll see a number of imports and exports.
6464
Import the file for the action that you want to enable, e.g. for stac-map:
6565

6666
```js
67-
import Stacmap from './src/actions/items/Stacmap.js';
67+
import StacMap from './src/actions/objects/StacMap.js';
6868
```
6969

70-
The path is fixed to `./src/actions/items/`, the file extension is always `.js`.
70+
The path is fixed to `./src/actions/objects/`, the file extension is always `.js`.
7171
In-between add the file name from the list above.
7272
The import name should be the file name without extension (i.e. `Stacmap` again).
7373

@@ -76,7 +76,7 @@ Lastly, add the import name to the list of exports, e.g.
7676
```js
7777
export default {
7878
OtherAction,
79-
Stacmap
79+
StacMap
8080
};
8181
```
8282

@@ -121,17 +121,17 @@ Save the file and rebuild / restart STAC Browser.
121121
Implementing actions for assets, items and links follows a very similar pattern.
122122
The main difference is that each action implements its own interface:
123123
- assets implement the [`AssetActionPlugin` interface](../src/actions/AssetActionPlugin.js)
124-
- items implement the [`ItemActionPlugin` interface](../src/actions/ItemActionPlugin.js)
124+
- items implement the [`ObjectActionPlugin` interface](../src/actions/ObjectActionPlugin.js)
125125
- links implement the [`LinkActionPlugin` interface](../src/actions/LinkActionPlugin.js)
126126
Similarly, actions are stored in their own folder:
127127
- assets are stored in the folder [`src/actions/assets`](../src/actions/assets)
128-
- items are stored in the folder [`src/actions/items`](../src/actions/items)
128+
- items are stored in the folder [`src/actions/objects`](../src/actions/objects)
129129
- links are stored in the folder [`src/actions/links`](../src/actions/links)
130130

131131
All interfaces look as follows:
132132

133133
- `constructor(data: object, component: Vue, id: string)`
134-
- `data`: The asset, item or link object, it is available in the class through `this.asset` (for assets), `this.item` (for items) and `this.link` (for links).
134+
- `data`: The asset, item or link object, it is available in the class through `this.asset` (for assets), `this.object` (for items) and `this.link` (for links).
135135
- `component`: The parent Asset/Item/Link Vue component (available in the class through `this.component`)
136136
- `id`: Internal ID of the asset, item or link, not meant to be used.
137137
- `get btnOptions() : object`

itemActions.config.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

objectActions.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// import StacMap from './src/actions/objects/StacMap.js';
2+
3+
export default {
4+
// StacMap,
5+
};

src/actions/ItemActionPlugin.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/actions/ObjectActionPlugin.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import ActionPlugin from './ActionPlugin';
2+
3+
export default class ObjectActionPlugin extends ActionPlugin {
4+
5+
constructor(object, component, id) {
6+
super(id, component);
7+
this.object = object;
8+
}
9+
}

src/actions/items/StacMap.js renamed to src/actions/objects/StacMap.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import ItemActionPlugin from "../ItemActionPlugin";
1+
import ObjectActionPlugin from "../ObjectActionPlugin";
22
import URI from 'urijs';
33
import i18n from "../../i18n";
44

5-
export default class StacMap extends ItemActionPlugin {
5+
export default class StacMap extends ObjectActionPlugin {
66

77
get show() {
8-
return true;
8+
return this.object.isItem();
99
}
1010

1111
get uri() {
12-
return new URI(`https://developmentseed.org/stac-map/?href=${this.item.getAbsoluteUrl()}`);
12+
return new URI(`https://developmentseed.org/stac-map/?href=${this.object.getAbsoluteUrl()}`);
1313
}
1414

1515
get text() {

src/components/HrefActions.vue

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<b-icon-download v-else />
1111
{{ buttonText }}
1212
</b-button>
13-
<CopyButton variant="primary" :copyText="href" :title="href" v-if="!isItem">
13+
<CopyButton variant="primary" :copyText="href" :title="href">
1414
{{ copyButtonText }}
1515
</CopyButton>
1616
<b-button v-if="hasShowButton" @click="show" variant="primary">
@@ -43,7 +43,6 @@ import Description from './Description.vue';
4343
import Utils, { imageMediaTypes, mapMediaTypes } from '../utils';
4444
import { mapGetters, mapState } from 'vuex';
4545
import AssetActions from '../../assetActions.config';
46-
import ItemActions from '../../itemActions.config';
4746
import LinkActions from '../../linkActions.config';
4847
import { stacRequestOptions } from '../store/utils';
4948
import URI from 'urijs';
@@ -77,10 +76,6 @@ export default {
7776
type: Boolean,
7877
default: false
7978
},
80-
isItem: {
81-
type: Boolean,
82-
default: false
83-
},
8479
vertical: {
8580
type: Boolean,
8681
default: false
@@ -120,7 +115,7 @@ export default {
120115
}
121116
},
122117
actions() {
123-
return Object.entries(this.isAsset ? AssetActions : this.isItem ? ItemActions : LinkActions)
118+
return Object.entries(this.isAsset ? AssetActions : LinkActions)
124119
.map(([id, plugin]) => new plugin(this.data, this, id))
125120
.filter(plugin => plugin.show);
126121
},
@@ -152,7 +147,6 @@ export default {
152147
hasButtons() {
153148
return this.href && (this.requiresAuth
154149
|| this.hasDownloadButton()
155-
|| !this.isItem
156150
|| this.hasShowButton()
157151
|| (this.actions && this.actions.length > 0));
158152
},
@@ -221,7 +215,7 @@ export default {
221215
}
222216
},
223217
href() {
224-
if (typeof this.data.href !== 'string' && !this.isItem) {
218+
if (typeof this.data.href !== 'string') {
225219
return null;
226220
}
227221
return this.getRequestUrl(this.data.getAbsoluteUrl());

src/components/Item.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919
</small>
2020
</b-card-text>
2121
</b-card-body>
22-
<HrefActions isItem :data="item" size="sm" />
22+
<ObjectActions :data="item" size="sm" />
2323
</b-card>
2424
</template>
2525

2626
<script>
2727
import { mapState, mapGetters } from 'vuex';
2828
import FileFormatsMixin from './FileFormatsMixin';
2929
import ThumbnailCardMixin from './ThumbnailCardMixin';
30-
import HrefActions from './HrefActions.vue';
30+
import ObjectActions from './ObjectActions.vue';
3131
import StacLink from './StacLink.vue';
3232
import { STAC } from 'stac-js';
3333
import { formatTemporalExtent, formatTimestamp, formatMediaType } from '@radiantearth/stac-fields/formatters';
@@ -40,7 +40,7 @@ export default {
4040
name: 'Item',
4141
components: {
4242
StacLink,
43-
HrefActions,
43+
ObjectActions,
4444
Keywords: () => import('./Keywords.vue')
4545
},
4646
filters: {
@@ -145,7 +145,7 @@ export default {
145145
position: relative;
146146
}
147147
148-
&:has(.actions) {
148+
&:has(.obj-actions) {
149149
padding-bottom: 0.5rem;
150150
}
151151
}

src/components/ObjectActions.vue

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<template>
2+
<b-button-group class="obj-actions" :vertical="vertical" :size="size" v-if="hasButtons">
3+
<b-button v-for="action of actions" v-bind="action.btnOptions" :key="action.id" variant="primary" @click="action.onClick">
4+
<component v-if="action.icon" :is="action.icon" class="mr-1" />
5+
{{ action.text }}
6+
</b-button>
7+
</b-button-group>
8+
</template>
9+
10+
11+
<script>
12+
import { BIconBoxArrowUpRight } from 'bootstrap-vue';
13+
import ObjectActions from '../../objectActions.config';
14+
15+
let i = 0;
16+
17+
export default {
18+
name: 'ObjectActions',
19+
components: {
20+
BIconBoxArrowUpRight
21+
},
22+
props: {
23+
data: {
24+
type: Object,
25+
required: true
26+
},
27+
vertical: {
28+
type: Boolean,
29+
default: false
30+
},
31+
size: {
32+
type: String,
33+
default: 'md'
34+
}
35+
},
36+
data() {
37+
return {
38+
id: i++
39+
};
40+
},
41+
computed: {
42+
actions() {
43+
return Object.entries(ObjectActions)
44+
.map(([id, plugin]) => new plugin(this.data, this, id))
45+
.filter(plugin => plugin.show);
46+
},
47+
hasButtons() {
48+
return this.actions && this.actions.length > 0;
49+
}
50+
}
51+
};
52+
</script>

src/views/Item.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
</b-tabs>
1515
</b-card>
1616
</section>
17-
<HrefActions isItem :data="data" />
17+
<ObjectActions :data="data" />
1818
<Assets v-if="hasAssets" :assets="assets" :context="data" :shown="selectedReferences" @showAsset="showAsset" />
1919
<Links v-if="additionalLinks.length > 0" :title="$t('additionalResources')" :links="additionalLinks" :context="data" />
2020
</b-col>
@@ -39,7 +39,7 @@
3939
<script>
4040
import { mapState, mapGetters } from 'vuex';
4141
import Description from '../components/Description.vue';
42-
import HrefActions from '../components/HrefActions.vue';
42+
import ObjectActions from '../components/ObjectActions.vue';
4343
import ReadMore from "vue-read-more-smooth";
4444
import ShowAssetLinkMixin from '../components/ShowAssetLinkMixin';
4545
import DeprecationMixin from '../components/DeprecationMixin';
@@ -55,7 +55,7 @@ export default {
5555
BTab,
5656
CollectionLink: () => import('../components/CollectionLink.vue'),
5757
Description,
58-
HrefActions,
58+
ObjectActions,
5959
DeprecationNotice: () => import('../components/DeprecationNotice.vue'),
6060
Keywords: () => import('../components/Keywords.vue'),
6161
Links: () => import('../components/Links.vue'),
@@ -125,7 +125,7 @@ export default {
125125
align-self: center;
126126
}
127127
128-
div:has(> .actions) + .assets {
128+
.obj-actions + .assets {
129129
margin-top: 1rem;
130130
}
131131

0 commit comments

Comments
 (0)