Lets add Arc Context awareness (https://www.cratis.io/docs/Arc/frontend/react/arc.html).
We don’t need to have configuration for where the API surface is located, it should be by default through the same location as the current page.
But, if the page is not configured with Arc, we can’t really do anything anyways. So on opening the extension, we need to get the Arc Context and its configuration to use as basis for commands & queries. If there is no Arc context, we should hide the command & query pages and instead add a warning saying this is not an Arc application.
To get the Arc context, we can do something similar to this:
function findArcContext() {
const root = document.getElementById('root');
const fiberKey = Object.keys(root).find(k => k.startsWith('__reactFiber'));
let fiber = (root as any)[fiberKey];
while (fiber) {
const contextValue = fiber.memoizedProps?.value;
// Identify ArcContext by the shape of its value
if (contextValue && 'reconnectQueries' in contextValue) {
return contextValue;
}
fiber = fiber.child ?? fiber.sibling ?? fiber.return;
}
}
Lets add Arc Context awareness (https://www.cratis.io/docs/Arc/frontend/react/arc.html).
We don’t need to have configuration for where the API surface is located, it should be by default through the same location as the current page.
But, if the page is not configured with Arc, we can’t really do anything anyways. So on opening the extension, we need to get the Arc Context and its configuration to use as basis for commands & queries. If there is no Arc context, we should hide the command & query pages and instead add a warning saying this is not an Arc application.
To get the Arc context, we can do something similar to this: