-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve loading 2, mirrors page (#841)
Convert mirrors page to render on client --------- Co-authored-by: Kaushik Iska <[email protected]>
- Loading branch information
1 parent
a77979a
commit 2500b34
Showing
4 changed files
with
135 additions
and
94 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { getTruePeer } from '@/app/api/peers/getTruePeer'; | ||
import prisma from '@/app/utils/prisma'; | ||
|
||
export const dynamic = 'force-dynamic'; | ||
|
||
const stringifyConfig = (flowArray: any[]) => { | ||
flowArray.forEach((flow) => { | ||
if (flow.config_proto) { | ||
flow.config_proto = new TextDecoder().decode(flow.config_proto); | ||
} | ||
}); | ||
return flowArray; | ||
}; | ||
|
||
export async function GET(request: Request) { | ||
const mirrors = await prisma.flows.findMany({ | ||
distinct: 'name', | ||
include: { | ||
sourcePeer: true, | ||
destinationPeer: true, | ||
}, | ||
}); | ||
|
||
const flows = mirrors?.map((mirror) => { | ||
let newMirror: any = { | ||
...mirror, | ||
sourcePeer: getTruePeer(mirror.sourcePeer), | ||
destinationPeer: getTruePeer(mirror.destinationPeer), | ||
}; | ||
return newMirror; | ||
}); | ||
return new Response(JSON.stringify(stringifyConfig(flows))); | ||
} |
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,60 @@ | ||
import { CatalogPeer } from '@/app/dto/PeersDTO'; | ||
import { | ||
BigqueryConfig, | ||
EventHubConfig, | ||
EventHubGroupConfig, | ||
Peer, | ||
PostgresConfig, | ||
S3Config, | ||
SnowflakeConfig, | ||
SqlServerConfig, | ||
} from '@/grpc_generated/peers'; | ||
|
||
export const getTruePeer = (peer: CatalogPeer) => { | ||
const newPeer: Peer = { | ||
name: peer.name, | ||
type: peer.type, | ||
}; | ||
const options = peer.options; | ||
let config: | ||
| BigqueryConfig | ||
| SnowflakeConfig | ||
| PostgresConfig | ||
| EventHubConfig | ||
| S3Config | ||
| SqlServerConfig | ||
| EventHubGroupConfig; | ||
switch (peer.type) { | ||
case 0: | ||
config = BigqueryConfig.decode(options); | ||
newPeer.bigqueryConfig = config; | ||
break; | ||
case 1: | ||
config = SnowflakeConfig.decode(options); | ||
newPeer.snowflakeConfig = config; | ||
break; | ||
case 3: | ||
config = PostgresConfig.decode(options); | ||
newPeer.postgresConfig = config; | ||
break; | ||
case 4: | ||
config = EventHubConfig.decode(options); | ||
newPeer.eventhubConfig = config; | ||
break; | ||
case 5: | ||
config = S3Config.decode(options); | ||
newPeer.s3Config = config; | ||
break; | ||
case 6: | ||
config = SqlServerConfig.decode(options); | ||
newPeer.sqlserverConfig = config; | ||
break; | ||
case 7: | ||
config = EventHubGroupConfig.decode(options); | ||
newPeer.eventhubGroupConfig = config; | ||
break; | ||
default: | ||
return newPeer; | ||
} | ||
return newPeer; | ||
}; |
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