refactor: allow smart tabs to render inactive tabs as an option

This commit is contained in:
Andrew Bastin
2022-06-28 16:33:39 +05:30
parent ed6e1c0f94
commit cfdab014c7
12 changed files with 43 additions and 6 deletions

View File

@@ -1,6 +1,10 @@
<template> <template>
<div v-if="show"> <div v-if="show">
<SmartTabs :id="'collections_tab'" v-model="selectedCollectionTab"> <SmartTabs
:id="'collections_tab'"
v-model="selectedCollectionTab"
render-inactive-tabs
>
<SmartTab <SmartTab
:id="'my-collections'" :id="'my-collections'"
:label="`${$t('collection.my_collections')}`" :label="`${$t('collection.my_collections')}`"

View File

@@ -3,6 +3,7 @@
<SmartTabs <SmartTabs
v-model="selectedOptionTab" v-model="selectedOptionTab"
styles="sticky bg-primary top-upperPrimaryStickyFold z-10" styles="sticky bg-primary top-upperPrimaryStickyFold z-10"
render-inactive-tabs
> >
<SmartTab <SmartTab
:id="'query'" :id="'query'"

View File

@@ -3,6 +3,7 @@
v-model="selectedNavigationTab" v-model="selectedNavigationTab"
styles="sticky bg-primary z-10 top-0" styles="sticky bg-primary z-10 top-0"
vertical vertical
render-inactive-tabs
> >
<SmartTab :id="'history'" icon="clock" :label="`${t('tab.history')}`"> <SmartTab :id="'history'" icon="clock" :label="`${t('tab.history')}`">
<History <History
@@ -64,6 +65,7 @@
<SmartTabs <SmartTabs
v-model="selectedGqlTab" v-model="selectedGqlTab"
styles="border-t border-b border-dividerLight bg-primary sticky z-10 top-sidebarPrimaryStickyFold" styles="border-t border-b border-dividerLight bg-primary sticky z-10 top-sidebarPrimaryStickyFold"
render-inactive-tabs
> >
<SmartTab <SmartTab
v-if="queryFields.length > 0" v-if="queryFields.length > 0"

View File

@@ -2,6 +2,7 @@
<SmartTabs <SmartTabs
v-model="selectedRealtimeTab" v-model="selectedRealtimeTab"
styles="sticky bg-primary top-upperMobilePrimaryStickyFold sm:top-upperPrimaryStickyFold z-10" styles="sticky bg-primary top-upperMobilePrimaryStickyFold sm:top-upperPrimaryStickyFold z-10"
render-inactive-tabs
> >
<SmartTab <SmartTab
:id="'params'" :id="'params'"

View File

@@ -3,6 +3,7 @@
v-model="selectedNavigationTab" v-model="selectedNavigationTab"
styles="sticky bg-primary z-10 top-0" styles="sticky bg-primary z-10 top-0"
vertical vertical
render-inactive-tabs
> >
<SmartTab :id="'history'" icon="clock" :label="`${$t('tab.history')}`"> <SmartTab :id="'history'" icon="clock" :label="`${$t('tab.history')}`">
<History ref="historyComponent" :page="'rest'" /> <History ref="historyComponent" :page="'rest'" />

View File

@@ -3,6 +3,7 @@
v-if="response" v-if="response"
v-model="selectedLensTab" v-model="selectedLensTab"
styles="sticky z-10 bg-primary top-lowerPrimaryStickyFold" styles="sticky z-10 bg-primary top-lowerPrimaryStickyFold"
render-inactive-tabs
> >
<SmartTab <SmartTab
v-for="(lens, index) in validLenses" v-for="(lens, index) in validLenses"

View File

@@ -51,7 +51,11 @@
</div> </div>
</div> </div>
<div v-if="!minimized" class="overflow-hidden bg-primaryLight"> <div v-if="!minimized" class="overflow-hidden bg-primaryLight">
<SmartTabs v-model="selectedTab" styles="bg-primaryLight"> <SmartTabs
v-model="selectedTab"
styles="bg-primaryLight"
render-inactive-tabs
>
<SmartTab v-if="isJSON(entry.payload)" id="json" label="JSON" /> <SmartTab v-if="isJSON(entry.payload)" id="json" label="JSON" />
<SmartTab id="raw" label="Raw" /> <SmartTab id="raw" label="Raw" />
</SmartTabs> </SmartTabs>

