Skip to content

Commit

Permalink
Replace some lab commponents
Browse files Browse the repository at this point in the history
  • Loading branch information
origami-z committed Oct 4, 2024
1 parent 60ad380 commit 6d159a5
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 17 deletions.
4 changes: 0 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions packages/copy-manager/ui-src/__tests__/NodeKeyInput.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { NodeKeyInput } from "../components/NodeKeyInput";
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
import userEvents from "@testing-library/user-event";
import React from "react";
import { beforeEach, describe, expect, test, vi } from "vitest";
import { SelectableTextNodeInfo } from "../../shared-src/messages";

describe("NodeKeyInput", () => {
test("call onUpdateNodeKey on blur", async () => {
const mockNodeInfo = {
characters: "a",
checked: false,
id: "node1:1",
key: "key",
name: "Frame 1",
} satisfies SelectableTextNodeInfo;
const updateSpy = vi.fn();
render(
<NodeKeyInput nodeInfo={mockNodeInfo} onUpdateNodeKey={updateSpy} />
);
await userEvents.type(
screen.getByPlaceholderText(mockNodeInfo.name),
"abc"
);
expect(updateSpy).not.toBeCalled();
fireEvent.blur(screen.getByPlaceholderText(mockNodeInfo.name));
expect(updateSpy).toBeCalledWith(mockNodeInfo.id, "keyabc");
});
});
15 changes: 8 additions & 7 deletions packages/copy-manager/ui-src/components/NodeKeyInput.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Button } from "@salt-ds/core";
import { Button, Input } from "@salt-ds/core";
import { CloseSmallIcon, WarningIcon } from "@salt-ds/icons";
import { Input } from "@salt-ds/lab";
import React from "react";
import { SelectableTextNodeInfo } from "../../shared-src/messages";

Expand All @@ -17,7 +16,13 @@ export const NodeKeyInput = ({
// Use `key` to force rerender a new Input when nodeInfo key changes
key={`input-${nodeInfo.key}`}
defaultValue={nodeInfo.key}
inputProps={{ placeholder: nodeInfo.name }}
inputProps={{
placeholder: nodeInfo.name,
onBlur: (e) => {
const updatedValue = e.target.value;
onUpdateNodeKey(nodeInfo.id, updatedValue);
},
}}
endAdornment={
nodeInfo.key ? (
<Button onClick={() => onUpdateNodeKey(nodeInfo.id, "")}>
Expand All @@ -27,10 +32,6 @@ export const NodeKeyInput = ({
<WarningIcon />
)
}
onBlur={(e) => {
const updatedValue = e.currentTarget.value;
onUpdateNodeKey(nodeInfo.id, updatedValue);
}}
/>
);
};
6 changes: 3 additions & 3 deletions packages/copy-manager/ui-src/view/AdvancedView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,12 @@ export const AdvancedView = () => {
<table>
<thead>
<tr>
<th className="checkbox-col">
<td className="checkbox-col">
{/* <Checkbox className="tableCheckbox headerCheckbox" /> */}
</th>
</td>
<th>Key</th>
<th>Characters</th>
<th className="button-col">{/* Button column */}</th>
<td className="button-col">{/* Button column */}</td>
</tr>
</thead>
<tbody>
Expand Down
1 change: 0 additions & 1 deletion packages/export-styles/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"dependencies": {
"@salt-ds/core": "^1.27.1",
"@salt-ds/icons": "^1.11.2",
"@salt-ds/lab": "^1.0.0-alpha.44",
"@salt-ds/theme": "^1.15.0",
"react": "^18.3.0",
"react-dom": "^18.3.0"
Expand Down
1 change: 0 additions & 1 deletion packages/table-generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"dependencies": {
"@salt-ds/core": "^1.27.1",
"@salt-ds/icons": "^1.11.2",
"@salt-ds/lab": "^1.0.0-alpha.44",
"@salt-ds/theme": "^1.15.0",
"papaparse": "^5.4.1",
"react": "^18.3.0",
Expand Down
26 changes: 26 additions & 0 deletions packages/table-generator/ui-src/__tests__/view/DataView.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,32 @@ describe("DataView", () => {
vi.resetAllMocks();
});

describe("default launch", () => {
test("shows initialzing message", () => {
expect(screen.getByText("Configure Data"));
expect(screen.getByText("Initializing"));
expect(screen.getByText("Please wait while parsing the data."));
});

test("invalid message after initialing", () => {
renderResult.rerender(
<DataView
setTableConfig={() => {}}
tableConfig={DEFAULT_TABLE_CONFIG}
validTableSelected={false}
initializing={false}
/>
);
expect(screen.getByText("Configure Data"));
expect(screen.getByText("Invalid selection"));
expect(
screen.getByText(
"Please select a table generated by the plugin to populate data."
)
);
});
});

describe("settings", async () => {
beforeEach(() => {
fireEvent(
Expand Down
16 changes: 16 additions & 0 deletions packages/table-generator/ui-src/components/ContentStatus.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { StackLayout, StatusIndicator, Text } from "@salt-ds/core";

// Salt pattern - https://www.saltdesignsystem.com/salt/patterns/content-status
export const ContentStatus = (props: { message: string; title: string }) => {
return (
<StackLayout>
<StatusIndicator status="info" size={2} />
<StackLayout gap={1}>
<Text>
<strong>{props.title}</strong>
</Text>
<Text>{props.message}</Text>
</StackLayout>
</StackLayout>
);
};
2 changes: 1 addition & 1 deletion packages/table-generator/ui-src/view/DataView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
Tooltip,
} from "@salt-ds/core";
import { CsvIcon, DownloadIcon } from "@salt-ds/icons";
import { ContentStatus } from "@salt-ds/lab";
import { ContentStatus } from "../components/ContentStatus";
import { ParseResult, parse, unparse } from "papaparse";
import { useCallback, useEffect, useReducer, useState } from "react";
import { PostToFigmaMessage, PostToUIMessage } from "../../shared-src/messages";
Expand Down

0 comments on commit 6d159a5

Please sign in to comment.