-
- {#each Object.keys(displayedData[0]) as header}
-
- {header}
- |
+ Context |
+ {#each Object.keys(transform(obj)) as key}
+
+ {key}
+ |
{/each}
-
+
- {#each Object.entries(displayedData) as [id, obj] }
- {#if id == activeRowIndex}
-
- {#each Object.values(obj) as val }
- {val} |
- {/each}
-
- {:else }
-
- {#each Object.values(obj) as val }
- {val} |
- {/each}
-
- {/if}
+ {#each stores as store}
+
+ {store.contextName} |
+
{/each}
diff --git a/frontend/src/Legend.svelte b/frontend/src/Legend.svelte
index 14f8cf9..6f64145 100644
--- a/frontend/src/Legend.svelte
+++ b/frontend/src/Legend.svelte
@@ -54,8 +54,10 @@
// update active contexts
if (toggle) {
+ console.log("INFO: adding context store:", name)
addContextStore.set(name)
} else {
+ console.log("INFO: removing context store: ", name)
removeContextStore.set(name)
}
}
diff --git a/frontend/src/activeContextStore.ts b/frontend/src/activeContextStore.ts
index e38c26e..8b96d61 100644
--- a/frontend/src/activeContextStore.ts
+++ b/frontend/src/activeContextStore.ts
@@ -19,9 +19,11 @@ addContextStore.subscribe((context) => {
activeContextStore.update((allContexts) => {
let resourceQuery = new GqlResourceQuery(context)
allContexts.set(context, resourceQuery)
+ // console.log(allContexts)
// clear addContextStore after activeContextStore is updated
- addContextStore.set(null)
+ // this calls addtional unnecessary invocations?
+ // addContextStore.set(null)
return allContexts
})
@@ -32,15 +34,17 @@ export async function execActiveContexts(activeContextMap, queryVars, execAll) {
if (execAll) {
activeContextMap.forEach((queryObject, contextName) => {
if (contextName != "" && contextName != null) {
- queryObject.executeQuery(queryVars)
- fetchContextData(queryObject)
+ queryObject.executeSubscription(queryVars)
+ // queryObject.fetchDataFromStore()
+ // fetchContextData(queryObject)
}
})
} else {
activeContextMap.forEach((queryObject, contextName) => {
if (!queryObject.queryIssued && contextName != "" && contextName != null) {
- queryObject.executeQuery(queryVars)
- fetchContextData(queryObject)
+ queryObject.executeSubscription(queryVars)
+ // queryObject.fetchDataFromStore()
+ // fetchContextData(queryObject)
}
})
}
@@ -50,33 +54,76 @@ export async function execActiveContexts(activeContextMap, queryVars, execAll) {
async function fetchContextData(queryObject) {
const delay = ms => new Promise(resolve => setTimeout(resolve, ms))
let retries = 0
- let queryStore = queryObject.queryStore
+ let store = queryObject.queryStore ?? queryObject.subscriptionStore
let fetching, error, data
- queryStore.subscribe(store => {
+ store.subscribe(store => {
fetching = store.fetching
error = store.error
data = store.data
})
+ // works with bugs
+ // store.subscribe(store => {
+ // if (store.error) {
+ // console.log("ERROR: GraphQL Query Store: ", queryObject.contextName)
+ // throw new Error(error)
+ // }
+ // else if (store.data) {
+ // // update tableDataStore with fetched data
+ // tableDataStore.update(m => {
+ // const resourceObject = queryObject.transform(store.data)
+ //
+ // // cluster context exists in map, append object to array
+ // if (m.has(queryObject.contextName)) {
+ // m.get(queryObject.contextName).set(resourceObject.uid, resourceObject)
+ // } else { // map entry dne
+ // m.set(queryObject.contextName, new Map())
+ // m.get(queryObject.contextName).set(resourceObject.uid, resourceObject)
+ // }
+ // queryObject.queryIssued = true
+ // return m
+ // })
+ // }
+ // })
while (retries < 40) {
- if (fetching) {
- console.log("INFO: GraphQL Query Store fetching: ", queryObject.contextName)
- } else if (error) {
+ // if (fetching) {
+ // console.log("INFO: GraphQL Query Store fetching: ", queryObject.contextName)
+ // } else
+ if (error) {
console.log("ERROR: GraphQL Query Store: ", queryObject.contextName)
throw new Error(error)
} else if (data) {
+ // update tableDataStore with fetched data
+ // tableDataStore.update(m => {
+ // m.set(queryObject.contextName, queryObject.transform(data))
+ // return m
+ // })
+ // queryObject.queryIssued = true
+ // return
+ console.log("Updating")
// update tableDataStore with fetched data
tableDataStore.update(m => {
- m.set(queryObject.contextName, queryObject.transform(data))
+ const resourceObject = queryObject.transform(data)
+ console.log(resourceObject)
+ // cluster context exists in map, append object to array
+ if (m.has(queryObject.contextName)) {
+ m.get(queryObject.contextName).set(resourceObject.uid, resourceObject)
+ } else { // map entry dne
+ m.set(queryObject.contextName, new Map())
+ m.get(queryObject.contextName).set(resourceObject.uid, resourceObject)
+ }
return m
})
+
queryObject.queryIssued = true
return
}
+
if (retries >= 39) {
console.log("INFO: GraphQL Query Store retries exhausted: ", queryObject.contextName)
return
}
+
retries++
await delay(250)
}
@@ -98,5 +145,22 @@ removeContextStore.subscribe((context) => {
return tableData
})
- removeContextStore.set(null)
-})
\ No newline at end of file
+ // removeContextStore.set(null)
+})
+
+// subscribe to active contexts updates
+// activeContextStore.subscribe( activeContexts => {
+//
+// // for each active context, update the table store
+// activeContexts.forEach( activeContext => {
+// const contextName = activeContext.contextName
+// activeContext.fetchDataFromStore()
+// // tableDataStore.update( m => {
+// // if (!m.has(contextName)) {
+// // m.set(contextName, new Map())
+// // }
+// // return m
+// // })
+// })
+//
+// })
\ No newline at end of file
diff --git a/frontend/src/gqlQuery.ts b/frontend/src/gqlQuery.ts
index 07bbedb..01a0d60 100644
--- a/frontend/src/gqlQuery.ts
+++ b/frontend/src/gqlQuery.ts
@@ -1,6 +1,14 @@
-import type {AnyVariables, Client, OperationResult, OperationResultStore, TypedDocumentNode} from "@urql/svelte";
+import {
+ type AnyVariables,
+ type Client,
+ type OperationResult,
+ type OperationResultStore,
+ subscriptionStore,
+ type TypedDocumentNode
+} from "@urql/svelte";
import {getContextClient, gql, queryStore} from "@urql/svelte";
import type {tableObject} from "./jsonTable";
+import {resourceClass} from "./resourceQuery";
// BaseQuery implements BaseQueryInterface
export class BaseQuery {
@@ -9,9 +17,12 @@ export class BaseQuery {
readonly bodyQueryString: string
readonly footerQueryString: string
readonly contextName: string
+ data: any
+ transformedData: any
client: Client
- queryIssued: boolean = false
+ querySuccess: boolean = false
queryStore: OperationResultStore
+ subscriptionStore: OperationResultStore
enableTemplating: boolean
constructor(contextName: string, debug?: boolean) {
@@ -48,9 +59,48 @@ export class BaseQuery {
query: this.enableTemplating ? this.templateContext() : this.query,
variables
})
+ this.data = this.queryStore.subscribe( store => store.data)
+ this.transform()
}
- transform(resultObj: OperationResult): tableObject {
- return {}
+ executeSubscription(variables?: any) {
+ if (!this.client){
+ // Note: getContextClient() must be called from within a svelte component!
+ this.client = getContextClient()
+ }
+ this.subscriptionStore = subscriptionStore({
+ client: this.client,
+ query: this.enableTemplating ? this.templateContext() : this.query,
+ variables
+ })
+ this.data = this.subscriptionStore.subscribe( store => store.data)
+ this.transform()
+
+ }
+
+ transform() {
+ let obj
+ // TODO is this necessary?
+ Object.entries(this.data).map(([i, v]) => { // loop over context objects
+ const r = v as resourceClass
+ // TODO https://basarat.gitbook.io/typescript/future-javascript/destructuring
+ obj = {
+ "cluster": i,
+ "uid": r.metadata.uid,
+ "eventType": r.eventType,
+ "name": r.metadata.name,
+ "namespace": r.metadata.namespace,
+ "kind": r.kind,
+ "apiVersion": r.apiVersion,
+ "labels": r.metadata.labels,
+ "annotations": r.metadata.annotations
+ }
+ })
+
+ this.transformedData = obj
+ }
+
+ async fetchDataFromStore(){
+ this.data = {}
}
}
\ No newline at end of file
diff --git a/frontend/src/jsonTable.ts b/frontend/src/jsonTable.ts
index cd9ae00..c89a9e1 100644
--- a/frontend/src/jsonTable.ts
+++ b/frontend/src/jsonTable.ts
@@ -7,7 +7,7 @@ const filterOptions = {
threshold: 0.40 // 0 = perfect match, 1 = indiscriminate
}
-export const tableDataStore: Writable