View File

@@ -1,5 +1,5 @@
<template> <template>
<div v-show="active" class="flex flex-col flex-1"> <div v-if="shouldRender" v-show="active" class="flex flex-col flex-1">
<slot></slot> <slot></slot>
</div> </div>
</template> </template>
@@ -33,11 +33,24 @@ const tabMeta = computed<TabMeta>(() => ({
label: props.label, label: props.label,
})) }))
const { activeTabID, addTabEntry, updateTabEntry, removeTabEntry } = const {
inject<TabProvider>("tabs-system")! activeTabID,
renderInactive,
addTabEntry,
updateTabEntry,
removeTabEntry,
} = inject<TabProvider>("tabs-system")!
const active = computed(() => activeTabID.value === props.id) const active = computed(() => activeTabID.value === props.id)
const shouldRender = computed(() => {
// If render inactive is true, then it should be rendered nonetheless
if (renderInactive.value) return true
// Else, return whatever is the active state
return active.value
})
onMounted(() => { onMounted(() => {
addTabEntry(props.id, tabMeta.value) addTabEntry(props.id, tabMeta.value)
}) })

View File

@@ -80,6 +80,8 @@ export type TabMeta = {
} }
export type TabProvider = { export type TabProvider = {
// Whether inactive tabs should remain rendered
renderInactive: ComputedRef<boolean>
activeTabID: ComputedRef<string> activeTabID: ComputedRef<string>
addTabEntry: (tabID: string, meta: TabMeta) => void addTabEntry: (tabID: string, meta: TabMeta) => void
updateTabEntry: (tabID: string, newMeta: TabMeta) => void updateTabEntry: (tabID: string, newMeta: TabMeta) => void
@@ -91,6 +93,10 @@ const props = defineProps({
type: String, type: String,
default: "", default: "",
}, },
renderInactiveTabs: {
type: Boolean,
default: false,
},
vertical: { vertical: {
type: Boolean, type: Boolean,
default: false, default: false,
@@ -144,6 +150,7 @@ const removeTabEntry = (tabID: string) => {
} }
provide<TabProvider>("tabs-system", { provide<TabProvider>("tabs-system", {
renderInactive: computed(() => props.renderInactiveTabs),
activeTabID: computed(() => props.value), activeTabID: computed(() => props.value),
addTabEntry, addTabEntry,
updateTabEntry, updateTabEntry,

View File

@@ -83,7 +83,7 @@
<FirebaseLogout outline /> <FirebaseLogout outline />
</div> </div>
</div> </div>
<SmartTabs v-model="selectedProfileTab"> <SmartTabs v-model="selectedProfileTab" render-inactive-tabs>
<SmartTab :id="'sync'" :label="t('settings.account')"> <SmartTab :id="'sync'" :label="t('settings.account')">
<div class="grid grid-cols-1"> <div class="grid grid-cols-1">
<section class="p-4"> <section class="p-4">

View File

@@ -86,10 +86,12 @@
<SmartTabs <SmartTabs
v-model="selectedTab" v-model="selectedTab"
styles="sticky bg-primary top-upperPrimaryStickyFold z-10" styles="sticky bg-primary top-upperPrimaryStickyFold z-10"
render-inactive-tabs
> >
<SmartTab <SmartTab
:id="'communication'" :id="'communication'"
:label="`${t('websocket.communication')}`" :label="`${t('websocket.communication')}`"
render-inactive-tabs
> >
<RealtimeCommunication <RealtimeCommunication
:show-event-field="true" :show-event-field="true"

View File

@@ -38,6 +38,7 @@
<SmartTabs <SmartTabs
v-model="selectedTab" v-model="selectedTab"
styles="sticky bg-primary top-upperPrimaryStickyFold z-10" styles="sticky bg-primary top-upperPrimaryStickyFold z-10"
render-inactive-tabs
> >
<SmartTab <SmartTab
:id="'communication'" :id="'communication'"