Skip to content

Commit e5d4966

Browse files
authored
Main nutritionfacts obj readme (#47)
* add `name to top meta * add name to export * correct types * update readme * remove unused workflow * correct camel casing
1 parent 16a8e85 commit e5d4966

File tree

6 files changed

+107
-173
lines changed

6 files changed

+107
-173
lines changed

.github/workflows/release.yml

Lines changed: 0 additions & 29 deletions
This file was deleted.

packages/nutritionfacts/README.md

Lines changed: 80 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -53,68 +53,95 @@ The "Copy embed code" generates an iFrame that is sized to fit the content witho
5353
> [!NOTE]
5454
> Only the iFrame content is rendered dynamically. The copy of the product name / description are not dynamically updated and will need to be manually updated if either change significantly from the time the embed code is generated.
5555
56-
### Importing
56+
### JSON
57+
58+
When viewing a Nutrition Facts page a "Copy JSON Object" helper is displayed in the header. This object is for use with @instructure/ui AI Components.
59+
60+
```JSON
61+
{
62+
"id": "askyourdata",
63+
"sha256": "ce29be981e1f8fc6ee4b68f653223ffefc6ca7ca378cfe4d81fd427277ee1ee9",
64+
"lastUpdated": "1758638262",
65+
"nutritionFacts": "<StrictNutritionFacts>",
66+
"dataPermissionsLevel": "<AiPermissions>",
67+
"AiInformation": "<StrictAiInformation>"
68+
}
69+
```
5770

58-
You can import a Nutrition Facts object by referencing its unique id in the query parameter such as `?id=igniteAgent`. Parameter values are case insensitive. If an invalid ID is provided the default product (an empty~ish object) is returned.
71+
This makes outputting AI Components fairly simple, and standard.
5972

60-
> [!WARNING]
61-
> The following import methods are DEPRECATED. They may still work, but are no longer being supported, and may be removed in a future version.
73+
#### AiInformation
6274

63-
Two import types are provided: object-based and named params. Object-based import values take precedence, meaning if you include both, the value in the object will be imported. `/?q={"name":"foo"}&name=bar` will result in `bar` being stored. `/?q={"description":"I am a foo."}&name=foo` will store both `name` and `description` values.
75+
```jsx
76+
const ai = {jsonObj}
6477

65-
#### Object-based Imports
78+
<AiInformation
79+
trigger={<Button>AI information</Button>}
6680

67-
The site accepts the query param `q` and a value that is a subset of the `ProductNutritionFacts` object. This will be coerced into a `NutritionFacts` compatible object. The basic structure is a bare object with `name`, `description`, and `data[]` keys.
81+
data={ai.AiInformation}
82+
dataPermissionLevelsCurrentFeature={ai.name}
83+
dataPermissionLevelsData={ai.dataPermissionsLevel}
84+
nutritionFactsFeatureName={ai.name}
85+
nutritionFactsData={ai.nutritionFacts.data}
6886

69-
```json
70-
/?q={"name": "foo", "description: "bar"}
87+
title="Features"
88+
89+
dataPermissionLevelsTitle="Data Permission Levels"
90+
dataPermissionLevelsCurrentFeatureText="Current Feature:"
91+
dataPermissionLevelsCloseIconButtonScreenReaderLabel="Close"
92+
dataPermissionLevelsCloseButtonText="Close"
93+
dataPermissionLevelsModalLabel="This is a Data Permission Levels modal"
94+
dataPermissionLevelsTriggerText="Data Permission Levels"
95+
96+
nutritionFactsModalLabel="This is a modal for AI facts"
97+
nutritionFactsTitle="Nutrition Facts"
98+
nutritionFactsCloseButtonText="Close"
99+
nutritionFactsCloseIconButtonScreenReaderLabel="Close"
100+
nutritionFactsTriggerText="Nutrition Facts"
101+
/>
102+
```
103+
104+
#### NutritionFacts
105+
106+
If you're just providing a `NutritionFacts` component, it can be destructured from the main JSON.
107+
108+
```jsx
109+
const ai = {jsonObj} // Direct reference
110+
const { nutritionFacts } = jsonObj // Destructured
111+
112+
<NutritionFacts
113+
featureName={ai.name || nutritionFacts.name}
114+
data={ai.nutritionFacts.data || nutritionFacts.data }
115+
116+
title="Nutrition Facts"
117+
modalLabel="This is a modal for AI facts"
118+
closeButtonText="Close"
119+
closeIconButtonScreenReaderLabel="Close"
120+
triggerText="Nutrition Facts"
121+
/>
71122
```
72-
try using the `Copy` export function and then pasting the clipboard to the query param to see it in action.
73-
74-
#### Named Parameter Imports
75-
76-
Parameters use dot notation for arrays and commas for values.
77-
78-
```typescript
79-
name=<string>
80-
description=<string>
81-
model.
82-
base.
83-
value=<string>
84-
valueDescription=<string>
85-
trained.
86-
value=<boolean>
87-
data.
88-
value=<array["None", "Course", "Faculty", "Student", "Other"]>
89-
valueDescription=<string>
90-
privacy.
91-
retention.
92-
valueDescription=<string>
93-
logging.
94-
value=<boolean>
95-
valueDescription=<string>
96-
regions.
97-
value<array["Global", "Virginia", "Oregon", "Montreal", "Dublin", "Frankfurt", "Singapore", "Sydney", "Other"]>
98-
valueDescription=<string>
99-
pii.
100-
value=<boolean>
101-
valueDescription=<string>
102-
outputs.
103-
outputs.
104-
control.
105-
value=<boolean>
106-
human.
107-
value=<boolean>
108-
valueDescription=<string>
109-
guardrails.
110-
valueDescription=<string>
111-
risks.
112-
valueDescription=<string>
113-
outcomes.
114-
valueDescription=<string>
123+
124+
#### DataPermissionLevels
125+
126+
```jsx
127+
const ai = {jsonObj}
128+
129+
<DataPermissionLevels
130+
131+
currentFeature={ai.name}
132+
data={ai.dataPermissionsLevel}
133+
134+
title="Data Permission Levels"
135+
currentFeatureText="Current Feature:"
136+
closeIconButtonScreenReaderLabel="Close"
137+
closeButtonText="Close"
138+
modalLabel="This is a Data Permission Levels modal"
139+
triggerText="Data Permission Levels"
115140
```
116141

117-
Example: Set regions as Virginia & Oregon: `?privacy.regions.value="Virginia,Oregon"`
142+
### Importing
143+
144+
You can import a Nutrition Facts object by referencing its unique id in the query parameter such as `?id=igniteAgent`. Parameter values are case insensitive. If an invalid ID is provided the default product (an empty~ish object) is returned.
118145

119146
## Getting Started
120147

@@ -157,83 +184,6 @@ pnpm build nutritionfacts
157184

158185
The list of Nutrition Facts is fetched at every call. A fall-back cached version is included with the source and is updated on every build.
159186

160-
## Data
161-
162-
The main type for this project is the `ProductNutritionFacts` object which is a superset of the internal types provided by `@instructure/ui/NutritionFacts`. Inputs and outputs are coerced to/from `NutritionFacts` compatible types and formats.
163-
164-
```typescript
165-
export type SegmentBase = Readonly<
166-
{
167-
description: string;
168-
segmentTitle: string;
169-
valueHint?: string;
170-
descriptionHint?: string;
171-
inputOptions?: string[];
172-
inputType?: "text" | "textarea" | "select" | "checkbox" | "multi-select";
173-
} & (
174-
| { value: string; valueDescription?: string }
175-
| { value?: string; valueDescription: string }
176-
)
177-
>;
178-
179-
type ModelAndDataSegment = SegmentBase & {
180-
segmentTitle:
181-
| "Base Model"
182-
| "Trained with User Data"
183-
| "Data Shared with Model";
184-
};
185-
186-
type PrivacyComplianceSegment = SegmentBase & {
187-
segmentTitle: "Data Retention" | "Data Logging" | "Regions Supported" | "PII";
188-
};
189-
190-
export type OutputsSegment = SegmentBase & {
191-
segmentTitle:
192-
| "AI Settings Control"
193-
| "Human in the Loop"
194-
| "Guardrails"
195-
| "Expected Risks"
196-
| "Intended Outcomes";
197-
};
198-
199-
export type NutritionFactBlock =
200-
| { blockTitle: "Model & Data"; segmentData: ModelAndDataSegment[] }
201-
| {
202-
blockTitle: "Privacy & Compliance";
203-
segmentData: PrivacyComplianceSegment[];
204-
}
205-
| { blockTitle: "Outputs"; segmentData: OutputsSegment[] };
206-
207-
type Permission = {
208-
name: string;
209-
title: string;
210-
description: string;
211-
descriptionHint?: string;
212-
};
213-
214-
type Permissions = Readonly<Permission>[]
215-
216-
export type ProductNutritionFacts = Readonly<{
217-
name: string;
218-
description?: string;
219-
nameHint?: string;
220-
descriptionHint?: string;
221-
data: NutritionFactBlock[];
222-
revision?: string;
223-
id?: string;
224-
permissions?: 1 | 2 | 3 | 4 | undefined;
225-
group?:
226-
| "canvas"
227-
| "mastery"
228-
| "parchment"
229-
| "igniteai"
230-
| "intelligent insights"
231-
| "other"
232-
| "canvas career"
233-
| undefined;
234-
}>;
235-
```
236-
237187
## Project Structure
238188

239189
- `src/` — Main source code

packages/nutritionfacts/scripts/updateCache.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ if (remoteSha !== localSha) {
5252
sha256: newSha,
5353
lastUpdated: newTimestamp,
5454
id: id,
55+
name: getProductFromLine(values).name,
5556
nutritionFacts: getProductFromLine(values),
5657
};
5758
}

packages/nutritionfacts/src/Components/Export/Object.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const ExportJSON = (id: ProductNutritionFacts["id"]): FeatureMeta => {
3434
return {
3535
sha256: "",
3636
lastUpdated: "",
37-
dataPermissionsLevel: [] as StrictAiPermissions[],
37+
dataPermissionLevels: [] as StrictAiPermissions[],
3838
nutritionFacts: {
3939
id: "<id> not found",
4040
name: "",
@@ -85,14 +85,15 @@ const ExportJSON = (id: ProductNutritionFacts["id"]): FeatureMeta => {
8585

8686
const strictReturn = {
8787
id: id.toLowerCase(),
88+
name: cachedFeature.nutritionFacts.name,
8889
sha256: cachedFeature.sha256,
8990
lastUpdated: cachedFeature.lastUpdated,
9091
nutritionFacts: {
9192
name: cachedFeature.nutritionFacts.name,
9293
description: cachedFeature.nutritionFacts.description,
9394
data: strictNutritionFactsData
9495
} as StrictNutritionFacts,
95-
dataPermissionsLevel: strictPermissions,
96+
dataPermissionLevels: strictPermissions,
9697
AiInformation: strictAiInfo
9798
} as FeatureMeta
9899

0 commit comments

Comments
 (0)