Skip to content
This repository has been archived by the owner on May 4, 2019. It is now read-only.

Commit

Permalink
Merge pull request #250 from osu-cass/refactor/remove-section
Browse files Browse the repository at this point in the history
Refactor/remove section
  • Loading branch information
tnoelcke committed Oct 29, 2018
2 parents cdf9509 + 10ad689 commit 6aa6447
Show file tree
Hide file tree
Showing 20 changed files with 998 additions and 1,940 deletions.
9 changes: 2 additions & 7 deletions mocks/ItemBank/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,20 @@ export const itemRevisionMocks: ItemRevisionModel[] = [
hasBankKey: true,
bankKey: 187,
itemKey: 1111,
section: "siw",
valid: true
},
{
namespace: "itemreviewviewer",
hasBankKey: true,
bankKey: 1872,
itemKey: 2222,
section: "math",
valid: false
},
{
namespace: "itemreviewviewer",
hasBankKey: true,
bankKey: 1871,
itemKey: 3333,
section: "siw"
itemKey: 3333
},
{}
];
Expand All @@ -102,15 +99,13 @@ export const itemRevisionMocksError: ItemRevisionModel[] = [
hasBankKey: true,
bankKey: 187,
itemKey: 1111,
section: "siw",
valid: false
},
{
namespace: "itemreviewviewer",
hasBankKey: true,
bankKey: 1872,
itemKey: 2222,
section: "math"
itemKey: 2222
},
{}
];
2,320 changes: 570 additions & 1,750 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@
"@commitlint/cli": "^6.2.0",
"@commitlint/config-conventional": "^6.1.3",
"@osu-cass/tslint-config": "^1.1.1",
"@storybook/addon-a11y": "^3.4.3",
"@storybook/addon-actions": "^3.4.3",
"@storybook/addon-console": "^1.0.0",
"@storybook/addon-storyshots": "^3.4.3",
"@storybook/addons": "^3.4.3",
"@storybook/channels": "^3.4.3",
"@storybook/addon-a11y": "^3.4.11",
"@storybook/addon-actions": "^3.4.11",
"@storybook/addon-console": "1.0.4",
"@storybook/addon-storyshots": "^3.4.11",
"@storybook/addons": "^3.4.11",
"@storybook/channels": "^3.4.11",
"@storybook/cli": "^3.4.11",
"@storybook/react": "^3.4.11",
"@storybook/react": "",
"@types/bootstrap": "3.3.32",
"@types/enzyme": "^3.1.10",
"@types/enzyme-adapter-react-16": "^1.0.2",
Expand Down
6 changes: 6 additions & 0 deletions src/Assets/Styles/item-bank.less
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
border-width: 1px;
border-radius: @spacing-item;
table-layout: fixed;
width: 40px;
}

.current-items-table {
Expand Down Expand Up @@ -185,5 +186,10 @@
}

.submit-button {
width: 80px;
}

