Skip to content

Commit 7b7117b

Browse files
authored
Migrate the offline alert bar in Settings from Vuetify to KDS
1 parent 3330198 commit 7b7117b

File tree

3 files changed

+133
-6
lines changed

3 files changed

+133
-6
lines changed

contentcuration/contentcuration/frontend/settings/pages/SettingsIndex.vue

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@
1717
</VTab>
1818
</template>
1919
</AppBar>
20-
<OfflineText
21-
toolbar
22-
:offset="112"
23-
/>
20+
<StudioOfflineAlert :offset="104" />
2421
<VContent>
2522
<VContainer
2623
fluid
@@ -49,12 +46,12 @@
4946
import GlobalSnackbar from 'shared/views/GlobalSnackbar';
5047
import AppBar from 'shared/views/AppBar';
5148
import { routerMixin } from 'shared/mixins';
52-
import OfflineText from 'shared/views/OfflineText';
49+
import StudioOfflineAlert from 'shared/views/StudioOfflineAlert';
5350
import PolicyModals from 'shared/views/policies/PolicyModals';
5451
5552
export default {
5653
name: 'SettingsIndex',
57-
components: { GlobalSnackbar, AppBar, OfflineText, PolicyModals },
54+
components: { GlobalSnackbar, AppBar, StudioOfflineAlert, PolicyModals },
5855
mixins: [routerMixin],
5956
computed: {
6057
...mapState({
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<template>
2+
3+
<KTransition kind="component-vertical-slide-out-in">
4+
<div
5+
v-if="offline && !libraryMode"
6+
class="studio-offline-alert"
7+
:style="computedstyle"
8+
data-test="studio-offline-alert"
9+
>
10+
<KIcon
11+
icon="disconnected"
12+
class="kicon-style"
13+
/>
14+
<span>{{ $tr('offlineText') }}</span>
15+
</div>
16+
</KTransition>
17+
18+
</template>
19+
20+
21+
<script>
22+
23+
import { mapState } from 'vuex';
24+
import useKLiveRegion from 'kolibri-design-system/lib/composables/useKLiveRegion';
25+
26+
export default {
27+
name: 'StudioOfflineAlert',
28+
setup() {
29+
const { sendPoliteMessage } = useKLiveRegion();
30+
return { sendPoliteMessage };
31+
},
32+
props: {
33+
offset: {
34+
type: Number,
35+
default: 0,
36+
},
37+
},
38+
computed: {
39+
...mapState({
40+
offline: state => !state.connection.online,
41+
}),
42+
libraryMode() {
43+
return window.libraryMode;
44+
},
45+
computedstyle() {
46+
return {
47+
position: 'fixed',
48+
top: `${this.offset}px`,
49+
left: '0',
50+
right: '0',
51+
backgroundColor: this.$themeTokens.surface,
52+
zIndex: 16,
53+
};
54+
},
55+
},
56+
watch: {
57+
offline(newVal) {
58+
if (newVal) {
59+
this.sendPoliteMessage(this.$tr('offlineText'));
60+
} else {
61+
this.sendPoliteMessage(this.$tr('onlineText'));
62+
}
63+
},
64+
},
65+
$trs: {
66+
offlineText:
67+
'You seem to be offline. Your changes will be saved once your connection is back.',
68+
onlineText: 'You are back online.',
69+
},
70+
};
71+
72+
</script>
73+
74+
75+
<style scoped>
76+
77+
.studio-offline-alert {
78+
display: flex;
79+
width: 100%;
80+
padding: 12px;
81+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
82+
}
83+
84+
.kicon-style {
85+
flex-shrink: 0;
86+
margin-right: 14px;
87+
margin-left: 10px;
88+
}
89+
90+
</style>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { mount } from '@vue/test-utils';
2+
import StudioOfflineAlert from '../StudioOfflineAlert.vue';
3+
import storeFactory from 'shared/vuex/baseStore';
4+
5+
function makeWrapper() {
6+
const store = storeFactory();
7+
return {
8+
wrapper: mount(StudioOfflineAlert, {
9+
store,
10+
}),
11+
store,
12+
};
13+
}
14+
15+
describe('StudioOfflineAlert', () => {
16+
let wrapper, store;
17+
18+
beforeEach(() => {
19+
const setup = makeWrapper();
20+
wrapper = setup.wrapper;
21+
store = setup.store;
22+
});
23+
24+
it('displays alert component when offline', async () => {
25+
store.state.connection.online = false;
26+
await wrapper.vm.$nextTick();
27+
28+
expect(wrapper.find('[data-test="studio-offline-alert"]').exists()).toBe(true);
29+
expect(wrapper.text()).toMatch(
30+
'You seem to be offline. Your changes will be saved once your connection is back',
31+
);
32+
});
33+
34+
it('hides alert component when online', async () => {
35+
store.state.connection.online = true;
36+
await wrapper.vm.$nextTick();
37+
38+
expect(wrapper.find('[data-test="studio-offline-alert"]').exists()).toBe(false);
39+
});
40+
});

0 commit comments

Comments
 (0)