Skip to content

Commit

Permalink
Fix styling issues, lint issues, + remove unnecessary components
Browse files Browse the repository at this point in the history
  • Loading branch information
lublagg committed Sep 17, 2024
1 parent fca3b76 commit bb94562
Show file tree
Hide file tree
Showing 14 changed files with 63 additions and 179 deletions.
33 changes: 4 additions & 29 deletions src/components/CodapContext.tsx
Original file line number Diff line number Diff line change
@@ -1,48 +1,23 @@
import React, { createContext, ReactNode, useContext, useEffect } from "react";
import { ICollection, ICollections, IDataSet } from "../types";
import { InteractiveState, useCodapState } from "../hooks/useCodapState";

export type CodapState = {
init: () => Promise<void>,
handleSelectSelf: () => Promise<void>,
dataSets: IDataSet[],
selectedDataSet: any,
collections: ICollections,
handleSetCollections: (collections: ICollections) => void,
handleSelectDataSet: (name: string) => void,
getCollectionNameFromId: (id: number) => string | undefined,
handleUpdateInteractiveState: (update: Partial<InteractiveState>) => void,
interactiveState: InteractiveState,
cases: any[],
connected: boolean,
handleUpdateAttributePosition: (coll: ICollection, attrName: string, position: number) => Promise<void>,
handleAddCollection: (newCollectionName: string) => Promise<void>,
handleSortAttribute: (context: string, attrId: number, isDescending: boolean) => Promise<void>,
handleAddAttribute: (collection: ICollection, attrName: string) => Promise<void>,
updateTitle: (title: string) => Promise<void>,
selectCODAPCases: (caseIds: number[]) => Promise<void>,
listenForSelectionChanges: (callback: (notification: any) => void) => void,
handleCreateCollectionFromAttribute: (collection: ICollection, attr: any, parent: number|string) => Promise<void>,
handleUpdateCollections: () => Promise<void>
};
import { CodapState } from "../types";
import { useCodapState } from "../hooks/useCodapState";

const CodapContext = createContext({} as CodapState);


export const useCodapContext = () => {
return useContext(CodapContext);
};

