mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2026-01-08 03:57:31 +00:00
Update SettingsComponent, Indexadvisor.test, and ResultsView
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
import { IPivotItemProps, IPivotProps, Pivot, PivotItem } from "@fluentui/react";
|
import { IPivotItemProps, IPivotProps, Pivot, PivotItem } from "@fluentui/react";
|
||||||
import { readCollection } from "Common/dataAccess/readCollection";
|
|
||||||
import {
|
import {
|
||||||
ComputedPropertiesComponent,
|
ComputedPropertiesComponent,
|
||||||
ComputedPropertiesComponentProps,
|
ComputedPropertiesComponentProps,
|
||||||
@@ -307,7 +306,8 @@ export class SettingsComponent extends React.Component<SettingsComponentProps, S
|
|||||||
this.unsubscribe = useIndexingPolicyStore.subscribe((_,) => {
|
this.unsubscribe = useIndexingPolicyStore.subscribe((_,) => {
|
||||||
this.refreshCollectionData();
|
this.refreshCollectionData();
|
||||||
},
|
},
|
||||||
(state) => state.indexingPolicy);
|
(state) => state.indexingPolicies[this.collection.id()]
|
||||||
|
);
|
||||||
this.refreshCollectionData();
|
this.refreshCollectionData();
|
||||||
}
|
}
|
||||||
componentWillUnmount(): void {
|
componentWillUnmount(): void {
|
||||||
@@ -935,12 +935,25 @@ export class SettingsComponent extends React.Component<SettingsComponentProps, S
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
private refreshCollectionData = async (): Promise<void> => {
|
private refreshCollectionData = async (): Promise<void> => {
|
||||||
const latestCollection = await readCollection(this.collection.databaseId, this.collection.id());
|
const containerId = this.collection.id();
|
||||||
this.collection.rawDataModel = latestCollection;
|
const latestIndexingPolicy = useIndexingPolicyStore.getState().indexingPolicies[containerId];
|
||||||
this.collection.indexingPolicy(latestCollection.indexingPolicy);
|
const rawPolicy = latestIndexingPolicy ?? this.collection.indexingPolicy();
|
||||||
|
|
||||||
|
const latestCollection: DataModels.IndexingPolicy = {
|
||||||
|
automatic: rawPolicy?.automatic ?? true,
|
||||||
|
indexingMode: rawPolicy?.indexingMode ?? "consistent",
|
||||||
|
includedPaths: rawPolicy?.includedPaths ?? [],
|
||||||
|
excludedPaths: rawPolicy?.excludedPaths ?? [],
|
||||||
|
compositeIndexes: rawPolicy?.compositeIndexes ?? [],
|
||||||
|
spatialIndexes: rawPolicy?.spatialIndexes ?? [],
|
||||||
|
vectorIndexes: rawPolicy?.vectorIndexes ?? [],
|
||||||
|
fullTextIndexes: rawPolicy?.fullTextIndexes ?? [],
|
||||||
|
};
|
||||||
|
|
||||||
|
this.collection.rawDataModel.indexingPolicy = latestCollection;
|
||||||
this.setState({
|
this.setState({
|
||||||
indexingPolicyContent: latestCollection.indexingPolicy,
|
indexingPolicyContent: latestCollection,
|
||||||
indexingPolicyContentBaseline: latestCollection.indexingPolicy,
|
indexingPolicyContentBaseline: latestCollection,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -200,12 +200,6 @@ test("calls handleError if fetchIndexMetrics throws2nd", async () => {
|
|||||||
expect(screen.queryByRole("status")).not.toBeInTheDocument();
|
expect(screen.queryByRole("status")).not.toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("renders IndexAdvisorTab when clicked from ResultsView", async () => {
|
|
||||||
render(<IndexAdvisorTab />);
|
|
||||||
await waitFor(() => expect(screen.getByText("Included in Current Policy")).toBeInTheDocument());
|
|
||||||
expect(screen.getByText("/foo/?")).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("updates indexing policy after replace is triggered", async () => {
|
test("updates indexing policy after replace is triggered", async () => {
|
||||||
render(<IndexAdvisorTab />);
|
render(<IndexAdvisorTab />);
|
||||||
const barIndexText = await screen.findByText((content) =>
|
const barIndexText = await screen.findByText((content) =>
|
||||||
@@ -224,6 +218,12 @@ test("updates indexing policy after replace is triggered", async () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("renders IndexAdvisorTab when clicked from ResultsView", async () => {
|
||||||
|
render(<IndexAdvisorTab />);
|
||||||
|
await waitFor(() => expect(screen.getByText("Included in Current Policy")).toBeInTheDocument());
|
||||||
|
expect(screen.getByText("/foo/?")).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
test("IndexingPolicyStore stores updated policy on componentDidMount", async () => {
|
test("IndexingPolicyStore stores updated policy on componentDidMount", async () => {
|
||||||
render(<IndexAdvisorTab />);
|
render(<IndexAdvisorTab />);
|
||||||
await waitFor(() => expect(mockRead).toHaveBeenCalled());
|
await waitFor(() => expect(mockRead).toHaveBeenCalled());
|
||||||
|
|||||||
@@ -659,7 +659,7 @@ export const IndexAdvisorTab: React.FC = () => {
|
|||||||
partitionKey: containerDef.partitionKey,
|
partitionKey: containerDef.partitionKey,
|
||||||
indexingPolicy: updatedPolicy,
|
indexingPolicy: updatedPolicy,
|
||||||
});
|
});
|
||||||
useIndexingPolicyStore.getState().setIndexingPolicyOnly(updatedPolicy);
|
useIndexingPolicyStore.getState().setIndexingPolicyFor(containerId, updatedPolicy);
|
||||||
const selectedIndexSet = new Set(selectedIndexes.map(s => s.index));
|
const selectedIndexSet = new Set(selectedIndexes.map(s => s.index));
|
||||||
const updatedNotIncluded: typeof notIncluded = [];
|
const updatedNotIncluded: typeof notIncluded = [];
|
||||||
const newlyIncluded: typeof included = [];
|
const newlyIncluded: typeof included = [];
|
||||||
@@ -881,14 +881,18 @@ export const ResultsView: React.FC<ResultsViewProps> = ({ isMongoDB, queryResult
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
export interface IndexingPolicyStore {
|
export interface IndexingPolicyStore {
|
||||||
indexingPolicy: IndexingPolicy | null;
|
indexingPolicies: { [containerId: string]: IndexingPolicy };
|
||||||
setIndexingPolicyOnly: (indexingPolicy: IndexingPolicy) => void;
|
setIndexingPolicyFor: (containerId: string, indexingPolicy: IndexingPolicy) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useIndexingPolicyStore = create<IndexingPolicyStore>((set) => ({
|
export const useIndexingPolicyStore = create<IndexingPolicyStore>((set) => ({
|
||||||
indexingPolicy: null,
|
indexingPolicies: {},
|
||||||
setIndexingPolicyOnly: (indexingPolicy) =>
|
setIndexingPolicyFor: (containerId, indexingPolicy) =>
|
||||||
set(() => ({ indexingPolicy: { ...indexingPolicy } })),
|
set((state) => ({
|
||||||
|
indexingPolicies: {
|
||||||
|
...state.indexingPolicies,
|
||||||
|
[containerId]: { ...indexingPolicy },
|
||||||
|
},
|
||||||
|
})),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user