Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(catalog): conditionally add public labels header #560

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 39 additions & 53 deletions src/components/CatalogTableList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,70 +64,56 @@
</div>
</template>

<script lang="ts">
<script lang="ts" setup>
import { FeatureFlags } from '@/constants/feature-flags'
import useLDFeatureFlag from '@/hooks/useLDFeatureFlag'
import { useI18nStore, CatalogItemModel } from '@/stores'
import { defineComponent, ref, computed, watch, PropType } from 'vue'
import { ref, computed, watch, PropType } from 'vue'
import { useRouter } from 'vue-router'

export default defineComponent({
name: 'CatalogTableList',
props: {
products: {
type: Array as PropType<CatalogItemModel[]>,
default: () => []
},
loading: {
type: Boolean,
default: false
}
const props = defineProps({
products: {
type: Array as PropType<CatalogItemModel[]>,
default: () => []
},
setup (props) {
const $router = useRouter()
const helpText = useI18nStore().state.helpText.catalogTable
const key = ref(0)
const fetcherCacheKey = computed(() => key.value.toString())
const revalidate = () => {
key.value += 1
}
loading: {
type: Boolean,
default: false
}
})

function handleRowClick (e, row) {
$router.push({ path: `/spec/${row.id}` })
}
const $router = useRouter()
const helpText = useI18nStore().state.helpText.catalogTable
const key = ref(0)
const fetcherCacheKey = computed(() => key.value.toString())
const revalidate = () => {
key.value += 1
}

function fetcher () {
return {
total: props.products.length,
data: props.products
}
}
function handleRowClick (e, row) {
$router.push({ path: `/spec/${row.id}` })
}

watch(() => props.products, () => {
revalidate()
}, { deep: true })
function fetcher () {
return {
total: props.products.length,
data: props.products
}
}

return {
handleRowClick,
fetcher,
fetcherCacheKey,
helpText
}
},
data () {
const publicLabelsUIEnabled = useLDFeatureFlag(FeatureFlags.publicLabelsUI, false)
watch(() => props.products, () => {
revalidate()
}, { deep: true })

return {
publicLabelsUIEnabled,
tableHeaders: [
{ label: 'Title', key: 'title' },
{ label: 'Description', key: 'description' },
{ label: 'Latest Version', key: 'latestVersion' },
{ label: 'Labels', key: 'publicLabels' },
{ label: 'Details', key: 'links' }
]
}
}
const publicLabelsUIEnabled = useLDFeatureFlag(FeatureFlags.publicLabelsUI, false)
const tableHeaders = computed(() => {
return [
{ label: 'Title', key: 'title' },
{ label: 'Description', key: 'description' },
{ label: 'Latest Version', key: 'latestVersion' },
...(publicLabelsUIEnabled ? [{ label: 'Public Labels', key: 'publicLabels' }] : []),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the meat of this PR, as it conditionally adds the header, therefore not rendering the JSON when the flag evaluates to false.

{ label: 'Details', key: 'links' }
]
})
</script>

Expand Down
Loading