Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
4rthem committed Dec 14, 2023
1 parent 5a3c73c commit fd6c182
Show file tree
Hide file tree
Showing 26 changed files with 177 additions and 95 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ INDEXER_DATABOX_OWNER_ID=
INDEXER_DATABOX_CONCURRENCY=3
INDEXER_WATCH_DIR=/fs-watch
INDEXER_WATCH_DIR_PREFIX=fs
INDEXER_WATCH_SOURCE_DIR=/tmp
INDEXER_WATCH_SOURCE_DIR=./tmp
INDEXER_BUCKET_NAME=test-indexer
INDEXER_PHRASEANET_DATABOX_ID=
INDEXER_PHRASEANET_SEARCH_QUERY=
Expand Down
8 changes: 8 additions & 0 deletions configurator/src/Command/ConfigureCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ public function __construct(
parent::__construct();
}

protected function configure()
{
parent::configure();

$this->addOption('preset');
}


public function execute(InputInterface $input, OutputInterface $output): int
{
$this->configurator->configure($output);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function configure(OutputInterface $output): void
] as $scope) {
$this->keycloakManager->createScope($scope);
}

foreach ($this->getAppScopes() as $app => $appScopes) {
foreach ($appScopes as $scope) {
$this->keycloakManager->createScope($scope, [
Expand Down Expand Up @@ -76,6 +77,24 @@ public function configure(OutputInterface $output): void
);
}

if (getenv('INDEXER_DATABOX_CLIENT_ID')) {
$clientData = $this->keycloakManager->createClient(
getenv('INDEXER_DATABOX_CLIENT_ID'),
getenv('INDEXER_DATABOX_CLIENT_SECRET'),
null,
[
'standardFlowEnabled' => false,
'implicitFlowEnabled' => false,
'directAccessGrantsEnabled' => false,
'serviceAccountsEnabled' => true,
],
);

foreach ($this->getAppScopes()['databox'] as $scope) {
$this->keycloakManager->addScopeToClient($scope, $clientData['id']);
}
}

$defaultAdmin = $this->keycloakManager->createUser([
'username' => getenv('DEFAULT_ADMIN_USERNAME'),
'enabled' => true,
Expand Down
5 changes: 4 additions & 1 deletion databox/client/src/components/Root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ export default function Root({}: Props) {
}, []);

return (
<AuthenticationProvider oauthClient={oauthClient} onLogout={onLogout}>
<AuthenticationProvider
oauthClient={oauthClient}
onLogout={onLogout}
>
<MatomoUser/>
<UserPreferencesProvider>
<ModalStack>
Expand Down
14 changes: 12 additions & 2 deletions databox/client/src/components/Routing/RouteProxy.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {MatomoRouteProxy} from '@alchemy/navigation';
import {MatomoRouteProxy, OverlayOutlet} from '@alchemy/navigation';
import type {RouteProxyProps} from '@alchemy/navigation';
import {useAuth, useKeycloakUrls} from '@alchemy/react-auth';
import {keycloakClient} from '../../api/api-client.ts';
import config from '../../config.ts';
import {modalRoutes} from "../../routes.ts";

export default function RouteProxy({
component: Component,
Expand All @@ -21,5 +22,14 @@ export default function RouteProxy({
return <></>;
}

return <MatomoRouteProxy component={Component} {...rest} />;
return <MatomoRouteProxy
component={() => <>
<OverlayOutlet
routes={modalRoutes}
queryParam={'_m'}
/>
<Component/>
</>}
{...rest}
/>;
}
2 changes: 1 addition & 1 deletion databox/indexer/nodemon.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"watch": ["src"],
"ext": ".ts,.js",
"ignore": [],
"exec": "vite build && node ./dist/index.mjs",
"exec": "vite build && node ./dist/console.mjs",
"env": {
"NODE_ENV": "development"
}
Expand Down
5 changes: 4 additions & 1 deletion databox/indexer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
"description": "Consumes S3 events from AMQP and synchronize Databox",
"main": "dist/index.mjs",
"license": "MIT",
"bin": {
"console": "node dist/console.mjs"
},
"scripts": {
"console": "node dist/index.mjs",
"console": "node dist/console.mjs",
"dev": "nodemon",
"build": "rimraf ./dist && vite build",
"test": "jest",
Expand Down
3 changes: 3 additions & 0 deletions databox/indexer/src/command/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {createLogger} from '../lib/logger.js';
import {indexers} from '../indexers.js';
import {getLocation} from '../locations.js';
import {consume} from '../databox/entrypoint.js';
import {runServer} from "../server";

export type IndexOptions = {
createNewWorkspace?: boolean;
Expand All @@ -26,5 +27,7 @@ export default async function indexCommand(
const logger = createLogger(location.name);
const iterator = indexer(location, logger, databoxClient, options);

runServer(mainLogger);

await consume(location, databoxClient, iterator, logger);
}
10 changes: 10 additions & 0 deletions databox/indexer/src/command/list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {getLocations} from '../locations';

export default async function listCommand() {
const locations = getLocations();

Object.entries(locations).forEach(([key, l]) => {
console.log(`${key}:`);
console.log(l);
});
}
11 changes: 10 additions & 1 deletion databox/indexer/src/console.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import {Command} from 'commander';
import indexCommand from './command/index.js';
import listCommand from "./command/list";

const program = new Command();

program.name('list').description('Databox indexer').version('1.0.0');
program
.name('indexer')
.description('Databox Indexer')
.version('1.0.0');

program
.command('index')
Expand All @@ -16,4 +20,9 @@ program
)
.action(indexCommand);

program
.command('list')
.description('List locations')
.action(listCommand);

program.parse();
2 changes: 2 additions & 0 deletions databox/indexer/src/handlers/fs/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export function createAsset(
const p = dirPrefix ? dirPrefix + relativePath : path;
const sourcePath = sourceDir ? sourceDir + relativePath : path;

console.log('generatePublicUrl(p, locationName)', generatePublicUrl(p, locationName));

return {
workspaceId,
key: p,
Expand Down
1 change: 0 additions & 1 deletion databox/indexer/src/index.ts

This file was deleted.

4 changes: 4 additions & 0 deletions databox/indexer/src/locations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ export function getLocation<T extends ConfigOptions = any>(

return location;
}

export function getLocations() {
return locations;
}
2 changes: 1 addition & 1 deletion databox/indexer/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {VitePluginNode} from 'vite-plugin-node';
export default defineConfig({
plugins: [
...VitePluginNode({
appPath: './src/index.ts',
appPath: './src/console.ts',

// Optional, default: 'viteNodeApp'
// the name of named export of you app from the appPath file
Expand Down
19 changes: 19 additions & 0 deletions doc/databox-indexer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Databox Indexer

## Using console

```bash
# Index a location
dc run --rm databox-indexer pnpm build && dc run --rm databox-indexer index <location-name>
# Watch a location
dc run --rm databox-indexer pnpm build && dc run --rm databox-indexer watch <location-name>
# List locations
dc run --rm databox-indexer pnpm build && dc run --rm databox-indexer list
```

## Dev

```bash
dc run --rm databox-indexer bash
node@51341e79df22:/srv/workspace/databox/indexer$ pnpm dev <command-name>
```
7 changes: 0 additions & 7 deletions doc/indexer.md

This file was deleted.

8 changes: 1 addition & 7 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -245,16 +245,10 @@ services:
volumes:
- ./configurator:/usr/app

databox-watcher:
extends:
service: a_client
command: ["pnpm", "start:dev"]
volumes:
- ./databox/indexer:/srv/workspace/databox/indexer

databox-indexer:
extends:
service: a_client
entrypoint: ''
volumes:
- ./databox/indexer:/srv/workspace/databox/indexer

Expand Down
18 changes: 3 additions & 15 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ services:
- "traefik.project_name=${COMPOSE_PROJECT_NAME}"
- "traefik.http.routers.databox-api.rule=Host(`api-databox.${PHRASEA_DOMAIN}`)"

a_indexer:
databox-indexer:
image: ${REGISTRY_NAMESPACE}databox-indexer:${DOCKER_TAG}
command: [ "/bin/sh", "-c", "exit" ]
build:
Expand Down Expand Up @@ -761,20 +761,6 @@ services:
- api-databox.${PHRASEA_DOMAIN}:${PS_GATEWAY_IP}
- minio.${PHRASEA_DOMAIN}:${PS_GATEWAY_IP}
- ${PHRASEANET_DOMAIN}:${PS_GATEWAY_IP}

databox-indexer:
extends:
service: a_indexer
command: [ "/bin/sh", "-c", "exit" ]
environment:
- PHRASEANET_SEARCH_QUERY=${INDEXER_PHRASEANET_SEARCH_QUERY}
- PHRASEANET_SEARCH_ORDER=${INDEXER_PHRASEANET_SEARCH_ORDER}

databox-watcher:
extends:
service: a_indexer
depends_on:
- rabbitmq
labels:
- "traefik.enable=true"
- "traefik.project_name=${COMPOSE_PROJECT_NAME}"
Expand Down Expand Up @@ -1002,6 +988,8 @@ services:
- MAILER_DSN
- DEFAULT_ADMIN_USERNAME
- DEFAULT_ADMIN_PASSWORD
- INDEXER_DATABOX_CLIENT_ID
- INDEXER_DATABOX_CLIENT_SECRET
extra_hosts:
- keycloak.${PHRASEA_DOMAIN}:${PS_GATEWAY_IP}
volumes:
Expand Down
17 changes: 12 additions & 5 deletions lib/js/navigation/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import {
getPath,
compileRoutes
} from './src/Router';
import {compileRoutes, getPath} from './src/Router';
import {getCurrentPath, getFullPath} from "./src/utils";
import RouterProvider from "./src/RouterProvider";
import ModalStack, {StackedModalProps, useModals} from "./src/useModalStack";
import MatomoRouteProxy from "./src/proxy/MatomoRouteProxy";
import {useInRouterDirtyFormPrompt, useOutsideRouterDirtyFormPrompt} from "./src/useNavigationPrompt";
import {NavigateToOverlayFunction, CloseOverlayFunction, useNavigateToOverlay, useCloseOverlay} from "./src/useNavigateToOverlay";
import {
CloseOverlayFunction,
NavigateToOverlayFunction,
useCloseOverlay,
useNavigateToOverlay
} from "./src/useNavigateToOverlay";
import {Link, useLocation, useNavigate, useParams} from "react-router-dom";
import OverlayOutlet from "./src/Overlay/OverlayOutlet";
import {useOverlay} from "./src/Overlay/OverlayContext";

export * from "./src/types";
export {
useOverlay,
OverlayOutlet,
getPath,
compileRoutes,
getCurrentPath,
Expand Down
18 changes: 0 additions & 18 deletions lib/js/navigation/src/Drawer/OverlayRouteContext.ts

This file was deleted.

15 changes: 0 additions & 15 deletions lib/js/navigation/src/Drawer/OverlayRouterContext.ts

This file was deleted.

19 changes: 19 additions & 0 deletions lib/js/navigation/src/Overlay/OverlayContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React, {Context, createContext} from 'react';

export type TOverlayContext = {
close: () => void;
};

const contexts: Record<string, Context<TOverlayContext | undefined>> = {};

export function getOverlayContext(name: string): Context<TOverlayContext | undefined> {
if (contexts[name]) {
return contexts[name];
}

return contexts[name] = createContext<TOverlayContext | undefined>(undefined);
}

export function useOverlay(name: string) {
return React.useContext(getOverlayContext(name));
}
Loading

0 comments on commit fd6c182

Please sign in to comment.