Skip to content

Commit

Permalink
Merge branch 'refactor/error_handling_be' into refactor/error_handlin…
Browse files Browse the repository at this point in the history
…g_fe
  • Loading branch information
soneda-yuya committed Jan 10, 2025
2 parents 313b0a5 + e26ddec commit c8f2686
Show file tree
Hide file tree
Showing 31 changed files with 1,954 additions and 1,067 deletions.
2 changes: 1 addition & 1 deletion server/e2e/gql_storytelling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ func TestStoryPageCRUD(t *testing.T) {
res.Object().
Value("errors").Array().
Element(0).Object().
ValueEqual("message", "input: updateStoryPage page not found")
ValueEqual("message", "page not found")

_, _, pageID2 := createPage(e, sID, storyID, "test 2", true)
_, _, pageID3 := createPage(e, sID, storyID, "test 3", false)
Expand Down
11 changes: 5 additions & 6 deletions server/e2e/gql_workspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestDeleteTeam(t *testing.T) {
}
o = Request(e, uId1.String(), request).Object()

o.Value("errors").Array().First().Object().Value("message").Equal("input: deleteTeam operation denied")
o.Value("errors").Array().First().Object().Value("message").Equal("operation denied")
}

func TestUpdateTeam(t *testing.T) {
Expand All @@ -67,7 +67,7 @@ func TestUpdateTeam(t *testing.T) {
Query: query,
}
o = Request(e, uId1.String(), request).Object()
o.Value("errors").Array().First().Object().Value("message").Equal("input: updateTeam not found")
o.Value("errors").Array().First().Object().Value("message").Equal("not found")
}

func TestAddMemberToTeam(t *testing.T) {
Expand All @@ -93,7 +93,7 @@ func TestAddMemberToTeam(t *testing.T) {
Query: query,
}
Request(e, uId1.String(), request).Object().
Value("errors").Array().First().Object().Value("message").Equal("input: addMemberToTeam user already joined")
Value("errors").Array().First().Object().Value("message").Equal("user already joined")
}

func TestRemoveMemberFromTeam(t *testing.T) {
Expand All @@ -114,7 +114,7 @@ func TestRemoveMemberFromTeam(t *testing.T) {
assert.False(t, w.Members().HasUser(uId3))

o := Request(e, uId1.String(), request).Object()
o.Value("errors").Array().First().Object().Value("message").Equal("input: removeMemberFromTeam target user does not exist in the workspace")
o.Value("errors").Array().First().Object().Value("message").Equal("target user does not exist in the workspace")
}

func TestUpdateMemberOfTeam(t *testing.T) {
Expand All @@ -128,7 +128,6 @@ func TestUpdateMemberOfTeam(t *testing.T) {
Query: query,
}
Request(e, uId1.String(), request)

w, err = r.Workspace.FindByID(context.Background(), wId2)
assert.Nil(t, err)
assert.Equal(t, w.Members().User(uId3).Role, workspace.RoleWriter)
Expand All @@ -138,5 +137,5 @@ func TestUpdateMemberOfTeam(t *testing.T) {
Query: query,
}
o := Request(e, uId1.String(), request).Object()
o.Value("errors").Array().First().Object().Value("message").Equal("input: updateMemberOfTeam operation denied")
o.Value("errors").Array().First().Object().Value("message").Equal("operation denied")
}
5 changes: 5 additions & 0 deletions server/internal/app/graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ func GraphqlAPI(conf config.GraphQLConfig, dev bool) echo.HandlerFunc {
} else {
systemError = e.Error()
}

if graphqlErr.Extensions == nil {
graphqlErr.Extensions = make(map[string]interface{})
}

graphqlErr.Extensions["system_error"] = systemError

return graphqlErr
Expand Down
2 changes: 1 addition & 1 deletion web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
"@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",
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
53 changes: 38 additions & 15 deletions web/src/beta/features/Editor/hooks/useLayers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,22 @@ 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)
prev.length > 0
? prev
: [...originNlsLayers]
.sort((a, b) => (a.index ?? 0) - (b.index ?? 0))
.map((l) => l.id)
);
}, [originNlsLayers]);

Expand Down Expand Up @@ -185,17 +189,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 +254,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
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { PluginType } from "../constants";

import { myPlugin } from "./custom/myPlugin";
import { header } from "./ui/header";
import { responsivePanel } from "./ui/responsivePanel";
import { sidebar } from "./ui/sidebar";

Expand All @@ -21,6 +22,6 @@ export const presetPlugins: PresetPlugins = [
{
id: "ui",
title: "UI",
plugins: [responsivePanel, sidebar]
plugins: [responsivePanel, sidebar, header]
}
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { FileType, PluginType } from "../../constants";
import { PRESET_PLUGIN_COMMON_STYLE } from "../common";

const yamlFile: FileType = {
id: "ui-header-reearth-yml",
title: "reearth.yml",
sourceCode: `id: header-plugin
name: Header
version: 1.0.0
extensions:
- id: header
type: widget
name: Header Widget
description: Header Widget
widgetLayout:
extended: true
defaultLocation:
zone: outer
section: center
area: top
`,
disableEdit: true,
disableDelete: true
};

const widgetFile: FileType = {
id: "ui-header-widget",
title: "header.js",
sourceCode: `reearth.ui.show(\`
${PRESET_PLUGIN_COMMON_STYLE}
<style>
.header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px 16px;
position: sticky;
top: 0;
}
.header-logo img {
height: 40px;
cursor: pointer;
}
.header-menu {
list-style: none;
display: flex;
gap: 15px;
margin: 0;
padding: 0;
}
.header-menu li {
font-size: 14px;
color: #555;
cursor: pointer;
transition: color 0.3s ease;
}
.header-menu li:active {
color: #000;
}
</style>
<div id="wrapper">
<div class="header">
<div class="header-logo">
<p>Re:Earth</p>
</div>
<ul class="header-menu">
<li>Home</li>
<li>About</li>
<li>Services</li>
<li>Contact</li>
<li>FAQ</li>
</ul>
</div>
</div>
\`); `
};

export const header: PluginType = {
id: "header",
title: "Header",
files: [widgetFile, yamlFile]
};
Loading

0 comments on commit c8f2686

Please sign in to comment.