export const CodapProvider = ({ children }: { children: ReactNode }) => {
const codapState = useCodapState(); // Now useCodapState is called here
const codapState = useCodapState();

useEffect(() => {
codapState.init();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

if (!codapState.connected) {
return <div>Loading...</div>; // Handle loading state in the provider itself
return <div>Loading...</div>;
}

return (
Expand Down
37 changes: 0 additions & 37 deletions src/components/FocusContext.tsx

This file was deleted.

4 changes: 2 additions & 2 deletions src/components/app.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { useCallback, useEffect, useState } from "react";
import { InteractiveState } from "../hooks/useCodapState";
import { useCodapContext } from "./CodapContext";
import { InteractiveState } from "../types";
import { NestedTable } from "./nested-table";
import { Hierarchy } from "./hierarchy-view/hierarchy";
import { CardView } from "./card-view/card-view";
import { useCodapContext } from "./CodapContext";

import css from "./app.scss";

Expand Down
2 changes: 1 addition & 1 deletion src/components/card-view/card-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface ICardViewProps {

export const CardView = (props: ICardViewProps) => {
const { onSelectDataSet } = props;
const { dataSets, selectedDataSet, collections, selectCODAPCases, listenForSelectionChanges,
const { selectedDataSet, collections, selectCODAPCases, listenForSelectionChanges,
updateTitle } = useCodapState();
const listeningToDataSetId = useRef(0);
const [codapSelectedCase, setCodapSelectedCase] = useState<ICaseObjCommon|undefined>(undefined);
Expand Down
3 changes: 1 addition & 2 deletions src/components/flat-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ export const FlatTable = (props: ITableProps) => {
isHidden={attrVisibilities[key]}
isParent={false}
/>
)

);
})}
</tr>
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/hierarchy-view/hierarchy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface IProps {

export const Hierarchy = (props: IProps) => {
const { onSelectDataSet } = props;
const { dataSets, selectedDataSet, collections, handleSetCollections, handleAddCollection,
const { selectedDataSet, collections, handleSetCollections, handleAddCollection,
handleAddAttribute, handleUpdateAttributePosition, handleSelectSelf } = useCodapState();

const {activeAttr, handleDragStart, handleDragOver, handleDragEnd} = useDragging({collections,
Expand Down
7 changes: 3 additions & 4 deletions src/components/landscape-view.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { ICollection, INestedTableProps, IProcessedCaseObj, ITableProps, Values } from "../types";
import { ICollection, INestedTableProps, IProcessedCaseObj, Values } from "../types";
import { DraggagleTableHeader } from "./draggable-table-tags";
import { getAttrPrecisions, getAttrTypes, getAttrVisibility } from "../utils/utils";
import { TableHeaders } from "./table-headers";
Expand All @@ -8,7 +8,6 @@ import { useCodapContext } from "./CodapContext";

import css from "./tables.scss";


export const LandscapeView = (props: INestedTableProps) => {
const {collectionClasses, getClassName, getValueLength, paddingStyle} = props;
const {collections, selectedDataSet, interactiveState} = useCodapContext();
Expand Down Expand Up @@ -39,7 +38,7 @@ export const LandscapeView = (props: INestedTableProps) => {
values={headerValues}
attrVisibilities={attrVisibilities}
/>
)
);
})}
</tr>
<tr className={css[className]}>
Expand Down Expand Up @@ -124,7 +123,7 @@ export const LandscapeView = (props: INestedTableProps) => {
precision={precisions[key]}
isHidden={attrVisibilities[key]}
/>
)
);
})}
</tr>
</>
Expand Down
3 changes: 2 additions & 1 deletion src/components/menu.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from "react";
import css from "./menu.scss";
import { useCodapContext } from "./CodapContext";

import css from "./menu.scss";

interface IProps {
onSelectDataSet: (e: React.ChangeEvent<HTMLSelectElement>) => void,

Expand Down
18 changes: 7 additions & 11 deletions src/components/nested-table.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { useCallback, useEffect, useState } from "react";
import { InteractiveState } from "../hooks/useCodapState";
import { ICollection, ICollectionClass, IProcessedCaseObj, Values } from "../types";
import { Menu } from "./menu";
import { PortraitView } from "./portrait-view";
Expand Down Expand Up @@ -90,26 +89,21 @@ export const NestedTable = (props: IProps) => {

const renderTable = () => {
const isNoHierarchy = collections.length === 1;
// const classesExist = collectionClasses.length > 0;
const tableProps = {
getValueLength,
collectionClasses,
getClassName,
paddingStyle
};
const flatProps = {getValueLength, paddingStyle};
const nestedTableProps = {...flatProps, collectionClasses, getClassName};
if (isNoHierarchy) {
return (
<FlatTable
getValueLength={getValueLength}
paddingStyle={paddingStyle}
/>
)
);
} else {
return (
interactiveState.displayMode === portrait ?
<PortraitView {...tableProps} /> :
<PortraitView {...nestedTableProps} /> :
interactiveState.displayMode === landscape ?
<LandscapeView {...tableProps} /> :
<LandscapeView {...nestedTableProps} /> :
<div/>
);
}
Expand All @@ -126,6 +120,8 @@ export const NestedTable = (props: IProps) => {
toggleShowHeaders={toggleShowHeaders}
displayMode={interactiveState?.displayMode}
showDisplayMode={showDisplayMode}
padding={interactiveState?.padding}
showHeaders={interactiveState?.showHeaders}
/>
<DraggableTableContext.Provider value={draggableTable}>
{/* <FocusProvider> */}
Expand Down
15 changes: 8 additions & 7 deletions src/components/portrait-view.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React, { useRef, useState } from "react";
import React, { useRef } from "react";
import { ICollection, INestedTableProps, IProcessedCaseObj, Values } from "../types";
import { DraggableTableContainer, DroppableTableData, DroppableTableHeader } from "./draggable-table-tags";
import { TableScrollTopContext, useTableScrollTop } from "../hooks/useTableScrollTop";
import { getAttrPrecisions, getAttrTypes, getAttrVisibility } from "../utils/utils";

import css from "./tables.scss";
import { TableHeaders } from "./table-headers";
import { useCodapContext } from "./CodapContext";
import { TableCell } from "./table-cell";

import css from "./tables.scss";

interface IPortraitViewRowProps extends INestedTableProps {
collectionId: number;
caseObj: IProcessedCaseObj;
Expand Down Expand Up @@ -46,7 +46,7 @@ export const PortraitViewRow = (props: IPortraitViewRowProps) => {
precision={precisions[key]}
isHidden={attrVisibilities[key]}
/>
)
);
})}
</tr>
);
Expand Down Expand Up @@ -79,6 +79,7 @@ export const PortraitViewRow = (props: IPortraitViewRowProps) => {
attrType={attrTypes[i]}
precision={precisions[i]}
isHidden={attrVisibilities[key]}
isParent={isParent}
/>
))}
<DroppableTableData collectionId={collectionId} style={paddingStyle}>
Expand Down Expand Up @@ -130,7 +131,7 @@ export const PortraitView = (props: INestedTableProps) => {

const renderTable = () => {
const parentColl = collections.filter((coll: ICollection) => !coll.parent)[0];
const className = "collections0";
const className = `collection0`;
const firstRowValues = parentColl.cases.map(caseObj => caseObj.values);
const valueCount = getValueLength(firstRowValues);
const precisions = getAttrPrecisions(collections);
Expand All @@ -139,8 +140,8 @@ export const PortraitView = (props: INestedTableProps) => {

return (
<DraggableTableContainer>
<table className={`${css.mainTable} ${css.portraitTable} ${css[className]}`} ref={tableRef}>
<tbody className={`table-body ${css[className]}`}>
<table className={`${css.mainTable} ${css.portraitTable} ${`tables-${className}`}`} ref={tableRef}>
<tbody className={`table-body ${className}`}>
<tr className={css.mainHeader}>
<th className={css.datasetNameHeader} colSpan={valueCount}>{selectedDataSet.name}</th>
</tr>
Expand Down
73 changes: 0 additions & 73 deletions src/components/table-cells.tsx

This file was deleted.

3 changes: 1 addition & 2 deletions src/components/table-headers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export const TableHeaders: React.FC<MapHeadersFromValuesProps> = ({
<>
{Object.keys(values).map((key, index) => {
if (!attrVisibilities[key] && (typeof values[key] === "string" || typeof values[key] === "number")) {
console.log("Rendering header for key:", key); // Debugging log
return (
<DraggagleTableHeader
key={`${collectionId}-${rowKey}-${key}-${index}`}
Expand All @@ -34,7 +33,7 @@ export const TableHeaders: React.FC<MapHeadersFromValuesProps> = ({
</DraggagleTableHeader>
);
}
return null; // Return null if the condition is not met
return null;
})}
</>
);
Expand Down
10 changes: 1 addition & 9 deletions src/hooks/useCodapState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
updateAttributePosition,
} from "@concord-consortium/codap-plugin-api";
import { getCases, getDataSetCollections, sortAttribute } from "../utils/apiHelpers";
import { ICollections, ICollection, IDataSet } from "../types";
import { ICollections, ICollection, IDataSet, InteractiveState } from "../types";

const iFrameDescriptor = {
version: "0.5.0",
Expand All @@ -26,14 +26,6 @@ const iFrameDescriptor = {
}
};

export interface InteractiveState {
view: "nested-table" | "hierarchy" | "card-view" | null
dataSetName: string|null;
padding: boolean;
showHeaders: boolean;
displayMode: string;
}

export const useCodapState = () => {
const [connected, setConnected] = useState(false);
const [dataSets, setDataSets] = useState<IDataSet[]>([]);
Expand Down
Loading

0 comments on commit bb94562

Please sign in to comment.