-
Notifications
You must be signed in to change notification settings - Fork 452
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(server-actions): add UI for editing server actions in studio
GitOrigin-RevId: 9683b8caa9c7535416b01f7fb397ad9bc4c1f1c9
- Loading branch information
1 parent
40d5b8a
commit 7b08378
Showing
10 changed files
with
1,120 additions
and
147 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
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
124 changes: 124 additions & 0 deletions
124
platform/wab/src/wab/client/components/sidebar-tabs/ServerQuery/ServerQueryBottomModal.tsx
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,124 @@ | ||
import { useBottomModalActions } from "@/wab/client/components/BottomModal"; | ||
import { DataPickerTypesSchema } from "@/wab/client/components/sidebar-tabs/DataBinding/DataPicker"; | ||
import { ServerQueryOpExprFormAndPreview } from "@/wab/client/components/sidebar-tabs/ServerQuery/ServerQueryOpPicker"; | ||
import { extractDataCtx } from "@/wab/client/state-management/interactions-meta"; | ||
import { ViewCtx } from "@/wab/client/studio-ctx/view-ctx"; | ||
import { ExprCtx } from "@/wab/shared/core/exprs"; | ||
import { EventHandlerKeyType } from "@/wab/shared/core/tpls"; | ||
import { | ||
ComponentServerQuery, | ||
CustomFunctionExpr, | ||
Interaction, | ||
TplNode, | ||
} from "@/wab/shared/model/classes"; | ||
import { observer } from "mobx-react"; | ||
import * as React from "react"; | ||
|
||
interface ServerQueryOpExprBottomModalContentProps { | ||
value?: CustomFunctionExpr; | ||
onSave: (expr: CustomFunctionExpr, opExprName?: string) => unknown; | ||
onCancel: () => unknown; | ||
readOnly?: boolean; | ||
readOpsOnly?: boolean; | ||
env?: Record<string, any>; | ||
allowedOps?: string[]; | ||
livePreview?: boolean; | ||
exprCtx: ExprCtx; | ||
interaction?: Interaction; | ||
viewCtx?: ViewCtx; | ||
tpl?: TplNode; | ||
schema?: DataPickerTypesSchema; | ||
parent?: ComponentServerQuery | TplNode; | ||
eventHandlerKey?: EventHandlerKeyType; | ||
} | ||
|
||
/** For managing a single query modal with a known query key. */ | ||
export function useServerQueryBottomModal(queryKey: string) { | ||
const serverQueryModals = useServerQueryBottomModals(); | ||
return { | ||
open: ( | ||
props: { | ||
title?: string; | ||
} & ServerQueryOpExprBottomModalContentProps | ||
) => { | ||
serverQueryModals.open(queryKey, props); | ||
}, | ||
close: () => { | ||
serverQueryModals.close(queryKey); | ||
}, | ||
}; | ||
} | ||
|
||
/** For managing multiple query modals or an unknown/dynamic query. */ | ||
export function useServerQueryBottomModals() { | ||
// const ctx = useDataSourceOpPickerContext(); | ||
const modalActions = useBottomModalActions(); | ||
return { | ||
open: ( | ||
queryKey: string, | ||
{ | ||
title, | ||
...props | ||
}: { | ||
title?: string; | ||
} & ServerQueryOpExprBottomModalContentProps | ||
) => { | ||
modalActions.open(queryKey, { | ||
title: title || `Configure server query`, | ||
children: <ServerQueryOpExprBottomModalContent {...props} />, | ||
}); | ||
}, | ||
close: (queryKey: string) => { | ||
modalActions.close(queryKey); | ||
}, | ||
}; | ||
} | ||
|
||
const ServerQueryOpExprBottomModalContent = observer( | ||
function ServerQueryOpExprBottomModalContent({ | ||
value, | ||
onSave, | ||
onCancel, | ||
readOnly, | ||
readOpsOnly, | ||
schema, | ||
parent, | ||
allowedOps, | ||
livePreview, | ||
interaction, | ||
exprCtx, | ||
viewCtx, | ||
tpl, | ||
eventHandlerKey, | ||
...rest | ||
}: ServerQueryOpExprBottomModalContentProps) { | ||
const wrappedOnSave = React.useCallback( | ||
(newExpr: CustomFunctionExpr, opExprName?: string) => { | ||
onSave(newExpr, opExprName); | ||
}, | ||
[onSave] | ||
); | ||
|
||
const env = rest.env | ||
? rest.env | ||
: viewCtx && tpl | ||
? extractDataCtx(viewCtx, tpl, undefined, interaction, eventHandlerKey) | ||
: undefined; | ||
|
||
return ( | ||
<ServerQueryOpExprFormAndPreview | ||
value={value} | ||
onSave={wrappedOnSave} | ||
onCancel={onCancel} | ||
env={env} | ||
schema={schema} | ||
parent={parent} | ||
readOnly={readOnly} | ||
readOpsOnly={readOpsOnly} | ||
allowedOps={allowedOps} | ||
exprCtx={exprCtx} | ||
interaction={interaction} | ||
/> | ||
); | ||
} | ||
); |
50 changes: 50 additions & 0 deletions
50
...rm/wab/src/wab/client/components/sidebar-tabs/ServerQuery/ServerQueryOpPicker.module.scss
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,50 @@ | ||
@import "src/wab/styles/tokens"; | ||
@import "../../../../styles/_vars.sass"; | ||
|
||
.trashIcon { | ||
color: $neutral-secondary; | ||
position: absolute; | ||
right: 10px; | ||
top: 50%; | ||
transform: translateY(-50%); | ||
cursor: pointer; | ||
width: 15px; | ||
height: 15px; | ||
|
||
&:hover { | ||
color: $neutral-primary; | ||
} | ||
} | ||
|
||
.stringDictKeyInput { | ||
max-width: 34%; | ||
} | ||
.dataSourceExprValue { | ||
// !important to override `.flex > *` | ||
min-width: 100% !important; | ||
max-width: 4vw; | ||
text-overflow: ellipsis; | ||
} | ||
.container { | ||
user-select: text; | ||
background: #fafafa; | ||
} | ||
|
||
.blueIndicatorContainer { | ||
width: 12px; | ||
height: 12px; | ||
display: grid; | ||
justify-items: center; | ||
align-items: center; | ||
margin-right: 4px; | ||
flex-shrink: 0; | ||
} | ||
|
||
.blueIndicator { | ||
border-radius: 50%; | ||
height: 4px; | ||
width: 4px; | ||
z-index: 10; | ||
box-shadow: 0 0 0 2px white; | ||
background: $indicator-set; | ||
} |
Oops, something went wrong.