Skip to content

Commit

Permalink
Implement lock-on feature
Browse files Browse the repository at this point in the history
  • Loading branch information
dejan committed Apr 27, 2024
1 parent 339db6e commit 0a7a42f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
17 changes: 11 additions & 6 deletions extension/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@
import Requests from './components/Requests.vue'
import { fakeEvents } from './fixtures/fakeEvents'
import { useEventsStore } from './stores/events';
import { useSettingsStore } from './stores/settings';
import { onMounted, onUnmounted, nextTick } from 'vue'
const store = useEventsStore()
const eventsStore = useEventsStore();
const settingsStore = useSettingsStore();
onUnmounted(() => store.clear())
onUnmounted(() => eventsStore.clear());
onMounted(() => {
if (typeof chrome.devtools == 'undefined') {
console.log("STANDALONE mode... mocking requests")
fakeEvents.forEach((data) => store.pushEvents(data.request_id, data.events));
console.log("STANDALONE mode... mocking requests");
fakeEvents.forEach((data) => eventsStore.pushEvents(data.request_id, data.events));
} else {
chrome.devtools.network.onRequestFinished.addListener(function(request) {
var headers = request.response.headers;
Expand All @@ -28,9 +30,12 @@ onMounted(() => {
url.search = "";
console.log(url)
chrome.runtime.sendMessage({action:'getJSON',url:url}, (data) => {
store.pushEvents(requestId, data);
const autoReselect = !settingsStore.lockOn;
eventsStore.pushEvents(requestId, data, autoReselect);
nextTick(() => {
document.querySelectorAll('[data-pc-section="wrapper"]')[0].scrollTop = 1000000
if (autoReselect) {
document.querySelectorAll('[data-pc-section="wrapper"]')[0].scrollTop = 1000000;
}
})
});
};
Expand Down
4 changes: 4 additions & 0 deletions extension/src/components/Toolbar.vue
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
<template>
<span class="fixed right-0 z-10 cursor-pointer space-x-2 text-base p-[6px]">
<Button size="small" severity="secondary" text outlined rounded class="text-xs" icon="pi pi-ban" label="Clear" @click="eventsStore.clear()"></Button>
<InputSwitch v-model="settingsStore.lockOn" /><span class="text-xs">Lock-on</span>
<Button size="small" severity="secondary" text outlined rounded class="text-xs" icon="pi pi-sliders-h" label="Settings" @click="settingsVisible=true"></Button>
</span>
<SettingsDialog v-model:visible="settingsVisible" @save="settingsVisible=false"/>
</template>

<script setup>
import Button from 'primevue/button';
import InputSwitch from 'primevue/inputswitch';
import SettingsDialog from './SettingsDialog.vue';
import { useEventsStore } from '../stores/events';
import { useSettingsStore } from '../stores/settings';
import { ref } from 'vue';
const settingsVisible = ref(false);
const eventsStore = useEventsStore();
const settingsStore = useSettingsStore();
</script>
7 changes: 5 additions & 2 deletions extension/src/stores/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const useEventsStore = defineStore('events', () => {
const selectedCacheCalls = computed(() => cacheCalls.value.get(selectedRequest.value.id));
const selectedParams = computed(() => selectedRequest.value.params);

function pushEvents(requestId, newEvents) {
function pushEvents(requestId, newEvents, autoReselect = true) {
const actionEvent = newEvents.find((event) => event.name == "process_action.action_controller")
const action = {
id: requestId,
Expand All @@ -44,7 +44,10 @@ export const useEventsStore = defineStore('events', () => {
params: Object.entries(actionEvent.payload.params).map(([name, value]) => ({ name, value }) )
}
actions.value.set(requestId, action);
selectedRequest.value = action;

if (actions.value.size == 1 || autoReselect) {
selectedRequest.value = action;
}

activeRecordQueries.value.set(requestId, newEvents.flatMap((event) => {
if (event.name == "sql.active_record" && event.payload.name != "SCHEMA" && event.payload.name != "EXPLAIN") {
Expand Down
8 changes: 7 additions & 1 deletion extension/src/stores/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const defaultEditor = editors[0].id;
export const useSettingsStore = defineStore('settings', () => {
const filepathLinkBehaviour = ref(localStorage.getItem('railspanel.filepathLinkBehaviour') || 'copy');
const editor = ref(editors.find((e) => e.id == (localStorage.getItem('railspanel.editor') || defaultEditor)) || defaultEditor);
const lockOn = ref(localStorage.getItem('railspanel.lockOn') === "true");

watch(editor, (newVal, oldVal) => {
localStorage.setItem('railspanel.editor', newVal.id);
Expand All @@ -16,9 +17,14 @@ export const useSettingsStore = defineStore('settings', () => {
localStorage.setItem('railspanel.filepathLinkBehaviour', newVal);
});

watch(lockOn, (newVal, oldVal) => {
localStorage.setItem('railspanel.lockOn', newVal);
});

return {
editors,
editor,
filepathLinkBehaviour
filepathLinkBehaviour,
lockOn
}
})

0 comments on commit 0a7a42f

Please sign in to comment.