mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2024-11-25 06:56:38 +00:00
sample db handling
This commit is contained in:
parent
edfd6cfc30
commit
ac8dbbc0d2
@ -8,6 +8,7 @@ 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);
|
||||
}
|
||||
|
||||
@ -22,6 +23,7 @@ export async function readSampleCollection(): Promise<DataModels.Collection> {
|
||||
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<DataModels.Collection> {
|
||||
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;
|
||||
}
|
||||
|
@ -1158,7 +1158,7 @@ export default class Explorer {
|
||||
|
||||
public async refreshSampleData(): Promise<void> {
|
||||
try {
|
||||
if (!userContext.sampleDataConnectionInfo) {
|
||||
if (!userContext.sampleDataConnectionInfo || useDatabases.getState().sampleDataResourceTokenCollection) {
|
||||
return;
|
||||
}
|
||||
const collection: DataModels.Collection = await readSampleCollection();
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -23,8 +23,10 @@ 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) =>
|
||||
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 }),
|
||||
}));
|
||||
|
Loading…
Reference in New Issue
Block a user