Skip to content

Commit

Permalink
Implement query editor entity inspector
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed May 23, 2024
1 parent 3573673 commit 1bd6f0f
Show file tree
Hide file tree
Showing 19 changed files with 702 additions and 39 deletions.
6 changes: 3 additions & 3 deletions etc/v4/flecs.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,14 +273,14 @@ const flecs = {

if (this.request.status < 200 || this.request.status >= 300) {
// Error status
if (this.err) {
if (this.err && !this.aborted) {
this.err(this.request.responseText);
}
} else {
requestOk = true;

// Request OK
if (this.recv) {
if (this.recv && !this.aborted) {
this.recv(this.request.responseText, this.url);
}
}
Expand Down Expand Up @@ -461,7 +461,7 @@ const flecs = {
if (params) {
for (var k in params) {
// Ignore client-side only parameters
if (k === "raw" || k === "full_paths" || k === "poll_interval" || k === "host") {
if (k === "poll_interval" || k === "host") {
continue;
}
if (params[k] !== undefined) {
Expand Down
3 changes: 2 additions & 1 deletion etc/v4/query_editor/css/colors.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
--dark-blue: #00346E;
--less-dark-blue: #094a94;
--green: #42b983;
--light-green: #A2D8B4;
--blue: rgb(103, 154, 209);
--purple: rgb(188, 137, 189);
--yellow: #b9a542;
Expand All @@ -41,7 +42,7 @@
--bg-error: var(--red);
--bg-ok: var(--green);
--border: rgb(57, 57, 62);
--panel-color: #24292e;
--panel-color: hsl(210, 12%, 16%);
--text-color: rgb(175, 175, 175);
--highlight-bg: var(--blue);
--highlight-text: white;
Expand Down
25 changes: 17 additions & 8 deletions etc/v4/query_editor/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,17 @@ let components = [
// Entities page
loadModule('js/components/pages/entities/page.vue', options),
loadModule('js/components/pages/entities/pane-tree.vue', options),
loadModule('js/components/pages/entities/pane-inspector.vue', options),
loadModule('js/components/pages/entities/entity-tree.vue', options),
loadModule('js/components/pages/entities/entity-subtree.vue', options),
loadModule('js/components/pages/entities/entity-tree-item.vue', options),
loadModule('js/components/pages/entities/entity-tree-icon.vue', options),
loadModule('js/components/pages/entities/entity-inspector.vue', options),
loadModule('js/components/pages/entities/entity-inspector-module.vue', options),
loadModule('js/components/pages/entities/entity-inspector-component.vue', options),
loadModule('js/components/pages/entities/entity-inspector-value.vue', options),
loadModule('js/components/pages/entities/entity-inspector-kv.vue', options),
loadModule('js/components/pages/entities/entity-inspector-field.vue', options),

// Queries page
loadModule('js/components/pages/queries/page.vue', options),
Expand Down Expand Up @@ -228,13 +235,9 @@ Promise.all(components).then((values) => {
this.app_state.requests.error = this.conn.requests.error;
this.app_state.bytes.received = this.conn.bytes.received;

for (let i = 0; i < msg.ids.length; i ++) {
let el = msg.ids[i];
if (el == "flecs.monitor.WorldSummary") {
this.app_state.world_info = msg.values[i];
this.app_state.build_info = msg.values[i].build_info;
return;
}
if (msg.components && msg.components.WorldSummary) {
this.app_state.world_info = msg.components.WorldSummary;
this.app_state.build_info = msg.components.WorldSummary.build_info;
}
}.bind(this)
});
Expand Down Expand Up @@ -266,7 +269,7 @@ Promise.all(components).then((values) => {
data() {
return {
app_state: {
host: undefined,
// Populated by code
app_name: "Flecs app",
status: undefined,
heartbeat: undefined,
Expand All @@ -282,11 +285,17 @@ Promise.all(components).then((values) => {
world_info: undefined,
build_info: undefined,
command_counts: new Array(120).fill(0),

// Populated by user
host: undefined,
query: {
expr: QueryParam,
name: undefined,
use_name: false
},
entity: {
path: undefined
}
},
page: "queries",
conn: undefined,
Expand Down
1 change: 1 addition & 0 deletions etc/v4/query_editor/js/components/icon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const style = computed(() => {
width: ${props.size}px;
height: ${props.size}px;
transform: rotate(${props.rotate}deg);
transition: transform 0.1s ease-out;
vertical-align: middle;
height: 100%;`;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<template>
<div class="component">
<div class="component-header noselect" @click="toggle">
<template v-if="value">
<div class="chevron-icon">
<icon src="chevron-right"
:opacity="0.5"
:size="16"
:rotate="chevronRotation">
</icon>
</div>
</template>
<div class="component-icon">
<icon :src="icon_src" :size="16" :opacity="0.5"></icon>
</div>
<div class="component-name">
{{ name }}
<template v-if="singleTarget">
<icon src="arrow-right"
:opacity="0.5"
:size="16">
</icon>&nbsp;{{ shortenEntity(targets) }}
</template>
</div>
</div>
<template v-if="expand && value">
<div class="component-value">
<entity-inspector-value
:value="value"
:type="type">
</entity-inspector-value>
</div>
</template>
</div>
</template>

<script>
export default { name: "entity-inspector-component" }
</script>

<script setup>
import { defineProps, ref, computed } from 'vue';
const props = defineProps({
name: {type: String, required: true},
icon_src: {type: String, required: true},
value: {type: Object, required: false},
type: {type: Object, required: false},
targets: {required: false},
});
const expand = ref(true);
const chevronRotation = computed(() => {
if (expand.value) {
return 90;
} else {
return 0;
}
})
function toggle() {
expand.value = !expand.value;
}
const singleTarget = computed(() => {
return props.targets && !Array.isArray(props.targets);
})
function shortenEntity(entity) {
return entity.split(".").pop();
}
</script>

<style scoped>
div.component {
margin-bottom: 8px;
}
div.component-header {
display: grid;
grid-template-columns: 20px 20px 1fr;
padding: 4px;
padding-left: 8px;
cursor: pointer;
border-radius: var(--border-radius-medium);
background-color: rgba(0,0,0,0);
color: var(--primary-text);
transition: background-color 0.1s ease-out;
}
div.component-header:hover {
background-color: var(--bg-content-hover);
}
div.chevron-icon {
grid-column: 1;
}
div.component-icon {
grid-column: 2;
}
div.component-name {
grid-column: 3;
padding-left: 2px;
}
div.component-value {
padding-left: 52px;
}
</style>
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<template>
<div :class="css">
{{ value }}
</div>
</template>

<script>
export default { name: "entity-inspector-field" }
</script>

<script setup>
import { defineProps, ref, computed } from 'vue';
const props = defineProps({
value: {required: true},
type: {type: Object, required: true}
});
const css = computed(() => {
let classes = ["value"];
classes.push(`value-${props.type[0]}`);
return classes;
});
</script>

<style scoped>
div.value {
padding: 4px;
padding-left: 8px;
background-color: var(--bg-content);
border-radius: var(--border-radius-medium);
color: var(--secondary-text);
}
div.value-bool {
color: #4981B5;
}
div.value-int {
color: var(--light-green);
}
div.value-float {
color: var(--light-green);
}
div.value-text {
color: #B5894B;
}
div.value-enum, div.value-bitmask {
color: #7D67B5;
}
</style>
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<template>
<div class="key">
{{ keyname }}
</div>
<div class="value">
<entity-inspector-field
:value="value"
:type="type">
</entity-inspector-field>
</div>
<div class="edit">
<icon src="edit" :opacity="0.7"></icon>
</div>
</template>

<script>
export default { name: "entity-inspector-kv" }
</script>

<script setup>
import { defineProps, ref, computed } from 'vue';
const props = defineProps({
keyname: {type: String, required: true},
value: {required: true},
type: {type: Object, required: true}
});
</script>

<style scoped>
div.key {
grid-column: 1;
color: var(--secondary-text);
text-align: right;
padding: 4px;
padding-right: 8px;
}
div.value {
grid-column: 2;
margin-bottom: 2px;
}
div.edit {
grid-column: 3;
padding-left: 4px;
}
</style>
Loading

0 comments on commit 1bd6f0f

Please sign in to comment.