Skip to content

Commit

Permalink
Removes console.logs
Browse files Browse the repository at this point in the history
Removes unused functions
  • Loading branch information
eireland committed Mar 20, 2024
1 parent 13ca3da commit 5b5144c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 27 deletions.
1 change: 0 additions & 1 deletion src/components/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export const Menu = (props: IProps) => {
showHeaders, padding, toggleShowHeaders, displayMode, selectedDataSet, showDisplayMode} = props;

const displayModes = [none, portrait, landscape];
console.log("********** in Menu");
return (
<div className={css.menu}>
<div className={css.option}>
Expand Down
55 changes: 31 additions & 24 deletions src/hooks/useCodapState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface InteractiveState {
export const useCodapState = () => {
const [connected, setConnected] = useState(false);
const [dataSets, setDataSets] = useState<IDataSet[]>([]);
const [selectedDataSet, setSelectedDataSet] = useState<any>(null);
const [selectedDataSet, setSelectedDataSet] = useState<IDataSet|null>(null);
const [selectedDataSetName, setSelectedDataSetName] = useState<string>("");
const [collections, setCollections] = useState<ICollections>([]);
const [items, setItems] = useState<any[]>([]);
Expand Down Expand Up @@ -67,17 +67,17 @@ export const useCodapState = () => {
};

const init = async () => {
const newState = await initializePlugin(iFrameDescriptor);
addDataContextsListListener(handleDocumentChangeNotice);
await getDataSets();
const newState = await initializePlugin(iFrameDescriptor);
addDataContextsListListener(handleDocumentChangeNotice);
await getDataSets();

// plugins in new documents return an empty object for the interactive state
// so ignore the new state and keep the default starting state in that case
if (Object.keys(newState || {}).length > 0) {
setInteractiveState(newState);
}
setConnected(true);
};
// plugins in new documents return an empty object for the interactive state
// so ignore the new state and keep the default starting state in that case
if (Object.keys(newState || {}).length > 0) {
setInteractiveState(newState);
}
setConnected(true);
};


useEffect(() => {
Expand Down Expand Up @@ -132,40 +132,49 @@ export const useCodapState = () => {
}, [selectedDataSetName]);

useEffect(() => {
console.log("*********** in useEffect selectedDataSet ***********", selectedDataSet);
if (selectedDataSet) {
updateCollections();
} else {
setCollections([]);
}
}, [selectedDataSet]);

Check warning on line 138 in src/hooks/useCodapState.tsx

View workflow job for this annotation

GitHub Actions / Build and Run Jest Tests

React Hook useEffect has a missing dependency: 'updateCollections'. Either include it or remove the dependency array

Check warning on line 138 in src/hooks/useCodapState.tsx

View workflow job for this annotation

GitHub Actions / Build and Run Jest Tests

React Hook useEffect has a missing dependency: 'updateCollections'. Either include it or remove the dependency array

Check warning on line 138 in src/hooks/useCodapState.tsx

View workflow job for this annotation

GitHub Actions / S3 Deploy

React Hook useEffect has a missing dependency: 'updateCollections'. Either include it or remove the dependency array

Check warning on line 138 in src/hooks/useCodapState.tsx

View workflow job for this annotation

GitHub Actions / S3 Deploy

React Hook useEffect has a missing dependency: 'updateCollections'. Either include it or remove the dependency array

useEffect(() => {
const fetchItems = async () => {
const itemRes = await getCases(selectedDataSetName, collections[0].name);
const fetchedItems = itemRes.map((item: any) => item.values);
setItems(fetchedItems);
};

if (collections.length === 1 && selectedDataSet) {
fetchItems();
} else {
setItems([]);
}
}, [collections, selectedDataSetName, updateCollections]);

Check warning on line 152 in src/hooks/useCodapState.tsx

View workflow job for this annotation

GitHub Actions / Build and Run Jest Tests

React Hook useEffect has a missing dependency: 'selectedDataSet'. Either include it or remove the dependency array

Check warning on line 152 in src/hooks/useCodapState.tsx

View workflow job for this annotation

GitHub Actions / Build and Run Jest Tests

React Hook useEffect has a missing dependency: 'selectedDataSet'. Either include it or remove the dependency array

Check warning on line 152 in src/hooks/useCodapState.tsx

View workflow job for this annotation

GitHub Actions / S3 Deploy

React Hook useEffect has a missing dependency: 'selectedDataSet'. Either include it or remove the dependency array

Check warning on line 152 in src/hooks/useCodapState.tsx

View workflow job for this annotation

GitHub Actions / S3 Deploy

React Hook useEffect has a missing dependency: 'selectedDataSet'. Either include it or remove the dependency array

const handleSelectDataSet = (name: string) => {
const selected = dataSets.filter((d) => d.title === name);
return selected.length ? handleSetDataSet(selected[0].name) : handleSetDataSet(null);
};

const handleRefreshDataSet = () => {
setNumUpdates(numUpdates + 1);
return selectedDataSet ? handleSetDataSet(selectedDataSet) : handleSetDataSet(null);
const handleSelectDataSet = (name: string) => {
const selected = dataSets.find((d) => d.title === name);
return selected && handleSetDataSet(selected.name);
};

const getCollectionNameFromId = (id: number) => {
return collections.find((c: ICollection) => c.id === id)?.name;
};

const handleUpdateAttributePosition = async (coll: ICollection, attrName: string, position: number) => {
if (selectedDataSet === null) return;
await updateAttributePosition(selectedDataSet.name, coll.name, attrName, position);
};

const handleAddCollection = async (newCollectionName: string) => {
if (selectedDataSet === null) return;
await createNewCollection(selectedDataSet.name, newCollectionName, [{"name": "newAttr"}]);
// update collections because CODAP does not send dataContextChangeNotice
updateCollections();
};

const handleCreateCollectionFromAttribute = async (collection: ICollection, attr: any, parent: number|string) => {
if (selectedDataSet === null) return;
const parentStr = parent.toString();
await createCollectionFromAttribute(selectedDataSet.name, collection.name, attr, parentStr);
// update collections because CODAP does not send dataContextChangeNotice
Expand All @@ -174,10 +183,10 @@ export const useCodapState = () => {

const handleSortAttribute = async (context: string, attrId: number, isDescending: boolean) => {
sortAttribute(context, attrId, isDescending);
// updateCollections();
};

const handleAddAttribute = async (collection: ICollection, attrName: string) => {
if (selectedDataSet === null) return;
const proposedName = attrName.length ? attrName : "newAttr";
let newAttributeName;
const allAttributes: Array<any> = [];
Expand Down Expand Up @@ -249,14 +258,12 @@ export const useCodapState = () => {
collections,
handleSetCollections: setCollections,
handleSelectDataSet,
handleRefreshDataSet,
getCollectionNameFromId,
updateInteractiveState,
init,
interactiveState,
items,
connected,
numUpdates,
handleUpdateAttributePosition,
handleAddCollection,
handleSortAttribute,
Expand Down
2 changes: 0 additions & 2 deletions src/utils/apiHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
import { ICollections } from "../types";

export const getCases = async (selectedDataSetName: string, collName: string) => {
console.log("*********** in getCases ***********");
const processCase = async (caseObj: any) => {
if (caseObj.children) {
for (let i = 0; i < caseObj.children.length; i++){
Expand Down Expand Up @@ -40,7 +39,6 @@ export const getCases = async (selectedDataSetName: string, collName: string) =>
export const getDataSetCollections = async (selectedDataSetName: string) => {
const collectionList = (await getCollectionList(selectedDataSetName)).values;
const colls: ICollections = [];
console.log("*********** in getDataSetCollections ***********");

for (let i = 0; i < collectionList.length; i++) {
const coll = (await getCollection(selectedDataSetName, collectionList[i].name)).values;
Expand Down

0 comments on commit 5b5144c

Please sign in to comment.