Skip to content

Commit

Permalink
feat(ClientSideAPI): Add API ready property
Browse files Browse the repository at this point in the history
  • Loading branch information
Darran Boyd committed Jan 12, 2024
1 parent 716aac3 commit 3fc1449
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ window.threatcomposer = {
Promise.resolve(PLACEHOLDER_EXCHANGE_DATA_FOR_WORKSPACE),
deleteWorkspace: () => Promise.resolve(),
renameWorkspace: () => Promise.resolve(),
apiReady: false,
};

/**
Expand All @@ -69,35 +70,23 @@ const WindowExporter: FC<PropsWithChildren<{}>> = ({ children }) => {

useEffect(() => {
window.threatcomposer.getWorkspaceList = () => workspaceList;
}, [workspaceList]);

useEffect(() => {
window.threatcomposer.getCurrentWorkspaceMetadata = () => currentWorkspace;
}, [currentWorkspace]);

useEffect(() => {
window.threatcomposer.getCurrentWorkspaceData = getWorkspaceData;
}, [getWorkspaceData]);

useEffect(() => {
window.threatcomposer.setCurrentWorkspaceData = setWorkspaceData;
}, [setWorkspaceData]);

useEffect(() => {
window.threatcomposer.createWorkspace = addWorkspace;
}, [addWorkspace]);

useEffect(() => {
window.threatcomposer.deleteWorkspace = deleteWorkspace;
}, [deleteWorkspace]);

useEffect(() => {
window.threatcomposer.switchWorkspace = switchWorkspace;
}, [switchWorkspace]);

useEffect(() => {
window.threatcomposer.renameWorkspace = renameWorkspace;
}, [renameWorkspace]);
window.threatcomposer.apiReady = true;
}, [
workspaceList,
currentWorkspace,
getWorkspaceData,
addWorkspace,
deleteWorkspace,
switchWorkspace,
renameWorkspace,
]);

return <>{children}</>;
};
Expand Down
1 change: 1 addition & 0 deletions packages/threat-composer/src/customTypes/dataExchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,5 @@ export interface ThreatComposerNamespace {
metadata?: Workspace['metadata']) => Promise<Workspace>;
deleteWorkspace: (id: string) => Promise<void>;
renameWorkspace: (id: string, newWorkspaceName: string) => Promise<void>;
apiReady: boolean;
}

0 comments on commit 3fc1449

Please sign in to comment.