diff --git a/src/Common/dataAccess/readCollection.ts b/src/Common/dataAccess/readCollection.ts index 3943b762d..1fae4d460 100644 --- a/src/Common/dataAccess/readCollection.ts +++ b/src/Common/dataAccess/readCollection.ts @@ -8,6 +8,7 @@ import { handleError } from "../ErrorHandlingUtils"; export async function readCollection(databaseId: string, collectionId: string): Promise { const cosmosClient = client(); + console.log("RUNNING HERE - readCollection"); return await readCollectionInternal(cosmosClient, databaseId, collectionId); } @@ -22,6 +23,7 @@ export async function readSampleCollection(): Promise { return undefined; } + console.log("RUNNING HERE - readSampleCollection"); return await readCollectionInternal(cosmosClient, databaseId, collectionId); } @@ -30,6 +32,7 @@ export async function readCollectionInternal( databaseId: string, collectionId: string, ): Promise { + console.log("RUNNING HERE - Read Collection Internal"); let collection: DataModels.Collection; const clearMessage = logConsoleProgress(`Querying container ${collectionId}`); try { @@ -38,7 +41,8 @@ export async function readCollectionInternal( } catch (error) { handleError(error, "ReadCollection", `Error while querying container ${collectionId}`); throw error; + } finally { + clearMessage(); } - clearMessage(); return collection; } diff --git a/src/Explorer/Explorer.tsx b/src/Explorer/Explorer.tsx index bb198e6c3..5658ca376 100644 --- a/src/Explorer/Explorer.tsx +++ b/src/Explorer/Explorer.tsx @@ -1158,7 +1158,7 @@ export default class Explorer { public async refreshSampleData(): Promise { try { - if (!userContext.sampleDataConnectionInfo) { + if (!userContext.sampleDataConnectionInfo || useDatabases.getState().sampleDataResourceTokenCollection) { return; } const collection: DataModels.Collection = await readSampleCollection(); diff --git a/src/Explorer/Menus/NotificationConsole/NotificationConsoleComponent.tsx b/src/Explorer/Menus/NotificationConsole/NotificationConsoleComponent.tsx index 7cefa9ac2..8fba57077 100644 --- a/src/Explorer/Menus/NotificationConsole/NotificationConsoleComponent.tsx +++ b/src/Explorer/Menus/NotificationConsole/NotificationConsoleComponent.tsx @@ -265,22 +265,70 @@ export class NotificationConsoleComponent extends React.Component< }; private updateConsoleData = (prevProps: NotificationConsoleComponentProps): void => { - if (!this.areConsoleDataEqual(this.props.consoleData, prevProps.consoleData)) { - this.setState({ allConsoleData: [this.props.consoleData, ...this.state.allConsoleData] }); - } + this.setState((prevState) => { + let allConsoleData = [...prevState.allConsoleData]; + let hasChanged = false; - if ( - this.props.inProgressConsoleDataIdToBeDeleted && - prevProps.inProgressConsoleDataIdToBeDeleted !== this.props.inProgressConsoleDataIdToBeDeleted - ) { - const allConsoleData = this.state.allConsoleData.filter( - (data: ConsoleData) => - !(data.type === ConsoleDataType.InProgress && data.id === this.props.inProgressConsoleDataIdToBeDeleted), - ); - this.setState({ allConsoleData }); - } + if (!this.areConsoleDataEqual(this.props.consoleData, prevProps.consoleData)) { + allConsoleData = [this.props.consoleData, ...allConsoleData]; + hasChanged = true; + } + + if ( + this.props.inProgressConsoleDataIdToBeDeleted && + prevProps.inProgressConsoleDataIdToBeDeleted !== this.props.inProgressConsoleDataIdToBeDeleted + ) { + console.log("Deleting ", this.props.inProgressConsoleDataIdToBeDeleted); + allConsoleData = allConsoleData.filter( + (data: ConsoleData) => + !(data.type === ConsoleDataType.InProgress && data.id === this.props.inProgressConsoleDataIdToBeDeleted), + ); + hasChanged = true; + } + + // Only update the state if there are changes + if (hasChanged) { + return { allConsoleData }; + } else { + return null; + } + }); }; + // private updateConsoleData = (prevProps: NotificationConsoleComponentProps): void => { + // let allConsoleData: ConsoleData[] = [...this.state.allConsoleData]; + // let updateState: boolean = false; + + // if (!this.areConsoleDataEqual(this.props.consoleData, prevProps.consoleData)) { + // // this.setState({ allConsoleData: [this.props.consoleData, ...this.state.allConsoleData] }); + // allConsoleData = [this.props.consoleData, ...allConsoleData]; + // updateState = true; + // } + + // if ( + // this.props.inProgressConsoleDataIdToBeDeleted && + // prevProps.inProgressConsoleDataIdToBeDeleted !== this.props.inProgressConsoleDataIdToBeDeleted + // ) { + // this.pendingDeletionIds.add(this.props.inProgressConsoleDataIdToBeDeleted); + // // const allConsoleData = this.state.allConsoleData.filter( + // // (data: ConsoleData) => + // // !(data.type === ConsoleDataType.InProgress && data.id === this.props.inProgressConsoleDataIdToBeDeleted), + // // ); + // // allConsoleData = allConsoleData.filter( + // // (data: ConsoleData) => + // // !(data.type === ConsoleDataType.InProgress && data.id === this.props.inProgressConsoleDataIdToBeDeleted), + // // ); + // // console.log(this.props.inProgressConsoleDataIdToBeDeleted); + // // console.log(allConsoleData); + // } + // if (this.pendingDeletionIds.size > 0) { + // allConsoleData = allConsoleData.filter((data: ConsoleData) => !this.pendingDeletionIds.has(data.id)); + // this.pendingDeletionIds.clear(); + // updateState = true; + // } + // updateState && this.setState({ allConsoleData }); + // }; + private areConsoleDataEqual = (currentData: ConsoleData, prevData: ConsoleData): boolean => { if (!currentData || !prevData) { return !currentData && !prevData; diff --git a/src/Utils/NotificationConsoleUtils.ts b/src/Utils/NotificationConsoleUtils.ts index b3c63e5a7..68ce772f2 100644 --- a/src/Utils/NotificationConsoleUtils.ts +++ b/src/Utils/NotificationConsoleUtils.ts @@ -11,6 +11,7 @@ function log(type: ConsoleDataType, message: string): () => void { }).format(new Date()); useNotificationConsole.getState().setNotificationConsoleData({ type, date, message, id }); + console.log(message, id); return () => useNotificationConsole.getState().setInProgressConsoleDataIdToBeDeleted(id); } diff --git a/src/hooks/useNotificationConsole.ts b/src/hooks/useNotificationConsole.ts index 460c8eaa4..28cd22e99 100644 --- a/src/hooks/useNotificationConsole.ts +++ b/src/hooks/useNotificationConsole.ts @@ -23,8 +23,10 @@ export const useNotificationConsole: UseStore = create expandConsole: () => set((state) => ({ ...state, isExpanded: true })), setIsExpanded: (isExpanded) => set((state) => ({ ...state, isExpanded })), setNotificationConsoleData: (consoleData: ConsoleData) => set((state) => ({ ...state, consoleData })), - setInProgressConsoleDataIdToBeDeleted: (id: string) => - set((state) => ({ ...state, inProgressConsoleDataIdToBeDeleted: id })), + setInProgressConsoleDataIdToBeDeleted: (id: string) => { + console.log("SETTING TO BE DELETED", id); + set((state) => ({ ...state, inProgressConsoleDataIdToBeDeleted: id })); + }, setConsoleAnimationFinished: (consoleAnimationFinished: boolean) => set({ consoleAnimationFinished: consoleAnimationFinished }), }));