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

fix: enable display method selection for schemas with default values #886

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
37 changes: 14 additions & 23 deletions ui/src/components/credentials/IssueCredentialForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,17 @@ export function IssueCredentialForm({

const [inputErrors, setInputErrors] = useState<InputErrors>();

const [refreshServiceChecked, setRefreshServiceChecked] = useState(
initialValues.refreshService.enabled
);
const [displayMethodChecked, setDisplayMethodChecked] = useState(
initialValues.displayMethod.enabled
);
const displayMethodChecked =
Form.useWatch<IssueCredentialFormData["displayMethod"]["enabled"]>(
["displayMethod", "enabled"],
form
) || initialValues.displayMethod.enabled;

const refreshServiceChecked =
Form.useWatch<IssueCredentialFormData["refreshService"]["enabled"]>(
["refreshService", "enabled"],
form
) || initialValues.refreshService.enabled;

const isPositiveBigInt = (x: string) => {
try {
Expand Down Expand Up @@ -321,16 +326,14 @@ export function IssueCredentialForm({
initialValues.credentialSubject || {}
),
displayMethod: {
enabled: initialValues.displayMethod.enabled,
enabled: !!schemaDefaultDisplayMethod,
...(schemaDefaultDisplayMethod
? { type: schemaDefaultDisplayMethod.type, url: schemaDefaultDisplayMethod.url }
: { type: "", url: "" }),
},
}
: initialValues;
form.setFieldsValue(initialValuesWithSchemaValues);
setRefreshServiceChecked(initialValues.refreshService.enabled);
setDisplayMethodChecked(initialValues.displayMethod.enabled);
} else {
if (!isAbortedError(response.error)) {
setJsonSchema({ error: response.error, status: "failed" });
Expand Down Expand Up @@ -585,12 +588,7 @@ export function IssueCredentialForm({
noStyle
valuePropName="checked"
>
<Checkbox
checked={refreshServiceChecked}
onChange={() => {
setRefreshServiceChecked(!refreshServiceChecked);
}}
>
<Checkbox checked={refreshServiceChecked}>
Refresh Service{" ("}
<Typography.Link
href="https://docs.privado.id/docs/category/refresh-service"
Expand Down Expand Up @@ -631,14 +629,7 @@ export function IssueCredentialForm({
noStyle
valuePropName="checked"
>
<Checkbox
checked={displayMethodChecked}
onChange={() => {
setDisplayMethodChecked(!displayMethodChecked);
}}
>
Display Method
</Checkbox>
<Checkbox checked={displayMethodChecked}>Display Method</Checkbox>
</Form.Item>
<Form.Item hidden={!displayMethodChecked} name={["displayMethod", "url"]}>
<Select
Expand Down
18 changes: 16 additions & 2 deletions ui/src/components/schemas/SchemaViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { UpdateSchema } from "src/adapters/api/schemas";

import ChevronDownIcon from "src/assets/icons/chevron-down.svg?react";
import IconLink from "src/assets/icons/link-external-01.svg?react";
import IconClose from "src/assets/icons/x.svg?react";
import { JSONHighlighter } from "src/components/schemas/JSONHighlighter";
import { SchemaTree } from "src/components/schemas/SchemaTree";
import { DisplayMethod, Json, JsonLdType, JsonSchema } from "src/domain";
Expand Down Expand Up @@ -44,6 +45,10 @@ export function SchemaViewer({
}
)) {
const [form] = Form.useForm<UpdateSchema>();
const selectedDisplayMethod = Form.useWatch<UpdateSchema["displayMethodID"]>(
"displayMethodID",
form
);
const [jsonView, setJsonView] = useState<JsonView>("formatted");

const {
Expand Down Expand Up @@ -73,7 +78,6 @@ export function SchemaViewer({
style={{ marginBottom: 0, width: "100%" }}
>
<Select className="full-width" placeholder="Choose the default display method">
<Select.Option value={null}>None</Select.Option>
{Object.values(displayMethods).map((displayMethods) => (
<Select.Option key={displayMethods.id} value={displayMethods.id}>
{displayMethods.name}
Expand All @@ -83,11 +87,21 @@ export function SchemaViewer({
</Form.Item>

<Button
disabled={!displayMethodID}
disabled={!selectedDisplayMethod}
icon={<IconClose />}
onClick={() => {
onEdit({ ...form.getFieldsValue(), displayMethodID: null });
}}
style={{ flexShrink: 0 }}
/>

<Button
disabled={!selectedDisplayMethod}
href={generatePath(ROUTES.displayMethodDetails.path, {
displayMethodID: displayMethodID ?? "",
})}
icon={<IconLink />}
style={{ flexShrink: 0 }}
target="_blank"
/>
</Flex>
Expand Down
Loading