mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-10-13 23:38:45 +01:00
Update SettingsComponent, Indexadvisor.test, and ResultsView
This commit is contained in:
parent
253a85efea
commit
c2b3330e4f
@ -1,5 +1,4 @@
|
||||
import { IPivotItemProps, IPivotProps, Pivot, PivotItem } from "@fluentui/react";
|
||||
import { readCollection } from "Common/dataAccess/readCollection";
|
||||
import {
|
||||
ComputedPropertiesComponent,
|
||||
ComputedPropertiesComponentProps,
|
||||
@ -307,7 +306,8 @@ export class SettingsComponent extends React.Component<SettingsComponentProps, S
|
||||
this.unsubscribe = useIndexingPolicyStore.subscribe((_,) => {
|
||||
this.refreshCollectionData();
|
||||
},
|
||||
(state) => state.indexingPolicy);
|
||||
(state) => state.indexingPolicies[this.collection.id()]
|
||||
);
|
||||
this.refreshCollectionData();
|
||||
}
|
||||
componentWillUnmount(): void {
|
||||
@ -935,12 +935,25 @@ export class SettingsComponent extends React.Component<SettingsComponentProps, S
|
||||
);
|
||||
};
|
||||
private refreshCollectionData = async (): Promise<void> => {
|
||||
const latestCollection = await readCollection(this.collection.databaseId, this.collection.id());
|
||||
this.collection.rawDataModel = latestCollection;
|
||||
this.collection.indexingPolicy(latestCollection.indexingPolicy);
|
||||
const containerId = this.collection.id();
|
||||
const latestIndexingPolicy = useIndexingPolicyStore.getState().indexingPolicies[containerId];
|
||||
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({
|
||||
indexingPolicyContent: latestCollection.indexingPolicy,
|
||||
indexingPolicyContentBaseline: latestCollection.indexingPolicy,
|
||||
indexingPolicyContent: latestCollection,
|
||||
indexingPolicyContentBaseline: latestCollection,
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -200,12 +200,6 @@ test("calls handleError if fetchIndexMetrics throws2nd", async () => {
|
||||
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 () => {
|
||||
render(<IndexAdvisorTab />);
|
||||
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 () => {
|
||||
render(<IndexAdvisorTab />);
|
||||
await waitFor(() => expect(mockRead).toHaveBeenCalled());
|
||||
|
@ -659,7 +659,7 @@ export const IndexAdvisorTab: React.FC = () => {
|
||||
partitionKey: containerDef.partitionKey,
|
||||
indexingPolicy: updatedPolicy,
|
||||
});
|
||||
useIndexingPolicyStore.getState().setIndexingPolicyOnly(updatedPolicy);
|
||||
useIndexingPolicyStore.getState().setIndexingPolicyFor(containerId, updatedPolicy);
|
||||
const selectedIndexSet = new Set(selectedIndexes.map(s => s.index));
|
||||
const updatedNotIncluded: typeof notIncluded = [];
|
||||
const newlyIncluded: typeof included = [];
|
||||
@ -881,14 +881,18 @@ export const ResultsView: React.FC<ResultsViewProps> = ({ isMongoDB, queryResult
|
||||
);
|
||||
};
|
||||
export interface IndexingPolicyStore {
|
||||
indexingPolicy: IndexingPolicy | null;
|
||||
setIndexingPolicyOnly: (indexingPolicy: IndexingPolicy) => void;
|
||||
indexingPolicies: { [containerId: string]: IndexingPolicy };
|
||||
setIndexingPolicyFor: (containerId: string, indexingPolicy: IndexingPolicy) => void;
|
||||
}
|
||||
|
||||
export const useIndexingPolicyStore = create<IndexingPolicyStore>((set) => ({
|
||||
indexingPolicy: null,
|
||||
setIndexingPolicyOnly: (indexingPolicy) =>
|
||||
set(() => ({ indexingPolicy: { ...indexingPolicy } })),
|
||||
indexingPolicies: {},
|
||||
setIndexingPolicyFor: (containerId, indexingPolicy) =>
|
||||
set((state) => ({
|
||||
indexingPolicies: {
|
||||
...state.indexingPolicies,
|
||||
[containerId]: { ...indexingPolicy },
|
||||
},
|
||||
})),
|
||||
}));
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user