Skip to content

Commit

Permalink
reverse card expand (#243)
Browse files Browse the repository at this point in the history
Co-authored-by: Mailn Nifeli Snieske <[email protected]>
  • Loading branch information
malinnsnieske and Mailn Nifeli Snieske authored Jan 21, 2025
1 parent 0251c49 commit 6046f89
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 71 deletions.
3 changes: 1 addition & 2 deletions src/components/delete-function-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Props = {
export function DeleteFunctionModal({ onClose, isOpen, functionId }: Props) {
const { func, removeFunction } = useFunction(functionId);
const navigate = Route.useNavigate();
const { path, flags, filters, expandedCards } = Route.useSearch();
const { path, flags, filters } = Route.useSearch();

return (
<Modal onClose={onClose} isOpen={isOpen} isCentered>
Expand Down Expand Up @@ -62,7 +62,6 @@ export function DeleteFunctionModal({ onClose, isOpen, functionId }: Props) {
: pathString,
) ?? ["1"],
filters,
expandedCards,
flags: flags,
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { MetadataView } from "./metadata/metadata-view";
import { useMetadata } from "@/hooks/use-metadata";
import { Route } from "@/routes";
import { OboFlowFeature } from "../../frisk.config";
import { Stack } from "@kvib/react";
import { Flex, Skeleton, Stack, Text } from "@kvib/react";
import { EditAndSelectButtons } from "./edit-and-select-buttons";

export function FunctionCardExpandableContent({
export function FunctionCardSelectedView({
functionId,
}: { functionId: number }) {
const { func } = useFunction(functionId);
Expand All @@ -14,7 +15,21 @@ export function FunctionCardExpandableContent({
const { flags } = Route.useSearch();

return (
<Stack pl="10px" overflow="hidden">
<Stack pl="10px" w="100%" overflow="hidden">
<Flex alignItems="center" w="100%" flex-wrap="wrap">
<Skeleton isLoaded={!func.isLoading} flex={1} minWidth={0}>
<Text
fontWeight="bold"
as="span"
display="flex"
w="100%"
overflow="hidden"
>
{func.data?.name ?? "<Det skjedde en feil>"}
</Text>
</Skeleton>
<EditAndSelectButtons functionId={functionId} selected />
</Flex>
{config.metadata?.map((meta) => (
<MetadataView key={meta.key} metadata={meta} functionId={functionId} />
))}
Expand Down
87 changes: 28 additions & 59 deletions src/components/function-card.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useFunction } from "@/hooks/use-function";
import { Route } from "@/routes";
import { Card, Flex, IconButton, Skeleton, Stack, Text } from "@kvib/react";
import { Card, Flex, IconButton, Skeleton, Text } from "@kvib/react";
import { FunctionCardEdit } from "./function-card-edit";
import { FunctionCardExpandableContent } from "./function-card-expandable-content";
import { FunctionCardSelectedView } from "./function-card-selected-view";
import { EditAndSelectButtons } from "./edit-and-select-buttons";
import { useEffect, useMemo, useState } from "react";
import { useEffect, useState } from "react";
import { useHasFunctionAccess } from "@/hooks/use-has-function-access";

export function FunctionCard({
Expand All @@ -16,21 +16,6 @@ export function FunctionCard({
const search = Route.useSearch();
const navigate = Route.useNavigate();

const isCardExpanded = useMemo(() => {
return search.expandedCards?.includes(functionId) ?? false;
}, [functionId, search.expandedCards]);

const toggleCardExpanded = () => {
navigate({
search: {
...search,
expandedCards: isCardExpanded
? search.expandedCards?.filter((id) => id !== functionId)
: [...(search.expandedCards ?? []), functionId],
},
});
};

const [bottomMargin, setBottomMargin] = useState(0);

function getParentDistance() {
Expand Down Expand Up @@ -71,7 +56,6 @@ export function FunctionCard({
? [func?.data?.path.slice(0, func?.data?.path.lastIndexOf("."))]
: [`${func?.data?.path}`]),
],
expandedCards: search.expandedCards,
filters: search.filters,
edit: search.edit,
flags: search.flags,
Expand All @@ -90,47 +74,32 @@ export function FunctionCard({
>
{search.edit === functionId && hasAccess ? (
<FunctionCardEdit functionId={functionId} />
) : selected ? (
<FunctionCardSelectedView functionId={functionId} />
) : (
<Stack w="100%">
<Flex alignItems="center" w="100%" flex-wrap="wrap">
<IconButton
type="button"
colorScheme="gray"
variant="ghost"
aria-label="drag"
icon="drag_indicator"
isDisabled={!hasAccess}
/>
<IconButton
colorScheme="gray"
variant="tertiary"
aria-label={isCardExpanded ? "close card" : "expand card"}
icon={isCardExpanded ? "keyboard_arrow_down" : "chevron_right"}
onClick={(e) => {
e.stopPropagation();
toggleCardExpanded();
}}
/>
<Skeleton isLoaded={!func.isLoading} flex="1" minWidth={0}>
<Text
fontWeight="bold"
as="span"
display="flex"
w="100%"
overflow="hidden"
>
{func.data?.name ?? "<Det skjedde en feil>"}
</Text>
</Skeleton>
<EditAndSelectButtons
functionId={functionId}
selected={selected}
/>
</Flex>
{isCardExpanded && (
<FunctionCardExpandableContent functionId={functionId} />
)}
</Stack>
<>
<IconButton
type="button"
colorScheme="gray"
variant="ghost"
aria-label="drag"
icon="drag_indicator"
isDisabled={!hasAccess}
/>

<Skeleton isLoaded={!func.isLoading} flex="1" minWidth={0}>
<Text
fontWeight="bold"
as="span"
display="flex"
w="100%"
overflow="hidden"
>
{func.data?.name ?? "<Det skjedde en feil>"}
</Text>
</Skeleton>
<EditAndSelectButtons functionId={functionId} selected={false} />
</>
)}
</Flex>
</Card>
Expand Down
3 changes: 0 additions & 3 deletions src/components/search-field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,10 @@ export function SearchField() {
}}
onChange={(newFunc: { value: string } | null) => {
if (newFunc) {
const newPath = newFunc.value;
const newId = Number.parseInt(newPath.split(".").pop() ?? "1");
navigate({
search: {
...search,
path: [newFunc.value],
expandedCards: [newId],
},
});
}
Expand Down
3 changes: 0 additions & 3 deletions src/effects/create-and-redirect-effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export function CreateAndRedirectEffect() {
newMetadataKey,
newMetadataValue,
redirect,
expandedCards,
} = Route.useSearch();

const { func } = useFunction(functionId ?? 1);
Expand All @@ -40,7 +39,6 @@ export function CreateAndRedirectEffect() {
search: {
path: path,
flags: flags,
expandedCards: expandedCards,
},
});
}
Expand All @@ -54,7 +52,6 @@ export function CreateAndRedirectEffect() {
path,
flags,
addMetadata,
expandedCards,
navigate,
]);

Expand Down
1 change: 0 additions & 1 deletion src/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const functionSearchSchema = object({
),
["1"],
),
expandedCards: array(number()).optional(),
functionId: number().optional(),
edit: number().optional(),
newMetadataKey: string().optional(),
Expand Down

0 comments on commit 6046f89

Please sign in to comment.