-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add workspace sidebar. Add workspace localstorage save * Add invite user modal * Add fix for name in sidebar
- Loading branch information
Showing
46 changed files
with
1,124 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
airbyte-webapp/src/components/hooks/services/Feature/FeatureService.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import React, { useContext, useMemo } from "react"; | ||
import { Feature, FeatureServiceApi } from "./types"; | ||
|
||
const featureServiceContext = React.createContext<FeatureServiceApi | null>( | ||
null | ||
); | ||
|
||
export function FeatureService({ | ||
children, | ||
features = [], | ||
}: { | ||
children: React.ReactNode; | ||
features?: Feature[]; | ||
}) { | ||
const featureService = useMemo( | ||
() => ({ | ||
features, | ||
hasFeature: (featureId: string): boolean => | ||
!!features.find((feature) => feature.id === featureId), | ||
}), | ||
[features] | ||
); | ||
|
||
return ( | ||
<> | ||
<featureServiceContext.Provider value={featureService}> | ||
{children} | ||
</featureServiceContext.Provider> | ||
</> | ||
); | ||
} | ||
|
||
export const useFeatureService: () => FeatureServiceApi = () => { | ||
const featureService = useContext(featureServiceContext); | ||
if (!featureService) { | ||
throw new Error("useFeatureService must be used within a FeatureService."); | ||
} | ||
return featureService; | ||
}; | ||
|
||
export const WithFeature: React.FC<{ featureId: string }> = ({ | ||
featureId, | ||
children, | ||
}) => { | ||
const { hasFeature } = useFeatureService(); | ||
return hasFeature(featureId) ? <>{children}</> : null; | ||
}; |
2 changes: 2 additions & 0 deletions
2
airbyte-webapp/src/components/hooks/services/Feature/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./FeatureService"; | ||
export * from "./types"; |
10 changes: 10 additions & 0 deletions
10
airbyte-webapp/src/components/hooks/services/Feature/types.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
type Feature = { | ||
id: string; | ||
}; | ||
|
||
type FeatureServiceApi = { | ||
features: Feature[]; | ||
hasFeature: (featureId: string) => boolean; | ||
}; | ||
|
||
export type { Feature, FeatureServiceApi }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { useEffect, useMemo } from "react"; | ||
import { useMap } from "react-use"; | ||
|
||
type Service = any; | ||
|
||
type ServicesProvider = { | ||
register(name: string, rm: Service): void; | ||
unregister(name: string): void; | ||
services: Service[]; | ||
}; | ||
|
||
let services: { | ||
[key: string]: Service; | ||
} = {}; | ||
|
||
export function getServices() { | ||
return Object.values(services); | ||
} | ||
|
||
export function getService(serviceId: string): Service { | ||
return services[serviceId]; | ||
} | ||
|
||
export function registerService(serviceId: string, service: Service): void { | ||
services[serviceId] = service; | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
export const useServicesProvider = (): ServicesProvider => { | ||
const [registeredServices, { remove, set }] = useMap<{ | ||
[key: string]: Service; | ||
}>(); | ||
|
||
useEffect(() => { | ||
services = registeredServices; | ||
}, [registeredServices]); | ||
|
||
return useMemo<ServicesProvider>( | ||
() => ({ | ||
services: Object.values(registeredServices), | ||
register: set, | ||
unregister: remove, | ||
}), | ||
[registeredServices, remove, set] | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export const api = { | ||
cloud: "https://dev-cloud.airbyte.io/cloud/v1/", | ||
cloud: process.env.REACT_APP_CLOUD_API_URL ?? "/", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.