Skip to content

Commit

Permalink
refactored mirror section to use same source component and added exte…
Browse files Browse the repository at this point in the history
…rnal and start time support
  • Loading branch information
pricelessrabbit committed Sep 1, 2024
1 parent 76b97ee commit a0a1501
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 51 deletions.
5 changes: 5 additions & 0 deletions frontend/docs/entities/stream/def/stream-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ Mirror {
/** is taken from stream names */
name: string // omitted if empty
optStartSeq: number // omitted if zero
optStartTime: string // omitted if empty
filterSubject: string // omitted if empty
external: { // omitted if null
api: string
deliver: string
}
}
```

Expand Down
72 changes: 24 additions & 48 deletions frontend/src/components/stacks/streams/detail/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import MaxNumberCmp from "@/components/input/MaxNumberCmp"
import MaxTimeCmp from "@/components/input/MaxTimeCmp"
import { StreamStore } from "@/stores/stacks/streams/detail"
import { EDIT_STATE } from "@/types"
import { DISCARD, RETENTION, STORAGE } from "@/types/Stream"
import {DISCARD, RETENTION, Source, STORAGE} from "@/types/Stream"
import { dateShow } from "@/utils/time"
import { useStore } from "@priolo/jon"
import { FunctionComponent } from "react"
import SourcesCmp from "./cmp/SourcesCmp"
import { Accordion, EditList, EditStringRow, IconToggle, ListDialog, NumberInput, StringUpRow, TextInput, TitleAccordion } from "@priolo/jack"
import EditSourceCmp from "@/components/stacks/streams/detail/cmp/EditSourceCmp.tsx";



Expand All @@ -32,6 +33,10 @@ const Form: FunctionComponent<Props> = ({
config.mirror = { ...config.mirror, ...prop }
streamSo.setStreamConfig(config)
}
const handleMirrorChange = (mirror: Source) => {
config.mirror = mirror
streamSo.setStreamConfig(config)
}
const handleRepublishPropChange = (prop: { [name: string]: any }) => {
const config = { ...streamSa.stream.config }
config.republish = { ...config.republish, ...prop }
Expand All @@ -44,7 +49,7 @@ const Form: FunctionComponent<Props> = ({
}
const handleMirrorCheck = (check: boolean) => {
if (check && !config.mirror) {
handlePropChange({ mirror: { name: "", optStartSeq: 0, filterSubject: "" } })
handlePropChange({ mirror: { name: "", optStartSeq: 0, optStartTime: null, filterSubject: "" } })
return
}
if (!check && config.mirror) {
Expand Down Expand Up @@ -153,10 +158,12 @@ const Form: FunctionComponent<Props> = ({
RenderRow={EditStringRow}
/>
</div>
</TitleAccordion>

<TitleAccordion title="SOURCE / MIRROR" open={!inRead}>
<div className="lyt-v">
<div className="jack-lbl-prop">SOURCES</div>
<SourcesCmp store={streamSo} />
<SourcesCmp store={streamSo}/>
</div>

<div className="lyt-v">
Expand All @@ -169,64 +176,33 @@ const Form: FunctionComponent<Props> = ({
<div className="jack-lbl-prop">MIRROR</div>
</div>
<Accordion open={!!config.mirror}>
<div className="jack-lyt-quote">
<div className="lyt-v">
<div className="jack-lbl-prop">NAME</div>
{/* <TextInput
value={config.mirror?.name}
onChange={name => handleMirrorPropChange({ name })}
readOnly={inRead || !inNew}
/> */}
<ListDialog width={200}
store={streamSo}
select={allStreams?.indexOf(config?.mirror?.name) ?? -1}
items={allStreams}
readOnly={inRead || !inNew}
onSelect={index => {
handleMirrorPropChange({ name: allStreams[index] })
}}
/>
</div>
<div className="lyt-v">
<div className="jack-lbl-prop">START SEQUENCE</div>
<NumberInput
style={{ flex: 1 }}
value={config.mirror?.optStartSeq}
onChange={optStartSeq => handleMirrorPropChange({ optStartSeq })}
readOnly={inRead || !inNew}
/>
</div>
<div className="lyt-v">
<div className="jack-lbl-prop">FILTER SUBJECT</div>
<TextInput
value={config.mirror?.filterSubject}
onChange={filterSubject => handleMirrorPropChange({ filterSubject })}
readOnly={inRead || !inNew}
/>
</div>
</div>
{config.mirror && <EditSourceCmp
source={config.mirror}
readOnly={inRead || !inNew}
allStream={streamSa.allStreams}
onChange={handleMirrorChange}
/>}
</Accordion>
</div>
</TitleAccordion>


<TitleAccordion title="RETENTION" open={!inRead}>
<div className="lyt-v">
<div className="jack-lbl-prop">POLICY</div>
<ListDialog width={100}
store={streamSo}
select={Object.values(RETENTION).indexOf(config.retention ?? RETENTION.INTEREST)}
items={Object.values(RETENTION)}
RenderRow={StringUpRow}
readOnly={inRead || !inNew}
onSelect={index => handlePropChange({ retention: Object.values(RETENTION)[index] })}
store={streamSo}
select={Object.values(RETENTION).indexOf(config.retention ?? RETENTION.INTEREST)}
items={Object.values(RETENTION)}
RenderRow={StringUpRow}
readOnly={inRead || !inNew}
onSelect={index => handlePropChange({retention: Object.values(RETENTION)[index]})}
/>
</div>
<div className="lyt-v">
<div className="jack-lbl-prop">DISCARD</div>
<ListDialog width={80}
store={streamSo}
select={Object.values(DISCARD).indexOf(config.discard ?? DISCARD.OLD)}
store={streamSo}
select={Object.values(DISCARD).indexOf(config.discard ?? DISCARD.OLD)}
items={Object.values(DISCARD)}
RenderRow={StringUpRow}
readOnly={inRead}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import dayjs from "dayjs";

interface Props {
source: Source
external?: boolean
readOnly?: boolean
allStream?: string[]
onChange: (source: Source) => void
Expand Down Expand Up @@ -34,7 +33,7 @@ const EditSourceCmp: FunctionComponent<Props> = ({
const handleStartTimeChange = (startTime: any) => {
setOptStartTime(startTime)
const time = dayjs(startTime)
const isoTime = time.isValid() ? time.toISOString() : ""
const isoTime = time.isValid() ? time.toISOString() : null
onChange?.({ ...source, optStartTime: isoTime })
}
const handleFilterSubjectChange = (filterSubject: string) => onChange?.({ ...source, filterSubject })
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/stores/stacks/streams/utils/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,6 @@ export function newSource(): Source {
external: null,
filterSubject: "",
optStartSeq: 0,
optStartTime: ""
optStartTime: null
}
}

0 comments on commit a0a1501

Please sign in to comment.