Skip to content

Commit 3b702ba

Browse files
author
psubram3
committed
WIP: temp store fix
1 parent 7ca57f9 commit 3b702ba

File tree

5 files changed

+51
-20
lines changed

5 files changed

+51
-20
lines changed

src/lib/server/oidc.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,9 @@ const mutation = `mutation InsertUser($input: users_insert_input!) {
245245
async function upsertUser(decodedAccessToken: HasuraToken, accessToken: string): Promise<void> {
246246
const username = decodedAccessToken['https://hasura.io/jwt/claims']['x-hasura-user-id'];
247247
const defaultRole = decodedAccessToken['https://hasura.io/jwt/claims']['x-hasura-default-role'];
248+
// defaultRole = defaultRole.split('-')[1];
248249
const allowedRoles = decodedAccessToken['https://hasura.io/jwt/claims']['x-hasura-allowed-roles'];
250+
// allowedRoles = allowedRoles.map(v => v.split('-')[1]);
249251
const input = { default_role: defaultRole, username };
250252
const user: User = {
251253
activeRole: defaultRole,

src/routes/plans/[id]/+page.svelte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@
198198
let schedulingStatusText: string = '';
199199
let lastSimulationDatasetId: number | null = null;
200200
201+
$: console.log(`Subscriber - Plan Id: ${$planId}`); //, ${JSON.stringify($initialPlan)}, ${JSON.stringify($plan)}`);
202+
201203
$: ({ invalidActivityCount, ...activityErrorCounts } = $activityErrorRollups.reduce(
202204
(prevCounts, activityErrorRollup) => {
203205
const extra = prevCounts.extra + activityErrorRollup.errorCounts.extra;

src/routes/plans/[id]/+page.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ export const load: PageLoad = async ({ parent, params, url }) => {
1818
user = (await parent()).user;
1919
}
2020

21+
console.log('BROWSER LOADING +page.ts', params);
22+
2123
const { id } = params;
2224
const planId = parseFloat(id);
2325

src/stores/plan.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { derived, writable, type Readable, type Writable } from 'svelte/store';
1+
import { derived, get, writable, type Readable, type Writable } from 'svelte/store';
22
import type { ActivityType } from '../types/activity';
33
import type { Plan, PlanMergeRequest, PlanMergeRequestSchema, PlanMetadata } from '../types/plan';
44
import type { PlanDataset } from '../types/simulation';
@@ -36,7 +36,10 @@ export const viewTimeRange: Writable<TimeRange> = writable({ end: 0, start: 0 })
3636
/* "plan" store dependencies */
3737
export const initialPlan: Writable<Plan | null> = writable(null);
3838

39-
export const planId: Readable<number> = derived(initialPlan, $plan => ($plan ? $plan.id : -1));
39+
export const planId: Readable<number> = derived(initialPlan, $plan => {
40+
console.log('PLAN ID IS GETTING A VALUE: ', $plan ? $plan.id : -1);
41+
return $plan ? $plan.id : -1;
42+
});
4043

4144
export const planMetadata = gqlSubscribable<PlanMetadata | null>(gql.SUB_PLAN_METADATA, { planId }, null);
4245

@@ -102,12 +105,14 @@ export const planMergeRequestsOutgoing = gqlSubscribable<PlanMergeRequest[]>(
102105
planMergeRequests.map(planMergeRequest => ({ ...planMergeRequest, pending: false, type: 'outgoing' })),
103106
);
104107

105-
export const planRevision = gqlSubscribable<number>(
106-
gql.SUB_PLAN_REVISION,
107-
{ planId },
108-
-1,
109-
({ revision }: Pick<Plan, 'revision'>) => revision,
110-
);
108+
export const planRevision = gqlSubscribable<number>(gql.SUB_PLAN_REVISION, { planId }, -1, revisionObject => {
109+
console.log('????? plan revision Object', JSON.stringify(revisionObject), get(planId));
110+
console.log(`revision's plan??? ${JSON.stringify(get(initialPlan))}`);
111+
if (revisionObject && revisionObject['plan'] && revisionObject['plan']['revision']) {
112+
return revisionObject['plan']['revision'];
113+
}
114+
return -1;
115+
});
111116

112117
/* Helper Functions. */
113118

src/stores/subscribable.ts

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ export function gqlSubscribable<T>(
105105
const [key] = Object.keys(data);
106106
const { [key]: newValue } = data;
107107
if (!isEqual(value, newValue)) {
108+
if (query.includes('SubPlanRevision')) {
109+
console.log(
110+
`Plan Revision value stuff: ${JSON.stringify(value)} ${JSON.stringify(newValue)} ${JSON.stringify(data)}`,
111+
);
112+
}
108113
value = transformer(newValue);
109114
subscribers.forEach(({ next }) => {
110115
next(value as T);
@@ -134,6 +139,7 @@ export function gqlSubscribable<T>(
134139
}
135140

136141
function setVariables(newVariables: QueryVariables): void {
142+
console.log('????');
137143
newVariables = { ...variables, ...newVariables };
138144

139145
if (!isEqual(variables, newVariables)) {
@@ -148,6 +154,9 @@ export function gqlSubscribable<T>(
148154
* These variables could be stores themselves or plain values.
149155
*/
150156
function subscribeToVariables(initialVariables: QueryVariables | null): void {
157+
if (query.includes('SubPlanRevision')) {
158+
console.log(`PlanRevision SubscribeToVariables: ${JSON.stringify(initialVariables)}`);
159+
}
151160
variableUnsubscribers.forEach(variableUnsubscribe => variableUnsubscribe());
152161
variableUnsubscribers = [];
153162

@@ -159,7 +168,11 @@ export function gqlSubscribable<T>(
159168
// and resubscribe to the main query with those new variables
160169
const store = variable as Readable<any>;
161170
const unsubscriber = store.subscribe(storeValue => {
162-
variables = { ...variables, [name]: storeValue };
171+
if (query.includes('SubPlanRevision') || query.includes('PlanMergeRequestsOutgoing')) {
172+
const shortQuery = query.includes('SubPlanRevision') ? 'SubPlanRevision' : 'PlanMergeRequestsOutgoing';
173+
console.log(`SUBSCRIBER: ${name}, ${storeValue} -> ${shortQuery}`);
174+
}
175+
// variables = { ...variables, [name]: storeValue };
163176
resubscribe();
164177
});
165178
variableUnsubscribers.push(unsubscriber);
@@ -169,17 +182,24 @@ export function gqlSubscribable<T>(
169182
}
170183

171184
function subscribe(next: Subscriber<T>): Unsubscriber {
172-
// If we are in the browser and do not yet have a web socket client
173-
// we will create one and subscribe to variables
174-
subscribeToVariables(variables); // should not be harmful if this runs every time subscribe is called
175-
176-
// Subscribe within the WS to the GQL query
177-
// Note that subscribeToVariables may immediately result in a resubscription if
178-
// any of the variables are stores since the stores will call next(value) on
179-
// initial subscription. This call below covers the case where no stores are passed
180-
// in as variables. If resubscribe is called by subscribeToVariables then the debounce
181-
// should take care of the duplication.
182-
debouncedClientSubscribe();
185+
if (browser) {
186+
if (query.includes('SubPlanRevision') || query.includes('PlanMergeRequestsOutgoing')) {
187+
const shortQuery = query.includes('SubPlanRevision') ? 'SubPlanRevision' : 'PlanMergeRequestsOutgoing';
188+
console.log('RUNNING -> ', shortQuery);
189+
}
190+
191+
// If we are in the browser and do not yet have a web socket client
192+
// we will create one and subscribe to variables
193+
subscribeToVariables(variables); // should not be harmful if this runs every time subscribe is called
194+
195+
// Subscribe within the WS to the GQL query
196+
// Note that subscribeToVariables may immediately result in a resubscription if
197+
// any of the variables are stores since the stores will call next(value) on
198+
// initial subscription. This call below covers the case where no stores are passed
199+
// in as variables. If resubscribe is called by subscribeToVariables then the debounce
200+
// should take care of the duplication.
201+
debouncedClientSubscribe();
202+
}
183203

184204
const subscriber: Subscription<T> = { next };
185205
subscribers.add(subscriber);

0 commit comments

Comments
 (0)