Skip to content

Commit

Permalink
Merge branch 'dev' into fix/popupPosition
Browse files Browse the repository at this point in the history
  • Loading branch information
tcsola committed Dec 18, 2024
2 parents bc6eb5d + fe721e2 commit dd6132c
Show file tree
Hide file tree
Showing 8 changed files with 181 additions and 105 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/deploy-extension-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ on:
types: [deploy-extension-dev]

env:
GCS_DEST: gs://plateau-dev-reearth-app-bucket
GCS_DEST_2: gs://plateau-dev-reearth-static-bucket
PLATEAU_ORIGIN: https://static.reearth.plateau.dev.reearth.io/extension
GCS_DEST: gs://plateau-dev-reearth-static-bucket
# used by build
PLATEAU_DEFAULT_GOOGLE_STREETVIEW_TOKEN: ${{ secrets.PLATEAU_DEFAULT_GOOGLE_STREETVIEW_TOKEN }}
# used by build
PLATEAU_ORIGIN: https://static.reearth.plateau.dev.reearth.io/extension

jobs:
deploy_extension:
Expand Down Expand Up @@ -48,8 +49,6 @@ jobs:
run: yarn build
- name: Deploy
run: gsutil -m -h "Cache-Control:no-store" rsync -x "^estat/.*$" -dr dist ${{ env.GCS_DEST }}/extension
- name: Deploy2
run: gsutil -m -h "Cache-Control:no-store" rsync -x "^estat/.*$" -dr dist ${{ env.GCS_DEST_2 }}/extension
- name: Pack extension
run: tar -zcvf plateauview-extension.tar.gz dist
- name: Save as artifact
Expand Down
9 changes: 4 additions & 5 deletions .github/workflows/deploy-extension-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ name: ⭐️ Deploy PLATEAU Extension production
on:
workflow_dispatch:
env:
GCS_DEST: gs://plateau-prod-reearth-app-bucket
GCS_DEST_2: gs://plateau-prod-reearth-static-bucket
PLATEAU_ORIGIN: https://static.reearth.plateau.reearth.io/extension
GCS_DEST: gs://plateau-prod-reearth-static-bucket
# used by build
PLATEAU_DEFAULT_GOOGLE_STREETVIEW_TOKEN: ${{ secrets.PLATEAU_DEFAULT_GOOGLE_STREETVIEW_TOKEN }}
# used by build
PLATEAU_ORIGIN: https://static.reearth.plateau.reearth.io/extension

jobs:
deploy_extension:
Expand Down Expand Up @@ -43,8 +44,6 @@ jobs:
run: yarn build
- name: Deploy
run: gsutil -m -h "Cache-Control:no-store" rsync -x "^estat/.*$" -dr dist ${{ env.GCS_DEST }}/extension
- name: Deploy2
run: gsutil -m -h "Cache-Control:no-store" rsync -x "^estat/.*$" -dr dist ${{ env.GCS_DEST_2 }}/extension
- name: Pack extension
run: tar -zcvf plateauview-extension.tar.gz dist
- name: Save as artifact
Expand Down
40 changes: 27 additions & 13 deletions extension/src/prototypes/view/ui-containers/DatasetTreeSelect.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Typography, type SelectChangeEvent } from "@mui/material";
import { atom, useAtom, useAtomValue, useSetAtom, type Getter, type SetStateAction } from "jotai";
import { atom, useAtom, useAtomValue, useSetAtom, type SetStateAction } from "jotai";
import { differenceBy, groupBy } from "lodash";
import { memo, useCallback, useMemo, type FC } from "react";
import invariant from "tiny-invariant";
Expand All @@ -22,10 +22,15 @@ interface Params {
datumId: string;
}

