Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(web): ENG-503 wire up the func editor to the router #1238

Merged
merged 1 commit into from
Aug 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions app/web/src/organisms/Workspace/WorkspaceLab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<ChangeSetPanel class="border-b-2 dark:border-neutral-500 mb-2" />
<FuncPicker
:func-list="funcList"
:selected-func-id="selectedFunc.id"
:selected-func-id="selectedFuncId"
@selected-func="selectFunc"
@create-func="createFunc"
/>
Expand All @@ -19,8 +19,8 @@
class="grow overflow-x-hidden overflow-y-hidden dark:bg-neutral-800 dark:text-white text-lg font-semi-bold px-2 pt-2 flex flex-col"
>
<FuncEditorTabs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be a little annoying, but if you can set this up to use RouterLink components (from vue-router) then it will enable right click to open in a new tab.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yeah that's a good call

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't make that happen until this tailwindlabs/headlessui#1680 fix gets bundled into a release for headless UI (or we could pull headless ui directly from github instead of the npm package). It's the source of a few glitches in the app currently that I was very confused about until I realized that the tab group is not in fact acting as a controlled component.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah shoot. Headless ui is pretty neat and useful in some places, but definitely causes some problems in others… might want to ditch it for tabs in favor of something we build.

v-if="selectedFunc.id > 0"
:selected-func-id="selectedFunc.id"
v-if="selectedFuncId > 0"
:selected-func-id="selectedFuncId"
@selected-func="selectFunc"
/>
<div
Expand All @@ -39,13 +39,14 @@
:min-resize="200"
>
<!-- if hiding is added later, condition is selectedFuncId < 1 -->
<FuncDetails :func-id="selectedFunc.id" />
<FuncDetails :func-id="selectedFuncId" />
</SiPanel>
</div>
</template>

<script lang="ts" setup>
import { ref } from "vue";
import { ref, computed } from "vue";
import { useRoute, useRouter } from "vue-router";
import { refFrom } from "vuse-rx/src";
import { bufferTime } from "rxjs/operators";
import SiPanel from "@/atoms/SiPanel.vue";
Expand All @@ -64,9 +65,25 @@ import { visibility$ } from "@/observable/visibility";
import { saveFuncToBackend$ } from "@/observable/func";
import { clearFuncs } from "../FuncEditor/func_state";

const props = defineProps<{ funcId?: string }>();

const selectedFuncId = computed(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one more thing - in the past I've set up a router hook/guard to automatically cast the props numbers where appropriate. Just removes some annoying code on routes where we are using it...

router.beforeEach(async (to, from, next) => {
  // automatically cast any integer params into proper integers
  // so that components can set params to expect a Number
  // NOTE - this is so that when we user router link or programatically navigate
  // that we can set the param as an int
  if (to.params) {
    const castNumericParams = _.mapValues(to.params, (val) => {
      if (parseInt(val).toString() === val) return parseInt(val);
      return val;
    });
    if (_.isEqual(castNumericParams, to.params)) return next();
    return next({
      ...to,
      params: castNumericParams,
    });
  }

  return next();
});

const funcId = parseInt(props.funcId ?? "");
if (Number.isNaN(funcId)) {
return -1;
}
return funcId;
});

const router = useRouter();
const route = useRoute();

const routeToFunction = (funcId?: number) =>
router.push(`/w/${route.params.workspaceId}/l/${funcId ?? ""}`);

const selectedFunc = ref<ListedFuncView>(nullListFunc);
const selectFunc = (func: ListedFuncView) => {
selectedFunc.value = func;
routeToFunction(func.id);
};

const funcList = refFrom<ListFuncsResponse>(FuncService.listFuncs(), {
Expand All @@ -90,7 +107,7 @@ const createFunc = async () => {

visibility$.subscribe(() => {
clearFuncs();
selectFunc(nullListFunc);
routeToFunction();
});

saveFuncToBackend$
Expand Down
3 changes: 2 additions & 1 deletion app/web/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ const routes: RouteRecordRaw[] = [
component: WorkspaceCompose,
},
{
path: "l",
path: "l/:funcId?",
name: "workspace-lab",
component: WorkspaceLab,
props: true,
},
{
path: "v",
Expand Down