Skip to content

Commit 7b4136f

Browse files
committed
show tags on version select
1 parent ad9a15c commit 7b4136f

File tree

2 files changed

+142
-3
lines changed

2 files changed

+142
-3
lines changed

src/components/Content.vue

Lines changed: 107 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import { obpMyCollectionsEndpointKey, obpResourceDocsKey } from '@/obp/keys'
3030
import { ArrowLeftBold, ArrowRightBold } from '@element-plus/icons-vue'
3131
import { ElNotification } from 'element-plus'
3232
import { inject, onMounted, provide, ref } from 'vue'
33-
import { onBeforeRouteUpdate, useRoute } from 'vue-router'
33+
import { onBeforeRouteUpdate, useRoute, useRouter } from 'vue-router'
3434
import {
3535
OBP_API_DEFAULT_RESOURCE_DOC_VERSION,
3636
createMyAPICollection,
@@ -43,9 +43,12 @@ import { SUMMARY_PAGER_LINKS_COLOR as summaryPagerLinksColorSetting } from '../o
4343
import { initializeAPICollections, setTabActive } from './SearchNav.vue'
4444
4545
const route = useRoute()
46+
const router = useRouter()
4647
const obpVersion = OBP_API_DEFAULT_RESOURCE_DOC_VERSION
4748
const description = ref('')
4849
const summary = ref('')
50+
const tags = ref<string[]>([])
51+
const allTags = ref<string[]>([])
4952
const resourceDocs = inject(obpResourceDocsKey)
5053
const displayPrev = ref(true)
5154
const displayNext = ref(true)
@@ -63,8 +66,20 @@ let apiCollectionsEndpoint = inject(obpMyCollectionsEndpointKey)!
6366
6467
const setOperationDetails = (id: string, version: string): void => {
6568
const operation = getOperationDetails(version, id, resourceDocs)
69+
console.log('Operation details:', operation)
70+
console.log('Tags from operation:', operation?.tags)
6671
description.value = operation?.description
6772
summary.value = operation?.summary
73+
tags.value = operation?.tags || []
74+
console.log('Tags ref value:', tags.value)
75+
}
76+
77+
const filterByTag = (tag: string) => {
78+
router.push({
79+
name: 'api',
80+
params: { version: version },
81+
query: { tags: tag }
82+
})
6883
}
6984
7085
const setPager = (id: string): void => {
@@ -144,6 +159,17 @@ const showNotification = (message: string, type: string): void => {
144159
})
145160
}
146161
162+
const getAllTags = (version: string) => {
163+
const docs = resourceDocs[version]?.resource_docs || []
164+
const tagSet = new Set<string>()
165+
docs.forEach((doc: any) => {
166+
if (doc.tags && Array.isArray(doc.tags)) {
167+
doc.tags.forEach((tag: string) => tagSet.add(tag))
168+
}
169+
})
170+
return Array.from(tagSet).sort()
171+
}
172+
147173
onMounted(async () => {
148174
routeId = route.query.operationid
149175
version = route.params.version ? route.params.version : obpVersion
@@ -153,6 +179,7 @@ onMounted(async () => {
153179
showPlaceholder.value = true
154180
placeholderVersion.value = version
155181
totalEndpoints.value = resourceDocs[version]?.resource_docs?.length || 0
182+
allTags.value = getAllTags(version)
156183
} else {
157184
showPlaceholder.value = false
158185
setOperationDetails(routeId, version)
@@ -165,10 +192,11 @@ onBeforeRouteUpdate(async (to) => {
165192
version = to.params.version ? to.params.version : obpVersion
166193
167194
if (!routeId) {
168-
// No operation selected, show placeholder
195+
// Version changed but no endpoint selected
169196
showPlaceholder.value = true
170197
placeholderVersion.value = version
171198
totalEndpoints.value = resourceDocs[version]?.resource_docs?.length || 0
199+
allTags.value = getAllTags(version)
172200
} else {
173201
showPlaceholder.value = false
174202
setOperationDetails(routeId, version)
@@ -186,6 +214,20 @@ onBeforeRouteUpdate(async (to) => {
186214
<h2>Version {{ placeholderVersion }} Selected</h2>
187215
<p>There are {{ totalEndpoints }} endpoints available in this version.</p>
188216
<p>Please click an endpoint on the left to view its details.</p>
217+
218+
<div v-if="allTags.length > 0" class="placeholder-tags">
219+
<h3>Filter by Tag:</h3>
220+
<div class="tags-grid">
221+
<a
222+
v-for="tag in allTags"
223+
:key="tag"
224+
class="tag-link"
225+
@click.prevent="filterByTag(tag)"
226+
>
227+
{{ tag }}
228+
</a>
229+
</div>
230+
</div>
189231
</div>
190232
<div v-else>
191233
<el-row>
@@ -197,6 +239,18 @@ onBeforeRouteUpdate(async (to) => {
197239
<!--<el-button text>★</el-button>-->
198240
</el-col>
199241
</el-row>
242+
<div class="tags-section">
243+
<span class="tags-label">Tags ({{ tags.length }}):</span>
244+
<a
245+
v-for="tag in tags"
246+
:key="tag"
247+
class="tag-link"
248+
@click.prevent="filterByTag(tag)"
249+
>
250+
{{ tag }}
251+
</a>
252+
<span v-if="tags.length === 0" style="color: #909399; font-size: 12px;">No tags available</span>
253+
</div>
200254
<div v-html="description" class="content"></div>
201255
</div>
202256
</el-main>
@@ -236,6 +290,39 @@ span {
236290
font-size: 28px;
237291
}
238292
293+
.tags-section {
294+
margin: 15px 0;
295+
display: flex;
296+
align-items: center;
297+
gap: 8px;
298+
flex-wrap: wrap;
299+
}
300+
301+
.tags-label {
302+
font-size: 14px !important;
303+
font-weight: 600;
304+
color: #606266;
305+
}
306+
307+
.tag-link {
308+
display: inline-block;
309+
padding: 4px 12px;
310+
font-size: 12px !important;
311+
color: #409eff;
312+
background-color: #ecf5ff;
313+
border: 1px solid #d9ecff;
314+
border-radius: 4px;
315+
cursor: pointer;
316+
transition: all 0.2s ease;
317+
text-decoration: none;
318+
}
319+
320+
.tag-link:hover {
321+
background-color: #409eff;
322+
color: white;
323+
border-color: #409eff;
324+
}
325+
239326
.placeholder-message {
240327
text-align: center;
241328
padding: 60px 20px;
@@ -254,6 +341,24 @@ span {
254341
line-height: 1.6;
255342
}
256343
344+
.placeholder-tags {
345+
margin-top: 40px;
346+
text-align: left;
347+
}
348+
349+
.placeholder-tags h3 {
350+
font-size: 18px;
351+
margin-bottom: 20px;
352+
color: #39455f;
353+
}
354+
355+
.tags-grid {
356+
display: flex;
357+
flex-wrap: wrap;
358+
gap: 10px;
359+
justify-content: flex-start;
360+
}
361+
257362
div {
258363
font-size: 14px;
259364
}

src/components/SearchNav.vue

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,12 @@ watch(
119119
async (version) => {
120120
console.log('SearchNav: version changed to:', version)
121121
selectedVersion = version
122-
docs.value = getGroupedResourceDocs(version, resourceDocs.value)
122+
selectedTags = route.query.tags ? route.query.tags : 'NONE'
123+
if(selectedTags === 'NONE') {
124+
docs.value = getGroupedResourceDocs(version, resourceDocs.value)
125+
} else {
126+
docs.value = getFilteredGroupedResourceDocs(version, selectedTags, resourceDocs.value)
127+
}
123128
groups.value = JSON.parse(JSON.stringify(docs.value))
124129
activeKeys.value = Object.keys(groups.value)
125130
sortedKeys.value = activeKeys.value.sort()
@@ -137,6 +142,35 @@ watch(
137142
}
138143
)
139144
145+
watch(
146+
() => route.query.tags,
147+
async (tags) => {
148+
console.log('SearchNav: tags changed to:', tags)
149+
selectedTags = tags ? tags : 'NONE'
150+
if(selectedTags === 'NONE') {
151+
docs.value = getGroupedResourceDocs(selectedVersion, resourceDocs.value)
152+
} else {
153+
docs.value = getFilteredGroupedResourceDocs(selectedVersion, selectedTags, resourceDocs.value)
154+
}
155+
groups.value = JSON.parse(JSON.stringify(docs.value))
156+
activeKeys.value = Object.keys(groups.value)
157+
sortedKeys.value = activeKeys.value.sort()
158+
await initializeAPICollections()
159+
await nextTick()
160+
countApis()
161+
// Update the version display text
162+
let element = document.getElementById("selected-api-version")
163+
if (element !== null) {
164+
const totalRows = Object.values(groups.value).reduce((acc, currentValue) => acc + currentValue.length, 0)
165+
if(selectedTags === 'NONE') {
166+
element.textContent = `${selectedVersion} ( ${totalRows} APIs )`;
167+
} else {
168+
element.textContent = `${selectedVersion} ( ${totalRows} APIs filtered by tags: ${selectedTags})`;
169+
}
170+
}
171+
}
172+
)
173+
140174
141175
142176
const countApis = () => {

0 commit comments

Comments
 (0)