Skip to content

Commit

Permalink
Merge pull request #223 from Kanaries/feat-causal-auto_vis_tab-ks-1130
Browse files Browse the repository at this point in the history
[Refactor] causal store
  • Loading branch information
ObservedObserver authored Dec 2, 2022
2 parents 1614619 + 9b4bdb0 commit b2aebd0
Show file tree
Hide file tree
Showing 86 changed files with 3,896 additions and 4,345 deletions.
3 changes: 0 additions & 3 deletions packages/rath-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
"airtable": "^0.11.4",
"ali-react-table": "^2.6.1",
"codemirror": "^6.0.1",
"d3-dag": "^0.11.5",
"d3-shape": "^3.1.0",
"dayjs": "^1.11.6",
"immer": "^9.0.6",
"localforage": "^1.10.0",
Expand Down Expand Up @@ -55,7 +53,6 @@
"@testing-library/react": "^11.2.3",
"@testing-library/user-event": "^12.6.0",
"@types/crypto-js": "^4.1.0",
"@types/d3-shape": "^3.1.0",
"@types/jest": "^26.0.20",
"@types/node": "^12.19.12",
"@types/react": "^17.0.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/rath-client/src/components/fieldPlaceholder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const PillPlaceholder = styled.div`
`

interface FieldPlaceholderProps {
fields: IFieldMeta[];
fields: readonly IFieldMeta[];
onAdd: (fid: string) => void;
}
const FieldPlaceholder: React.FC<FieldPlaceholderProps> = props => {
Expand Down
2 changes: 1 addition & 1 deletion packages/rath-client/src/components/filterCreationPill.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const Cont = styled.div`
min-width: 16em;
`;
interface FilterCreationPillProps {
fields: IFieldMeta[];
fields: readonly IFieldMeta[];
onFilterSubmit: (field: IFieldMeta, filter: IFilter) => void;
onRenderPill?: (text: string, handleClick: () => void) => void;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/rath-client/src/components/react-vega.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { EDITOR_URL } from '../constants';
import { getVegaTimeFormatRules } from '../utils';

interface ReactVegaProps {
dataSource: any[];
dataSource: readonly any[];
spec: any;
actions?: boolean;
signalHandler?: {
Expand Down
2 changes: 1 addition & 1 deletion packages/rath-client/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const STORAGES = {
DATASOURCE: 'datasource',
WORKSPACE: 'workspace',
META: 'meta',
MODEL: 'model',
CAUSAL_MODEL: 'causal',
STATE: 'state',
ITERATOR: 'iterator',
CONFIG: 'config',
Expand Down
69 changes: 69 additions & 0 deletions packages/rath-client/src/hooks/use-bounding-client-rect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { RefObject, useEffect, useRef, useState } from "react";


export type BoundingClientRectAttributes = {
/** @default true */
-readonly [key in keyof Omit<DOMRect, 'toJSON'>]?: boolean;
};

/**
* Updates on certain keys of DOMRect changes, detected using `ResizeObserver`.
* DISCUSS: use `IntersectionObserver` with ref elements to implements position changes.
*/
const useBoundingClientRect = <
T extends BoundingClientRectAttributes = { -readonly [key in keyof Omit<DOMRect, 'toJSON'>]: true },
M extends { -readonly [key in keyof Omit<DOMRect, 'toJSON'>]: T[key] extends true ? key : never } = { -readonly [key in keyof Omit<DOMRect, 'toJSON'>]: T[key] extends true ? key : never },
E extends Exclude<M[keyof M], never> & keyof DOMRect = Exclude<M[keyof M], never> & keyof DOMRect,
R extends { readonly [key in E]?: DOMRect[key] } = { readonly [key in E]?: DOMRect[key] },
>(
ref: RefObject<HTMLElement>,
/** @default {height:true,width:true,x:true,y:true,bottom:true,left:true,right:true,top:true} */
attributes: T = {
height: true,
width: true,
x: true,
y: true,
bottom: true,
left: true,
right: true,
top: true,
} as T,
): R => {
const compareKeysRef = useRef<(keyof BoundingClientRectAttributes)[]>([]);
compareKeysRef.current = (["height", "width", "x", "y", "bottom", "left", "right", "top"] as const).filter(key => {
return attributes[key] === true;
});

const [box, setBox] = useState<R>({} as R);

const prevRectRef = useRef<DOMRect>();
const shouldReportRef = useRef<(next: DOMRect) => boolean>(() => true);
shouldReportRef.current = (next: DOMRect): boolean => {
return !prevRectRef.current || compareKeysRef.current.some(k => next[k] !== prevRectRef.current![k]);
};

useEffect(() => {
const { current: element } = ref;

if (element) {
const cb = () => {
const rect = element.getBoundingClientRect();
if (shouldReportRef.current(rect)) {
setBox(Object.fromEntries(compareKeysRef.current.map(key => [key, rect[key]])) as R);
}
prevRectRef.current = rect;
};
const ro = new ResizeObserver(cb);
ro.observe(element);
cb();
return () => {
ro.disconnect();
};
}
}, [ref]);

return box;
};


export default useBoundingClientRect;
6 changes: 6 additions & 0 deletions packages/rath-client/src/pages/causal/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export type IAlgoSchema = {
};

/**
* @deprecated
* a number match { -1 | [0, 1] }
*
* -1 for not connected: src ---x--> tar
Expand All @@ -36,6 +37,9 @@ export type IAlgoSchema = {
*/
export type BgConfidenceLevel = number;

/**
* @deprecated
*/
export type BgKnowledge = {
src: string;
tar: string;
Expand All @@ -56,8 +60,10 @@ export interface PagLink {
tar_type: PAG_NODE;
}

/** @deprecated */
export type BgKnowledgePagLink = PagLink;

/** @deprecated */
export type ModifiableBgKnowledge = {
src: BgKnowledge['src'];
tar: BgKnowledge['tar'];
Expand Down
Loading

1 comment on commit b2aebd0

@vercel
Copy link

@vercel vercel bot commented on b2aebd0 Dec 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.