Skip to content

Commit 7a9e176

Browse files
authored
fix: disable clicking if no template is chosen (#153)
* fix: disable clicking if no template is chosen * fix: disable test checkbox if no template & fallback to README if no code file
1 parent 917867c commit 7a9e176

File tree

3 files changed

+49
-9
lines changed

3 files changed

+49
-9
lines changed

src/components/FormCheckbox.vue

+5-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
type="checkbox"
77
:id="checkboxId"
88
:required="required"
9+
:disabled="noTemplate"
910
v-model="checked"
1011
@change.prevent="saveChecked"
1112
/>
@@ -18,7 +19,7 @@
1819

1920
<script>
2021
import { ref, toRefs, computed } from 'vue'
21-
import { saveConfig } from '../store.js'
22+
import { saveConfig, store } from '../store.js'
2223
2324
export default {
2425
props: {
@@ -42,6 +43,7 @@ export default {
4243
const saveChecked = () => saveConfig(saveKey.value, checked.value)
4344
const checkboxId = computed(() => saveKey.value + '-checkbox')
4445
const isRequired = computed(() => (required.value ? '*' : ''))
46+
const noTemplate = computed(() => !store.config.template)
4547
4648
return {
4749
label,
@@ -50,7 +52,8 @@ export default {
5052
checked,
5153
saveChecked,
5254
checkboxId,
53-
isRequired
55+
isRequired,
56+
noTemplate
5457
}
5558
}
5659
}

src/components/PaneLeft.vue

+27-5
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
v-for="tab in tabs"
55
:key="tab"
66
class="left-pane-tab"
7-
:class="{ active: currentTab === tab }"
8-
@click="currentTab = tab"
7+
:class="{ active: currentTab === tab, disable: !hasTemplate }"
8+
@click="switchTab(tab)"
99
>
1010
{{ tab }}
1111
</div>
@@ -25,20 +25,36 @@ import TabHandlers from './TabHandlers.vue'
2525
import TabLoggers from './TabLoggers.vue'
2626
import Message from './Message.vue'
2727
import { computed, ref } from 'vue'
28-
import { msg } from '../store.js'
28+
import { msg, store } from '../store.js'
2929
3030
export default {
3131
components: { TabTemplates, TabTraining, TabLoggers, TabHandlers, Message },
3232
setup() {
3333
const currentTab = ref('Templates')
34-
const tabs = ref(['Templates', 'Training', 'Handlers', 'Loggers'])
34+
const tabs = ['Templates', 'Training', 'Handlers', 'Loggers']
3535
3636
// computed properties
3737
const currentTabComponent = computed(() => {
3838
return 'tab-' + currentTab.value.toLowerCase()
3939
})
4040
41-
return { currentTab, tabs, currentTabComponent, msg }
41+
const switchTab = (tab) => {
42+
if (store.config.template) {
43+
currentTab.value = tab
44+
}
45+
}
46+
const hasTemplate = computed(() => {
47+
return store.config.template
48+
})
49+
50+
return {
51+
currentTab,
52+
tabs,
53+
currentTabComponent,
54+
msg,
55+
switchTab,
56+
hasTemplate
57+
}
4258
}
4359
}
4460
</script>
@@ -69,6 +85,12 @@ export default {
6985
padding: 0.4rem 0.8rem;
7086
border-bottom: 3px solid transparent;
7187
}
88+
.disable {
89+
cursor: not-allowed;
90+
}
91+
.active {
92+
cursor: pointer;
93+
}
7294
.left-pane-tab:hover,
7395
.active {
7496
color: var(--c-brand-red);

src/components/PaneRight.vue

+17-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
{{ tab }}
1313
</div>
1414
</div>
15-
<div class="right-pane-contexts" v-if="store.code[currentTab]">
15+
<div class="right-pane-contexts" v-if="currentCode()">
1616
<KeepAlive>
1717
<CodeBlock :lang="getLang" :code="formattedCode()" />
1818
</KeepAlive>
@@ -59,7 +59,22 @@ export default {
5959
}
6060
const getLang = computed(() => currentTab.value.split('.')[1])
6161
const formattedCode = () => store.code[currentTab.value].trim()
62-
return { store, currentTab, tabs, getLang, getFileType, formattedCode }
62+
const currentCode = () => {
63+
const code = store.code[currentTab.value]
64+
if (code) {
65+
return code
66+
}
67+
currentTab.value = 'README.md'
68+
return store.code[currentTab.value]
69+
}
70+
return {
71+
currentCode,
72+
currentTab,
73+
tabs,
74+
getLang,
75+
getFileType,
76+
formattedCode
77+
}
6378
}
6479
}
6580
</script>

0 commit comments

Comments
 (0)