This repository was archived by the owner on Jun 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathDefinition.tsx
More file actions
42 lines (37 loc) · 1.45 KB
/
Definition.tsx
File metadata and controls
42 lines (37 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { Generable } from '@circleci/circleci-config-sdk/dist/src/lib/Components';
import ComponentMapping from '../../mappings/ComponentMapping';
import { useStoreActions } from '../../state/Hooks';
import { InspectorDefinitionMenuNav } from '../menus/definitions/InspectorDefinitionMenu';
const Definition = (props: { data: Generable; type: ComponentMapping }) => {
const Summary = props.type.components.summary;
const navigateTo = useStoreActions((actions) => actions.navigateTo);
const setDragging = useStoreActions((actions) => actions.setDragging);
return (
<button
className="w-full mb-2 p-2 text-sm cursor-pointer text-left text-circle-black
bg-white border border-circle-gray-300 rounded-md2"
draggable="true"
onDragStart={(e) => {
const type = props.type;
if (type?.dragTarget) {
setDragging({ dataType: type, data: props.data });
}
}}
onClick={(e) => {
// this generated object should always have a single key
const generated = props.data.generate() as { [key: string]: object };
const flattened = Object.entries(generated).map(([key, value]) => ({
name: key,
...value,
}))[0];
navigateTo({
component: InspectorDefinitionMenuNav,
props: { editing: true, values: flattened, dataType: props.type },
});
}}
>
<Summary data={props.data} />
</button>
);
};
export default Definition;