-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New task link from the object details view (#5365)
* update copy buttons * remove id in details list * get description from object instead of schema if possible * add fragment * update mock data * fix hfid * fix component check * update tests * update test * change the details button to keep the help button as it is * update fragment * update node select for filters * update hfid copied value * update name select component * update task filter for node * lint * add fragment
- Loading branch information
Showing
7 changed files
with
266 additions
and
136 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add a new link in the object details button to redirect to the tasks list with a filter for the current object |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import { namespacesState, schemaState } from "@/state/atoms/schema.atom"; | ||
import { useAtomValue } from "jotai"; | ||
import { useEffect } from "react"; | ||
import { useFormContext } from "react-hook-form"; | ||
import { DEFAULT_FORM_FIELD_VALUE } from "./constants"; | ||
import DropdownField from "./fields/dropdown.field"; | ||
import { FormAttributeValue } from "./type"; | ||
import { isRequired } from "./utils/validation"; | ||
|
||
export const NameSelect = () => { | ||
const namespaces = useAtomValue(namespacesState); | ||
const nodes = useAtomValue(schemaState); | ||
|
||
const form = useFormContext(); | ||
const selectedNamespaceField: FormAttributeValue = form.watch("namespace"); | ||
const selectedNameField: FormAttributeValue = form.watch("name"); | ||
|
||
const namespaceOptions = [ | ||
{ | ||
value: "*", | ||
label: "*", | ||
}, | ||
...namespaces.map((namespace) => { | ||
return { | ||
value: namespace.name, | ||
label: namespace.name, | ||
}; | ||
}), | ||
]; | ||
|
||
const selectedNamespace = | ||
selectedNamespaceField?.value === "*" | ||
? { value: "*", name: "*" } | ||
: namespaces | ||
.filter((namespace) => { | ||
if (!selectedNameField?.value) { | ||
return true; | ||
} | ||
|
||
return namespace.used_by?.includes(selectedNameField?.value); | ||
}) | ||
.find((namespace) => { | ||
return namespace.name === selectedNamespaceField?.value; | ||
}); | ||
|
||
const nameOptions = [ | ||
{ | ||
value: "*", | ||
label: "*", | ||
}, | ||
...nodes | ||
.filter((node) => { | ||
if (!selectedNamespace || selectedNamespace?.name === "*") return true; | ||
|
||
return node.namespace === selectedNamespace?.name; | ||
}) | ||
.map((node) => ({ | ||
value: node.name, | ||
label: node.label, | ||
badge: node.namespace, | ||
})), | ||
]; | ||
|
||
useEffect(() => { | ||
// Break if namespace already set | ||
if (selectedNamespaceField?.value) return; | ||
|
||
// Break if no name is provided | ||
if (!selectedNameField?.value) return; | ||
|
||
// Get current node from form field value | ||
const currentNode = nodes.find((node) => node.name === selectedNameField?.value); | ||
if (!currentNode) return; | ||
|
||
form.setValue("namespace", { value: currentNode.namespace, label: currentNode.namespace }); | ||
}, [selectedNameField?.value]); | ||
|
||
return ( | ||
<> | ||
<DropdownField | ||
name={"namespace"} | ||
label="Namespace" | ||
defaultValue={DEFAULT_FORM_FIELD_VALUE} | ||
items={namespaceOptions} | ||
rules={{ validate: { required: isRequired } }} | ||
/> | ||
|
||
<DropdownField | ||
key={selectedNamespaceField?.value} | ||
name={"name"} | ||
label="Name" | ||
defaultValue={DEFAULT_FORM_FIELD_VALUE} | ||
items={nameOptions} | ||
rules={{ validate: { required: isRequired } }} | ||
/> | ||
</> | ||
); | ||
}; |
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,101 @@ | ||
import { namespacesState, schemaState } from "@/state/atoms/schema.atom"; | ||
import { useAtomValue } from "jotai"; | ||
import { useEffect } from "react"; | ||
import { useFormContext } from "react-hook-form"; | ||
import { DEFAULT_FORM_FIELD_VALUE } from "./constants"; | ||
import DropdownField from "./fields/dropdown.field"; | ||
import { FormAttributeValue } from "./type"; | ||
|
||
type NodeSelectProps = { | ||
isRequired?: boolean; | ||
}; | ||
|
||
export const NodeSelect = ({ isRequired }: NodeSelectProps) => { | ||
const namespaces = useAtomValue(namespacesState); | ||
const nodes = useAtomValue(schemaState); | ||
|
||
const form = useFormContext(); | ||
const selectedNamespaceField: FormAttributeValue = form.watch("namespace"); | ||
const selectedNameField: FormAttributeValue = form.watch("name"); | ||
|
||
const namespaceOptions = [ | ||
{ | ||
value: "*", | ||
label: "*", | ||
}, | ||
...namespaces.map((namespace) => { | ||
return { | ||
value: namespace.name, | ||
label: namespace.name, | ||
}; | ||
}), | ||
]; | ||
|
||
const selectedNamespace = | ||
selectedNamespaceField?.value === "*" | ||
? { value: "*", name: "*" } | ||
: namespaces | ||
.filter((namespace) => { | ||
if (!selectedNameField?.value) { | ||
return true; | ||
} | ||
|
||
return namespace.used_by?.includes(selectedNameField?.value); | ||
}) | ||
.find((namespace) => { | ||
return namespace.name === selectedNamespaceField?.value; | ||
}); | ||
|
||
const nameOptions = [ | ||
{ | ||
value: "*", | ||
label: "*", | ||
}, | ||
...nodes | ||
.filter((node) => { | ||
if (!selectedNamespace || selectedNamespace?.name === "*") return true; | ||
|
||
return node.namespace === selectedNamespace?.name; | ||
}) | ||
.map((node) => ({ | ||
value: node.name, | ||
label: node.label, | ||
badge: node.namespace, | ||
})), | ||
]; | ||
|
||
useEffect(() => { | ||
// Break if namespace already set | ||
if (selectedNamespaceField?.value) return; | ||
|
||
// Break if no name is provided | ||
if (!selectedNameField?.value) return; | ||
|
||
// Get current node from form field value | ||
const currentNode = nodes.find((node) => node.name === selectedNameField?.value); | ||
if (!currentNode) return; | ||
|
||
form.setValue("namespace", { value: currentNode.namespace, label: currentNode.namespace }); | ||
}, [selectedNameField?.value]); | ||
|
||
return ( | ||
<> | ||
<DropdownField | ||
name={"namespace"} | ||
label="Namespace" | ||
defaultValue={DEFAULT_FORM_FIELD_VALUE} | ||
items={namespaceOptions} | ||
rules={{ required: true, validate: { required: isRequired } }} | ||
/> | ||
|
||
<DropdownField | ||
key={selectedNamespaceField?.value} | ||
name={"name"} | ||
label="Name" | ||
defaultValue={DEFAULT_FORM_FIELD_VALUE} | ||
items={nameOptions} | ||
rules={{ required: true, validate: { required: isRequired } }} | ||
/> | ||
</> | ||
); | ||
}; |
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
Oops, something went wrong.