Skip to content

Commit

Permalink
Merge branch 'main' into feat(web)-plugin-playground-presets-add-geojson
Browse files Browse the repository at this point in the history
  • Loading branch information
airslice committed Jan 16, 2025
2 parents db38003 + 1e41e1c commit a7dd8bf
Show file tree
Hide file tree
Showing 45 changed files with 2,745 additions and 1,194 deletions.
4 changes: 3 additions & 1 deletion server/.env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# General
PORT=8080
REEARTH_DB=mongodb://localhost
REEARTH_DB=mongodb://localhost # for reearth database url
REEARTH_DB_ACCOUNT=reearth_account # for reearth account database name
REEARTH_DB_VIS=reearth # for reearth visualizer database name
REEARTH_HOST=https://localhost:8080
REEARTH_HOST_WEB=https://localhost:3000
REEARTH_ASSETBASEURL=https://localhost:8080/assets
Expand Down
3 changes: 2 additions & 1 deletion server/internal/app/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ type Config struct {
Host_Web string `pp:",omitempty"`
Dev bool `pp:",omitempty"`
DB string `default:"mongodb://localhost"`
DB_Account string `pp:",omitempty"`
DB_Account string `default:"reearth_account" pp:",omitempty"`
DB_Users []appx.NamedURI `pp:",omitempty"`
DB_Vis string `default:"reearth" pp:",omitempty"`
GraphQL GraphQLConfig `pp:",omitempty"`
Published PublishedConfig `pp:",omitempty"`
GCPProject string `envconfig:"GOOGLE_CLOUD_PROJECT" pp:",omitempty"`
Expand Down
66 changes: 36 additions & 30 deletions server/internal/app/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,9 @@ import (
"go.opentelemetry.io/contrib/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo"
)

const databaseName = "reearth"

func initReposAndGateways(ctx context.Context, conf *config.Config, debug bool) (*repo.Container, *gateway.Container, *accountrepo.Container, *accountgateway.Container) {
gateways := &gateway.Container{}
acGateways := &accountgateway.Container{}

// Mongo
client, err := mongo.Connect(
ctx,
options.Client().
ApplyURI(conf.DB).
SetMonitor(otelmongo.NewMonitor()),
)
if err != nil {
log.Fatalf("mongo error: %+v\n", err)
}

// repos
func initAccountDatabase(client *mongo.Client, txAvailable bool, ctx context.Context, conf *config.Config) *accountrepo.Container {
accountDatabase := conf.DB_Account
accountRepoCompat := false
if accountDatabase == "" {
accountDatabase = databaseName
accountRepoCompat = true
}
log.Infof("accountDatabase: %s", accountDatabase)

accountUsers := make([]accountrepo.User, 0, len(conf.DB_Users))
for _, u := range conf.DB_Users {
Expand All @@ -59,17 +38,44 @@ func initReposAndGateways(ctx context.Context, conf *config.Config, debug bool)
accountUsers = append(accountUsers, accountmongo.NewUserWithHost(mongox.NewClient(accountDatabase, c), u.Name))
}

txAvailable := mongox.IsTransactionAvailable(conf.DB)
// this flag is for old database structure compatibility
// on this service, it is always false
useLegacyStructure := false
accountRepos, err := accountmongo.New(ctx, client, accountDatabase, txAvailable, useLegacyStructure, accountUsers)
if err != nil {
log.Fatalf("Failed to init mongo database account: %+v\n", err)
}
return accountRepos
}

accountRepos, err := accountmongo.New(ctx, client, accountDatabase, txAvailable, accountRepoCompat, accountUsers)
func initVisDatabase(client *mongo.Client, txAvailable bool, accountRepos *accountrepo.Container, ctx context.Context, conf *config.Config) *repo.Container {
visDatabase := conf.DB_Vis
log.Infof("visDatabase: %s", visDatabase)

repos, err := mongorepo.NewWithExtensions(ctx, client.Database(visDatabase), accountRepos, txAvailable, conf.Ext_Plugin)
if err != nil {
log.Fatalf("Failed to init mongo: %+v\n", err)
log.Fatalf("Failed to init mongo database visualizer: %+v\n", err)
}
return repos
}

func initReposAndGateways(ctx context.Context, conf *config.Config, debug bool) (*repo.Container, *gateway.Container, *accountrepo.Container, *accountgateway.Container) {
gateways := &gateway.Container{}
acGateways := &accountgateway.Container{}

repos, err := mongorepo.NewWithExtensions(ctx, client.Database(databaseName), accountRepos, txAvailable, conf.Ext_Plugin)
// Mongo
client, err := mongo.Connect(
ctx,
options.Client().
ApplyURI(conf.DB).
SetMonitor(otelmongo.NewMonitor()),
)
if err != nil {
log.Fatalf("Failed to init mongo: %+v\n", err)
log.Fatalf("mongo error: %+v\n", err)
}
txAvailable := mongox.IsTransactionAvailable(conf.DB)
accountRepos := initAccountDatabase(client, txAvailable, ctx, conf)
visRepos := initVisDatabase(client, txAvailable, accountRepos, ctx, conf)

// File
gateways.File = initFile(ctx, conf)
Expand All @@ -92,11 +98,11 @@ func initReposAndGateways(ctx context.Context, conf *config.Config, debug bool)
}

// release lock of all scenes
if err := repos.SceneLock.ReleaseAllLock(context.Background()); err != nil {
if err := visRepos.SceneLock.ReleaseAllLock(context.Background()); err != nil {
log.Fatalf("repo initialization error: %v", err)
}

return repos, gateways, accountRepos, acGateways
return visRepos, gateways, accountRepos, acGateways
}

func initFile(ctx context.Context, conf *config.Config) (fileRepo gateway.File) {
Expand Down
17 changes: 17 additions & 0 deletions server/pkg/builtin/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2349,6 +2349,23 @@ extensions:
label: Light
- key: dark
label: Dark
- id: languageSetting
title: Language Setting
fields:
- id: language
type: string
title: Language
defaultValue: auto
choices:
- key: auto
label: Auto
- key: en
label: English
- key: ja
label: Japanese
- key: cn
label: Chinese

- id: story
name: Story
type: story
Expand Down
29 changes: 29 additions & 0 deletions server/pkg/builtin/manifest_ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1426,4 +1426,33 @@ extensions:
url:
title: リンクURL

googleMapSearch:
name: Googleマップ検索(実験版)
description: Googleマップを利用して地図上の場所を検索できるウィジェット
propertySchema:
default:
title: Googleマップ検索ウィジェット
fields:
apiToken:
title: APIトークン
description: Google Maps APIキー
appearance:
title: 外観
fields:
theme:
title: テーマ
choices:
light: 明るい
dark: 暗い
languageSetting:
title: 言語設定
fields:
language:
title: 言語
choices:
auto: 自動
en: 英語
ja: 日本語
cn: 中国語


6 changes: 4 additions & 2 deletions web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@reearth/visualizer",
"version": "1.0.0-beta.1.0",
"version": "1.0.0-beta.2.0",
"repository": "https://github.com/reearth/reearth-visualizer.git",
"author": "Re:Earth contributors <[email protected]>",
"license": "Apache-2.0",
Expand Down Expand Up @@ -113,6 +113,7 @@
"@emotion/styled": "11.11.0",
"@floating-ui/dom": "1.6.10",
"@floating-ui/react": "0.24.7",
"@googlemaps/js-api-loader": "1.16.8",
"@graphiql/toolkit": "0.11.0",
"@lexical/code": "0.12.0",
"@lexical/hashtag": "0.12.0",
Expand All @@ -128,10 +129,11 @@
"@monaco-editor/react": "4.6.0",
"@popperjs/core": "2.11.8",
"@radix-ui/react-slot": "1.1.0",
"@reearth/core": "0.0.7-alpha.23",
"@reearth/core": "0.0.7-alpha.26",
"@rot1024/use-transition": "1.0.0",
"@sentry/browser": "7.77.0",
"@seznam/compose-react-refs": "1.0.6",
"@types/google.maps": "3.58.1",
"@ungap/event-target": "0.2.4",
"apollo-link-sentry": "3.2.3",
"apollo-upload-client": "18.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ const PresetLayerStyle: FC<PresetLayerStyleProps> = ({
]
},
{
id: "geometry",
title: "Geometry",
id: "geojson",
title: "GeoJSON",
icon: "folderSimple",
subItem: [
{
Expand Down
70 changes: 50 additions & 20 deletions web/src/beta/features/Editor/hooks/useLayers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,31 @@ export default function ({
useAddNLSLayerSimple,
useRemoveNLSLayer,
useUpdateNLSLayer,
useUpdateNLSLayers,
useUpdateCustomProperties
} = useLayersFetcher();

const { nlsLayers: originNlsLayers } = useGetLayersQuery({ sceneId });

// TODO: support by gql mutation
const [sortedLayerIds, setSortedLayerIds] = useState<string[]>([]);

useEffect(() => {
if (!originNlsLayers) return;
setSortedLayerIds((prev) =>
prev.length > 0 ? prev : originNlsLayers.map((l) => l.id)
);
}, [originNlsLayers]);
useEffect(() => {
if (!originNlsLayers) return;

setSortedLayerIds((prev) => {
const originIds = originNlsLayers.map((l) => l.id);
if (
prev.length === originIds.length &&
prev.every((id, idx) => id === originIds[idx])
) {
return prev;
}
return [...originNlsLayers]
.sort((a, b) => (a.index ?? 0) - (b.index ?? 0))
.map((l) => l.id);
});
}, [originNlsLayers]);


const nlsLayers: NLSLayer[] = useMemo(
() =>
Expand Down Expand Up @@ -185,17 +196,25 @@ export default function ({

const handleLayerAdd = useCallback(
async (inp: LayerAddProps) => {
const maxIndex: number = nlsLayers.reduce(
(max: number, layer: NLSLayer) =>
layer.index != null ? Math.max(max, layer.index) : max,
-1
);

const nextIndex = maxIndex + 1;

await useAddNLSLayerSimple({
sceneId: inp.sceneId,
config: inp.config,
visible: inp.visible,
layerType: inp.layerType,
title: t(inp.title),
index: inp.index,
index: nextIndex,
schema: inp.schema
});
},
[t, useAddNLSLayerSimple]
[nlsLayers, t, useAddNLSLayerSimple]
);

const handleLayerNameUpdate = useCallback(
Expand Down Expand Up @@ -242,18 +261,29 @@ export default function ({
});
}, [nlsLayers]);

// TODO: support by gql mutation
const handleLayerMove = useCallback((inp: LayerMoveProps) => {
setSortedLayerIds((prev) => {
const newSortedLayerIds = [...prev];
const index = newSortedLayerIds.indexOf(inp.layerId);
if (index !== -1) {
newSortedLayerIds.splice(index, 1);
newSortedLayerIds.splice(inp.index, 0, inp.layerId);
const handleLayerMove = useCallback(
async (inp: LayerMoveProps) => {
if (!originNlsLayers) return;

const updatedLayerIds = [...sortedLayerIds];
const currentIndex = updatedLayerIds.indexOf(inp.layerId);
if (currentIndex !== -1) {
const [movedItem] = updatedLayerIds.splice(currentIndex, 1);
updatedLayerIds.splice(inp.index, 0, movedItem);
}
return newSortedLayerIds;
});
}, []);
setSortedLayerIds(updatedLayerIds);

const layersInput = {
layers: updatedLayerIds.map((layerId, i) => ({
layerId,
index: i
}))
};

await useUpdateNLSLayers(layersInput);
},
[originNlsLayers, sortedLayerIds, useUpdateNLSLayers]
);

const handleCustomPropertySchemaClick = useCallback((id?: string) => {
if (!id) return;
Expand Down
Loading

0 comments on commit a7dd8bf

Please sign in to comment.