.clear-button {
float: right;
width: 80px;
}
14 changes: 6 additions & 8 deletions src/CsvEntry/CsvEntryModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ export function toCsvText(items: CsvRowModel[]): string {
items.forEach(item => {
if (item.itemKey) {
const itemString = item.bankKey
? `${item.namespace},${item.bankKey},${item.itemKey},${item.section}\n`
: `${item.namespace},${item.itemKey},${item.section}\n`;
? `${item.namespace},${item.bankKey},${item.itemKey}\n`
: `${item.namespace},${item.itemKey}\n`;
csvString = `${csvString}${itemString}`;
}
});
Expand All @@ -60,9 +60,9 @@ function parseLines(lines: string[], namespaces: NamespaceModel[]) {
// row.namespace = values[0];
setNamespace(row, values[0], namespaces);

if (values.length === 4) {
if (values.length === 3) {
setCsvRowWithBankKey(row, values);
} else if (values.length === 3) {
} else if (values.length === 2) {
setCsvRowWithoutBankKey(row, values, namespaces);
} else {
continue;
Expand Down Expand Up @@ -90,8 +90,7 @@ function setNamespace(
function setCsvRowWithBankKey(row: CsvRowModel, values: string[]) {
row.hasBankKey = true;
row.bankKey = +values[1];
row.itemKey = +values[2];
row.section = values[3].trim();
row.itemKey = +values[2].trim();
}

function setCsvRowWithoutBankKey(
Expand All @@ -101,8 +100,7 @@ function setCsvRowWithoutBankKey(
) {
row.hasBankKey = false;
row.bankKey = getBankKeyByNamespace(row.namespace, namespaces);
row.itemKey = +values[1];
row.section = values[2].trim();
row.itemKey = +values[1].trim();
}

function getBankKeyByNamespace(
Expand Down
4 changes: 2 additions & 2 deletions src/CsvEntry/__tests__/__snapshots__/CsvEntry.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ exports[`CsvEntry matches snapshot 1`] = `
<textarea
className="csv-text-entry"
onChange={[Function]}
value="undefined,3000,187,math
undefined,2332,187,math
value="undefined,3000,187
undefined,2332,187
"
/>
</div>
Expand Down
44 changes: 10 additions & 34 deletions src/ItemBank/ItemBankContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export interface ItemBankContainerProps {
) => Promise<AboutItemRevisionModel>;
revisionsClient: (item: ItemRevisionModel) => Promise<RevisionModel[]>;
namespaces: NamespaceModel[];
sectionsClient: () => Promise<SectionModel[]>;
itemViewUrl?: string;
items?: ItemRevisionModel[];
setUrl: (item: ItemRevisionModel) => void;
Expand All @@ -48,7 +47,6 @@ export interface ItemBankContainerState {
accResourceGroups: Resource<AccResourceGroupModel[]>;
currentItem?: ItemRevisionModel;
items: ItemRevisionModel[];
sections: Resource<SectionModel[]>;
revisions: Resource<RevisionModel[]>;
nextItem?: ItemRevisionModel;
previousItem?: ItemRevisionModel;
Expand Down Expand Up @@ -76,14 +74,12 @@ export class ItemBankContainer extends React.Component<
items,
aboutItemRevisionModel: { kind: "loading" },
accResourceGroups: { kind: "loading" },
sections: { kind: "loading" },
revisions: { kind: "loading" },
hasError: false
};
}

componentDidMount() {
this.fetchSections().catch(e => this.onError(e));
this.handleChangeViewItem();
this.handleChangeRevision();
}
Expand Down Expand Up @@ -180,19 +176,6 @@ export class ItemBankContainer extends React.Component<
this.handleUpdateItems(validItems);
}

async fetchSections() {
const prom = this.props.sectionsClient();
const promiseWrapper = this.subscription.add("sectionsClient", prom);
const sections = await promiseWrapper.promise;
this.onFetchSectionsSuccess(sections);

return sections;
}

onFetchSectionsSuccess(data: SectionModel[]) {
this.setState({ sections: { kind: "success", content: data } });
}

onError(err: string, cb?: () => void) {
if (err !== "Canceled") {
this.setState(
Expand Down Expand Up @@ -445,24 +428,17 @@ export class ItemBankContainer extends React.Component<

renderItemBankEntry() {
const { namespaces } = this.props;
const { sections, items } = this.state;
let content: JSX.Element | undefined;

const sectionsContent = getResourceContent(sections);
if (sectionsContent) {
content = (
<ItemBankEntry
namespaces={namespaces}
sections={sectionsContent}
items={items}
deleteItem={this.deleteItem}
clearItems={this.clearItems}
submitItems={this.handleSubmit}
/>
);
}
const { items } = this.state;

return content;
return (
<ItemBankEntry
namespaces={namespaces}
items={items}
deleteItem={this.deleteItem}
clearItems={this.clearItems}
submitItems={this.handleSubmit}
/>
);
}

renderItemBankViewer() {
Expand Down
4 changes: 0 additions & 4 deletions src/ItemBank/ItemBankEntry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
Accordion,
ItemRevisionModel,
NamespaceModel,
SectionModel,
ItemEntryTable,
CsvEntry
} from "@src/index";
Expand All @@ -13,7 +12,6 @@ export interface ItemBankEntryProps {
clearItems: () => void;
submitItems: (items: ItemRevisionModel[]) => void;
namespaces: NamespaceModel[];
sections: SectionModel[];
items: ItemRevisionModel[];
}

Expand Down Expand Up @@ -78,7 +76,6 @@ export class ItemBankEntry extends React.Component<
items,
clearItems,
namespaces,
sections,
deleteItem,
submitItems
} = this.props;
Expand All @@ -92,7 +89,6 @@ export class ItemBankEntry extends React.Component<
<ItemEntryTable
itemRows={items}
namespaces={namespaces}
sections={sections}
onDeleteItem={deleteItem}
onClearItems={clearItems}
onSubmit={submitItems}
Expand Down
11 changes: 3 additions & 8 deletions src/ItemBank/ItemBankModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export interface ItemRevisionModel {
bankKey?: number;
hasBankKey?: boolean;
namespace?: string;
section?: string;
revision?: string;
isaap?: string;
valid?: boolean;
Expand All @@ -35,8 +34,7 @@ export function itemsAreEqual(
right &&
left.itemKey === right.itemKey &&
left.bankKey === right.bankKey &&
left.namespace === right.namespace &&
left.section === right.section
left.namespace === right.namespace
);
}

Expand Down Expand Up @@ -122,18 +120,15 @@ export function concatNamespaceWith(
}

export function itemRevisionKey(itemRevisionModel: ItemRevisionModel) {
return `${itemRevisionModel.bankKey}-${itemRevisionModel.itemKey}-${
itemRevisionModel.section
}`;
return `${itemRevisionModel.bankKey}-${itemRevisionModel.itemKey}`;
}

export function validItemRevisionModel(itemRevisionModel?: ItemRevisionModel) {
let value = false;
if (
itemRevisionModel &&
itemRevisionModel.namespace &&
itemRevisionModel.itemKey &&
itemRevisionModel.section
itemRevisionModel.itemKey
) {
value = true;

Expand Down

0 comments on commit 6aa6447

Please sign in to comment.