function createParamsArray(get: Getter, layers: readonly RootLayerConfigForDataset[]): Params[] {
type DefaultDataIdOfDatasetMap = { [K in string]: string | undefined };

function createParamsArray(
layers: readonly RootLayerConfigForDataset[],
defaultDataIdOfDatasetMap: DefaultDataIdOfDatasetMap,
): Params[] {
return layers
.map(({ id, currentDataIdAtom }) => {
const datumId = get(currentDataIdAtom);
.map(({ id }) => {
const datumId = defaultDataIdOfDatasetMap[id];
return datumId != null ? { datasetId: id, datumId } : undefined;
})
.filter(isNotNullish);
Expand All @@ -48,6 +53,7 @@ export interface DatasetTreeSelectProps {
allowContinuousAdd?: boolean;
}

// This component just shows only datasets, not dataset's items.
export const DatasetTreeSelect: FC<DatasetTreeSelectProps> = memo(
({ datasets, municipalityCode, disabled, label, allowContinuousAdd }) => {
invariant(datasets.length > 0);
Expand All @@ -56,6 +62,15 @@ export const DatasetTreeSelect: FC<DatasetTreeSelectProps> = memo(
const templates = useAtomValue(templatesAtom);

const datasetIds = useMemo(() => datasets.map(d => d.id), [datasets]);
// This component just shows only datasets, so datumId should be first one always even if actual datumId is different.
const defaultDataIdOfDatasetMap = useMemo(
() =>
datasets.reduce(
(r, d) => ({ ...r, [d.id]: d.items[0]?.id }),
{} as DefaultDataIdOfDatasetMap,
),
[datasets],
);

const filteredRootLayers = useMemo(
() =>
Expand All @@ -69,20 +84,18 @@ export const DatasetTreeSelect: FC<DatasetTreeSelectProps> = memo(
const removeLayer = useSetAtom(removeLayerAtom);
const paramsAtom = useMemo(() => {
return atom(
get => createParamsArray(get, filteredRootLayers),
(get, set, dataIds: SetStateAction<Params[]>) => {
const prevParams = createParamsArray(get, filteredRootLayers);
() => createParamsArray(filteredRootLayers, defaultDataIdOfDatasetMap),
(_get, set, dataIds: SetStateAction<Params[]>) => {
const prevParams = createParamsArray(filteredRootLayers, defaultDataIdOfDatasetMap);
const nextParams = typeof dataIds === "function" ? dataIds(prevParams) : dataIds;

const paramsToRemove = differenceBy(prevParams, nextParams, ({ datasetId }) => datasetId);
const paramsToAdd = differenceBy(nextParams, prevParams, ({ datasetId }) => datasetId);
const paramsToUpdate = nextParams.filter(({ datasetId, datumId }) =>
prevParams.some(params => params.datasetId === datasetId && params.datumId !== datumId),
const paramsToUpdate = nextParams.filter(({ datasetId }) =>
prevParams.some(params => params.datasetId === datasetId),
);
paramsToRemove.forEach(({ datumId }) => {
const layer = filteredRootLayers.find(
({ currentDataIdAtom }) => get(currentDataIdAtom) === datumId,
);
paramsToRemove.forEach(({ datasetId }) => {
const layer = filteredRootLayers.find(({ id }) => id === datasetId);
invariant(layer != null);
removeLayer(layer.id);
});
Expand Down Expand Up @@ -117,6 +130,7 @@ export const DatasetTreeSelect: FC<DatasetTreeSelectProps> = memo(
removeLayer,
settings,
templates,
defaultDataIdOfDatasetMap,
]);

const [params, setParams] = useAtom(paramsAtom);
Expand Down
17 changes: 2 additions & 15 deletions server/citygml/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/xml"
"fmt"
"io"
"net/http"
"slices"
"strconv"
"strings"
Expand Down Expand Up @@ -428,19 +427,7 @@ func init() {
initSchema()
}

func Attributes(c *http.Client, url string, gmlID []string) ([]map[string]any, error) {
resp, err := c.Get(url)
if err != nil {
return nil, fmt.Errorf("fetch: %w", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("unexpected status: %d", resp.StatusCode)
}
return attribute(resp.Body, gmlID)
}

func attribute(r io.Reader, gmlID []string) ([]map[string]any, error) {
func Attributes(r io.Reader, gmlID []string) ([]map[string]any, error) {
ae := attributeExtractor{
dec: xmlb.NewDecoder(r, make([]byte, 32*1024)),
}
Expand All @@ -465,7 +452,7 @@ func attribute(r io.Reader, gmlID []string) ([]map[string]any, error) {
id := ae.gmlID(el.Attr)
if slices.Contains(gmlID, id) {
val := map[string]any{
"gml:id": gmlID,
"gml:id": id,
"feature_type": tagName(el.Name),
}
h := toTagHandler(tagName(el.Name), schemaDefs)
Expand Down
81 changes: 39 additions & 42 deletions server/citygml/attributes_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package citygml

import (
"encoding/json"
"net/http"
"net/http/httptest"
"net/url"
"os"
"strings"
"testing"

"github.com/jarcoal/httpmock"
Expand All @@ -13,68 +15,63 @@ import (
"github.com/stretchr/testify/require"
)

func TestAttributes(t *testing.T) {
const testdata = "52382287_bldg_6697_psc_op.gml"
ids := []string{"bldg_53e2a9a9-d512-408f-8250-eae30b7523d6"}
expected := []map[string]any{
{
"bldg:measuredHeight": 14.3,
"bldg:measuredHeight_uom": "m",
"feature_type": "bldg:Building",
"gen:genericAttribute": []any{
map[string]any{
"name": "風致地区",
"type": "string",
"value": "第1種風致地区(大崩)",
},
const testdata = "52382287_bldg_6697_psc_op.gml"

var ids = []string{"bldg_53e2a9a9-d512-408f-8250-eae30b7523d6"}
var expected = []map[string]any{
{
"bldg:measuredHeight": 14.3,
"bldg:measuredHeight_uom": "m",
"feature_type": "bldg:Building",
"gen:genericAttribute": []any{
map[string]any{
"name": "風致地区",
"type": "string",
"value": "第1種風致地区(大崩)",
},
"gml:id": []string{"bldg_53e2a9a9-d512-408f-8250-eae30b7523d6"},
"uro:buildingDataQualityAttribute": []any{map[string]any{}},
},
}
"gml:id": "bldg_53e2a9a9-d512-408f-8250-eae30b7523d6",
"uro:buildingDataQualityAttribute": []any{map[string]any{}},
},
}

citygml, err := os.ReadFile("testdata/" + testdata)
func TestAttributes(t *testing.T) {
citygml, err := os.Open("testdata/" + testdata)
require.NoError(t, err)
defer citygml.Close()

const citygmlURL = "http://example.com/test.gml"
httpmock.RegisterResponder("GET", citygmlURL, httpmock.NewBytesResponder(http.StatusOK, citygml))

httpmock.Activate()
defer httpmock.DeactivateAndReset()

attrs, err := Attributes(http.DefaultClient, citygmlURL, ids)

attrs, err := Attributes(citygml, ids)
assert.NoError(t, err)
assert.Equal(t, 1, len(attrs))
assert.Equal(t, []string{ids[0]}, attrs[0]["gml:id"])
assert.Equal(t, ids[0], attrs[0]["gml:id"])
assert.Equal(t, expected, attrs)
}

func TestAttributesAPI(t *testing.T) {
const citygmlURL = ""
const id = ""

if citygmlURL == "" || id == "" {
t.Skip("skipping test; citygmlURL or ids not set")
}
func TestAttributesHandler(t *testing.T) {
citygmlURL := "http://example.com/citygml.gml"
citygml, err := os.ReadFile("testdata/" + testdata)
require.NoError(t, err)

e := echo.New()
require.NoError(t, Echo(PackerConfig{}, e.Group("")))
httpmock.RegisterResponder(http.MethodGet, citygmlURL, httpmock.NewBytesResponder(http.StatusOK, citygml))
httpmock.Activate()
defer httpmock.Deactivate()

u := &url.URL{Path: "/attributes"}
q := url.Values{}
q.Set("url", citygmlURL)
q.Set("id", id)
q.Set("id", strings.Join(ids, ","))
u.RawQuery = q.Encode()

t.Logf("GET %s", u.String())
req := httptest.NewRequest(http.MethodGet, u.String(), nil)
rec := httptest.NewRecorder()
e.ServeHTTP(rec, req)
e := echo.New()
c := e.NewContext(req, rec)
assert.NoError(t, attributeHandler("")(c))

assert.Equal(t, http.StatusOK, rec.Code)
assert.Equal(t, "application/json; charset=UTF-8", rec.Header().Get(echo.HeaderContentType))
body := rec.Body.String()
assert.NotEmpty(t, body)
t.Logf("%s", body)

var j []map[string]any
assert.NoError(t, json.Unmarshal(rec.Body.Bytes(), &j))
assert.Equal(t, expected, j)
}
Loading

0 comments on commit dd6132c

Please sign in to comment.