Remove dependency on previous prop of deletion id

This commit is contained in:
Sung-Hyun Kang 2024-06-17 13:23:22 -05:00
parent ac8dbbc0d2
commit 1ab6bf3d81
3 changed files with 20 additions and 65 deletions

View File

@ -8,7 +8,6 @@ import { handleError } from "../ErrorHandlingUtils";
export async function readCollection(databaseId: string, collectionId: string): Promise<DataModels.Collection> {
const cosmosClient = client();
console.log("RUNNING HERE - readCollection");
return await readCollectionInternal(cosmosClient, databaseId, collectionId);
}
@ -23,7 +22,6 @@ export async function readSampleCollection(): Promise<DataModels.Collection> {
return undefined;
}
console.log("RUNNING HERE - readSampleCollection");
return await readCollectionInternal(cosmosClient, databaseId, collectionId);
}
@ -32,7 +30,6 @@ export async function readCollectionInternal(
databaseId: string,
collectionId: string,
): Promise<DataModels.Collection> {
console.log("RUNNING HERE - Read Collection Internal");
let collection: DataModels.Collection;
const clearMessage = logConsoleProgress(`Querying container ${collectionId}`);
try {
@ -41,8 +38,7 @@ export async function readCollectionInternal(
} catch (error) {
handleError(error, "ReadCollection", `Error while querying container ${collectionId}`);
throw error;
} finally {
clearMessage();
}
clearMessage();
return collection;
}

View File

@ -265,70 +265,31 @@ export class NotificationConsoleComponent extends React.Component<
};
private updateConsoleData = (prevProps: NotificationConsoleComponentProps): void => {
this.setState((prevState) => {
let allConsoleData = [...prevState.allConsoleData];
let hasChanged = false;
let updatedConsoleData: ConsoleData[] = [...this.state.allConsoleData];
let refresh = false;
if (!this.areConsoleDataEqual(this.props.consoleData, prevProps.consoleData)) {
allConsoleData = [this.props.consoleData, ...allConsoleData];
hasChanged = true;
}
if (!this.areConsoleDataEqual(this.props.consoleData, prevProps.consoleData)) {
updatedConsoleData = [this.props.consoleData, ...updatedConsoleData];
refresh = true;
}
if (
this.props.inProgressConsoleDataIdToBeDeleted &&
prevProps.inProgressConsoleDataIdToBeDeleted !== this.props.inProgressConsoleDataIdToBeDeleted
) {
console.log("Deleting ", this.props.inProgressConsoleDataIdToBeDeleted);
allConsoleData = allConsoleData.filter(
if (this.props.inProgressConsoleDataIdToBeDeleted) {
const hasMatchingItem = updatedConsoleData.some(
(data: ConsoleData) =>
data.type === ConsoleDataType.InProgress && data.id === this.props.inProgressConsoleDataIdToBeDeleted,
);
if (hasMatchingItem) {
updatedConsoleData = updatedConsoleData.filter(
(data: ConsoleData) =>
!(data.type === ConsoleDataType.InProgress && data.id === this.props.inProgressConsoleDataIdToBeDeleted),
);
hasChanged = true;
refresh = true;
}
// Only update the state if there are changes
if (hasChanged) {
return { allConsoleData };
} else {
return null;
}
});
}
refresh && this.setState({ allConsoleData: updatedConsoleData });
};
// 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;

View File

@ -23,10 +23,8 @@ export const useNotificationConsole: UseStore<NotificationConsoleState> = create
expandConsole: () => set((state) => ({ ...state, isExpanded: true })),
setIsExpanded: (isExpanded) => set((state) => ({ ...state, isExpanded })),
setNotificationConsoleData: (consoleData: ConsoleData) => set((state) => ({ ...state, consoleData })),
setInProgressConsoleDataIdToBeDeleted: (id: string) => {
console.log("SETTING TO BE DELETED", id);
set((state) => ({ ...state, inProgressConsoleDataIdToBeDeleted: id }));
},
setInProgressConsoleDataIdToBeDeleted: (id: string) =>
set((state) => ({ ...state, inProgressConsoleDataIdToBeDeleted: id })),
setConsoleAnimationFinished: (consoleAnimationFinished: boolean) =>
set({ consoleAnimationFinished: consoleAnimationFinished }),
}));